import { a7 as head, a4 as escape_html, a5 as ensure_array_like, a6 as attr } 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 'papaparse';
import '../../../../chunks/false.js-B2gHlHjM.js';

function _page($$renderer, $$props) {
  $$renderer.component(($$renderer2) => {
    let { form } = $$props;
    let csv = "";
    let preview = [];
    let previewHeaders = [];
    head("x33jhd", $$renderer2, ($$renderer3) => {
      $$renderer3.title(($$renderer4) => {
        $$renderer4.push(`<title>Importar usuarios · Inventario EDUmind</title>`);
      });
    });
    $$renderer2.push(`<div class="mx-auto max-w-3xl"><nav class="mb-4 text-sm text-slate-500"><a href="/users" class="hover:underline">Usuarios</a> · <span>Importar CSV</span></nav> <h1 class="mb-2 text-2xl font-bold text-slate-900">Volcado de usuarios (CSV)</h1> <p class="mb-6 text-slate-600">Sube o pega un CSV. Columnas admitidas: <code class="rounded bg-slate-100 px-1">nombre</code> (obligatoria), <code class="rounded bg-slate-100 px-1">email</code>, <code class="rounded bg-slate-100 px-1">identificador</code>, <code class="rounded bg-slate-100 px-1">rol</code>. Si el email ya existe, se actualiza.</p> `);
    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(`<!--]--> `);
    if (form?.success) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<p class="mb-4 rounded-lg bg-emerald-50 px-4 py-3 text-sm font-medium text-emerald-700" role="status">${escape_html(form.success)} <a href="/users" class="underline">Ver usuarios</a></p>`);
    } else {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]--> <form method="POST" class="card space-y-4 p-6"><div class="flex flex-wrap items-center gap-3"><label class="btn-secondary cursor-pointer">Subir archivo… <input type="file" accept=".csv,text/csv" class="hidden"/></label> <button type="button" class="btn-secondary">Cargar ejemplo</button></div> <div><label class="label" for="csv">Contenido CSV</label> <textarea class="input font-mono text-xs" id="csv" name="csv" rows="8" placeholder="nombre,email,identificador,rol Ana García,ana@centro.edu,12345678A,gestor">`);
    const $$body = escape_html(csv);
    if ($$body) {
      $$renderer2.push(`${$$body}`);
    }
    $$renderer2.push(`</textarea></div> `);
    {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]--> `);
    if (preview.length > 0) {
      $$renderer2.push("<!--[0-->");
      $$renderer2.push(`<div><p class="mb-2 text-sm font-medium text-slate-700">Previsualización (${escape_html(preview.length)} fila(s) de muestra)</p> <div class="overflow-x-auto rounded-lg border border-slate-200"><table class="w-full text-left text-xs"><thead class="bg-slate-50 text-slate-500"><tr><!--[-->`);
      const each_array = ensure_array_like(previewHeaders);
      for (let $$index = 0, $$length = each_array.length; $$index < $$length; $$index++) {
        let h = each_array[$$index];
        $$renderer2.push(`<th class="px-3 py-2 font-semibold">${escape_html(h)}</th>`);
      }
      $$renderer2.push(`<!--]--></tr></thead><tbody class="divide-y divide-slate-100"><!--[-->`);
      const each_array_1 = ensure_array_like(preview);
      for (let i = 0, $$length = each_array_1.length; i < $$length; i++) {
        let row = each_array_1[i];
        $$renderer2.push(`<tr><!--[-->`);
        const each_array_2 = ensure_array_like(row);
        for (let j = 0, $$length2 = each_array_2.length; j < $$length2; j++) {
          let cell = each_array_2[j];
          $$renderer2.push(`<td class="px-3 py-1.5 text-slate-700">${escape_html(cell)}</td>`);
        }
        $$renderer2.push(`<!--]--></tr>`);
      }
      $$renderer2.push(`<!--]--></tbody></table></div></div>`);
    } else {
      $$renderer2.push("<!--[-1-->");
    }
    $$renderer2.push(`<!--]--> <div class="flex gap-2"><button class="btn-primary" type="submit"${attr("disabled", !csv.trim(), true)}>Importar usuarios</button> <a class="btn-secondary" href="/users">Cancelar</a></div></form></div>`);
  });
}

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