import { J as jsxRuntimeExports } from "./server-CZT6KZsz.js";
import { u as useSuspenseQuery } from "./useSuspenseQuery-CRUy30GM.js";
import { A as AppShell } from "./AppShell-CCqmKL3X.js";
import { w as ordenesQO, I as tecnicosQO, o as getInitials, e as clienteNombre, f as direccion } from "./router-Bsssaenw.js";
import { T as TipoBadge, E as EstadoBadge } from "./StatusBadge-TGBW-9F9.js";
import { C as Clock } from "./clock-D0Vv5P35.js";
import { M as MapPin } from "./map-pin-2TMtQ5Pc.js";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
import "./package-D5atLoEx.js";
import "./wrench-CccwRKu3.js";
const horas = ["08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00"];
function AgendaPage() {
  const {
    data: ordenes
  } = useSuspenseQuery(ordenesQO());
  const {
    data: tecnicos
  } = useSuspenseQuery(tecnicosQO());
  const proximas = ordenes.filter((o) => o.fecha_programada).sort((a, b) => a.fecha_programada < b.fecha_programada ? -1 : 1).slice(0, 6);
  return /* @__PURE__ */ jsxRuntimeExports.jsx(AppShell, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-6", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs uppercase tracking-widest text-muted-foreground font-mono", children: "Planificación" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("h1", { className: "text-3xl font-bold mt-1", children: "Agenda" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-muted-foreground mt-1", children: "Asignación de técnicos · vista por jornada" })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-xl shadow-card overflow-hidden", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-[140px_1fr] divide-x divide-border", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-muted/30 p-4 text-xs uppercase tracking-wider font-mono text-muted-foreground", children: "Técnico" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-10 divide-x divide-border", children: horas.map((h) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "bg-muted/30 p-2 text-xs text-center font-mono text-muted-foreground", children: h }, h)) })
      ] }),
      tecnicos.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-6 text-sm text-muted-foreground text-center", children: "No hay técnicos cargados todavía." }),
      tecnicos.map((t) => {
        const tareas = ordenes.filter((o) => o.tecnico_id === t.user_id);
        return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-[140px_1fr] divide-x divide-border border-t border-border", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-3 flex items-center gap-2", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "size-8 rounded-full bg-secondary grid place-items-center text-xs font-semibold", children: getInitials(t.nombre || "?") }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "min-w-0", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-medium truncate", children: (t.nombre || "—").split(" ")[0] }),
              /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] text-muted-foreground uppercase tracking-wider", children: t.especialidad ?? "—" })
            ] })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "relative grid grid-cols-10 divide-x divide-border min-h-[80px]", children: [
            horas.map((_, i) => /* @__PURE__ */ jsxRuntimeExports.jsx("div", {}, i)),
            tareas.map((task, idx) => {
              const start = (idx * 2 + 1) % 8;
              const span = task.tipo === "abono" ? 2 : task.tipo === "relevamiento" ? 3 : 2;
              const colors = task.tipo === "abono" ? "bg-info/15 border-info/30 text-info" : task.tipo === "reparacion" ? "bg-destructive/10 border-destructive/30 text-destructive" : task.tipo === "urgencia" ? "bg-destructive border-destructive text-destructive-foreground" : "bg-accent border-accent-foreground/20 text-accent-foreground";
              return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: `absolute top-1 bottom-1 rounded-md border ${colors} px-2 py-1.5 text-xs overflow-hidden`, style: {
                left: `${start / 10 * 100}%`,
                width: `${span / 10 * 100}%`
              }, children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-[10px] opacity-70", children: task.codigo }),
                /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium truncate", children: clienteNombre(task) })
              ] }, task.id);
            })
          ] })
        ] }, t.id);
      })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "font-display font-semibold text-lg mb-3", children: "Próximas visitas" }),
      proximas.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm text-muted-foreground", children: "Sin visitas programadas." }),
      /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid md:grid-cols-2 lg:grid-cols-3 gap-3", children: proximas.map((o) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-lg p-4 shadow-card", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between gap-2 mb-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(TipoBadge, { tipo: o.tipo }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(EstadoBadge, { estado: o.estado })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium text-sm", children: clienteNombre(o) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-muted-foreground mt-0.5", children: o.descripcion }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-3 flex items-center gap-3 text-xs text-muted-foreground", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex items-center gap-1", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(Clock, { className: "size-3" }),
            " ",
            o.fecha_programada?.slice(0, 16).replace("T", " ")
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex items-center gap-1", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "size-3" }),
            " ",
            direccion(o)
          ] })
        ] })
      ] }, o.id)) })
    ] })
  ] }) });
}
export {
  AgendaPage as component
};
