package com.adealink.weparty.commonui.tip

import android.app.Activity
import com.adealink.frame.aab.util.getCompatString
import com.adealink.frame.base.Rlt
import com.adealink.weparty.R
import com.adealink.weparty.commonui.BaseActivity

fun showFailedTip(activity: Activity?, rlt: Rlt<*>) {
    val baseActivity = activity as? BaseActivity
    if (rlt is Rlt.Failed) {
        var tip = getCompatString(R.string.common_failed)
        if (rlt.error.msg.isNotEmpty()) {
            tip = rlt.error.msg
        }
        baseActivity?.showTipDialog(tip)
    }
}

fun showCenterTip(activity: Activity?, tip: String, duration: Long = 1500) {
    val baseActivity = activity as? BaseActivity
    baseActivity?.showTipDialog(tip, duration)
}

fun showSuccessTip(activity: Activity?, rlt: Rlt<*>) {
    val baseActivity = activity as? BaseActivity
    if (rlt is Rlt.Success) {
        baseActivity?.showTipDialog(R.drawable.commonui_success_white_tick_ic, R.string.common_success)
    }
}

fun showTip(activity: Activity?, rlt: Rlt<*>) {
    when (rlt) {
        is Rlt.Success -> {
            showSuccessTip(activity, rlt)
        }
        is Rlt.Failed -> {
            showFailedTip(activity, rlt)
        }
    }
}