package com.base.superfilemanager.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.base.superfilemanager.databinding.DialogLayoutFlowTypeBinding
import com.base.superfilemanager.databinding.DialogPermissonOpenBinding

object DialogViews {

    fun showGerPermission(context: Context, onClose: (view: Dialog) -> Unit, onClose2: (view: Dialog) -> Unit?):Dialog {
        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 = "quanxian_go_full_file/images/"
        binding.idFullLottie.setAnimation("quanxian_go_full_file/data.json")
        binding.idFullLottie.playAnimation()
        binding.idDeny.setOnClickListener {
            dialog.dismiss()
            onClose2.invoke(dialog)
        }
        binding.idTvAllow.setOnClickListener {
            dialog.dismiss()
            onClose.invoke(dialog)
        }
        dialog.show()
        return dialog
    }

    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()
    }
}