package com.dlc.chemical.ui.dialog

import android.app.Dialog
import android.content.Context
import android.content.res.Resources
import android.os.Bundle
import android.view.LayoutInflater
import com.dlc.chemical.R
import com.dlc.chemical.databinding.DialogSimpleTipsBinding
import com.rc.core.util.DeviceUtils

/**
 * info
 *
 * @author ReiChin_
 */
class SimpleTipsDialog(
    context: Context,
    private val message: String,
    private val confirmText: String = "确认",
    private val dialogListener: (() -> Unit)? = null
) :
    Dialog(context, R.style.AlertDialogStyle) {

    private val viewBinding: DialogSimpleTipsBinding by lazy {
        DialogSimpleTipsBinding.inflate(LayoutInflater.from(context))
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(viewBinding.root)
        initWindowConfig()
        initViews()
    }

    private fun initWindowConfig() {
        window?.apply {
            val dm = Resources.getSystem().displayMetrics
            attributes.width = (dm.widthPixels * 0.32f).toInt()
            attributes.height = DeviceUtils.dip2px(context, 158.0f)
        }
    }

    private fun initViews() {
        viewBinding.message.text = message

        // 确认
        viewBinding.confirm.text = confirmText
        viewBinding.confirm.setOnClickListener {
            dialogListener?.invoke()
            dismiss()
        }
    }

}