package com.za.ui.view

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.DialogFragment
import com.za.base.view.CommonDialog

class CommonDialogFragment(val title: String? = null,
                           val message: String? = null,
                           val cancelText: String? = null,
                           val confirmText: String = "确定",
                           val confirm: () -> Unit = {},
                           val cancel: () -> Unit = {}) : DialogFragment() {
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return ComposeView(requireContext()).apply {
            setContent {
                CommonDialog(
                    confirm = {
                        dismiss()
                        confirm()
                    },
                    cancel = {
                        dismiss()
                        cancel()
                    },
                    title = title,
                    message = message,
                    confirmText = confirmText,
                    cancelText = cancelText,
                    dismiss = { dismiss() })
            }
        }
    }
}