import { T as reactExports, K as jsxRuntimeExports } from "./server-ChzsfjB9.js";
import { a as AppLayout, C as Card, f as CardContent, P as Package, U as Users, x as Skeleton } from "./card-HyNxoILF.js";
import { e as createLucideIcon, I as Input, B as Button, a as cn } from "./input-muzHTpl5.js";
import { L as Label } from "./label-2bHC70jG.js";
import { S as Select, c as SelectTrigger, d as SelectValue, a as SelectContent, b as SelectItem } from "./select-YkkkCruU.js";
import { B as Badge } from "./badge-DHuXnmRX.js";
import { u as useCurrentCliente, l as useCurrentClienteId, g as formatDateBR, L as LoadingOverlay, i as formatDateToSQL, a as executeClienteQuery, e as executeClienteBatchQuery, t as toNum, C as ClienteDbStatus, T as TriangleAlert, f as formatBRL, k as formatPercent, j as formatNumber, c as exportChartToPDF, b as exportChartToExcel } from "./exporters-Br36eL2f.js";
import { C as ChartCard } from "./ChartCard-C25D4EJU.js";
import { L as Layers } from "./layers-CNNG_TMf.js";
import { S as SquareUserRound } from "./square-user-round-DET6Zr_F.js";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
import "./router-uu4vGjiO.js";
import "./index-BxBx9O65.js";
import "./index-CZazwQDH.js";
import "./lock-0me_4kb9.js";
import "./sheet-CpXgBl29.js";
const __iconNode = [
  [
    "path",
    {
      d: "M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",
      key: "vktsd0"
    }
  ],
  ["circle", { cx: "7.5", cy: "7.5", r: ".5", fill: "currentColor", key: "kqv944" }]
];
const Tag = createLucideIcon("tag", __iconNode);
const today = () => formatDateToSQL(/* @__PURE__ */ new Date());
const firstOfMonth = () => {
  const d = /* @__PURE__ */ new Date();
  return formatDateToSQL(new Date(d.getFullYear(), d.getMonth(), 1));
};
const emptySection = {
  rows: [],
  loading: false,
  error: null
};
function Page() {
  const cliente = useCurrentCliente();
  const clienteId = useCurrentClienteId();
  const [dataIni, setDataIni] = reactExports.useState(firstOfMonth());
  const [dataFim, setDataFim] = reactExports.useState(today());
  const [loja, setLoja] = reactExports.useState("__all__");
  const [lojas, setLojas] = reactExports.useState([]);
  const [loading, setLoading] = reactExports.useState(false);
  const [produtos, setProdutos] = reactExports.useState(emptySection);
  const [clientes, setClientes] = reactExports.useState(emptySection);
  const [grupos, setGrupos] = reactExports.useState(emptySection);
  const [marcas, setMarcas] = reactExports.useState(emptySection);
  const [vendedores, setVendedores] = reactExports.useState(emptySection);
  const lastLoadKeyRef = reactExports.useRef("");
  const params = reactExports.useMemo(() => ({
    data_ini: dataIni,
    data_fim: dataFim,
    loja: loja === "__all__" ? null : Number(loja) || loja,
    limit: 100
  }), [dataIni, dataFim, loja]);
  const lojaNome = reactExports.useMemo(() => {
    if (loja === "__all__") return "Todas as lojas";
    return lojas.find((l) => String(l.id) === String(loja))?.nome ?? `Loja ${loja}`;
  }, [loja, lojas]);
  const reportSubtitle = reactExports.useMemo(() => `Período: ${formatDateBR(dataIni)} a ${formatDateBR(dataFim)}  •  Loja: ${lojaNome}${cliente ? `  •  Cliente: ${cliente.fantasyName}` : ""}`, [dataIni, dataFim, lojaNome, cliente]);
  async function carregar() {
    if (!clienteId) {
      const error = {
        code: "NO_ACTIVE_CLIENT",
        message: "Nenhum cliente ativo selecionado."
      };
      setProdutos({
        rows: [],
        loading: false,
        error
      });
      setClientes({
        rows: [],
        loading: false,
        error
      });
      setGrupos({
        rows: [],
        loading: false,
        error
      });
      setMarcas({
        rows: [],
        loading: false,
        error
      });
      setVendedores({
        rows: [],
        loading: false,
        error
      });
      return;
    }
    setLoading(true);
    setProdutos({
      ...emptySection,
      loading: true
    });
    setClientes({
      ...emptySection,
      loading: true
    });
    setGrupos({
      ...emptySection,
      loading: true
    });
    setMarcas({
      ...emptySection,
      loading: true
    });
    setVendedores({
      ...emptySection,
      loading: true
    });
    try {
      if (lojas.length === 0) {
        const r = await executeClienteQuery("ranking.lojas", {}, clienteId);
        if (r.code === "OK") setLojas(r.rows);
      }
      const steps = [{
        key: "abc.produtos",
        setter: setProdutos
      }, {
        key: "abc.clientes",
        setter: setClientes
      }, {
        key: "abc.grupos",
        setter: setGrupos
      }, {
        key: "abc.marcas",
        setter: setMarcas
      }, {
        key: "abc.vendedores",
        setter: setVendedores
      }];
      const batch = await executeClienteBatchQuery(steps.map(({
        key
      }) => ({
        key,
        params
      })), clienteId);
      for (const {
        key,
        setter
      } of steps) {
        const r = batch.results[key];
        if (!r || r.code !== "OK") {
          setter({
            rows: [],
            loading: false,
            error: {
              code: r?.code ?? "INTERNAL",
              message: r?.message || `Falha em ${key}`
            }
          });
        } else if ((r.rows ?? []).length === 0) {
          setter({
            rows: [],
            loading: false,
            error: {
              code: "QUERY_FAIL",
              message: `${key}: retornou 0 linhas para o período selecionado.`
            }
          });
        } else {
          setter({
            rows: r.rows.map((row) => ({
              ...row,
              ranking: toNum(row.ranking),
              qtde: toNum(row.qtde),
              total: toNum(row.total),
              perc: toNum(row.perc),
              perc_acum: toNum(row.perc_acum)
            })),
            loading: false,
            error: null
          });
        }
      }
    } catch (e) {
      const error = {
        code: "INTERNAL",
        message: e instanceof Error ? e.message : "Erro inesperado"
      };
      setProdutos({
        rows: [],
        loading: false,
        error
      });
      setClientes({
        rows: [],
        loading: false,
        error
      });
      setGrupos({
        rows: [],
        loading: false,
        error
      });
      setMarcas({
        rows: [],
        loading: false,
        error
      });
      setVendedores({
        rows: [],
        loading: false,
        error
      });
    } finally {
      setLoading(false);
    }
  }
  reactExports.useEffect(() => {
    if (!clienteId) {
      lastLoadKeyRef.current = "";
      const error = {
        code: "NO_ACTIVE_CLIENT",
        message: "Nenhum cliente ativo selecionado."
      };
      setProdutos({
        rows: [],
        loading: false,
        error
      });
      setClientes({
        rows: [],
        loading: false,
        error
      });
      setGrupos({
        rows: [],
        loading: false,
        error
      });
      setMarcas({
        rows: [],
        loading: false,
        error
      });
      setVendedores({
        rows: [],
        loading: false,
        error
      });
      return;
    }
    const loadKey = JSON.stringify({
      clienteId,
      dataIni,
      dataFim,
      loja
    });
    if (lastLoadKeyRef.current === loadKey) return;
    const t = setTimeout(() => {
      lastLoadKeyRef.current = loadKey;
      carregar();
    }, 300);
    return () => clearTimeout(t);
  }, [clienteId, dataIni, dataFim, loja]);
  reactExports.useEffect(() => {
    if (lojas.length === 1 && loja === "__all__") setLoja(String(lojas[0].id));
  }, [lojas, loja]);
  return /* @__PURE__ */ jsxRuntimeExports.jsx(AppLayout, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative space-y-6", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(LoadingOverlay, { show: loading, title: "Carregando Curva ABC...", subtitle: "Aguarde, estamos processando os dados." }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap items-end justify-between gap-3", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "text-2xl font-bold tracking-tight", children: "Curva ABC" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground", children: "Análise de classificação ABC baseada no faturamento acumulado." }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground mt-1", children: cliente ? `Cliente: ${cliente.fantasyName}` : "Selecione um cliente ativo" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-wrap items-end gap-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { className: "text-xs", children: "De" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { type: "date", value: dataIni, onChange: (e) => setDataIni(e.target.value), className: "h-9 w-[150px]" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { className: "text-xs", children: "Até" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Input, { type: "date", value: dataFim, onChange: (e) => setDataFim(e.target.value), className: "h-9 w-[150px]" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { className: "text-xs", children: "Loja" }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs(Select, { value: loja, onValueChange: setLoja, children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(SelectTrigger, { className: "h-9 w-[200px]", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SelectValue, { placeholder: "Todas as lojas" }) }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs(SelectContent, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(SelectItem, { value: "__all__", children: "Todas as lojas" }),
              lojas.map((l) => /* @__PURE__ */ jsxRuntimeExports.jsx(SelectItem, { value: String(l.id), children: l.nome }, String(l.id)))
            ] })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { size: "sm", className: "h-9", onClick: () => {
          lastLoadKeyRef.current = "";
          carregar();
        }, disabled: loading, children: loading ? "Carregando…" : "Aplicar" })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Card, { className: "border-border/60", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(CardContent, { className: "py-3 px-4 flex flex-wrap items-center gap-4 text-xs", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-semibold text-muted-foreground", children: "Classificação:" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(AbcBadge, { cls: "A" }),
      " ",
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: "até 80% acumulado" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(AbcBadge, { cls: "B" }),
      " ",
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: "80% até 95%" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(AbcBadge, { cls: "C" }),
      " ",
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: "acima de 95%" })
    ] }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(AbcSection, { title: "Curva ABC — Produtos Mais Vendidos", subtitle: "Classificação dos produtos por faturamento acumulado.", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Package, { className: "h-4 w-4 text-primary" }), state: produtos, reportSubtitle, fileBase: "abc-produtos", kind: "produtos" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(AbcSection, { title: "Curva ABC — Clientes", subtitle: "Classificação dos clientes por faturamento acumulado.", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Users, { className: "h-4 w-4 text-primary" }), state: clientes, reportSubtitle, fileBase: "abc-clientes", kind: "clientes" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(AbcSection, { title: "Curva ABC — Grupos", subtitle: "Classificação dos grupos de produtos por faturamento acumulado.", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Layers, { className: "h-4 w-4 text-primary" }), state: grupos, reportSubtitle, fileBase: "abc-grupos", kind: "grupos" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(AbcSection, { title: "Curva ABC — Marcas", subtitle: "Classificação das marcas por faturamento acumulado.", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(Tag, { className: "h-4 w-4 text-primary" }), state: marcas, reportSubtitle, fileBase: "abc-marcas", kind: "marcas" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(AbcSection, { title: "Curva ABC — Vendedores", subtitle: "Classificação dos vendedores por faturamento acumulado.", icon: /* @__PURE__ */ jsxRuntimeExports.jsx(SquareUserRound, { className: "h-4 w-4 text-primary" }), state: vendedores, reportSubtitle, fileBase: "abc-vendedores", kind: "vendedores" })
  ] }) });
}
function AbcBadge({
  cls
}) {
  const map = {
    A: "bg-success/15 text-success border-success/30",
    B: "bg-warning/15 text-warning border-warning/30",
    C: "bg-muted text-muted-foreground border-border"
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Badge, { variant: "outline", className: cn("font-bold tracking-wide", map[cls]), children: cls });
}
function rowTint(abc) {
  if (abc === "A") return "bg-success/[0.04] hover:bg-success/[0.08]";
  if (abc === "B") return "bg-warning/[0.04] hover:bg-warning/[0.08]";
  return "hover:bg-muted/40";
}
function AbcSection({
  title,
  subtitle,
  icon,
  state,
  reportSubtitle,
  fileBase,
  kind
}) {
  const rows = state.rows.map((r) => ({
    ...r,
    qtde: toNum(r.qtde),
    total: toNum(r.total),
    perc: toNum(r.perc),
    perc_acum: toNum(r.perc_acum)
  }));
  const labelCol = (() => {
    switch (kind) {
      case "produtos":
        return {
          header: "Produto",
          key: "nome"
        };
      case "clientes":
        return {
          header: "Cliente",
          key: "nome"
        };
      case "grupos":
        return {
          header: "Grupo",
          key: "nome"
        };
      case "marcas":
        return {
          header: "Marca",
          key: "nome"
        };
      case "vendedores":
        return {
          header: "Vendedor",
          key: "nome"
        };
    }
  })();
  const qtdHeader = kind === "clientes" ? "Qtde compras" : kind === "vendedores" ? "Qtde vendas" : kind === "produtos" ? "Qtde" : "Qtde itens";
  const showCodigo = kind === "produtos" || kind === "clientes";
  const showGrupo = kind === "produtos";
  const handleExport = (fmt) => {
    const columns = [{
      header: "#",
      key: "ranking",
      format: "int"
    }, {
      header: "ABC",
      key: "abc",
      format: "text"
    }];
    if (showCodigo) columns.push({
      header: "Código",
      key: "codigo",
      format: "text"
    });
    columns.push({
      header: labelCol.header,
      key: "nome",
      format: "text"
    });
    if (showGrupo) columns.push({
      header: "Grupo",
      key: "grupo",
      format: "text"
    });
    columns.push({
      header: qtdHeader,
      key: "qtde",
      format: "int"
    });
    columns.push({
      header: "Total (R$)",
      key: "total",
      format: "brl"
    });
    columns.push({
      header: "%",
      key: "perc",
      format: "percent"
    });
    columns.push({
      header: "% Acumulado",
      key: "perc_acum",
      format: "percent"
    });
    const totals = {
      qtde: rows.reduce((a, r) => a + r.qtde, 0),
      total: rows.reduce((a, r) => a + r.total, 0)
    };
    if (fmt === "pdf") {
      exportChartToPDF({
        title,
        subtitle: reportSubtitle,
        columns,
        rows,
        totals,
        filename: `${fileBase}.pdf`
      });
    } else {
      exportChartToExcel({
        sheetName: title.slice(0, 31),
        columns,
        rows,
        filename: `${fileBase}.xlsx`
      });
    }
  };
  const totalGeral = rows.reduce((a, r) => a + r.total, 0);
  return /* @__PURE__ */ jsxRuntimeExports.jsx(ChartCard, { title, subtitle, icon, onExportPDF: state.rows.length ? () => handleExport("pdf") : void 0, onExportExcel: state.rows.length ? () => handleExport("xlsx") : void 0, contentClassName: "p-0", children: state.loading ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-4 space-y-2", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { className: "h-8 w-full" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { className: "h-8 w-full" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { className: "h-8 w-full" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Skeleton, { className: "h-8 w-full" })
  ] }) : state.error ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4", children: /* @__PURE__ */ jsxRuntimeExports.jsx(ClienteDbStatus, { code: state.error.code, message: state.error.message }) }) : rows.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-8 text-center text-sm text-muted-foreground flex flex-col items-center gap-2", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(TriangleAlert, { className: "h-5 w-5 opacity-60" }),
    "Nenhum dado encontrado para o período selecionado."
  ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-4 py-2 flex flex-wrap gap-3 text-xs text-muted-foreground border-b border-border/60 bg-muted/30", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "text-foreground", children: rows.length }),
        " registros"
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "•" }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
        "Total: ",
        /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "text-foreground", children: formatBRL(totalGeral) })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "•" }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
        "A:",
        " ",
        /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "text-success", children: rows.filter((r) => r.abc === "A").length }),
        " ",
        "/ B:",
        " ",
        /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "text-warning", children: rows.filter((r) => r.abc === "B").length }),
        " ",
        "/ C:",
        " ",
        /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "text-muted-foreground", children: rows.filter((r) => r.abc === "C").length })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "md:hidden max-h-[560px] overflow-auto p-3 space-y-2", children: rows.map((r) => {
      const borderCls = r.abc === "A" ? "border-l-4 border-l-success" : r.abc === "B" ? "border-l-4 border-l-warning" : "border-l-4 border-l-muted-foreground/40";
      return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: cn("rounded-lg border border-border bg-card p-3 shadow-sm", borderCls), children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between gap-3", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-2", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-xs font-semibold text-muted-foreground tabular-nums", children: [
              "#",
              r.ranking
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(AbcBadge, { cls: r.abc })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-right", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-bold tabular-nums", children: formatBRL(r.total) }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-[11px] text-muted-foreground tabular-nums", children: [
              formatPercent(r.perc_acum),
              " acum."
            ] })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-semibold leading-snug line-clamp-2", children: r.nome }),
          showCodigo && r.codigo != null && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-[11px] text-muted-foreground tabular-nums mt-0.5", children: [
            "Cód: ",
            r.codigo
          ] }),
          showGrupo && r.grupo && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[11px] text-muted-foreground truncate mt-0.5", children: r.grupo })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-2 flex items-end justify-between", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs text-muted-foreground tabular-nums", children: [
            qtdHeader,
            ": ",
            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-foreground font-medium", children: formatNumber(r.qtde) })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs font-semibold tabular-nums", children: formatPercent(r.perc) })
        ] })
      ] }, `m-${r.ranking}-${r.codigo ?? r.nome}`);
    }) }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "hidden md:block max-h-[440px] overflow-auto", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("table", { className: "w-full text-sm", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("thead", { className: "sticky top-0 bg-background/95 backdrop-blur border-b border-border z-10", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("tr", { className: "text-xs text-muted-foreground", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("th", { className: "text-left font-semibold px-3 py-2 w-12", children: "#" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("th", { className: "text-left font-semibold px-2 py-2 w-14", children: "ABC" }),
        showCodigo && /* @__PURE__ */ jsxRuntimeExports.jsx("th", { className: "text-left font-semibold px-2 py-2 w-24", children: "Código" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("th", { className: "text-left font-semibold px-2 py-2", children: labelCol.header }),
        showGrupo && /* @__PURE__ */ jsxRuntimeExports.jsx("th", { className: "text-left font-semibold px-2 py-2", children: "Grupo" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("th", { className: "text-right font-semibold px-2 py-2", children: qtdHeader }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("th", { className: "text-right font-semibold px-2 py-2", children: "Total" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("th", { className: "text-right font-semibold px-2 py-2 w-20", children: "%" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("th", { className: "text-right font-semibold px-3 py-2 w-28", children: "% Acum." })
      ] }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("tbody", { children: rows.map((r) => /* @__PURE__ */ jsxRuntimeExports.jsxs("tr", { className: cn("border-b border-border/40 transition-colors", rowTint(r.abc)), children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-3 py-2 text-muted-foreground tabular-nums", children: r.ranking }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-2 py-2", children: /* @__PURE__ */ jsxRuntimeExports.jsx(AbcBadge, { cls: r.abc }) }),
        showCodigo && /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-2 py-2 tabular-nums text-muted-foreground", children: r.codigo ?? "—" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-2 py-2 font-medium truncate max-w-[280px]", children: r.nome }),
        showGrupo && /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-2 py-2 text-muted-foreground truncate max-w-[180px]", children: r.grupo ?? "—" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-2 py-2 text-right tabular-nums", children: formatNumber(r.qtde) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-2 py-2 text-right tabular-nums font-semibold", children: formatBRL(r.total) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-2 py-2 text-right tabular-nums text-muted-foreground", children: formatPercent(r.perc) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: "px-3 py-2 text-right tabular-nums font-semibold", children: formatPercent(r.perc_acum) })
      ] }, `${r.ranking}-${r.codigo ?? r.nome}`)) })
    ] }) })
  ] }) });
}
export {
  Page as component
};
