import { C as error, O as fail, N as redirect } from '../../../../chunks/utils.js-mIi_c4Oz.js';
import { a as hasRole } from '../../../../chunks/auth.js-D502gejJ.js';
import { e as readDeviceForm, f as createDevice, l as listCategories } from '../../../../chunks/queries.js-BUUEc74j.js';

const load = async ({ locals }) => {
  if (!hasRole(locals.user, "gestor")) throw error(403, "Sin permisos.");
  return { categories: listCategories() };
};
const actions = {
  default: async ({ request, locals }) => {
    if (!hasRole(locals.user, "gestor")) throw error(403, "Sin permisos.");
    const form = await request.formData();
    const input = readDeviceForm(form);
    const result = createDevice(input);
    if (result.error) {
      return fail(400, { error: result.error, values: Object.fromEntries(form) });
    }
    throw redirect(303, `/devices/${result.id}`);
  }
};

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

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