import { J as jsxRuntimeExports } from "./server-CZT6KZsz.js";
import { w as ordenesQO, c as administracionesQO, I as tecnicosQO, l as formatARS, L as Link, e as clienteNombre, o as getInitials, h as estadoLabels } from "./router-Bsssaenw.js";
import { u as useSuspenseQuery } from "./useSuspenseQuery-CRUy30GM.js";
import { A as AppShell, C as ClipboardList, B as Building2 } from "./AppShell-CCqmKL3X.js";
import { T as TipoBadge, E as EstadoBadge } from "./StatusBadge-TGBW-9F9.js";
import { N as NuevaOSDialog } from "./NuevaOSDialog-C0gfGAkw.js";
import { c as createLucideIcon } from "./wrench-CccwRKu3.js";
import { T as TrendingUp } from "./trending-up-G3x4lSVY.js";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
import "./package-D5atLoEx.js";
import "./textarea-BUwzaNv6.js";
import "./check-CKvikDYV.js";
import "./circle-DhaxbiIf.js";
const __iconNode$3 = [
  ["path", { d: "M7 7h10v10", key: "1tivn9" }],
  ["path", { d: "M7 17 17 7", key: "1vkiza" }]
];
const ArrowUpRight = createLucideIcon("arrow-up-right", __iconNode$3);
const __iconNode$2 = [
  ["path", { d: "M8 2v4", key: "1cmpym" }],
  ["path", { d: "M16 2v4", key: "4m81vk" }],
  ["rect", { width: "18", height: "18", x: "3", y: "4", rx: "2", key: "1hopcy" }],
  ["path", { d: "M3 10h18", key: "8toen8" }]
];
const Calendar = createLucideIcon("calendar", __iconNode$2);
const __iconNode$1 = [
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
  ["line", { x1: "12", x2: "12", y1: "8", y2: "12", key: "1pkeuh" }],
  ["line", { x1: "12", x2: "12.01", y1: "16", y2: "16", key: "4dfq90" }]
];
const CircleAlert = createLucideIcon("circle-alert", __iconNode$1);
const __iconNode = [
  ["line", { x1: "12", x2: "12", y1: "2", y2: "22", key: "7eqyqh" }],
  ["path", { d: "M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6", key: "1b0p4s" }]
];
const DollarSign = createLucideIcon("dollar-sign", __iconNode);
function Dashboard() {
  const {
    data: ordenes
  } = useSuspenseQuery(ordenesQO());
  const {
    data: administraciones
  } = useSuspenseQuery(administracionesQO());
  const {
    data: tecnicos
  } = useSuspenseQuery(tecnicosQO());
  const cerradas = /* @__PURE__ */ new Set(["cobrado", "finalizado"]);
  const activas = ordenes.filter((o) => !cerradas.has(o.estado)).length;
  const urgentes = ordenes.filter((o) => o.prioridad === "urgente").length;
  const ingresoMensual = administraciones.reduce((s, a) => s + Number(a.abono_mensual ?? 0), 0);
  const presupuestos = ordenes.filter((o) => o.presupuesto).reduce((s, o) => s + Number(o.presupuesto ?? 0), 0);
  return /* @__PURE__ */ jsxRuntimeExports.jsx(AppShell, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col sm:flex-row sm:items-end sm:justify-between gap-4", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs uppercase tracking-widest text-muted-foreground font-mono", children: "Panel general" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "text-3xl font-bold mt-1", children: "Buen día" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-muted-foreground mt-1", children: [
          "Tenés ",
          /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-semibold text-foreground", children: [
            activas,
            " órdenes activas"
          ] }),
          " y ",
          urgentes,
          " urgentes esta semana."
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(NuevaOSDialog, { trigger: /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { className: "inline-flex items-center gap-2 px-4 py-2.5 rounded-md gradient-primary text-primary-foreground font-medium text-sm shadow-elevated hover:opacity-95 transition", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(ClipboardList, { className: "size-4" }),
        " Nueva Orden de Servicio"
      ] }) })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-2 lg:grid-cols-4 gap-4", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(KpiCard, { icon: ClipboardList, label: "OS Activas", value: String(activas), delta: `${ordenes.length} totales`, tone: "info" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(KpiCard, { icon: CircleAlert, label: "Urgentes", value: String(urgentes), delta: "Atención", tone: "destructive" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(KpiCard, { icon: DollarSign, label: "Abonos / mes", value: formatARS(ingresoMensual), delta: `${administraciones.length} cuentas`, tone: "success" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(KpiCard, { icon: TrendingUp, label: "Presupuestos vivos", value: formatARS(presupuestos), delta: `${ordenes.filter((o) => o.presupuesto).length} pendientes`, tone: "primary" })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid lg:grid-cols-3 gap-6", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "lg:col-span-2 bg-card border border-border rounded-xl shadow-card overflow-hidden", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-5 py-4 border-b border-border flex items-center justify-between", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "font-display font-semibold text-lg", children: "Órdenes recientes" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground", children: "Últimas OS creadas" })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs(Link, { to: "/ordenes", className: "text-xs font-medium text-primary inline-flex items-center gap-1 hover:gap-1.5 transition-all", children: [
            "Ver todas ",
            /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowUpRight, { className: "size-3" })
          ] })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "divide-y divide-border", children: [
          ordenes.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "px-5 py-10 text-sm text-center text-muted-foreground", children: "No hay órdenes todavía." }),
          ordenes.slice(0, 5).map((o) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-5 py-3.5 flex items-center gap-4 hover:bg-muted/40 transition-colors", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-xs text-muted-foreground w-28 shrink-0", children: o.codigo }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-medium text-sm truncate", children: [
                clienteNombre(o),
                o.edificio ? ` · ${o.edificio.nombre}` : ""
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-muted-foreground truncate", children: o.descripcion })
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(TipoBadge, { tipo: o.tipo }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(EstadoBadge, { estado: o.estado })
          ] }, o.id))
        ] })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-xl shadow-card overflow-hidden", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "px-5 py-4 border-b border-border", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "font-display font-semibold text-lg", children: "Equipo técnico" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-xs text-muted-foreground", children: "Carga actual" })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-3 space-y-2", children: [
          tecnicos.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 text-xs text-muted-foreground text-center", children: "Sin técnicos cargados aún." }),
          tecnicos.map((t) => {
            const trabajos = ordenes.filter((o) => o.tecnico_id === t.user_id).length;
            return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 p-2.5 rounded-lg hover:bg-muted/50", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "size-10 rounded-full bg-secondary text-secondary-foreground grid place-items-center font-semibold text-sm", children: getInitials(t.nombre || "?") }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium truncate", children: t.nombre || "—" }),
                /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-muted-foreground", children: t.especialidad ?? "Sin especialidad" })
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-right", children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-display font-bold text-lg leading-none", children: trabajos }),
                /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] uppercase tracking-wider text-muted-foreground", children: "OS" })
              ] })
            ] }, t.id);
          })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid lg:grid-cols-2 gap-6", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-xl shadow-card p-5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "font-display font-semibold flex items-center gap-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Building2, { className: "size-4 text-primary" }),
          " Top Administraciones"
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-4 space-y-3", children: administraciones.slice(0, 4).map((a) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "size-9 rounded-md bg-accent grid place-items-center text-accent-foreground font-semibold text-xs", children: getInitials(a.nombre) }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex-1 min-w-0", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium truncate", children: a.nombre }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs text-muted-foreground", children: [
              a.edificios?.length ?? 0,
              " edificios"
            ] })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-sm", children: formatARS(Number(a.abono_mensual ?? 0)) })
        ] }, a.id)) })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-xl shadow-card p-5", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "font-display font-semibold flex items-center gap-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Calendar, { className: "size-4 text-primary" }),
          " Estados del pipeline"
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-4 space-y-2", children: Object.entries(estadoLabels).map(([k, label]) => {
          const n = ordenes.filter((o) => o.estado === k).length;
          const pct = ordenes.length ? n / ordenes.length * 100 : 0;
          return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between text-xs mb-1", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-muted-foreground", children: label }),
              /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-mono font-semibold", children: n })
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-1.5 bg-muted rounded-full overflow-hidden", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "h-full gradient-primary rounded-full transition-all", style: {
              width: `${Math.max(pct, 3)}%`
            } }) })
          ] }, k);
        }) })
      ] })
    ] })
  ] }) });
}
function KpiCard({
  icon: Icon,
  label,
  value,
  delta,
  tone
}) {
  const toneMap = {
    info: "text-info bg-info/10",
    success: "text-success bg-success/10",
    destructive: "text-destructive bg-destructive/10",
    primary: "text-primary bg-primary/10"
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-xl p-5 shadow-card", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `size-9 rounded-lg grid place-items-center ${toneMap[tone]}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Icon, { className: "size-4" }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-[11px] font-mono text-muted-foreground", children: delta })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-4 font-display font-bold text-2xl tracking-tight", children: value }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-muted-foreground mt-0.5 uppercase tracking-wider", children: label })
  ] });
}
export {
  Dashboard as component
};
