import { Link, router, useForm } from '@inertiajs/react'; import InvestmentTerritory from '@/components/investment-territory'; import InvestmentMapPanel from '@/components/investment-map-panel'; import { TerritoryFields, type TerritoryOption, } from '@/components/investment-territory'; import { useState } from 'react'; import { Frame, Field, input, button, card, api } from './shared'; import PartnershipSourceLinks from '@/components/partnership-source-links'; import ZoneRelations from './zone-relations'; import ZoneMap from './zone-map'; import ZoneAttachments from './zone-attachments'; import type { ZoneTargets } from './zone-relations'; type Zone = { id: string; version_no: number; code: string; category: string; name: string; name_en: string | null; description: string | null; description_en: string | null; province: string | null; district: string | null; operator_id?: string; legal_source_id?: string; publication_status?: string; validation_status: string; physical_category?: string | null; legal_regime?: string | null; operational_status?: string; development_status?: string; availability_status?: string; area_value?: string | null; area_unit?: string | null; area_components?: unknown[]; source_evidence?: { title: string; url: string; source_type: string; supports: string; source_date?: string | null; }[]; aliases?: string[]; activities?: { name: string; status: string; source_reference?: string | null; }[]; resources?: { name: string; status: string; source_reference?: string | null; }[]; historical_territory?: { name: string; district?: string; province?: string; source_reference?: string; } | null; }; type Source = { id: string; title: string; url: string; diploma: string; article: string; competent_entity: string; valid_from: string; valid_until: string | null; version_no: number; validation_status: string; }; type ZoneEditorForm = { version_no: number; code: string; category: string; physical_category: string; legal_regime: string; operational_status: string; development_status: string; availability_status: string; area_value: string; area_unit: string; area_components_json: string; source_evidence_json: string; activities: { name: string; status: string; source_reference: string | null; }[]; resources: { name: string; status: string; source_reference: string | null; }[]; aliases_text: string; historical_name: string; historical_district: string; historical_province: string; historical_source_reference: string; name: string; name_en: string; description: string; description_en: string; operator_id: string; legal_source_id: string; }; type Props = { targets: ZoneTargets | null; related: { id: string; title: string }[]; relations: { id: string; version_no: number; association_type: string; validation_status: string; }[]; geometries: { id: string; version_no: number; purpose: string; validation_status: string; }[]; record: Zone; management: boolean; zoneExtensionsAvailable?: boolean; source: Source | null; operator: string | null; operators: { id: string; name: string }[]; legalSources: Source[]; links: { id: string; item_id: string; association_type: string; validation_status: string; version_no: number; }[]; revisions: { version_no: number; action: string; created_at: string }[]; locations: { id: string; name: string; location_type: string; scope_type: string; source_reference: string; validation_status: string; }[]; attachments: { id: string; kind: string; caption: string; source_reference: string; source_date: string | null; rights_status?: string; rights_basis?: string | null; personal_data_status?: string; review_status?: string; reviewed_by?: number | null; independent_review?: boolean; publicly_selected?: boolean; uploaded_by?: number; version_no?: number; file_name?: string; media_type: string; size_bytes: number | null; download_url: string; }[]; opportunities: { data: { id: number; title: string; slug: string }[]; next_page_url: string | null; prev_page_url: string | null; } | null; }; export default function ZonePage(props: Props) { return ( ); } function Editor({ targets, related, relations, geometries, record: z, management, zoneExtensionsAvailable = false, source, operator, operators, legalSources, links, revisions, locations, attachments, opportunities, }: Props) { const [message, setMessage] = useState(''); const [busy, setBusy] = useState(false); const [locationPath, setLocationPath] = useState([]); const [locationSource, setLocationSource] = useState(''); const [locationScope, setLocationScope] = useState('administrative'); const [activityName, setActivityName] = useState(''); const [activityStatus, setActivityStatus] = useState('potential'); const [activitySource, setActivitySource] = useState(''); const [resourceName, setResourceName] = useState(''); const [resourceStatus, setResourceStatus] = useState('unconfirmed'); const [resourceSource, setResourceSource] = useState(''); const [_attachmentFile, _setAttachmentFile] = useState(null); const [_attachmentKind, _setAttachmentKind] = useState('legal_instrument'); const [_attachmentCaption, _setAttachmentCaption] = useState(''); const [_attachmentSource, _setAttachmentSource] = useState(''); const [_attachmentSourceDate, _setAttachmentSourceDate] = useState(''); const [_attachmentRightsBasis, _setAttachmentRightsBasis] = useState(''); const [_attachmentRightsStatus, _setAttachmentRightsStatus] = useState('pending'); const [_reviewChoices, _setReviewChoices] = useState< Record >({}); const form = useForm({ version_no: z.version_no, code: z.code, category: z.category, physical_category: z.physical_category ?? 'unknown', legal_regime: z.legal_regime ?? 'pending', operational_status: z.operational_status ?? 'unknown', development_status: z.development_status ?? 'unknown', availability_status: z.availability_status ?? 'not_informed', area_value: z.area_value ?? '', area_unit: z.area_unit ?? '', area_components_json: JSON.stringify(z.area_components ?? [], null, 2), source_evidence_json: JSON.stringify(z.source_evidence ?? [], null, 2), activities: (z.activities ?? []).map((activity) => ({ ...activity, source_reference: activity.source_reference ?? null, })), resources: (z.resources ?? []).map((resource) => ({ ...resource, source_reference: resource.source_reference ?? null, })), aliases_text: (z.aliases ?? []).join('\n'), historical_name: z.historical_territory?.name ?? '', historical_district: z.historical_territory?.district ?? '', historical_province: z.historical_territory?.province ?? '', historical_source_reference: z.historical_territory?.source_reference ?? '', name: z.name, name_en: z.name_en ?? '', description: z.description ?? '', description_en: z.description_en ?? '', operator_id: z.operator_id ?? '', legal_source_id: z.legal_source_id ?? '', }); async function action(url: string, data: unknown) { setBusy(true); setMessage(''); try { await api(url, data); router.reload(); } catch (e) { setMessage(e instanceof Error ? e.message : 'Falha na operação.'); } finally { setBusy(false); } } return ( {!management && }

{z.code} · {z.category.toUpperCase()} · {z.validation_status} ·{' '} {z.province} {z.district}

A ficha é informativa. A associação territorial não atribui benefícios, licenças ou autorização aduaneira.

{message && (

{message}

)} {management ? ( <>
{ e.preventDefault(); setBusy(true); setMessage(''); try { const { area_components_json, source_evidence_json, ...base } = form.data; await api( `/api/v2/investment/admin/zones/${z.id}`, { ...base, area_components: JSON.parse(area_components_json), source_evidence: JSON.parse(source_evidence_json), _method: 'PUT', }, ); router.reload(); } catch (failure) { setMessage( failure instanceof Error ? failure.message : 'Falha ao guardar.', ); } finally { setBusy(false); } }} > {( [ ['code', 'Código'], ['name', 'Nome PT'], ['name_en', 'Nome EN'], ] as const ).map(([key, label]) => ( form.setData(key, e.target.value) } /> ))} {zoneExtensionsAvailable && ( )} {zoneExtensionsAvailable && ( )} form.setData('area_value', e.target.value) } /> {zoneExtensionsAvailable && (