package com.dlc.exam.ui.login

import android.app.Dialog
import android.content.Context
import android.content.res.Resources
import android.os.Bundle
import android.view.LayoutInflater
import android.view.WindowManager
import com.dlc.exam.R
import com.dlc.exam.databinding.DialogViolationHandlingBinding

/**
 * 违规处理通知
 *
 * @author ReiChin_
 */
class ViolationHandlingDialog(context: Context, private val listener: (hand: Boolean) -> Unit) :
    Dialog(context, R.style.AlertDialogStyle) {

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

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

        viewBinding.cancel.setOnClickListener {
            dismiss()
            listener.invoke(false)
        }
        viewBinding.handling.setOnClickListener {
            dismiss()
            listener.invoke(true)
        }
    }

    private fun initWindowConfig() {
        window?.apply {
            val dm = Resources.getSystem().displayMetrics
            attributes.width = (dm.widthPixels * 0.31f).toInt()
            attributes.height = WindowManager.LayoutParams.WRAP_CONTENT
        }
    }

}