import { u as updateUser } from '../../../chunks/auths_D_cJY4N0.mjs';
export { renderers } from '../../../renderers.mjs';

async function POST({ request, cookies, locals }) {
  const formData = await request.formData();
  const user = locals.user;
  const email = formData.get("email");
  const firstName = formData.get("first_name");
  const lastName = formData.get("last_name");
  const username = formData.get("username");
  const phone = formData.get("phone");
  const address = formData.get("address");
  const id = Number(formData.get("id"));
  if (typeof email !== "string" || typeof address !== "string" || typeof phone !== "string" || typeof username !== "string" || typeof lastName !== "string" || typeof firstName !== "string") {
    return new Response(
      JSON.stringify({
        message: "Text Inputs Only"
      }),
      {
        status: 400
      }
    );
  }
  if (Number(user.id) !== id || !user.isAdmin) {
    return new Response(
      JSON.stringify({
        message: "Unauthorised user"
      }),
      {
        status: 403
      }
    );
  }
  try {
    await updateUser(
      {
        email,
        firstName,
        lastName,
        username,
        phone,
        address
      },
      id
    );
    return new Response(
      JSON.stringify({
        message: "Account Created!"
      }),
      {
        status: 201
      }
    );
  } catch (error) {
    return new Response(
      JSON.stringify({
        message: error?.message
      }),
      {
        status: 500
      }
    );
  }
}

const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
  __proto__: null,
  POST
}, Symbol.toStringTag, { value: 'Module' }));

const page = () => _page;

export { page };
