import { publicReference, uniquePresentation } from '@/lib/public-presentation'; import PublicReference from './public-reference'; import { usePage } from '@inertiajs/react'; import EvidenceDetails from './evidence-details'; export type TerritorialSourceEvidence = { association: string; role: string; source_reference: string | null; source_quote: string | null; supports: string; traceability: string; official_source_accepted: boolean; existing_validation: string | null; }; export default function TerritorialSources({ sources, }: { sources?: TerritorialSourceEvidence[]; }) { const management = usePage().url.startsWith('/management/'); const visible = uniquePresentation( (sources ?? []).filter( (row) => management || publicReference(row.source_reference) || publicReference(row.source_quote) || publicReference(row.supports), ), (row) => JSON.stringify([ row.association, row.role, management ? row.source_reference : publicReference(row.source_reference), publicReference(row.source_quote), publicReference(row.supports), ...(management ? [row.traceability] : []), ]), ); if (!visible.length) return null; return ( {visible.map((source, i) => (

{source.role} — {source.association}

{(management || publicReference(source.source_reference)) && (

Fonte:{' '} {management ? ( source.source_reference ) : ( )}

)} {(publicReference(source.source_quote) || publicReference(source.supports)) && (

{publicReference(source.source_quote) || publicReference(source.supports)}

)}

{source.official_source_accepted ? 'Fonte oficial identificada.' : 'Ligação ao exemplar oficial por recuperar.'}

{(management || publicReference(source.traceability)) && (

{source.traceability}

)} {(management ? source.existing_validation : publicReference(source.existing_validation)) && (

{source.existing_validation}

)}
))}
); }