// RepresentantesLegales.tsx // Uso en FastCheck: // // import RepresentantesLegales from '../components/ui/RepresentantesLegales/RepresentantesLegales'; // // const normalizeRut = (rut: string | number): string => { if (rut == null) return ''; return String(rut).replace(/\./g, '').split('-')[0].trim(); }; const isSociedad = (rut: string): boolean => { const n = parseInt(normalizeRut(rut), 10); return !isNaN(n) && n >= 25_000_000; }; const mapSource = (src: string): string => ({ SII_REP: 'SII', SII: 'SII', SII_REC_COM: 'SII', RES: 'DO', DO: 'DO', DOH: 'DOH', DIARIO_OFICIAL: 'DO' } as Record)[src] ?? src ?? '--'; const detectMainRut = (relationships: any[]): string => { const freq: Record = {}; for (const r of relationships) { const s = normalizeRut(String(r.source || '')); if (s) freq[s] = (freq[s] || 0) + 1; } return Object.entries(freq).sort((a, b) => b[1] - a[1])[0]?.[0] ?? ''; }; interface RepresentantesLegalesProps { dequienesRelationships: any; mainRut: string; } const Legalrepresentatives = ({ dequienesRelationships, mainRut }: RepresentantesLegalesProps) => { //console.log(dequienesRelationships,"quieeeeeeeeeeeeeeeeeeeeeeeeee") if (!dequienesRelationships) return null; const { relationships = [], entityNames = {} } = dequienesRelationships; if (!relationships.length) return null; const cleanMain = normalizeRut(mainRut || '') || detectMainRut(relationships); const getName = (rut: string) => entityNames[rut] || entityNames[normalizeRut(rut)] || ''; const rootIsPerson = !isSociedad(cleanMain); const repRels = relationships.filter((r: any) => r.label === 'REPRESENTED_BY'); if (!repRels.length) return null; // Solo los representantes directos de la entidad consultada const reps = repRels .filter((r: any) => normalizeRut(String(r.source)) === cleanMain) .map((r: any) => ({ rut: normalizeRut(String(r.target || '')), name: getName(normalizeRut(String(r.target || ''))), fuente: mapSource(r.information_source?.source || ''), fecha: r.information_source?.started_at || r.information_source?.published_at || '', })); if (!reps.length) return null; const thStyle: React.CSSProperties = { border: '1px solid #e5e7eb', padding: '6px 8px', textAlign: 'left', fontWeight: 600, color: '#374151', backgroundColor: '#f3f4f6', wordBreak: 'break-word', }; const tdStyle: React.CSSProperties = { border: '1px solid #e5e7eb', padding: '6px 8px', fontSize: '13px', verticalAlign: 'middle', wordBreak: 'break-word', }; const EntityCell = ({ rut, name, color }: { rut: string; name: string; color: string }) => (
{rut} {name}
); const formatFecha = (fecha: string) => fecha ? fecha.split('-').reverse().join('-') : '--'; return (

Representantes Legales ({reps.length})

{rootIsPerson && } {rootIsPerson && } {reps.map((rep, idx) => ( {rootIsPerson && ( )} ))}
EmpresaRepresentante Fuente Desde
{rep.fuente} {formatFecha(rep.fecha)}
); }; export default Legalrepresentatives;