package com.base.locationsharewhite.ui.views

import android.app.AlertDialog
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.LinearLayout
import com.base.locationsharewhite.R
import com.base.locationsharewhite.databinding.DialogAllowAllTimeLocationBinding

object LocationPermissionDialog {


    fun Context.showLocationAllowAllTimeDialog(
        setAction: (() -> Unit)? = null,
        dismissAction: (() -> Unit)? = null
    ): AlertDialog {

        val dialog = AlertDialog.Builder(this).create()
        val binding = DialogAllowAllTimeLocationBinding.inflate(LayoutInflater.from(this))
        dialog.setView(binding.root)
        dialog.setCanceledOnTouchOutside(true)

        dialog.show()

        val params = dialog.window?.attributes
        params?.width = resources.getDimensionPixelOffset(R.dimen.dp_345)
        params?.height = LinearLayout.LayoutParams.WRAP_CONTENT
        params?.gravity = Gravity.CENTER
        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

        binding.flClose.setOnClickListener {
            dialog.dismiss()
        }
        binding.tvSettings.setOnClickListener {
            dialog.dismiss()
            setAction?.invoke()
        }
        dialog.setOnDismissListener {
            dismissAction?.invoke()
        }

        return dialog
    }
}