package com.base.locationsharewhite.ui.views

import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.graphics.Color
import android.view.Gravity
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.core.content.ContextCompat
import com.base.locationsharewhite.R
import com.base.locationsharewhite.databinding.DialogAppExitBinding
import com.base.locationsharewhite.databinding.DialogMapTypeBinding
import com.google.android.gms.maps.GoogleMap

object DialogView {

    fun Context.showMapTypeDialog(googleMap: GoogleMap) {
        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.BOTTOM
        params?.y = 20
        dialog.window?.attributes = params
        dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
        if (googleMap.mapType == GoogleMap.MAP_TYPE_SATELLITE) {
            binding.ivStatellite.background = ContextCompat.getDrawable(this, R.drawable.bg_stroke_03b988_15)
            binding.tvStatellite.setTextColor(Color.parseColor("#03B988"))
        } else {
            binding.ivStreet.background = ContextCompat.getDrawable(this, R.drawable.bg_stroke_03b988_15)
            binding.tvStreet.setTextColor(Color.parseColor("#03B988"))
        }

        binding.llStatellite.setOnClickListener {
            dialog.dismiss()
            googleMap.mapType = GoogleMap.MAP_TYPE_SATELLITE
        }

        binding.llStreet.setOnClickListener {
            dialog.dismiss()
            googleMap.mapType = GoogleMap.MAP_TYPE_NORMAL
        }
    }

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