package com.isidroid.ui.print_job._components

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.DateRange
import androidx.compose.material.icons.rounded.Lock
import androidx.compose.material3.Icon
import androidx.compose.material3.Surface
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.vector.ImageVector
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.sp
import com.isidroid.ui.print_job.R
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

@Composable
internal fun CardInfoComponent(
    code: String,
    modifier: Modifier = Modifier,
    createdAt: Date = Date(),
) {
    val itemSpace = 6.dp

    Column(modifier = modifier.fillMaxWidth()) {
        CardInfoItemComponent(
            text = stringResource(id = R.string.label_access_code, code),
            icon = Icons.Rounded.Lock
        )

        CardInfoItemComponent(
            text = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(createdAt),
            icon = Icons.Rounded.DateRange,
            modifier = Modifier.padding(top = itemSpace)
        )
    }
}

@Composable
private fun CardInfoItemComponent(text: String, icon: ImageVector, modifier: Modifier = Modifier) {
    Row(modifier = modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
        Icon(imageVector = icon, contentDescription = null, modifier = Modifier.size(16.dp))
        Text(
            text = text,
            modifier = Modifier.padding(start = 4.dp),
            fontSize = 14.sp,
            fontWeight = FontWeight.W400
        )
    }
}


@Composable
@Preview
private fun AccessCodeComponentPreview() {
    Surface {
        CardInfoComponent(code = "123411")
    }
}