package xn.xxp.home.auth

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.WindowManager
import xn.xxp.R
import xn.xxp.databinding.DialogPickSignTypeBinding

/**
 * 选择签到类型
 *
 * @author ReiChin_
 */
class PickSignTypeDialog(
    context: Context,
    private val listener: (type: Int) -> Unit
) :
    Dialog(context, R.style.AlertDialogStyle) {

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

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

    private fun initWindowConfig() {
        window?.apply {
            setType(WindowManager.LayoutParams.TYPE_APPLICATION_PANEL)
            setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
        }
    }

    private fun initViews() {
        viewBinding.close.setOnClickListener {
            dismiss()
        }

        viewBinding.patrolSign.setOnClickListener {
            dismiss()
            listener.invoke(SignType.PATROL.code)
        }
        viewBinding.accessSign.setOnClickListener {
            dismiss()
            listener.invoke(SignType.ACCESS.code)
        }
    }

}