import { TextAttributes, type KeyEvent, type TextareaRenderable } from '@opentui/core' import { useKeyboard } from '@opentui/solid' import { createEffect, createMemo, createSignal, For, Show, type JSX } from 'solid-js' import type { Context } from '@opencode/plugin/tui/context' import { filterModelOptions } from './tui-multi-run.js' import type { ModelOption } from './tui-multi-run.js' export type DialogTheme = ReturnType export type KeyHint = readonly [key: string, label: string] const PICKER_ROWS = 8 export function rowColors(theme: DialogTheme, state: { active: boolean; chosen?: boolean }) { if (state.active) { const text = theme.text.action.primary.focused return { background: theme.background.action.primary.focused, title: text, detail: text, marker: text, bold: true } } return { background: undefined, title: state.chosen ? theme.text.formfield.selected : theme.text.base, detail: theme.text.muted, marker: state.chosen ? theme.text.formfield.selected : theme.text.muted, bold: false, } } export function isSubmitKey(event: KeyEvent): boolean { return event.ctrl && event.name === 's' } export function useFieldFocus(count: () => number, enabled: () => boolean = () => true) { const [index, setIndex] = createSignal(0) createEffect(() => { if (index() >= count()) setIndex(Math.max(0, count() - 1)) }) useKeyboard((event) => { if (!enabled() || event.name !== 'tab') return event.preventDefault() setIndex((current) => (current + (event.shift ? count() - 1 : 1)) % count()) }) return [index, setIndex] as const } export function DialogShell(props: { theme: DialogTheme title: string subtitle?: string hints: readonly KeyHint[] error?: string | null busy?: string | null children: JSX.Element }) { return ( {props.title} {(subtitle) => ( {subtitle()} )} esc {props.children} {(message) => {message()}} {(message) => {message()}} {(hint) => ( {hint[0]} {hint[1]} )} ) } export function FieldLabel(props: { theme: DialogTheme; label: string; focused: boolean; detail?: string }) { return ( {props.label} {(detail) => {detail()}} ) } export function TextField(props: { theme: DialogTheme label: string initialValue: string placeholder?: string focused: boolean onInput: (value: string) => void onSubmit?: () => void }) { const initial = props.initialValue return ( props.onSubmit?.()} /> ) } export function TextAreaField(props: { theme: DialogTheme label: string initialValue: string placeholder?: string focused: boolean height: number onInput: (value: string) => void }) { const initial = props.initialValue let textarea: TextareaRenderable | undefined return (