import { useCallback, useState } from 'react'
import { Button } from './Button.jsx'
import { Dialog } from './Dialog.jsx'
import { useLabels } from './labels.js'
/**
* Asks before doing something: a small dialog inside the page, never the browser's confirm()
* (2026-11-21). tone 'danger' for deleting / throwing work away.
* It goes from the playlist.
*/
export function ConfirmDialog({ open, title, children, confirmLabel, cancelLabel, tone = 'primary', onConfirm, onCancel, busy = false, testId }) {
const labels = useLabels()
return (
)
}
/**
* The same as a hook that answers with a promise:
* const [confirm, confirmDialog] = useConfirm()
* if (!(await confirm({ title, body, confirmLabel, tone: 'danger' }))) return
* …render {confirmDialog} somewhere in the component.
*/
export function useConfirm() {
const [ask, setAsk] = useState(null)
const confirm = useCallback(opts => new Promise(resolve => setAsk({ ...opts, resolve })), [])
const answer = value => { ask?.resolve(value); setAsk(null) }
const dialog = ask ? (
answer(true)} onCancel={() => answer(false)}>{ask.body}
) : null
return [confirm, dialog]
}