import { a7 as head, a4 as escape_html, a5 as ensure_array_like, a6 as attr, Z as derived } from '../../../chunks/index.js-BVnekaYQ.js';
import { l as labelsPerSheet, g as getPreset } from '../../../chunks/labels-presets.js-DFpXmbAX.js';
import '../../../chunks/utils.js-mIi_c4Oz.js';
import '../../../chunks/utils2.js-BQzn9ikS.js';

function _page($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let { data } = $$props;
    let selected = new Set(data.preCode ? data.devices.filter((d) => d.code === data.preCode).map((d) => d.id) : []);
    let categoryFilter = "";
    let preset = data.presets[0].key;
    const visible = derived(() => data.devices);
    const selectedCount = derived(() => selected.size);
    const perSheet = derived(() => labelsPerSheet(getPreset(preset)));
    const sheets = derived(() => Math.ceil(Math.max(selectedCount(), 0) / perSheet()) || 0);
    head("1my987o", $$renderer2, ($$renderer3) => {
      $$renderer3.title(($$renderer4) => {
        $$renderer4.push(`<title>Etiquetas · Inventario EDUmind</title>`);
      });
    });
    $$renderer2.push(`<div class="mb-6"><h1 class="text-2xl font-bold text-slate-900">Generador de etiquetas</h1> <p class="text-slate-600">Etiquetas con QR, código y tipología en formatos APLI normalizados. En lote o individuales.</p></div> <form method="POST" action="/labels/pdf" target="_blank" class="grid gap-6 lg:grid-cols-3"><section class="card overflow-hidden lg:col-span-2"><header class="flex flex-wrap items-center justify-between gap-2 border-b border-slate-200 px-5 py-3"><h2 class="font-semibold text-slate-900">Equipos (${escape_html(selectedCount())} seleccionados)</h2> <div class="flex items-center gap-2">`);
    $$renderer2.select(
      {
        class: "input py-1.5",
        value: categoryFilter,
        "aria-label": "Filtrar por categoría"
      },
      ($$renderer3) => {
        $$renderer3.option({ value: "" }, ($$renderer4) => {
          $$renderer4.push(`Todas las categorías`);
        });
        $$renderer3.push(`<!--[-->`);
        const each_array = ensure_array_like(data.categories);
        for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
          let c = each_array[$$index];
          $$renderer3.option({ value: String(c.id) }, ($$renderer4) => {
            $$renderer4.push(`${escape_html(c.name)}`);
          });
        }
        $$renderer3.push(`<!--]-->`);
      }
    );
    $$renderer2.push(` <button type="button" class="btn-secondary py-1.5">Todos</button> <button type="button" class="btn-secondary py-1.5">Ninguno</button></div></header> <div class="max-h-[28rem] overflow-y-auto">`);
    if (visible().length === 0) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<p class="px-5 py-12 text-center text-slate-500">No hay equipos en esta categoría.</p>`);
    } else {
      $$renderer2.push("<!--[-1-->");
      $$renderer2.push(`<ul class="divide-y divide-slate-100"><!--[-->`);
      const each_array_1 = ensure_array_like(visible());
      for (let $$index_1 = 0, $$length = each_array_1.length; $$index_1 < $$length; $$index_1++) {
        let d = each_array_1[$$index_1];
        $$renderer2.push(`<li><label class="flex cursor-pointer items-center gap-3 px-5 py-2.5 hover:bg-slate-50"><input type="checkbox" name="id"${attr("value", d.id)}${attr("checked", selected.has(d.id), true)} class="h-4 w-4 rounded border-slate-300 text-brand-700 focus:ring-brand-500"/> <span class="font-mono font-semibold text-slate-900">${escape_html(d.code)}</span> <span class="text-sm text-slate-500">${escape_html(d.name || d.model || "")}</span> `);
        if (d.category_name) {
          $$renderer2.push("<!--[0-->");
          $$renderer2.push(`<span class="ml-auto text-xs text-slate-400">${escape_html(d.category_name)}</span>`);
        } else {
          $$renderer2.push("<!--[-1-->");
        }
        $$renderer2.push(`<!--]--></label></li>`);
      }
      $$renderer2.push(`<!--]--></ul>`);
    }
    $$renderer2.push(`<!--]--></div></section> <aside class="card h-fit space-y-5 p-5"><div><label class="label" for="preset">Formato de etiqueta</label> `);
    $$renderer2.select({ class: "input", id: "preset", name: "preset", value: preset }, ($$renderer3) => {
      $$renderer3.push(`<!--[-->`);
      const each_array_2 = ensure_array_like(data.presets);
      for (let $$index_2 = 0, $$length = each_array_2.length; $$index_2 < $$length; $$index_2++) {
        let p = each_array_2[$$index_2];
        $$renderer3.option({ value: p.key }, ($$renderer4) => {
          $$renderer4.push(`${escape_html(p.ref)} — ${escape_html(p.name)}`);
        });
      }
      $$renderer3.push(`<!--]-->`);
    });
    $$renderer2.push(`</div> <div><label class="label" for="start_index">Empezar en la casilla nº</label> <input class="input" id="start_index" name="start_index" type="number" min="0"${attr("max", perSheet() - 1)} value="0"/> <p class="mt-1 text-xs text-slate-500">Para reaprovechar una hoja ya empezada (0 = primera casilla). ${escape_html(perSheet())} por hoja.</p></div> <fieldset><legend class="label">Calibración de impresora (mm)</legend> <div class="grid grid-cols-2 gap-3"><div><label class="text-xs text-slate-500" for="offset_x">Desplaz. X</label> <input class="input" id="offset_x" name="offset_x" type="number" step="0.5"${attr("value", data.offsets.x)}/></div> <div><label class="text-xs text-slate-500" for="offset_y">Desplaz. Y</label> <input class="input" id="offset_y" name="offset_y" type="number" step="0.5"${attr("value", data.offsets.y)}/></div></div></fieldset> <div class="space-y-2"><label class="flex items-center gap-2 text-sm text-slate-700"><input type="checkbox" name="border" class="h-4 w-4 rounded border-slate-300 text-brand-700"/> Dibujar borde de guía (recorte)</label> <label class="flex items-center gap-2 text-sm text-slate-700"><input type="checkbox" name="center" class="h-4 w-4 rounded border-slate-300 text-brand-700" checked=""/> Incluir nombre del centro</label></div> <div class="rounded-lg bg-slate-50 p-3 text-sm text-slate-600">${escape_html(selectedCount())} etiqueta(s) · ${escape_html(sheets())} hoja(s) A4</div> <button class="btn-primary w-full" type="submit"${attr("disabled", selectedCount() === 0, true)}>Generar PDF</button> <p class="text-center text-xs text-slate-400">Se abre en una pestaña nueva, listo para imprimir.</p></aside></form>`);
  });
}

export { _page as default };
//# sourceMappingURL=_page.svelte.js-Dj32GxD_.js.map
