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

import android.content.res.Configuration
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
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.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButtonDefaults
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.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.laseroptek.raman.R
import com.laseroptek.raman.ui.theme.RobotoTypography
import com.laseroptek.raman.utils.ext.px
import timber.log.Timber

@Composable
fun EngineerTitltBarView(
    title: String = stringResource(R.string.engineer_mode),
    height: Dp = 40.px.dp,
    onOSSetupClick: () -> Unit= {},
    onCloseClick: () -> Unit= {},
) {
    Row(modifier = Modifier
        .fillMaxWidth()
        .height(height)
        , horizontalArrangement = Arrangement.Center
        , verticalAlignment = Alignment.CenterVertically
    ) {
        Text(
            text = title,
            style = RobotoTypography.headlineSmall,
            fontWeight = FontWeight.Light,
            fontSize = 28.px.sp,
            color = Color.Black,
        )

        Spacer(modifier = Modifier.weight(1f))

        TextButton(
            onClick = {
                Timber.d("Perform action when button is clicked")
                onOSSetupClick()
            },
            modifier = Modifier
                .size(107.px.dp, 34.px.dp)
                .clip(RoundedCornerShape(10.px.dp))
                .border(
                    width = 1.px.dp,
                    color = Color(209, 209, 209),
                    shape = RoundedCornerShape(10.px.dp)
                )
                //.shadow(elevation = 2.px.dp, shape = RoundedCornerShape(12.px.dp))
                //.padding(top = 1.5.px.dp, bottom = 1.5.px.dp, start = 6.px.dp, end = 6.px.dp)
                .background(Color(200, 56, 4))
        ) {
            Text(
                text = stringResource(R.string.os_setup),
                style = RobotoTypography.titleSmall,
                fontWeight = FontWeight.Normal,
                fontSize = 14.px.sp,
                color = Color.White
            )
        }

        Spacer(modifier = Modifier.width(10.px.dp))

        IconButton(
            onClick = onCloseClick,
            modifier = Modifier
                .size(90.px.dp, 36.px.dp),
            colors = IconButtonDefaults.iconButtonColors(
                contentColor = Color.Transparent, // Icon and Text color
                containerColor = Color.Transparent, // Background color
                disabledContentColor = Color.Transparent, // Icon color when disabled
                disabledContainerColor = Color.Transparent, // Background color when disabled
            )
        ) {
            Row {
                Image(
                    painter = painterResource(id = R.drawable.ic_x),
                    contentDescription = null,
                    modifier = Modifier.size(18.px.dp),
                    contentScale = ContentScale.Fit,
                )
                Spacer(modifier = Modifier.width(4.px.dp))
                Text(
                    text = stringResource(R.string.close),
                    style = RobotoTypography.titleSmall,
                    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 PreviewEngineerTitltBarView() {
    Column(horizontalAlignment = Alignment.CenterHorizontally) {
        EngineerTitltBarView()
    }
}