package com.base.superfilemanager.view

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.app.AlertDialog
import com.base.superfilemanager.R
import com.base.superfilemanager.databinding.DialogPermissionFilterBinding

object PermissionFilterDialog {

    fun Context.showPermissionFilterDialog(
        allClick: () -> Unit,
        authorizedClick: () -> Unit,
    ) {
        val binding = DialogPermissionFilterBinding.inflate(LayoutInflater.from(this))
        val dialog = AlertDialog.Builder(this).setView(binding.root).create()

        dialog.setContentView(binding.root)
        dialog.setCanceledOnTouchOutside(true)
        dialog.show()

        //修改dialog的尺寸
        val lp = dialog.window?.attributes
        lp?.width = resources.getDimensionPixelOffset(R.dimen.dp_360)
        lp?.height = ViewGroup.LayoutParams.WRAP_CONTENT
        dialog.window?.attributes = lp
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

        binding.tvAll.setOnClickListener {
            dialog.dismiss()
            allClick.invoke()
        }
        binding.tvAuthorized.setOnClickListener {
            dialog.dismiss()
            authorizedClick.invoke()
        }
    }
}