package com.laseroptek.raman.ui.screens.engineer.update

import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
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.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
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.res.stringResource
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 com.laseroptek.raman.R
import com.laseroptek.raman.ui.common.fullscreen.FullScreen
import com.laseroptek.raman.ui.theme.RobotoTypography
import com.laseroptek.raman.utils.ext.dropShadow
import com.laseroptek.raman.utils.ext.px
import timber.log.Timber

@Composable
fun UpdateConfirmPopup(
    title: String = stringResource(R.string.update_confirm_title),
    onClick: (Boolean) -> Unit= {}
) {
    FullScreen {
        Column(
            modifier = Modifier
                .size(312.px.dp, 132.px.dp)
                .clip(RoundedCornerShape(28.px.dp))
                .background(Color.White)
                .dropShadow(
                    shape = RoundedCornerShape(28.px.dp),
                    color = Color.Black.copy(alpha = 0.1f),
                    blur = 48.px.dp,
                    offsetX = 0.px.dp,
                    offsetY = 24.px.dp,
                    spread = 0.px.dp
                )
                .dropShadow(
                    shape = RoundedCornerShape(28.px.dp),
                    color = Color.Black.copy(alpha = 0.1f),
                    blur = 6.px.dp,
                    offsetX = 0.px.dp,
                    offsetY = 3.px.dp,
                    spread = 0.px.dp
                ),
            horizontalAlignment = Alignment.CenterHorizontally,
            verticalArrangement = Arrangement.Center,
        ) {
            // Title
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(64.px.dp)
                    .padding(start = 30.px.dp, end = 30.px.dp, bottom = 10.px.dp),
                horizontalArrangement = Arrangement.Center,
                verticalAlignment = Alignment.Bottom
            ) {
                Text(
                    text = title,
                    style = RobotoTypography.bodySmall,
                    fontWeight = FontWeight.Normal,
                    fontSize = 14.px.sp,
                    color = Color.Black,
                    textAlign = TextAlign.Center,
                    lineHeight = 20.px.sp
                )
            }

            // Two Button
            Row(
                modifier = Modifier
                    .fillMaxWidth()
                    .height(68.px.dp),
                horizontalArrangement = Arrangement.End,
                verticalAlignment = Alignment.CenterVertically
            ) {
                // Cancel
                TextButton(
                    modifier = Modifier
                        .size(68.px.dp, 40.px.dp),
                    onClick = {
                        Timber.d("Cancel Clicked")
                        onClick(false)
                    }
                ) {
                    Text(
                        text = stringResource(R.string.cancel),
                        style = RobotoTypography.labelLarge,
                        fontWeight = FontWeight.Normal,
                        fontSize = 14.px.sp,
                        color = Color.Black
                    )
                }

                // Ok
                TextButton(
                    modifier = Modifier
                        .size(68.px.dp, 40.px.dp),
                    onClick = {
                        Timber.d("Ok Clicked")
                        onClick(true)
                    }
                ) {
                    Text(
                        text = stringResource(R.string.ok),
                        style = RobotoTypography.labelLarge,
                        fontWeight = FontWeight.Normal,
                        fontSize = 14.px.sp,
                        color = Color.Black
                    )
                }
            }
        }
    }
}


@Preview(
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    showBackground = false,
    device = "spec:width=1920dp,height=1080dp,dpi=150,isRound=false,chinSize=0dp,orientation=landscape"
)
@Composable
fun PreviewUpdateConfirmPopup() {
    //val showPopup = remember { mutableStateOf(true) }
    UpdateConfirmPopup()
}