package com.isidroid.c23.ui.screen.render_preview._component

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
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.sp
import com.isidroid.c23.R
import com.isidroid.c23.ui.screen.render_preview.RenderContract
import com.isidroid.spot.model.PrintProfile
import com.isidroid.utils.asCost

@Composable
fun PaperInfoComponent(
    state: State<RenderContract.State>,
    modifier: Modifier = Modifier,
) {
    val printProfile = state.value.printProfile ?: return

    Column(modifier = modifier.fillMaxWidth()) {
        Text(
            text = printProfile.name,
            fontWeight = FontWeight.Bold,
            lineHeight = 32.sp,
            fontSize = 18.sp
        )
        Text(
            text = printProfileSizeName(printProfile),
            color = MaterialTheme.colorScheme.onSurface.copy(alpha = .75f),
            lineHeight = 24.sp,
            fontSize = 16.sp
        )
        Text(
            text = stringResource(id = R.string.print_profile_cost_info, printProfile.cost.asCost()),
            color = MaterialTheme.colorScheme.onSurface.copy(alpha = .75f),
            lineHeight = 24.sp,
            fontSize = 16.sp
        )
    }

}

private fun printProfileSizeName(printProfile: PrintProfile) = buildString {
    append(printProfile.name)
    append(" ")
    append("(${printProfile.width / 100}x${printProfile.height / 100}) mm")
}


@Preview
@Composable
private fun PaperInfoComponentPreview() {
    Surface {
        PaperInfoComponent(
            state = remember {
                mutableStateOf(
                    RenderContract.State(
                        printProfile = PrintProfile(
                            name = "Test Profile",
                            width = 215,
                            height = 279,
                            cost = 12f
                        )
                    )
                )
            }
        )
    }
}
