import { useState } from 'react'; import { Grid, Table, Input, Select, Space, Typography, Tag, Button, Tooltip } from 'antd'; import { EyeOutlined } from '@ant-design/icons'; import type { TableColumnsType } from 'antd'; import type { ProdutoSummary } from '@sar/api-interface'; import { useCatalog, usePautas } from '../../lib/queries/catalog'; import { useCondicoesComerciais, type CondicaoComercial } from '../../lib/condicoes-comerciais'; import { CondicaoTag } from '../../components/CondicaoTag'; import { ProductDetailDrawer } from './ProductDetailDrawer'; const { useBreakpoint } = Grid; const { Title, Text } = Typography; const { Search } = Input; function fmtPrice(v: string | null | undefined): string { const n = Number(v ?? 0); return n > 0 ? n.toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }) : '—'; } function buildColumns( onDetail: (id: number) => void, condicoesDe: (p: ProdutoSummary) => CondicaoComercial[], ): TableColumnsType { return [ { title: 'Código', dataIndex: 'codigo', width: 110, render: (v: string) => {v.trim()}, }, { title: 'Descrição', dataIndex: 'descricao', render: (v: string, row: ProdutoSummary) => (
{v.trim()}
{row.grupo &&
{row.grupo.trim()}
}
), }, { title: 'Und', dataIndex: 'unidade', width: 60, align: 'center', render: (v: string | null) => v ?? '—', }, { title: 'Marca', dataIndex: 'marca', width: 130, render: (v: string | null) => (v ? {v.trim()} : null), }, { title: 'Preço', dataIndex: 'vlPreco1', width: 120, align: 'right', render: (v: string) => ( 0 ? '#389e0d' : '#999' }}> {fmtPrice(v)} ), }, { title: 'Estoque', dataIndex: 'qtdEstoque', width: 90, align: 'right', render: (v: string | null) => { if (v == null) return '—'; const n = Number(v); return ( 0 ? 'inherit' : '#f5222d' }}>{n.toLocaleString('pt-BR')} ); }, }, { title: '', key: 'actions', width: 48, align: 'center', render: (_: unknown, row: ProdutoSummary) => (