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

import android.content.res.Configuration
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
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.theme.RobotoTypography
import com.laseroptek.raman.utils.ext.noRippleClickable
import com.laseroptek.raman.utils.ext.px

@Composable
fun CountItemView(
    modifier: Modifier = Modifier,
    count: Int = 0,
    onClick: () -> Unit = {},
    title:String = ""
) {
    Row(modifier = modifier,
        horizontalArrangement = Arrangement.SpaceBetween,
        verticalAlignment = Alignment.CenterVertically
    ) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .weight(1.2f)
                .height(30.px.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.Start
        ) {
            Text(
                text = title,
                style = RobotoTypography.labelMedium,
                fontWeight = FontWeight.Normal,
                fontSize = 12.px.sp,
                color = Color.Black
            )
        }

        Column(
            modifier = Modifier
                .fillMaxWidth()
                .weight(1f)
                .height(30.px.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.Start
        ) {
            Text(
                modifier = Modifier.fillMaxWidth(),
                text = "%9d".format(count),
                style = RobotoTypography.bodyMedium,
                fontWeight = FontWeight.Normal,
                fontSize = 12.px.sp,
                color = Color.Black,
                textAlign = TextAlign.End
            )
        }

        Column(
            modifier = Modifier
                .fillMaxWidth()
                .weight(1f)
                .height(30.px.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.Start
        ) {
            Text(
                modifier = Modifier.fillMaxWidth(),
                text = "Count",
                style = RobotoTypography.bodyMedium,
                fontWeight = FontWeight.Normal,
                fontSize = 12.px.sp,
                color = Color.Black,
                textAlign = TextAlign.End
            )
        }

        Column(
            modifier = Modifier
                //.noRippleClickable(onClick = onDeviceOpTimeClick)
                .fillMaxWidth()
                .weight(1f)
                .height(30.px.dp),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.End
        ) {
            Image(
                modifier = Modifier
                    .size(18.px.dp, 18.px.dp)
                    .noRippleClickable(onClick = { onClick.invoke() }),
                painter = painterResource(id = R.drawable.ic_edit),
                contentDescription = null,
                colorFilter = Color.Black.let { ColorFilter.tint(it) }
            )
        }
    }
}


@Preview(
    uiMode = Configuration.UI_MODE_NIGHT_NO,
    showBackground = false,
    device = "spec:width=640dp,height=60dp,dpi=150,isRound=false,chinSize=0dp,orientation=landscape"
)
@Composable
fun PreviewCountItemView() {
    Row {
        CountItemView(
            modifier = Modifier
                .fillMaxSize()
                .weight(1f),
            title = "Lamp \nTotal Count"
        )
    }
}