import { Button } from "@/components/ui/button"
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from "."
import ReactDOM from "react-dom"
import i18next from "i18next"
import { useRef, useState } from "react"
import { TipIcon } from "@/components/bs-icons/tip"
import { Cross2Icon } from "@radix-ui/react-icons"
import { createRoot } from "react-dom/client"
interface ConfirmParams {
title?: string
desc: string | React.ReactNode
canelTxt?: string
okTxt?: string
showClose?: boolean
onClose?: () => void
onCancel?: () => void
onOk?: (next) => void
}
let openFn = (_: ConfirmParams) => { }
function ConfirmWrapper() {
const [open, setOpen] = useState(false)
const paramRef = useRef(null)
openFn = (params: ConfirmParams) => {
paramRef.current = params
setOpen(true)
}
const close = () => {
paramRef.current?.onClose?.()
setOpen(false)
}
const handleCancelClick = () => {
paramRef.current?.onCancel?.()
close()
}
const handleOkClick = () => {
paramRef.current?.onOk
? paramRef.current?.onOk?.(close)
: close()
}
if (!paramRef.current) return null
const { title, desc, okTxt, canelTxt, showClose = true } = paramRef.current
return (
{showClose && }
{title}
{desc}
{canelTxt}
{okTxt}
)
}
(function () {
// 挂载组件
let el = document.getElementById('#confirm-wrap');
if (!el) {
el = document.createElement('div')
el.id = 'confirm-wrap'
document.body.append(el)
}
// ReactDOM.render(, el);
const root = createRoot(el);
root.render();
})();
const bsConfirm = (params: ConfirmParams) => {
const resource = i18next.getResourceBundle(i18next.language, 'bs')
openFn({
title: resource.prompt,
canelTxt: resource.cancel,
okTxt: resource.confirmButton,
...params,
})
}
export { bsConfirm }