package com.laseroptek.raman.ui.screens.home.count

import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.zIndex
import com.laseroptek.raman.data.datasource.db.RamanDatabase
import com.laseroptek.raman.data.source.db.RamanDatabaseService
import com.laseroptek.raman.repository.DatabaseRepository
import com.laseroptek.raman.repository.PreferenceRepository
import com.laseroptek.raman.repository.SerialPortRepository
import com.laseroptek.raman.ui.common.button.RoundTextButton
import com.laseroptek.raman.ui.screens.main.MainViewModel
import com.laseroptek.raman.ui.theme.RobotoTypography
import com.laseroptek.raman.utils.DefaultDispatcherProvider
import com.laseroptek.raman.utils.ext.px

@Composable
fun HpCountView(
    hpCountForMainScreen: String = "",
    onClick: () -> Unit = {},
) {
    Box(
        modifier = Modifier
            .size(190.px.dp, 120.px.dp)
            .padding(start = 0.px.dp)
            .background(Color.Transparent)
    ) {
        Row(
            modifier = Modifier
                .clip(RoundedCornerShape(topStart = 24.px.dp, bottomStart = 24.px.dp))
                .background(Color.Black)
                .size(170.px.dp, 40.px.dp)
                .align(Alignment.CenterStart)
                .padding(start = 20.px.dp)
                .zIndex(0f),
        ) {
            Text(
                text = hpCountForMainScreen,
                modifier = Modifier
                    .width(115.px.dp)
                    .align(alignment = Alignment.CenterVertically),
                style = RobotoTypography.titleMedium.copy(
                    textAlign = TextAlign.End,
                    fontSize = 22.px.sp,
                    fontWeight = FontWeight.Medium,
                    //lineHeight = 23.px.sp,
                ),
                color = Color.White
            )
            //Spacer(Modifier.width(5.px.dp))
            /*
            Text(
                text = "K",
                modifier = Modifier
                    .width(24.px.dp)
                    .align(alignment = Alignment.CenterVertically),
                style = RobotoTypography.titleSmall.copy(
                    textAlign = TextAlign.Start,
                    fontSize = 22.px.sp,
                    fontWeight = FontWeight.Thin,
                    letterSpacing = 0.2.px.sp
                ),
                color = Color.White,
            )
            */
            Spacer(Modifier.width(50.px.dp))
        }

        RoundTextButton(
            onClick = onClick,
            text = "H/P",
            contentDescription = "Action description",
            buttonSize = 50.px.dp,
            modifier = Modifier.align(Alignment.CenterEnd)
        )
    }
}


@Preview(
    apiLevel = 34,
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    showBackground = false,
    device = "spec:width=1920dp,height=1080dp,dpi=150,isRound=false,chinSize=0dp,orientation=landscape"
)
@Composable
fun PreviewHpCountView(
    mainViewModel:MainViewModel = MainViewModel(
        preferenceRepository = PreferenceRepository(LocalContext.current),
        serialPortRepository = SerialPortRepository.createWithFakeRepository(),
        databaseRepository = DatabaseRepository(RamanDatabaseService(RamanDatabase.getInstance(LocalContext.current))),
        dispatcherProvider = DefaultDispatcherProvider(),
        applicationContext = LocalContext.current
    )
) {
    HpCountView()
}