package com.base.pdfreaderallpdfreader.ui.view

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.base.pdfreaderallpdfreader.R
import com.base.pdfreaderallpdfreader.databinding.DialogDeleteBinding
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog

object DialogView {

    fun Context.showDeleteDialog(deleteAction: () -> Unit) {
        val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
        val binding = DialogDeleteBinding.inflate(LayoutInflater.from(this))
        dialog.setContentView(binding.root)
        dialog.setCanceledOnTouchOutside(true)

        dialog.show()

        val parentView = binding.root.parent as View
        val behavior = BottomSheetBehavior.from(parentView)
        //展开
        behavior.state = BottomSheetBehavior.STATE_EXPANDED

        binding.tvCancel.setOnClickListener {
            dialog.dismiss()
        }
        binding.tvDelete.setOnClickListener {
            dialog.dismiss()
            deleteAction.invoke()
        }
    }
}