import React, { useEffect, useState } from 'react'; import { useParams, Link } from 'react-router-dom'; import { getAttendanceById, getUserById, getFunnels } from '../services/dataService'; import { Attendance, User, FunnelStage, FunnelStageDef } from '../types'; import { ArrowLeft, CheckCircle2, AlertCircle, Clock, Calendar, MessageSquare, ShoppingBag, Award, TrendingUp } from 'lucide-react'; export const AttendanceDetail: React.FC = () => { const { id } = useParams<{ id: string }>(); const [data, setData] = useState(); const [agent, setAgent] = useState(); const [funnelDefs, setFunnelDefs] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const loadData = async () => { if (id) { setLoading(true); try { const tenantId = localStorage.getItem('ctms_tenant_id') || ''; const [att, fDefs] = await Promise.all([ getAttendanceById(id), getFunnels(tenantId) ]); setData(att); setFunnelDefs(fDefs); if (att) { const u = await getUserById(att.user_id); setAgent(u); } } catch (error) { console.error("Error loading details", error); } finally { setLoading(false); } } }; loadData(); }, [id]); if (loading) return
Carregando detalhes...
; if (!data) return
Registro de atendimento não encontrado
; const getStageColor = (stage: string) => { const def = funnelDefs.find(f => f.name === stage); if (def) return def.color_class; switch (stage) { case FunnelStage.WON: return 'text-green-700 bg-green-50 border-green-200 dark:text-green-400 dark:bg-green-900/30 dark:border-green-800'; case FunnelStage.LOST: return 'text-red-700 bg-red-50 border-red-200 dark:text-red-400 dark:bg-red-900/30 dark:border-red-800'; default: return 'text-blue-700 bg-blue-50 border-blue-200 dark:text-blue-400 dark:bg-blue-900/30 dark:border-blue-800'; } }; const getScoreColor = (score: number) => { if (score >= 80) return 'text-green-500'; if (score >= 60) return 'text-yellow-500'; return 'text-red-500'; }; const backendUrl = import.meta.env.PROD ? '' : 'http://localhost:3001'; return (
{/* Top Nav & Context */}
Voltar para Histórico
ID: {data.id}
{/* Hero Header */}
{data.funnel_stage} {new Date(data.created_at).toLocaleString('pt-BR')} {data.origin}

{data.summary}

{agent && (
Agente: {agent.name}
)}
Nota de Qualidade
{data.score}
de 100
{/* Main Content Grid */}
{/* Left Column: Analysis */}
{/* Summary / Transcript Stub */}

Resumo da Interação

{data.summary} O cliente perguntou sobre detalhes específicos relacionados ao {data.product_requested}. As discussões envolveram níveis de preços, prazos de implementação e potenciais descontos por volume. A interação foi concluída com {data.converted ? 'uma venda realizada' : 'o cliente pedindo mais tempo para decidir'}.

{/* Feedback Section */}
{/* Points of Attention */}

Pontos de Atenção

{data.attention_points && data.attention_points.length > 0 ? (
    {data.attention_points.map((pt, idx) => (
  • {pt}
  • ))}
) : (

Nenhum problema detectado.

)}
{/* Points of Improvement */}

Dicas de Melhoria

{data.improvement_points && data.improvement_points.length > 0 ? (
    {data.improvement_points.map((pt, idx) => (
  • {pt}
  • ))}
) : (

Continue o bom trabalho!

)}
{/* Right Column: Metadata & Metrics */}

Métricas de Performance

Primeira Resposta
{data.first_response_time_min} min
Tempo Atendimento
{data.handling_time_min} min

Contexto de Vendas

Produto Solicitado
{data.product_requested}
Desfecho {data.converted ? (
Venda Fechada {data.product_sold && {data.product_sold}}
) : (
Não Convertido
)}
); };