package com.base.locationsharewhite.ui.views

import android.app.Activity
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.DialogAppExitBinding
import com.base.locationsharewhite.databinding.DialogMapTypeBinding
import com.base.locationsharewhite.ui.views.DialogView.showMapTypeDialog

object DialogView {

    fun Context.showMapTypeDialog() {
        val dialog = AlertDialog.Builder(this).create()
        val binding = DialogMapTypeBinding.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_375)
        params?.height = LinearLayout.LayoutParams.WRAP_CONTENT
        params?.gravity = Gravity.CENTER
        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

    }

    fun Activity.showAppExitDialog() {
        val dialog = AlertDialog.Builder(this).create()
        val binding = DialogAppExitBinding.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_356)
        params?.height = LinearLayout.LayoutParams.WRAP_CONTENT
        params?.gravity = Gravity.BOTTOM
        params?.y = 50
        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)

        binding.tvCancel.setOnClickListener {
            dialog.dismiss()
        }
        binding.tvQuit.setOnClickListener {
            dialog.dismiss()
            finish()
        }
        binding.ivClose.setOnClickListener {
            dialog.dismiss()
        }
    }
}