import { a7 as head, a4 as escape_html, a5 as ensure_array_like, a3 as attr_class, a6 as attr, a8 as stringify } from '../../../chunks/index.js-BVnekaYQ.js';
import '../../../chunks/exports.js-8HOoaa4e.js';
import '../../../chunks/utils2.js-BQzn9ikS.js';
import '../../../chunks/utils.js-mIi_c4Oz.js';
import '../../../chunks/root.js-l4cSj5gU.js';
import '../../../chunks/state.svelte.js-DC2zSH9Y.js';
import { R as ROLE_LABEL } from '../../../chunks/roles.js-aWc1U_OX.js';
import '../../../chunks/false.js-B2gHlHjM.js';

function _page($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let { data, form } = $$props;
    const roleStyle = {
      admin: "bg-purple-100 text-purple-800",
      gestor: "bg-brand-100 text-brand-800",
      consulta: "bg-slate-100 text-slate-600"
    };
    head("9fk07v", $$renderer2, ($$renderer3) => {
      $$renderer3.title(($$renderer4) => {
        $$renderer4.push(`<title>Usuarios · Inventario EDUmind</title>`);
      });
    });
    $$renderer2.push(`<div class="mb-6 flex flex-wrap items-center justify-between gap-3"><div><h1 class="text-2xl font-bold text-slate-900">Usuarios</h1> <p class="text-slate-600">${escape_html(data.users.length)} usuario(s). Gestión de roles y acceso.</p></div> <div class="flex gap-2"><a class="btn-secondary" href="/users/import">Importar CSV</a> <a class="btn-primary" href="/users/new">Nuevo usuario</a></div></div> `);
    if (form?.error) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<p class="mb-4 rounded-lg bg-red-50 px-4 py-3 text-sm font-medium text-red-700" role="alert">${escape_html(form.error)}</p>`);
    } else {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]--> <div class="card overflow-hidden"><div class="overflow-x-auto"><table class="w-full text-left text-sm"><thead class="border-b border-slate-200 bg-slate-50 text-xs uppercase text-slate-500"><tr><th class="px-4 py-3 font-semibold">Nombre</th><th class="px-4 py-3 font-semibold">Correo</th><th class="px-4 py-3 font-semibold">Rol</th><th class="px-4 py-3 font-semibold">Acceso</th><th class="px-4 py-3 font-semibold">Estado</th><th class="px-4 py-3 text-right font-semibold">Acciones</th></tr></thead><tbody class="divide-y divide-slate-100"><!--[-->`);
    const each_array = ensure_array_like(data.users);
    for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
      let u = each_array[$$index];
      $$renderer2.push(`<tr${attr_class(`hover:bg-slate-50 ${u.active ? "" : "opacity-50"}`)}><td class="px-4 py-3"><a${attr("href", `/users/${stringify(u.id)}/edit`)} class="font-medium text-slate-900 hover:underline">${escape_html(u.name)}</a> `);
      if (u.identifier) {
        $$renderer2.push("<!--[0-->");
        $$renderer2.push(`<span class="block text-xs text-slate-400">${escape_html(u.identifier)}</span>`);
      } else {
        $$renderer2.push("<!--[-1-->");
      }
      $$renderer2.push(`<!--]--></td><td class="px-4 py-3 text-slate-600">${escape_html(u.email || "—")}</td><td class="px-4 py-3"><span${attr_class(`badge ${stringify(roleStyle[u.role])}`)}>${escape_html(ROLE_LABEL[u.role])}</span></td><td class="px-4 py-3">`);
      if (u.has_login) {
        $$renderer2.push("<!--[0-->");
        $$renderer2.push(`<span class="text-emerald-700">Sí</span>`);
      } else {
        $$renderer2.push("<!--[-1-->");
        $$renderer2.push(`<span class="text-slate-400">Solo préstamos</span>`);
      }
      $$renderer2.push(`<!--]--></td><td class="px-4 py-3">${escape_html(u.active ? "Activo" : "Inactivo")}</td><td class="px-4 py-3"><div class="flex justify-end gap-1"><a class="btn-secondary px-2 py-1 text-xs"${attr("href", `/users/${stringify(u.id)}/edit`)}>Editar</a> <form method="POST" action="?/toggleActive"><input type="hidden" name="id"${attr("value", u.id)}/> <button class="btn-secondary px-2 py-1 text-xs" type="submit">${escape_html(u.active ? "Desactivar" : "Activar")}</button></form></div></td></tr>`);
    }
    $$renderer2.push(`<!--]--></tbody></table></div></div>`);
  });
}

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