package com.meowarex.rlmobile.ui.screens.patching.components

import androidx.compose.foundation.basicMarquee
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.meowarex.rlmobile.patcher.steps.base.Step
import com.meowarex.rlmobile.patcher.steps.base.StepState
import com.meowarex.rlmobile.ui.util.thenIf

@Composable
fun StepItem(
    step: Step,
    modifier: Modifier = Modifier,
) {
    Row(
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.spacedBy(16.dp),
        modifier = modifier,
    ) {
        StepStateIcon(
            size = 18.dp,
            state = step.state,
            stepProgress = step.progress,
        )

        Text(
            text = stringResource(step.localizedName),
            style = MaterialTheme.typography.labelLarge,
            maxLines = 1,
            overflow = TextOverflow.Ellipsis,
            modifier = Modifier
                .weight(1f, true)
                .thenIf(step.state == StepState.Running) { basicMarquee() },
        )

        TimeElapsed(
            enabled = step.state != StepState.Pending,
            seconds = step.collectDurationAsState().value,
        )
    }
}
