package com.test.basd.onecleanmaster.view

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.blankj.utilcode.util.SpanUtils
import com.test.basd.onecleanmaster.databinding.DialogLayoutFlowTypeBinding
import com.test.basd.onecleanmaster.databinding.DialogPermissonOpenBinding

object DialogViews {
    fun showGerPermission(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(false)
        dialog.setCancelable(false)
        dialog.setContentView(binding.root)
        SpanUtils.with(binding.idTvTt)
            .append("Allow File Manager Select to access ")
            .setFontSize(13, true)
            .setForegroundColor(0xFF999999.toInt())
            .append("All Files Access ")
            .setBold()
            .setFontSize(13, true)
            .setForegroundColor(0xFF4273FF.toInt())
            .append("permission to manage files of your device?")
            .setFontSize(13, true)
            .setForegroundColor(0xFF999999.toInt())
            .create()
        binding.idFullLottie.imageAssetsFolder = "quick_quanxian_full_file/images/"
        binding.idFullLottie.setAnimation("quick_quanxian_full_file/data.json")
        binding.idFullLottie.playAnimation()
        binding.idDeny.setOnClickListener {
            dialog.dismiss()
            onClose2?.invoke()
        }
        binding.idTvAllow.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()
    }


}