import { S as reactExports, J as jsxRuntimeExports } from "./server-CZT6KZsz.js";
import { Q as useAuth, N as Navigate, L as Link, o as getInitials, e as clienteNombre, f as direccion, s as misOrdenesQO, M as tipoLabels, d as checklistAbono } from "./router-Bsssaenw.js";
import { u as useSuspenseQuery } from "./useSuspenseQuery-CRUy30GM.js";
import { T as TipoBadge, P as PrioridadBadge, E as EstadoBadge } from "./StatusBadge-TGBW-9F9.js";
import { c as createLucideIcon, L as LoaderCircle, W as Wrench } from "./wrench-CccwRKu3.js";
import { M as MapPin } from "./map-pin-2TMtQ5Pc.js";
import { C as Clock } from "./clock-D0Vv5P35.js";
import { C as Circle } from "./circle-DhaxbiIf.js";
import { P as Package } from "./package-D5atLoEx.js";
import { C as Camera } from "./camera-Dg3FN0cS.js";
import "node:async_hooks";
import "node:stream/web";
import "node:stream";
const __iconNode$3 = [
  ["path", { d: "m12 19-7-7 7-7", key: "1l729n" }],
  ["path", { d: "M19 12H5", key: "x3x0zl" }]
];
const ArrowLeft = createLucideIcon("arrow-left", __iconNode$3);
const __iconNode$2 = [["path", { d: "m9 18 6-6-6-6", key: "mthhwq" }]];
const ChevronRight = createLucideIcon("chevron-right", __iconNode$2);
const __iconNode$1 = [
  ["circle", { cx: "12", cy: "12", r: "10", key: "1mglay" }],
  ["path", { d: "m9 12 2 2 4-4", key: "dzmm74" }]
];
const CircleCheck = createLucideIcon("circle-check", __iconNode$1);
const __iconNode = [
  ["path", { d: "M12 19v3", key: "npa21l" }],
  ["path", { d: "M19 10v2a7 7 0 0 1-14 0v-2", key: "1vc78b" }],
  ["rect", { x: "9", y: "2", width: "6", height: "13", rx: "3", key: "s6n7sd" }]
];
const Mic = createLucideIcon("mic", __iconNode);
function TecnicoPage() {
  const {
    user,
    loading
  } = useAuth();
  const [active, setActive] = reactExports.useState(null);
  if (loading) return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen grid place-items-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(LoaderCircle, { className: "size-6 animate-spin text-muted-foreground" }) });
  if (!user) return /* @__PURE__ */ jsxRuntimeExports.jsx(Navigate, { to: "/login" });
  return /* @__PURE__ */ jsxRuntimeExports.jsx(TecnicoView, { userId: user.id, userName: user.user_metadata?.nombre || user.email || "Técnico", active, setActive });
}
function TecnicoView({
  userId,
  userName,
  active,
  setActive
}) {
  const {
    data: misOS
  } = useSuspenseQuery(misOrdenesQO(userId));
  const orden = misOS.find((o) => o.id === active);
  if (orden) return /* @__PURE__ */ jsxRuntimeExports.jsx(DetalleOS, { orden, onBack: () => setActive(null) });
  const cerradas = /* @__PURE__ */ new Set(["finalizado", "cobrado"]);
  const pendientes = misOS.filter((o) => !cerradas.has(o.estado));
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen bg-background", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "max-w-md mx-auto bg-card min-h-screen lg:my-6 lg:rounded-2xl lg:shadow-elevated lg:min-h-[calc(100vh-3rem)] overflow-hidden", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "gradient-primary p-5 text-primary-foreground", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between mb-4", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(Link, { to: "/", className: "text-xs opacity-80 inline-flex items-center gap-1", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowLeft, { className: "size-3" }),
          " Modo Admin"
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] uppercase tracking-widest opacity-80 font-mono", children: "PWA · Técnico" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "size-12 rounded-full bg-primary-foreground/20 backdrop-blur grid place-items-center font-bold", children: getInitials(userName) }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "font-display font-bold text-lg leading-none", children: [
            "Hola, ",
            userName.split(" ")[0]
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-xs opacity-80 mt-1", children: [
            misOS.length,
            " OS asignadas"
          ] })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-3 divide-x divide-border border-b border-border", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Stat, { label: "Pendientes", value: String(pendientes.length) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Stat, { label: "Hechas", value: String(misOS.length - pendientes.length) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Stat, { label: "Total", value: String(misOS.length) })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-4 space-y-3", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "font-display font-semibold", children: "Mi agenda" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "text-xs text-muted-foreground font-mono", children: [
          misOS.length,
          " ÓRDENES"
        ] })
      ] }),
      misOS.length === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-8 text-center text-sm text-muted-foreground border border-dashed border-border rounded-xl", children: "No tenés órdenes asignadas todavía." }),
      misOS.map((o) => /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { onClick: () => setActive(o.id), className: "w-full text-left bg-card border border-border rounded-xl p-4 shadow-card hover:border-primary/50 transition-colors active:scale-[0.99]", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-between gap-2 mb-2", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(TipoBadge, { tipo: o.tipo }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(PrioridadBadge, { prioridad: o.prioridad })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-semibold text-sm", children: clienteNombre(o) }),
        o.edificio && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-muted-foreground", children: o.edificio.nombre }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-2 text-xs text-muted-foreground line-clamp-2", children: o.descripcion }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mt-3 pt-3 border-t border-border flex items-center justify-between text-xs", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex items-center gap-1 text-muted-foreground", children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "size-3" }),
            " ",
            direccion(o).split(",")[0]
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex items-center gap-1 font-mono text-primary font-semibold", children: [
            "Abrir ",
            /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronRight, { className: "size-3" })
          ] })
        ] })
      ] }, o.id))
    ] })
  ] }) });
}
function Stat({
  label,
  value
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-4 text-center", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-display font-bold text-2xl", children: value }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] uppercase tracking-wider text-muted-foreground mt-0.5", children: label })
  ] });
}
function DetalleOS({
  orden,
  onBack
}) {
  const [checked, setChecked] = reactExports.useState(/* @__PURE__ */ new Set());
  const toggle = (id) => {
    const n = new Set(checked);
    if (n.has(id)) n.delete(id);
    else n.add(id);
    setChecked(n);
  };
  const showChecklist = orden.tipo === "abono";
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "min-h-screen bg-background", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "max-w-md mx-auto bg-background min-h-screen lg:my-6 lg:rounded-2xl lg:shadow-elevated lg:min-h-[calc(100vh-3rem)] overflow-hidden", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-sidebar text-sidebar-foreground p-4 sticky top-0 z-10", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { onClick: onBack, className: "inline-flex items-center gap-2 text-xs opacity-80 mb-3", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(ArrowLeft, { className: "size-3" }),
        " Volver"
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-start justify-between gap-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-mono text-[11px] opacity-60", children: orden.codigo }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { className: "font-display font-bold text-lg mt-0.5", children: clienteNombre(orden) }),
          orden.edificio && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm opacity-80", children: orden.edificio.nombre })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(EstadoBadge, { estado: orden.estado })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center gap-3 mt-3 text-xs opacity-80", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex items-center gap-1", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(MapPin, { className: "size-3" }),
          " ",
          direccion(orden)
        ] }),
        orden.fecha_programada && /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "inline-flex items-center gap-1", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Clock, { className: "size-3" }),
          " ",
          orden.fecha_programada.slice(0, 16).replace("T", " ")
        ] })
      ] })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "p-4 space-y-4", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(Section, { title: "Variables de complejidad", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-3 gap-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Pill, { label: "Altura", value: orden.complejidad_altura ?? "—" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Pill, { label: "Acceso", value: orden.complejidad_acceso ?? "—" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(Pill, { label: "Urgencia", value: orden.prioridad })
      ] }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Section, { title: "Descripción del trabajo", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-sm text-muted-foreground bg-card border border-border rounded-lg p-3", children: orden.descripcion }) }),
      showChecklist && /* @__PURE__ */ jsxRuntimeExports.jsx(Section, { title: `Checklist · ${tipoLabels[orden.tipo]}`, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-3", children: checklistAbono.map((cat) => /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-lg overflow-hidden", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "px-3 py-2 bg-muted/40 text-xs font-semibold uppercase tracking-wider text-muted-foreground", children: cat.categoria }),
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "divide-y divide-border", children: cat.items.map((item, i) => {
          const id = `${cat.id}-${i}`;
          const isChecked = checked.has(id);
          return /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { onClick: () => toggle(id), className: "w-full px-3 py-3 flex items-center gap-3 text-left hover:bg-muted/30", children: [
            isChecked ? /* @__PURE__ */ jsxRuntimeExports.jsx(CircleCheck, { className: "size-5 text-success shrink-0" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Circle, { className: "size-5 text-muted-foreground/40 shrink-0" }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: `text-sm ${isChecked ? "line-through text-muted-foreground" : ""}`, children: item })
          ] }, id);
        }) })
      ] }, cat.id)) }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Section, { title: "Materiales utilizados", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-lg divide-y divide-border", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "p-4 text-sm text-muted-foreground text-center", children: "Sin materiales cargados" }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { className: "w-full p-3 text-sm font-medium text-primary inline-flex items-center justify-center gap-2 hover:bg-primary/5", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(Package, { className: "size-4" }),
          " Cargar material del stock"
        ] })
      ] }) }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "grid grid-cols-2 gap-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(ActionBtn, { icon: Camera, label: "Tomar foto", badge: "0" }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(ActionBtn, { icon: Mic, label: "Nota de voz", badge: "IA" })
      ] }),
      /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { className: "w-full py-3.5 rounded-lg gradient-primary text-primary-foreground font-semibold shadow-elevated inline-flex items-center justify-center gap-2", children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(Wrench, { className: "size-4" }),
        " Marcar como finalizada"
      ] })
    ] })
  ] }) });
}
function Section({
  title,
  children
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-xs uppercase tracking-widest text-muted-foreground font-mono mb-2", children: title }),
    children
  ] });
}
function Pill({
  label,
  value
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-card border border-border rounded-lg p-2.5 text-center", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-[10px] uppercase tracking-wider text-muted-foreground", children: label }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-sm font-semibold mt-0.5 capitalize", children: value })
  ] });
}
function ActionBtn({
  icon: Icon,
  label,
  badge
}) {
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { className: "bg-card border border-border rounded-lg p-3 flex flex-col items-center gap-1 hover:border-primary/50 transition-colors relative", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Icon, { className: "size-5 text-primary" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs font-medium", children: label }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "absolute top-1.5 right-1.5 text-[9px] font-mono bg-accent text-accent-foreground px-1.5 py-0.5 rounded-full", children: badge })
  ] });
}
export {
  TecnicoPage as component
};
