import { TextAttributes } from "@opentui/core" import { Keymap } from "../context/keymap" import { useTheme } from "../context/theme" import { useDialog } from "../ui/dialog" import { createStore } from "solid-js/store" import { For } from "solid-js" export function DialogSessionDeleteFailed(props: { session: string workspace: string onDelete?: () => boolean | void | Promise onRestore?: () => boolean | void | Promise onDone?: () => void }) { const dialog = useDialog() const theme = useTheme("elevated") const [store, setStore] = createStore({ active: "delete" as "delete" | "restore", }) const options = [ { id: "delete" as const, title: "Delete workspace", description: "Delete the workspace and all sessions attached to it.", run: props.onDelete, }, { id: "restore" as const, title: "Restore to new workspace", description: "Try to restore this session into a new workspace.", run: props.onRestore, }, ] async function confirm() { const result = await options.find((item) => item.id === store.active)?.run?.() if (result === false) return props.onDone?.() if (!props.onDone) dialog.clear() } Keymap.createLayer(() => ({ mode: "modal", commands: [ { bind: "return", title: "Confirm recovery option", group: "Dialog", run: () => void confirm() }, { bind: "left", title: "Delete broken session", group: "Dialog", run: () => setStore("active", "delete") }, { bind: "up", title: "Delete broken session", group: "Dialog", run: () => setStore("active", "delete") }, { bind: "right", title: "Restore broken session", group: "Dialog", run: () => setStore("active", "restore"), }, { bind: "down", title: "Restore broken session", group: "Dialog", run: () => setStore("active", "restore"), }, ], })) return ( Failed to Delete Session dialog.clear()}> esc {`The session "${props.session}" could not be deleted because the workspace "${props.workspace}" is not available.`} Choose how you want to recover this broken workspace session. {(item) => ( { setStore("active", item.id) void confirm() }} > {item.title} {item.description} )} ) }