package com.remax.visualnovel.widget.ui.lock

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.view.isVisible
import com.remax.visualnovel.R
import com.remax.visualnovel.databinding.ButtonVipWithIconfontBinding
import com.remax.visualnovel.databinding.ButtonWithIconBinding
import com.remax.visualnovel.extension.setOnClick
import com.remax.visualnovel.widget.uitoken.changeBackground

/**
 * Created by HJW on 2025/8/15
 */

fun ButtonWithIconBinding.setTxtAndClick(
    content: String?,
    @DrawableRes iconRes: Int = R.mipmap.icon_diamond,
    isEnabled:Boolean = true,
    callback: () -> Unit
) {
    buttonText.text = content
    buttonText.isEnabled = isEnabled

    buttonIcon.isVisible = iconRes != 0
    if (iconRes != 0) {
        buttonIcon.setImageResource(iconRes)
    }

    button.isEnabled = isEnabled
    setOnClick(button) {
        callback()
    }
}

fun ButtonVipWithIconfontBinding.setTxtAndClick(
    content: String?,
    @StringRes radiusRes: Int? = null,
    callback: () -> Unit
) {
    vipText.text = content
    if (radiusRes != null) {
        vipBtn.changeBackground {
            radiusToken = root.context.getString(radiusRes!!)
        }
    }
    setOnClick(vipBtn) {
        callback()
    }
}