package com.tangem.feature.wallet.presentation.wallet.state.model

import androidx.annotation.DrawableRes
import androidx.compose.runtime.Immutable
import com.tangem.core.ui.ds.button.TangemButtonShape
import com.tangem.core.ui.ds.button.TangemButtonType
import com.tangem.core.ui.ds.button.TangemButtonUM
import com.tangem.core.ui.ds.image.TangemIconUM
import com.tangem.core.ui.extensions.TextReference
import com.tangem.core.ui.extensions.resourceReference
import com.tangem.core.ui.res.TangemTheme
import com.tangem.feature.wallet.impl.R

/**
 * Model for action buttons on the wallet card. It contains the button's text, icon, click listener, and enabled state.
 */
@Immutable
internal sealed class WalletActionButtons(
    private val text: TextReference,
    @DrawableRes private val iconRes: Int,
) {

    abstract val onClick: () -> Unit

    abstract val isEnabled: Boolean

    val buttonUM: TangemButtonUM
        get() = TangemButtonUM(
            text = text,
            tangemIconUM = TangemIconUM.Icon(
                iconRes = iconRes,
                tintReference = {
                    if (isEnabled) {
                        TangemTheme.colors2.graphic.neutral.primary
                    } else {
                        TangemTheme.colors2.graphic.neutral.quaternary
                    }
                },
            ),
            type = TangemButtonType.Secondary,
            shape = TangemButtonShape.Rounded,
            onClick = onClick,
            isEnabled = isEnabled,
        )

    data class Buy(
        override val onClick: () -> Unit,
        override val isEnabled: Boolean,
    ) : WalletActionButtons(
        text = resourceReference(R.string.common_buy),
        iconRes = R.drawable.ic_plus_default_24,
    )

    data class AddFunds(
        override val onClick: () -> Unit,
        override val isEnabled: Boolean,
    ) : WalletActionButtons(
        text = resourceReference(R.string.actionbutton_addfunds_title),
        iconRes = R.drawable.ic_arrow_down_24,
    )

    data class Swap(
        override val onClick: () -> Unit,
        override val isEnabled: Boolean,
    ) : WalletActionButtons(
        text = resourceReference(R.string.actionbutton_swap_title),
        iconRes = R.drawable.ic_exchange_default_24,
    )

    data class Sell(
        override val onClick: () -> Unit,
        override val isEnabled: Boolean,
    ) : WalletActionButtons(
        text = resourceReference(R.string.common_sell),
        iconRes = R.drawable.ic_dollar_default_24,
    )

    data class Transfer(
        override val onClick: () -> Unit,
        override val isEnabled: Boolean,
    ) : WalletActionButtons(
        text = resourceReference(R.string.actionbutton_transfer_title),
        iconRes = R.drawable.ic_arrow_up_24,
    )
}