import type { AssistantChangePreview, AssistantPlanEdits } from '@trek/shared';
import { Check, Pencil } from 'lucide-react';
import { lazy, Suspense, useEffect, useId, useState } from 'react';
import { useTranslation } from '../../i18n';
import { useAssistantStore } from '../../store/assistantStore';
import { EditorField, PANEL, TEXTAREA } from '../shared/dialogParts';
import {
DialogButton,
DialogFooter,
DialogHeader,
DialogShell,
DialogTile,
FooterSpacer,
NEUTRAL_TINT,
} from '../shared/DialogShell';
import { Tooltip } from '../shared/Tooltip';
import { isVisitProposal, planField, proposalNote } from './assistantPlanFieldsModel';
import { useAssistantView } from './assistantViewContext';
const AssistantPlaceProposal = lazy(() => import('./AssistantPlaceProposal'));
interface ProposalEditProps {
preview: AssistantChangePreview;
args?: unknown;
edits: AssistantPlanEdits | undefined;
disabled: boolean;
onEdit: (patch: AssistantPlanEdits) => void;
}
export default function AssistantPlanFields({ preview, args, edits, disabled, onEdit }: ProposalEditProps) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
return (
<>
{open &&
(isVisitProposal(preview) ? (
setOpen(false)}
/>
) : (
setOpen(false)}
/>
))}
>
);
}
function DayNoteEditDialog({ preview, edits, disabled, onEdit, onClose }: ProposalEditProps & { onClose: () => void }) {
const { t } = useTranslation();
const { tripId } = useAssistantView();
const { toolCallId } = preview;
const previewPlanEdit = useAssistantStore((s) => s.previewPlanEdit);
const id = useId();
const [draft, setDraft] = useState(() => edits ?? {});
const change = (patch: AssistantPlanEdits) => setDraft((current) => ({ ...current, ...patch }));
const note = proposalNote(preview, draft);
const noteTitle = draft.noteTitle ?? planField(preview, 'title') ?? preview.subject;
useEffect(() => previewPlanEdit(tripId, toolCallId, draft), [draft, previewPlanEdit, toolCallId, tripId]);
useEffect(() => () => previewPlanEdit(tripId, toolCallId, null), [previewPlanEdit, toolCallId, tripId]);
const noteLabel = t('assistant.change.label.content');
const save = () => {
if (Object.keys(draft).length > 0) onEdit(draft);
onClose();
};
return (
}
eyebrow={t('common.edit')}
titleInput={{
label: t('assistant.change.label.title'),
value: noteTitle,
required: true,
maxLength: 500,
readOnly: disabled,
onChange: (noteTitle) => change({ noteTitle }),
}}
onClose={onClose}
/>
}
footer={
{t('common.cancel')}
}
onClick={save}
disabled={disabled || !noteTitle.trim()}
>
{t('common.save')}
}
>
);
}