import { inputText } from '../../lib/input-text.ts'; import { Link, router, useForm } from '@inertiajs/react'; import { useEffect, useState } from 'react'; import { Frame, card, button } from '@/pages/investment/shared'; import { Field, control, labels, acts, NoticeContent, type Draft, type Lot, type Attachment, type Payload, } from './shared'; type Choice = { id: string | number; name?: string; title?: string; location_type?: string; published?: boolean; malware_scan_status?: string; }; type References = { regimes: Record; acts: Record; organizations: Choice[]; sectors: Choice[]; territories: Choice[]; opportunities: Choice[]; projects: Choice[]; documents: Choice[]; }; type RecordData = { id: string; version: number; draft: Draft; published: boolean; }; type Plan = { id: string; version: number; act: string; payload: Payload; hash: string; }; const dates = [ 'origin_published_at', 'clarifications_at', 'deadline', 'opening_at', ]; const groups: [string, string[]][] = [ [ 'Identificação e objecto', ['title', 'reference', 'modality', 'object', 'quantities'], ], [ 'Regime e financiamento', [ 'financier', 'instrument', 'edition', 'rule_source', 'financing_agreement', ], ], ['Participação', ['eligibility', 'requirements', 'proposal_validity']], [ 'Calendário e entrega', [ 'origin_published_at', 'clarifications_at', 'deadline', 'opening_at', 'delivery_channel', 'delivery_address', 'delivery_url', ], ], ['Divulgação e contacto', ['origin_url', 'dissemination']], ]; export default function Edit({ record, references, history, }: { record: RecordData | null; references: References; history: { version: number; act: string; reason: string; actor_id: number; published_at: string | null; created_at: string; }[]; }) { const empty: Draft = { timezone: 'Africa/Maputo', lots: [], attachments: [], contact_authorized: false, }; const form = useForm({ version: record?.version ?? 0, reason: '', draft: record?.draft ?? empty, }); const [act, setAct] = useState( record?.published ? 'clarification' : 'initial', ); const [preview, setPreview] = useState(null); const [message, setMessage] = useState(''); const [busy, setBusy] = useState(false); const [saved, setSaved] = useState(true); useEffect(() => { form.setData({ version: record?.version ?? 0, reason: '', draft: record?.draft ?? empty, }); setPreview(null); setSaved(true); }, [record?.id, record?.version]); // A server version is the recovery boundary. const change = (key: string, value: Draft[string]) => { form.setData('draft', { ...form.data.draft, [key]: value }); setPreview(null); setSaved(false); }; const value = (key: string) => inputText(form.data.draft[key] ?? ''); const select = (key: string, label: string, choices: Choice[]) => ( ); const input = (key: string, label?: string) => ( {dates.includes(key) ? ( change(key, e.target.value)} /> ) : (