import { RGBA, TextAttributes } from "@opentui/core" import open from "open" import { createSignal } from "solid-js" import { Keymap } from "../context/keymap" import { useTheme } from "../context/theme" import { useDialog, type DialogContext } from "../ui/dialog" import { Link } from "../ui/link" import { BgPulse } from "./bg-pulse" const GO_URL = "https://opencode.ai/go" const PAD_X = 3 const PAD_TOP_OUTER = 1 const FOREGROUND_ALPHA = 186 export type DialogRetryActionProps = { title: string message: string label: string link?: string onClose?: (dontShowAgain?: boolean) => void } function runAction(props: DialogRetryActionProps, dialog: ReturnType) { if (props.link) open(props.link).catch(() => {}) props.onClose?.() dialog.clear() } function dismiss(props: DialogRetryActionProps, dialog: ReturnType) { props.onClose?.(true) dialog.clear() } function panelOverlay(color: RGBA) { const [r, g, b] = color.toInts() return RGBA.fromInts(r, g, b, FOREGROUND_ALPHA) } export function DialogRetryAction(props: DialogRetryActionProps) { const dialog = useDialog() const theme = useTheme("elevated") const showGoTreatment = () => props.link === GO_URL const textBg = () => (showGoTreatment() ? panelOverlay(theme.background.default) : undefined) const [selected, setSelected] = createSignal<"dismiss" | "action">("action") Keymap.createLayer(() => ({ mode: "modal", commands: [ { bind: "left", title: "Previous retry option", group: "Dialog", run: () => setSelected((value) => (value === "action" ? "dismiss" : "action")), }, { bind: "right", title: "Next retry option", group: "Dialog", run: () => setSelected((value) => (value === "action" ? "dismiss" : "action")), }, { bind: "tab", title: "Next retry option", group: "Dialog", run: () => setSelected((value) => (value === "action" ? "dismiss" : "action")), }, { bind: "return", title: "Confirm retry option", group: "Dialog", run: () => { if (selected() === "action") runAction(props, dialog) else dismiss(props, dialog) }, }, ], })) return ( {showGoTreatment() ? ( ) : null} {props.title} dialog.clear()}> esc {props.message} {props.link ? ( showGoTreatment() ? ( ) : ( ) ) : ( )} setSelected("dismiss")} onMouseUp={() => dismiss(props, dialog)} > don't show again setSelected("action")} onMouseUp={() => runAction(props, dialog)} > {props.label} ) } DialogRetryAction.show = ( dialog: DialogContext, props: Pick, ) => { return new Promise((resolve) => { dialog.replace( () => resolve(dontShow ?? false)} />, () => resolve(false), ) }) }