package com.audio.record.screen.test.dialog

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.core.view.isVisible
import androidx.fragment.app.DialogFragment
import com.audio.record.screen.test.databinding.DialogAudioBinding
import com.audio.record.screen.test.databinding.DialogPermissionBinding
import com.audio.record.screen.test.tool.Permission
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

class DialogAudio(private var mClickType: (type: Int) -> Unit) : DialogFragment() {
    private lateinit var vb: DialogAudioBinding
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        vb = DialogAudioBinding.inflate(layoutInflater)
        init()
        return vb.root
    }

    override fun onStart() {
        super.onStart()
        val dialog = dialog
        if (dialog != null) {
            dialog.setCanceledOnTouchOutside(false)
            val window = dialog.window
            if (window != null) {
                window.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
                window.setLayout(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT
                )
            }
        }
    }

    private fun init() {
        vb.run {
            close.setOnClickListener {
                dismiss()
            }
            imWithAudio.setOnClickListener {
                mClickType.invoke(type_with_audio)
                dismiss()
            }
            imWithoutAudio.setOnClickListener {
                mClickType.invoke(type_without_audio)
                dismiss()
            }

        }

    }

    companion object {
        const val type_with_audio = 0
        const val type_without_audio = 1
    }

}