package com.wall.photography.wallpaper.activivty

import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.DialogFragment
import com.wall.photography.wallpaper.databinding.SelectDialogBinding


class SelectDialog(private var clickAction:(clickPos:Int)->Unit) : DialogFragment() {

    private lateinit var vb: SelectDialogBinding
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        vb = SelectDialogBinding.inflate(layoutInflater)
        dialog?.run {
            setCanceledOnTouchOutside(true)
            window?.run {
                setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
                setLayout(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
            }

        }
        initCLick()
        return vb.root
    }


    private fun initCLick(){
        vb.home.setOnClickListener {
            clickAction.invoke(clickType_home)
            dismiss()
        }
        vb.lock.setOnClickListener {
            clickAction.invoke(clickType_lock)
            dismiss()
        }
        vb.both.setOnClickListener {
            clickAction.invoke(clickType_both)
            dismiss()
        }
    }



    companion object {
        const val clickType_home = 0
        const val clickType_lock = 1
        const val clickType_both = 2
    }


}