import { a4 as escape_html, a5 as ensure_array_like, a6 as attr } from './index.js-BVnekaYQ.js';
import './exports.js-8HOoaa4e.js';
import './utils2.js-BQzn9ikS.js';
import './utils.js-mIi_c4Oz.js';
import './root.js-l4cSj5gU.js';
import './state.svelte.js-DC2zSH9Y.js';

function DeviceForm($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let {
      categories,
      device = null,
      values = null,
      error = null,
      submitLabel = "Guardar"
    } = $$props;
    const v = (k, alt = "") => values?.[k] ?? (device?.[k] != null ? String(device[k]) : alt);
    $$renderer2.push(`<form method="POST" class="card space-y-5 p-6">`);
    if (error) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<p class="rounded-lg bg-red-50 px-3 py-2 text-sm font-medium text-red-700" role="alert">${escape_html(error)}</p>`);
    } else {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]--> <div class="grid gap-5 sm:grid-cols-2"><div><label class="label" for="category_id">Categoría / tipología *</label> <select class="input" id="category_id" name="category_id" required="">`);
    $$renderer2.option({ value: "" }, ($$renderer3) => {
      $$renderer3.push(`Selecciona…`);
    });
    $$renderer2.push(`<!--[-->`);
    const each_array = ensure_array_like(categories);
    for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
      let c = each_array[$$index];
      $$renderer2.option({ value: c.id, selected: String(c.id) === v("category_id") }, ($$renderer3) => {
        $$renderer3.push(`${escape_html(c.name)} (${escape_html(c.code)})`);
      });
    }
    $$renderer2.push(`<!--]--></select></div> <div><label class="label" for="code">Código del equipo</label> <input class="input font-mono" id="code" name="code"${attr("value", v("code"))} placeholder="Se genera automáticamente (ej. POR-0001)"/> <p class="mt-1 text-xs text-slate-500">Déjalo vacío para autogenerar según la categoría.</p></div></div> <div><label class="label" for="name">Nombre / descripción</label> <input class="input" id="name" name="name"${attr("value", v("name"))} placeholder="Portátil aula 3B"/></div> <div class="grid gap-5 sm:grid-cols-3"><div><label class="label" for="brand">Marca</label> <input class="input" id="brand" name="brand"${attr("value", v("brand"))}/></div> <div><label class="label" for="model">Modelo</label> <input class="input" id="model" name="model"${attr("value", v("model"))}/></div> <div><label class="label" for="serial">Nº de serie</label> <input class="input" id="serial" name="serial"${attr("value", v("serial"))}/></div></div> <div class="grid gap-5 sm:grid-cols-2"><div><label class="label" for="location">Ubicación habitual</label> <input class="input" id="location" name="location"${attr("value", v("location"))} placeholder="Aula TIC"/></div> <div><label class="label" for="status">Estado</label> <select class="input" id="status" name="status"><!--[-->`);
    const each_array_1 = ensure_array_like(["disponible", "mantenimiento", "baja"]);
    for (let $$index_1 = 0, $$length = each_array_1.length; $$index_1 < $$length; $$index_1++) {
      let s = each_array_1[$$index_1];
      $$renderer2.option({ value: s, selected: v("status", "disponible") === s }, ($$renderer3) => {
        $$renderer3.push(`${escape_html(s === "disponible" ? "Disponible" : s === "mantenimiento" ? "Mantenimiento" : "De baja")}`);
      });
    }
    $$renderer2.push(`<!--]--></select> <p class="mt-1 text-xs text-slate-500">El estado «Prestado» se gestiona desde préstamos.</p></div></div> <div><label class="label" for="notes">Notas</label> <textarea class="input" id="notes" name="notes" rows="3">`);
    const $$body = escape_html(v("notes"));
    if ($$body) {
      $$renderer2.push(`${$$body}`);
    }
    $$renderer2.push(`</textarea></div> <div class="flex gap-2"><button class="btn-primary" type="submit">${escape_html(submitLabel)}</button> <a class="btn-secondary" href="/devices">Cancelar</a></div></form>`);
  });
}

export { DeviceForm as D };
//# sourceMappingURL=DeviceForm.js-Be8fD2DO.js.map
