package com.example.oscellamobile

import androidx.compose.foundation.text.ClickableText
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.sp
import androidx.lifecycle.ViewModel
import com.example.oscellamobile.screens.ibmplexmono

class Link() : ViewModel() {
    @Composable
    fun LinkText(gameLink: String) {
        val uriHandler = LocalUriHandler.current

        val annotatedString = buildAnnotatedString {
            pushStyle(SpanStyle(color = Color.Black, textDecoration = TextDecoration.None))
            append(gameLink)
            pop()
        }

        ClickableText(
            text = annotatedString,
            onClick = { offset ->
                uriHandler.openUri(gameLink)
            },
            style = TextStyle(
                fontFamily = ibmplexmono,
                fontSize = 15.sp,
                color = Color.Black,
                textAlign = TextAlign.Left
            )
        )
    }
}