import { useRef, useState } from 'react'; import { Link, router } from '@inertiajs/react'; import { Frame, card, input, button } from './shared'; import { profileJson, ProfileValidationError } from '@/lib/profile-json'; import { createOperationKey } from '@/lib/operation-key'; import { preparationValues, type CompanyFacts, type Party, } from '@/lib/company-preparation'; type Review = { issues: string[]; totals: Record | null; note: string; }; type Props = { case: { id: string; title: string; version: number }; canWrite: boolean; historical: boolean; definition: { version: string; forms: Record; roles: Record; template_notice: string; source: { title: string; edition: string; url: string }; }; facts: CompanyFacts; review: Review; saved: { revision: number; at: string } | null; sources: Record< string, { name: string; kind: 'person' | 'entity'; origin: string } >; history: { id: string; revision: number; at: string }[]; historyNext: number | null; }; export default function CompanyPreparation(props: Props) { return ( ); } function Preparation(props: Props) { const [facts, setFacts] = useState(props.facts); const [busy, setBusy] = useState(false); const [error, setError] = useState(''); const [fields, setFields] = useState>({}); const [recovery, setRecovery] = useState(null); const [version, setVersion] = useState(props.case.version); const [dirty, setDirty] = useState(false); const form = useRef(null); const operation = useRef(createOperationKey()); const base = `/investimentos/${props.case.id}/preparar-empresa`; const readOnly = !props.canWrite || props.historical; const corporate = !!facts.form && facts.form !== 'individual'; const shares = ['anonymous', 'simplified'].includes(facts.form ?? ''); function update(key: keyof CompanyFacts, value: string) { setFacts((old) => ({ ...old, [key]: value || null })); } function party(id: string, changes: Partial) { setFacts((old) => ({ ...old, parties: old.parties.map((p) => p.id === id ? { ...p, ...changes } : p, ), })); } function text( key: Exclude, label: string, multiline = false, ) { return (