import { a4 as escape_html, a6 as attr, a5 as ensure_array_like, Z as derived } 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';
import { R as ROLE_LABEL } from './roles.js-aWc1U_OX.js';

function UserForm($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let {
      user = null,
      values = null,
      error = null,
      submitLabel = "Guardar"
    } = $$props;
    const roles = ["consulta", "gestor", "admin"];
    const v = (k, alt = "") => values?.[k] ?? alt;
    const initialRole = derived(() => user?.role ?? v("role", "consulta"));
    const canBorrow = derived(() => user ? user.can_borrow === 1 : true);
    const active = derived(() => user ? user.active === 1 : true);
    $$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="name">Nombre completo *</label> <input class="input" id="name" name="name" required=""${attr("value", user?.name ?? v("name"))}/></div> <div><label class="label" for="identifier">Identificador (DNI, nº empleado…)</label> <input class="input" id="identifier" name="identifier"${attr("value", user?.identifier ?? v("identifier"))}/></div></div> <div><label class="label" for="email">Correo (usuario de acceso)</label> <input class="input" id="email" name="email" type="email"${attr("value", user?.email ?? v("email"))}/> <p class="mt-1 text-xs text-slate-500">Necesario solo si el usuario va a iniciar sesión en la app.</p></div> <div class="grid gap-5 sm:grid-cols-2"><div><label class="label" for="role">Rol</label> <select class="input" id="role" name="role"><!--[-->`);
    const each_array = ensure_array_like(roles);
    for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
      let r = each_array[$$index];
      $$renderer2.option({ value: r, selected: initialRole() === r }, ($$renderer3) => {
        $$renderer3.push(`${escape_html(ROLE_LABEL[r])}`);
      });
    }
    $$renderer2.push(`<!--]--></select> <p class="mt-1 text-xs text-slate-500">Consulta: solo ver · Gestor: préstamos y etiquetas · Admin: todo.</p></div> <div><label class="label" for="password">${escape_html(user?.has_login ? "Restablecer contraseña" : "Contraseña de acceso")}</label> <input class="input" id="password" name="password" type="password" minlength="8" autocomplete="new-password"/> <p class="mt-1 text-xs text-slate-500">${escape_html(user ? "Déjalo vacío para no cambiarla." : "Vacío = usuario sin acceso (solo préstamos).")}</p></div></div> <div class="flex flex-wrap gap-6"><label class="flex items-center gap-2 text-sm text-slate-700"><input type="checkbox" name="can_borrow" class="h-4 w-4 rounded border-slate-300 text-brand-700"${attr("checked", canBorrow(), true)}/> Puede recibir equipos en préstamo</label> <label class="flex items-center gap-2 text-sm text-slate-700"><input type="checkbox" name="active" class="h-4 w-4 rounded border-slate-300 text-brand-700"${attr("checked", active(), true)}/> Cuenta activa</label></div> <div class="flex gap-2"><button class="btn-primary" type="submit">${escape_html(submitLabel)}</button> <a class="btn-secondary" href="/users">Cancelar</a></div></form>`);
  });
}

export { UserForm as U };
//# sourceMappingURL=UserForm.js-CxupELTT.js.map
