import type { SelectOption } from "@opentui/core" import { resolveRowBackground, resolveRowTextColor } from "./commit-history/layout" import { getVisibleRange } from "../list-range" import type { FocusTarget } from "../types" import type { UiTheme } from "../theme" import { fitLine } from "../utils" import { ViewFrame, resolveViewContentWidth, resolveVisibleRows } from "./view-frame" import { SectionDivider } from "./section-divider" type SyncDialogProps = { open: boolean focus: FocusTarget terminalWidth: number terminalHeight: number options: SelectOption[] optionIndex: number details: string | null onOptionClick: (index: number) => void onOptionScroll: (direction: "up" | "down") => void theme: UiTheme } export function SyncDialog({ open, focus, terminalWidth, terminalHeight, options, optionIndex, details, onOptionClick, onOptionScroll, theme, }: SyncDialogProps) { if (!open) return null const visibleRows = resolveVisibleRows(terminalHeight, 14) const range = getVisibleRange(options.length, optionIndex, visibleRows) const rowWidth = Math.max(resolveViewContentWidth(terminalWidth) - 2, 1) return ( can't push yet remote changed. pick what to do next {details ? {fitLine(details, rowWidth)} : null} { const direction = event.scroll?.direction if (direction !== "up" && direction !== "down") return event.preventDefault() event.stopPropagation() onOptionScroll(direction) }} > {options.slice(range.start, range.end).map((option, visibleIndex) => { const absoluteIndex = range.start + visibleIndex const selected = absoluteIndex === optionIndex const optionName = option.name ?? String(option.value ?? "") const optionDescription = option.description ?? "" const prefix = selected ? "▶ " : " " const titleWidth = Math.max(rowWidth - prefix.length, 1) return ( { event.preventDefault() event.stopPropagation() onOptionClick(absoluteIndex) }} > {prefix} {fitLine(optionName, titleWidth)} {" "} {fitLine(optionDescription, rowWidth - 1)} ) })} ) }