import React, { useState, useEffect } from "react"; import { useAuth } from "../contexts/AuthContext"; import { getProfessionalFinancialStatement } from "../services/apiService"; import { formatCurrency } from "../utils/format"; interface FinancialTransactionDTO { id: string; data_evento: string; nome_evento: string; tipo_evento: string; empresa: string; valor_recebido: number; valor_free?: number; // Optional as backend might not have sent it yet if cache/delays valor_extra?: number; descricao_extra?: string; data_pagamento: string; status: string; } interface FinancialStatementResponse { total_recebido: number; pagamentos_confirmados: number; pagamentos_pendentes: number; transactions: FinancialTransactionDTO[]; } const ProfessionalStatement: React.FC = () => { const { user, token } = useAuth(); const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [selectedTransaction, setSelectedTransaction] = useState(null); const [isModalOpen, setIsModalOpen] = useState(false); useEffect(() => { if (token) { fetchStatement(); } else { const storedToken = localStorage.getItem("@Auth:token"); if (storedToken) { fetchStatement(storedToken); } else { console.error("No token found"); setLoading(false); } } }, [token]); const fetchStatement = async (overrideToken?: string) => { try { const t = overrideToken || token; if (!t) return; const response = await getProfessionalFinancialStatement(t); if (response.data) { setData(response.data); } else { console.error(response.error); } } catch (error) { console.error("Erro ao buscar extrato:", error); } finally { setLoading(false); } }; const handleRowClick = (t: FinancialTransactionDTO) => { setSelectedTransaction(t); setIsModalOpen(true); }; const StatusBadge = ({ status }: { status: string }) => { const isPaid = status === "Pago"; return ( {status} ); }; if (loading) { return
Carregando extrato...
; } if (!data) { return
Nenhum dado encontrado.
; } return (

Meus Pagamentos

Visualize todos os pagamentos recebidos pelos eventos fotografados

{/* Summary Cards */}

Total Recebido

{formatCurrency(data.total_recebido)}

Pagamentos Confirmados

{formatCurrency(data.pagamentos_confirmados)}

Pagamentos Pendentes

{formatCurrency(data.pagamentos_pendentes)}

{/* Transactions Table */}

Histórico de Pagamentos

{(data.transactions || []).length === 0 ? ( ) : ( (data.transactions || []).map((t) => ( handleRowClick(t)} > )) )}
Data Evento Nome Evento Tipo Evento Empresa Valor Recebido Data Pagamento Status
Nenhum pagamento registrado.
{t.data_evento} {t.nome_evento} {t.tipo_evento} {t.empresa} {formatCurrency(t.valor_recebido)} {t.data_pagamento}
Total de pagamentos: {(data.transactions || []).length}
{/* Details Modal */} {isModalOpen && selectedTransaction && (

Detalhes do Pagamento

{/* Header Info */}

Evento

{selectedTransaction.nome_evento}

{selectedTransaction.empresa} • {selectedTransaction.data_evento}

{/* Financial Breakdown */}
Valor Base (Free) {formatCurrency(selectedTransaction.valor_free || 0)}
{(selectedTransaction.valor_extra || 0) > 0 && (
Valor Extra {formatCurrency(selectedTransaction.valor_extra || 0)}
)} {/* Divider */}
Total Recebido {formatCurrency(selectedTransaction.valor_recebido)}
{/* Extra Description */} {(selectedTransaction.descricao_extra) && (

Descrição do Extra

{selectedTransaction.descricao_extra}
)} {/* Status Footer */}
Data do Pagamento
{selectedTransaction.data_pagamento}
)}
); }; export default ProfessionalStatement;