"use client"; import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { useState } from "react"; import { isRewrite, wordDiff } from "../suggest.js"; export const DEFAULT_SUGGESTION_LABELS = { heading: (label) => `Suggestion: ${label}`, accept: "Use this", reject: "Keep mine", pick: "Pick one", replaces: "Replaces your text:", added: "added", removed: "removed", }; /** * A proposal from writing help, shown as what changes (or, when most of the * text changes, as the new text whole). Both buttons are equal cells: the * screen's one primary action stays Publish. Nothing reaches the * text until the writer taps "Use this"; "Keep mine" drops it. Options (a few * titles) are one list of equal rows, the first chosen. The host applies the * choice with `applySuggestion`, which refuses when the text moved on. */ export function SuggestionCard({ suggestion, onAccept, onReject, busy = false, labels: overrides, }) { const labels = { ...DEFAULT_SUGGESTION_LABELS, ...overrides }; const options = suggestion.options?.length ? suggestion.options : [suggestion.after]; const [chosen, setChosen] = useState(0); const after = options[chosen] ?? suggestion.after; const parts = wordDiff(suggestion.before, after); const whole = suggestion.before === "" || isRewrite(parts); return (_jsxs("section", { className: "wk-suggestion", "aria-label": labels.heading(suggestion.label), children: [_jsx("h2", { className: "wk-panel-title", children: labels.heading(suggestion.label) }), options.length > 1 ? (_jsxs("fieldset", { className: "wk-options", children: [_jsx("legend", { className: "wk-meta", children: labels.pick }), options.map((option, i) => (_jsxs("label", { className: "wk-option", children: [_jsx("input", { type: "radio", name: `wk-suggestion-${suggestion.id}`, checked: chosen === i, onChange: () => setChosen(i) }), _jsx("span", { children: option })] }, `${i}-${option}`)))] })) : (_jsx("div", { className: "wk-diff", children: whole ? (_jsxs(_Fragment, { children: [suggestion.before !== "" && (_jsxs("span", { className: "wk-meta wk-replaces", children: [labels.replaces, " "] })), _jsx("ins", { children: after })] })) : (parts.map((part, i) => part.kind === "same" ? (_jsx("span", { children: part.text }, i)) : part.kind === "added" ? (_jsx("ins", { title: labels.added, children: part.text }, i)) : (_jsx("del", { title: labels.removed, children: part.text }, i)))) })), _jsxs("div", { className: "wk-actions-row", children: [_jsx("button", { type: "button", className: "wk-btn", disabled: busy, onClick: () => onAccept(after), children: labels.accept }), _jsx("button", { type: "button", className: "wk-btn", disabled: busy, onClick: onReject, children: labels.reject })] })] })); }