import { useState } from 'react'; import { App, Button, Card, Col, DatePicker, Modal, Input, Row, Space, Spin, Table, Tag, Tooltip, Typography, } from 'antd'; import type { TableColumnsType } from 'antd'; import type { Dayjs } from 'dayjs'; import { CopyOutlined, EyeOutlined, FileTextOutlined, SearchOutlined, ClearOutlined, ShoppingCartOutlined, } from '@ant-design/icons'; import type { PedidoErpConsultaItem } from '@sar/api-interface'; import { useOrderErpConsulta, useOrderDetail } from '../../lib/queries/orders'; const { RangePicker } = DatePicker; const { Title, Text } = Typography; function fmt(v: number | string) { return Number(v).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }); } function fmtDate(v: string | null | undefined) { if (!v) return '—'; return new Date(v).toLocaleDateString('pt-BR'); } // Status para registros tipo='E' (sig.pedidos entregas) const SIG_STATUS_ENTREGA: Record = { 1: { label: 'Pendente', color: 'orange' }, 2: { label: 'Liberado', color: 'green' }, 3: { label: 'Emitido', color: 'geekblue' }, 5: { label: 'Cancelado', color: 'red' }, }; function statusTag(row: PedidoErpConsultaItem) { const cfg = row.tipo === 'E' ? SIG_STATUS_ENTREGA[row.situa] : undefined; const label = row.statusDescr ?? cfg?.label ?? String(row.situa); return ( {label} ); } // ─── Modal de detalhes ──────────────────────────────────────────────────────── function ErpConsultaModal({ row, onClose, }: { row: PedidoErpConsultaItem | null; onClose: () => void; }) { const { data: detail, isLoading } = useOrderDetail( row?.idPedido ? `erp-${row.idPedido}` : undefined, ); const { message: msg } = App.useApp(); const label: React.CSSProperties = { fontSize: 11, fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', color: '#94A3B8', marginBottom: 2, display: 'block', }; return ( Pedido {row.numeroPedido} {row.tipo === 'P' ? 'Pedido' : 'Entrega'} {row && statusTag(row)} ) : ( 'Detalhes' ) } open={!!row} onCancel={onClose} centered width={860} destroyOnHidden styles={{ body: { padding: '20px 24px', maxHeight: 'calc(85vh - 110px)', overflowY: 'auto' }, }} footer={} > {!row ? null : ( {/* ── Cabeçalho ── */} Cliente {row.razaoCliente ?? row.nomeCliente ?? `Cód. ${row.idCliente}`} {row.nomeCliente && row.razaoCliente && ( {row.nomeCliente} )} Data {fmtDate(row.data)} {row.dtPrevent && ( Prev. Entrega {fmtDate(row.dtPrevent)} )} Forma Pagto. {row.formaPagamento ?? '—'} Total {fmt(row.total)} {row.numPedSar && ( Nº SAR {row.numPedSar} )} {row.obs && ( Observações {row.obs} )} {/* ── Dados de Entrega / NF (só tipo E) ── */} {row.tipo === 'E' && ( Nº Entrega {row.numeroEntrega ?? '—'} {row.dataEmissao && ( Data Emissão {fmtDate(row.dataEmissao)} )} {row.numeroNf && ( NF {row.numeroNf} )} {row.chaveAcessoNfe && ( Chave NF-e {row.chaveAcessoNfe}