package com.vpn.fastestvpnservice.customItems

import android.content.res.Configuration
import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.vpn.fastestvpnservice.R
import com.vpn.fastestvpnservice.beans.Server
import com.vpn.fastestvpnservice.beans.SubscriptionDataList
import com.vpn.fastestvpnservice.beans.subscriptionList

@Composable
fun SubscriptionDataItem(item: SubscriptionDataList) {
    Box(
        modifier = Modifier
            .fillMaxWidth()
            .background(MaterialTheme.colorScheme.background)
            .padding(bottom = 1.dp)
    ) {
        val context = LocalContext.current

        Row(
            verticalAlignment = Alignment.Top,
            horizontalArrangement = Arrangement.Start,
            modifier = Modifier
                .fillMaxWidth()
                .padding(start = 0.dp, end = 7.dp, top = 12.dp)
                .clickable(
                    indication = null,
                    interactionSource = remember {
                        MutableInteractionSource()
                    }
                ) {
                    Toast
                        .makeText(
                            context,
                            item.title,
                            Toast.LENGTH_SHORT
                        )
                        .show()
                }
        ) {
            Icon(
                painter = painterResource(id = R.drawable.yellowcheck3x),
                contentDescription = "Server Logo",
                tint = colorResource(id = R.color.yellow_text),
                modifier = Modifier
                    .padding(bottom = 16.dp, top = 3.dp)
                    .size(19.dp, 14.dp)
            )
            Column(
                modifier = Modifier
                    .padding(start = 16.dp)
            ) {
                Text(text = item.title,
                    style = TextStyle(
                        fontSize = 16.sp,
                        fontWeight = FontWeight.Medium,
                        color = MaterialTheme.colorScheme.primary
                    ),
                    maxLines = 1,
                    overflow = TextOverflow.Ellipsis,
                    modifier = Modifier
                        .padding(start = 0.dp, bottom = 0.dp)
                )
                Text(text = item.desc,
                    style = TextStyle(
                        fontSize = 14.sp,
                        color = MaterialTheme.colorScheme.primary
                    ),
                    maxLines = 2,
                    overflow = TextOverflow.Ellipsis,
                    modifier = Modifier
                        .padding(top = 6.dp, bottom = 10.dp)
                        .alpha(0.8F)
                )
            }
        }
    }
}

@Preview
@Composable
fun SubscriptionDataItemPreview() {
    SubscriptionDataItem(subscriptionList[0])
}

@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Composable
fun SubscriptionDataItemPreviewDark() {
    SubscriptionDataItem(subscriptionList[0])
}