package com.dlc.eboard.ui.dialog

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import com.dlc.eboard.R
import com.dlc.eboard.databinding.DialogCheckResultBinding
import com.rc.core.ui.dialog.RcBaseDialog

/**
 * 核验结果
 *
 * @author ReiChin_
 */
class CheckResultDialog : RcBaseDialog<DialogCheckResultBinding>() {

    private var success = false

    override fun createViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): DialogCheckResultBinding {
        return DialogCheckResultBinding.inflate(inflater, container, false)
    }

    fun setSuccess(success: Boolean) {
        this.success = success
    }

    override fun initViews(savedInstanceState: Bundle?) {
        if (success) {
            viewBinding.text.text = "核验成功"
            viewBinding.text.setTextColor(ContextCompat.getColor(requireContext(), R.color.text_color_success))
            viewBinding.image.setImageResource(R.mipmap.icon_sign_in_success)

        } else {
            viewBinding.text.text = "核验失败，请联系管理员！"
            viewBinding.text.setTextColor(ContextCompat.getColor(requireContext(), R.color.text_color_fail))
            viewBinding.image.setImageResource(R.mipmap.icon_sign_in_fail)
        }
    }

    override fun onResume() {
        super.onResume()
        // 显示5秒后，自动关闭
        mDismissHandler.sendEmptyMessageDelayed(1, 5000)
    }

    private val mDismissHandler = object : Handler(Looper.getMainLooper()) {

        override fun handleMessage(msg: Message) {
            dismiss()
        }
    }

}