import { a7 as head, a5 as ensure_array_like, a6 as attr, a4 as escape_html, a3 as attr_class, a8 as stringify, Z as derived } from '../../chunks/index.js-BVnekaYQ.js';
import { i as isOverdue, f as formatDate, a as formatDateTime } from '../../chunks/format.js-B0aMHEZW.js';
import '../../chunks/utils.js-mIi_c4Oz.js';
import '../../chunks/utils2.js-BQzn9ikS.js';

function _page($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let { data } = $$props;
    const cards = derived(() => [
      {
        label: "Equipos totales",
        value: data.counts.total,
        tone: "text-slate-900",
        href: "/devices"
      },
      {
        label: "Disponibles",
        value: data.counts.disponibles,
        tone: "text-emerald-600",
        href: "/devices?status=disponible"
      },
      {
        label: "Prestados",
        value: data.counts.prestados,
        tone: "text-amber-600",
        href: "/devices?status=prestado"
      },
      {
        label: "Vencidos",
        value: data.counts.overdue,
        tone: data.counts.overdue > 0 ? "text-red-600" : "text-slate-900",
        href: "/loans?filter=overdue"
      }
    ]);
    head("1uha8ag", $$renderer2, ($$renderer3) => {
      $$renderer3.title(($$renderer4) => {
        $$renderer4.push(`<title>Panel · 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">Panel</h1> <p class="text-slate-600">Estado general del inventario del centro.</p></div> <div class="flex gap-2"><a class="btn-secondary" href="/scan">Escanear</a> <a class="btn-primary" href="/devices/new">Nuevo equipo</a></div></div> <div class="grid grid-cols-2 gap-4 lg:grid-cols-4"><!--[-->`);
    const each_array = ensure_array_like(cards());
    for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
      let c = each_array[$$index];
      $$renderer2.push(`<a${attr("href", c.href)} class="card p-5 transition-shadow hover:shadow-md"><p class="text-sm font-medium text-slate-500">${escape_html(c.label)}</p> <p${attr_class(`mt-1 text-3xl font-bold ${stringify(c.tone)}`)}>${escape_html(c.value)}</p></a>`);
    }
    $$renderer2.push(`<!--]--></div> <div class="mt-8 grid gap-6 lg:grid-cols-2"><section class="card overflow-hidden"><header class="flex items-center justify-between border-b border-slate-200 px-5 py-4"><h2 class="font-semibold text-slate-900">Préstamos activos</h2> <a class="text-sm font-medium text-brand-700 hover:underline" href="/loans">Ver todos</a></header> `);
    if (data.activeLoans.length === 0) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<p class="px-5 py-10 text-center text-sm text-slate-500">No hay préstamos activos.</p>`);
    } else {
      $$renderer2.push("<!--[-1-->");
      $$renderer2.push(`<ul class="divide-y divide-slate-100"><!--[-->`);
      const each_array_1 = ensure_array_like(data.activeLoans);
      for (let $$index_1 = 0, $$length = each_array_1.length; $$index_1 < $$length; $$index_1++) {
        let loan = each_array_1[$$index_1];
        $$renderer2.push(`<li class="flex items-center justify-between gap-3 px-5 py-3"><div class="min-w-0"><a${attr("href", `/devices/${stringify(loan.device_id)}`)} class="font-medium text-slate-900 hover:underline">${escape_html(loan.device_code)}</a> <span class="text-slate-500">· ${escape_html(loan.device_name ?? loan.category_name ?? "")}</span> <p class="truncate text-sm text-slate-600">${escape_html(loan.borrower_name ?? "Sin asignar")}</p></div> <div class="shrink-0 text-right text-sm">`);
        if (loan.due_at) {
          $$renderer2.push("<!--[0-->");
          $$renderer2.push(`<span${attr_class(`font-medium ${isOverdue(loan.due_at, loan.returned_at) ? "text-red-600" : "text-slate-500"}`)}>${escape_html(isOverdue(loan.due_at, loan.returned_at) ? "Vencido " : "Vence ")}${escape_html(formatDate(loan.due_at))}</span>`);
        } else {
          $$renderer2.push("<!--[-1-->");
          $$renderer2.push(`<span class="text-slate-400">Sin fecha</span>`);
        }
        $$renderer2.push(`<!--]--></div></li>`);
      }
      $$renderer2.push(`<!--]--></ul>`);
    }
    $$renderer2.push(`<!--]--></section> <section class="card overflow-hidden"><header class="border-b border-slate-200 px-5 py-4"><h2 class="font-semibold text-slate-900">Actividad reciente</h2></header> `);
    if (data.recent.length === 0) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<p class="px-5 py-10 text-center text-sm text-slate-500">Aún no hay movimientos.</p>`);
    } else {
      $$renderer2.push("<!--[-1-->");
      $$renderer2.push(`<ul class="divide-y divide-slate-100"><!--[-->`);
      const each_array_2 = ensure_array_like(data.recent);
      for (let $$index_2 = 0, $$length = each_array_2.length; $$index_2 < $$length; $$index_2++) {
        let loan = each_array_2[$$index_2];
        $$renderer2.push(`<li class="flex items-center justify-between gap-3 px-5 py-3"><div class="min-w-0"><p class="truncate text-sm"><span class="font-medium text-slate-900">${escape_html(loan.device_code)}</span> `);
        if (loan.returned_at) {
          $$renderer2.push("<!--[0-->");
          $$renderer2.push(`<span class="text-emerald-700">devuelto</span>`);
        } else {
          $$renderer2.push("<!--[-1-->");
          $$renderer2.push(`<span class="text-amber-700">prestado a ${escape_html(loan.borrower_name ?? "—")}</span>`);
        }
        $$renderer2.push(`<!--]--></p> <p class="text-xs text-slate-500">${escape_html(formatDateTime(loan.returned_at ?? loan.checkout_at))}</p></div></li>`);
      }
      $$renderer2.push(`<!--]--></ul>`);
    }
    $$renderer2.push(`<!--]--></section></div>`);
  });
}

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