import { useEffect, useId } from 'react'; import CountrySelect, { type Country } from './country-select'; import { Field, input, button, card } from '@/pages/investment/shared'; import { useInvestmentProfileEditor, type OrganizationRecord, } from '@/lib/investment-profile-editor'; export default function OrganizationCountryEditor({ organization, countries, actorId, reportDirty, }: { organization: OrganizationRecord; countries: Country[]; actorId: number; reportDirty: (id: string, dirty: boolean) => void; }) { const fields = ['country', 'source_reference']; const editor = useInvestmentProfileEditor( { id: organization.id, version: organization.version, payload: { country: organization.country ?? '', source_reference: organization.provenance?.reference ?? '', }, }, fields, false, actorId, 'organization-' + organization.id, reportDirty, organization, ); const id = useId(), disabled = !editor.mayEdit || editor.busy || editor.uncertain || editor.blocked; useEffect(() => { if (Object.keys(editor.errors).length) document .getElementById(id) ?.querySelector('[aria-invalid="true"]') ?.focus(); }, [editor.errors, id]); return (

{organization.name}

Versão guardada: {organization.version}.{' '} {organization.provenance?.kind === 'representative_declaration' ? 'País declarado pelo representante.' : 'Fonte do país ainda não informada.'}

{!editor.mayEdit && (

Consulta do país de constituição. A sua representação actual não permite alterar esta informação.

)}
{ event.preventDefault(); void editor.save(); }} > editor.change('country', country) } />