import { TextAttributes } from "@opentui/core"
import { Keymap } from "../context/keymap"
import { useTheme } from "../context/theme"
import { useDialog, type DialogContext } from "./dialog"
export type DialogAlertProps = {
title: string
message: string
onConfirm?: () => void
}
export function DialogAlert(props: DialogAlertProps) {
const dialog = useDialog()
const theme = useTheme("elevated")
Keymap.createLayer(() => ({
mode: "modal",
commands: [
{
bind: "return",
title: "Confirm alert",
group: "Dialog",
run: () => {
props.onConfirm?.()
dialog.clear()
},
},
],
}))
return (
{props.title}
dialog.clear()}>
esc
{props.message}
{
props.onConfirm?.()
dialog.clear()
}}
>
ok
)
}
DialogAlert.show = (dialog: DialogContext, title: string, message: string) => {
return new Promise((resolve) => {
dialog.replace(
() => resolve()} />,
() => resolve(),
)
})
}