import React, { useState, useEffect, useMemo } from "react"; import { Download, ArrowUpDown, ArrowUp, ArrowDown, AlertCircle, } from "lucide-react"; interface PhotographerPayment { id: string; data: string; nomeEvento: string; tipoEvento: string; empresa: string; valorRecebido: number; dataPagamento: string; statusPagamento: "Pago" | "Pendente" | "Atrasado"; } type SortField = keyof PhotographerPayment | null; type SortDirection = "asc" | "desc" | null; const PhotographerFinance: React.FC = () => { const [payments, setPayments] = useState([ { id: "1", data: "2025-11-15", nomeEvento: "Formatura Medicina UFPR 2025", tipoEvento: "Formatura", empresa: "PhotoPro Studio", valorRecebido: 1500.0, dataPagamento: "2025-11-20", statusPagamento: "Pago", }, { id: "2", data: "2025-11-18", nomeEvento: "Formatura Direito PUC-PR 2025", tipoEvento: "Formatura", empresa: "PhotoPro Studio", valorRecebido: 1200.0, dataPagamento: "2025-11-25", statusPagamento: "Pago", }, { id: "3", data: "2025-12-01", nomeEvento: "Formatura Engenharia UTFPR 2025", tipoEvento: "Formatura", empresa: "Lens & Art", valorRecebido: 1800.0, dataPagamento: "2025-12-15", statusPagamento: "Pendente", }, ]); const [sortField, setSortField] = useState(null); const [sortDirection, setSortDirection] = useState(null); const [apiError, setApiError] = useState(""); // Load API data useEffect(() => { loadApiData(); }, []); const loadApiData = async () => { try { // TODO: Implementar chamada real da API // const response = await fetch("http://localhost:3000/api/photographer/payments"); // const data = await response.json(); // setPayments(data); } catch (error) { console.error("Erro ao carregar pagamentos:", error); setApiError( "Não foi possível carregar os dados da API. Usando dados de exemplo." ); } }; // Sorting logic const handleSort = (field: keyof PhotographerPayment) => { if (sortField === field) { if (sortDirection === "asc") { setSortDirection("desc"); } else if (sortDirection === "desc") { setSortDirection(null); setSortField(null); } } else { setSortField(field); setSortDirection("asc"); } }; const getSortIcon = (field: keyof PhotographerPayment) => { if (sortField !== field) { return ( ); } if (sortDirection === "asc") { return ; } if (sortDirection === "desc") { return ; } return ( ); }; const sortedPayments = useMemo(() => { if (!sortField || !sortDirection) return payments; return [...payments].sort((a, b) => { const aValue = a[sortField]; const bValue = b[sortField]; if (aValue === null || aValue === undefined) return 1; if (bValue === null || bValue === undefined) return -1; let comparison = 0; if (typeof aValue === "string" && typeof bValue === "string") { comparison = aValue.localeCompare(bValue); } else if (typeof aValue === "number" && typeof bValue === "number") { comparison = aValue - bValue; } else if (typeof aValue === "boolean" && typeof bValue === "boolean") { comparison = aValue === bValue ? 0 : aValue ? 1 : -1; } return sortDirection === "asc" ? comparison : -comparison; }); }, [payments, sortField, sortDirection]); // Export to CSV const handleExport = () => { const headers = [ "Data Evento", "Nome Evento", "Tipo Evento", "Empresa", "Valor Recebido", "Data Pagamento", "Status", ]; const csvContent = [ headers.join(","), ...sortedPayments.map((p) => [ p.data, `"${p.nomeEvento}"`, p.tipoEvento, p.empresa, p.valorRecebido.toFixed(2), p.dataPagamento, p.statusPagamento, ].join(",") ), ].join("\n"); const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" }); const link = document.createElement("a"); const url = URL.createObjectURL(blob); link.setAttribute("href", url); link.setAttribute("download", `meus_pagamentos_${Date.now()}.csv`); link.style.visibility = "hidden"; document.body.appendChild(link); link.click(); document.body.removeChild(link); }; // Calculate totals const totalRecebido = sortedPayments.reduce( (sum, p) => sum + p.valorRecebido, 0 ); const totalPago = sortedPayments .filter((p) => p.statusPagamento === "Pago") .reduce((sum, p) => sum + p.valorRecebido, 0); const totalPendente = sortedPayments .filter((p) => p.statusPagamento === "Pendente") .reduce((sum, p) => sum + p.valorRecebido, 0); const getStatusBadge = (status: string) => { const statusColors = { Pago: "bg-green-100 text-green-800", Pendente: "bg-yellow-100 text-yellow-800", Atrasado: "bg-red-100 text-red-800", }; return ( {status} ); }; return (
{/* Header */}

Meus Pagamentos

Visualize todos os pagamentos recebidos pelos eventos fotografados

{/* Summary Cards */}

Total Recebido

R$ {totalRecebido.toFixed(2)}

Pagamentos Confirmados

R$ {totalPago.toFixed(2)}

Pagamentos Pendentes

R$ {totalPendente.toFixed(2)}

{/* Main Card */}
{/* Actions Bar */}

Histórico de Pagamentos

{apiError && (

Aviso

{apiError}

)} {/* Table */}
{sortedPayments.length === 0 ? ( ) : ( sortedPayments.map((payment) => ( )) )}
Nenhum pagamento encontrado
{new Date(payment.data).toLocaleDateString("pt-BR")} {payment.nomeEvento} {payment.tipoEvento} {payment.empresa} R$ {payment.valorRecebido.toFixed(2)} {new Date(payment.dataPagamento).toLocaleDateString( "pt-BR" )} {getStatusBadge(payment.statusPagamento)}
{/* Footer */}

Total de pagamentos: {sortedPayments.length}

); }; export default PhotographerFinance;