/*
 * Copyright 2024 Mifos Initiative
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
 */
package org.mifospay.feature.standing.instruction.components

import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import org.mifospay.core.model.standinginstruction.StandingInstruction

@Composable
fun PriorityChip(
    priority: StandingInstruction.Option?,
    modifier: Modifier = Modifier,
) {
    val (backgroundColor, contentColor) = when (priority?.id) {
        1L -> MaterialTheme.colorScheme.error to MaterialTheme.colorScheme.surfaceContainerLowest
        2L -> MaterialTheme.colorScheme.errorContainer to MaterialTheme.colorScheme.surfaceContainerLowest
        3L -> MaterialTheme.colorScheme.secondary to MaterialTheme.colorScheme.surfaceContainerLowest
        4L -> MaterialTheme.colorScheme.tertiary to MaterialTheme.colorScheme.surfaceContainerLowest
        else -> MaterialTheme.colorScheme.outline to MaterialTheme.colorScheme.surfaceContainerLowest
    }

    Surface(
        modifier = modifier,
        shape = RoundedCornerShape(4.dp),
        color = backgroundColor,
        contentColor = contentColor,
    ) {
        Text(
            text = priority?.value ?: "",
            modifier = Modifier.padding(4.dp),
            style = MaterialTheme.typography.bodySmall,
            maxLines = 1,
        )
    }
}
