package com.zxhyis.toolss.ui.dialog

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.LayoutInflater
import com.blankj.utilcode.util.ClickUtils
import com.zxhyis.toolss.databinding.DialogLayoutFlowTypeBinding
import com.zxhyis.toolss.databinding.DialogLayoutLastStepBinding
import com.zxhyis.toolss.databinding.DialogPermissonOpenBinding

object DialogViews {
    fun showGerPermisson(context: Context, onClose: (() -> Unit)? = null, onClose2: (() -> Unit)?) {
        val dialog = Dialog(context)
        val binding = DialogPermissonOpenBinding.inflate(LayoutInflater.from(context))
        dialog.requestWindowFeature(1)
        dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        dialog.window!!.setLayout(-1, -1)
        dialog.setCanceledOnTouchOutside(true)
        dialog.setCancelable(true)
        dialog.setContentView(binding.root)
        binding.root.setOnClickListener {
            dialog.dismiss()
            onClose2?.invoke()
        }
        binding.idAllow.setOnClickListener {
            dialog.dismiss()
            onClose?.invoke()
        }
        dialog.show()
    }

    fun showBothtypes(context: Context, onClick: (potion: Int) -> Unit) {
        val dialog = Dialog(context)
        val binding = DialogLayoutFlowTypeBinding.inflate(LayoutInflater.from(context))
        dialog.requestWindowFeature(1)
        dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        dialog.window!!.setLayout(-1, -1)
        dialog.setCanceledOnTouchOutside(true)
        dialog.setCancelable(true)
        dialog.setContentView(binding.root)
        ClickUtils.applyPressedBgDark(binding.idMobileNetwork)
        ClickUtils.applyPressedBgDark(binding.idWifi)
        ClickUtils.applyPressedBgDark(binding.idTwoTypes)
        binding.idMobileNetwork.setOnClickListener {
            onClick(0)
            dialog.dismiss()
        }
        binding.idWifi.setOnClickListener {
            onClick(1)
            dialog.dismiss()
        }
        binding.idTwoTypes.setOnClickListener {
            onClick(2)
            dialog.dismiss()
        }

        dialog.show()
    }

    fun showLastStep(context: Context, onClick: () -> Unit) {
        val dialog = Dialog(context)
        val binding = DialogLayoutLastStepBinding.inflate(LayoutInflater.from(context))
        dialog.requestWindowFeature(1)
        dialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        dialog.window!!.setLayout(-1, -2)
        dialog.setCanceledOnTouchOutside(false)
        dialog.setCancelable(false)
        dialog.setContentView(binding.root)
        binding.idTvOk.setOnClickListener {
            onClick.invoke()
            dialog.dismiss()

        }

        dialog.show()
    }
}