import { C as error, N as redirect } from '../../../chunks/utils.js-mIi_c4Oz.js';
import { a as hasRole } from '../../../chunks/auth.js-D502gejJ.js';
import { p as parseScan } from '../../../chunks/qr.js-BYghGLdS.js';
import { h as getDeviceByCode } from '../../../chunks/queries.js-BUUEc74j.js';

const load = async ({ url, locals }) => {
  if (!hasRole(locals.user, "gestor")) throw error(403, "Sin permisos para escanear.");
  const raw = url.searchParams.get("code");
  if (!raw) return { notFoundCode: null };
  const parsed = parseScan(raw);
  if (parsed) {
    const device = getDeviceByCode(parsed.code);
    if (device) throw redirect(303, `/devices/${device.id}`);
    return { notFoundCode: parsed.code };
  }
  return { notFoundCode: raw };
};

var _page_server_ts = /*#__PURE__*/Object.freeze({
  __proto__: null,
  load: load
});

export { _page_server_ts as _ };
//# sourceMappingURL=_page.server.ts.js-CB3T3KoQ.js.map
