import React, { useEffect, useState } from 'react'; import { motion } from 'framer-motion'; import { AlertCircle, CalendarDays, CheckCircle2, Users, X } from 'lucide-react'; import { fetchOrganizationInsights } from '../../api/sysadmin'; import type { OrganizationInsights } from '../../api/sysadmin'; interface OrganizationInsightsModalProps { company: any; onClose: () => void; } const formatDate = (value?: string) => { if (!value) return '-'; return new Intl.DateTimeFormat('es-AR', { dateStyle: 'medium' }).format(new Date(value)); }; const fullName = (owner: OrganizationInsights['owner']) => { if (!owner) return '-'; return [owner.firstName, owner.lastName].filter(Boolean).join(' ') || owner.email || '-'; }; const phone = (owner: OrganizationInsights['owner']) => { if (!owner) return '-'; return [owner.phoneCountryCode, owner.phoneAreaCode, owner.phoneNumber].filter(Boolean).join(' ') || '-'; }; const collaboratorName = (collaborator: OrganizationInsights['collaborators'][number]) => { return collaborator.fullName || [collaborator.firstName, collaborator.lastName].filter(Boolean).join(' ') || collaborator.email || collaborator.userId || '-'; }; const StatCard = ({ label, value }: { label: string; value: number }) => (
{label}
{value}
); export const OrganizationInsightsModal: React.FC = ({ company, onClose }) => { const [insights, setInsights] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); useEffect(() => { const loadInsights = async () => { setLoading(true); setError(''); try { const result = await fetchOrganizationInsights(company.id || company._id); setInsights(result); } catch (e) { console.error(e); setError('No se pudo cargar el detalle de la organización.'); } finally { setLoading(false); } }; loadInsights(); }, [company]); return (

Detalle de {company.name}

Vista de solo lectura para SysAdmin.

{loading ? (
Cargando detalle...
) : error ? (
{error}
) : !insights ? (
No hay información disponible.
) : (

Organización

Nombre: {insights.organization.name}

Slug: {insights.organization.slug || '-'}

Estado: {insights.organization.banned ? 'Baneada' : 'Activa'}

Publicación: {insights.organization.published || '-'}

Onboarding: {insights.organization.onboardingCompleted ? 'Completo' : `Paso ${insights.organization.onboardingStep || 0}`}

Dueño

Nombre: {fullName(insights.owner)}

Email: {insights.owner?.email || '-'}

Teléfono: {phone(insights.owner)}

Verificado: {insights.owner?.verificated ? 'Sí' : 'No'}

Plan

{insights.subscription ? ( <>

Plan: {insights.subscription.plan?.name || 'Sin plan asociado'}

Código: {insights.subscription.plan?.code || '-'}

Estado: {insights.subscription.mpStatus || (insights.subscription.isActive ? 'active' : 'inactive')}

Inicio: {formatDate(insights.subscription.startDate)}

Fin: {formatDate(insights.subscription.endDate)}

) : (

No se encontró suscripción.

)}

Colaboradores

{insights.collaborators.length === 0 ? (

No hay colaboradores asociados.

) : (
{insights.collaborators.map((collaborator) => (
{collaborator.avatar ? : collaboratorName(collaborator).charAt(0).toUpperCase()}
{collaboratorName(collaborator)}
{collaborator.email || 'Sin email disponible'}
Roles: {collaborator.roles?.join(', ') || '-'}
{collaborator.active ? 'Activo' : 'Removido'}
))}
)}
)}
); };