import { d as defineEventHandler, g as getCookie, c as createError, r as readBody } from '../../nitro/nitro.mjs';
import { b as verifyToken, e as getUserById } from '../../_/auth.mjs';
import { d as deleteMember } from '../../_/members.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import 'bcryptjs';
import 'jsonwebtoken';
import 'fs';
import 'path';
import '../../_/encryption.mjs';
import 'crypto';

const members_delete = defineEventHandler(async (event) => {
  try {
    const token = getCookie(event, "auth_token");
    if (!token) {
      throw createError({
        statusCode: 401,
        message: "Nicht authentifiziert."
      });
    }
    const decoded = verifyToken(token);
    if (!decoded) {
      throw createError({
        statusCode: 401,
        message: "Ung\xFCltiges Token."
      });
    }
    const user = await getUserById(decoded.id);
    if (!user || user.role !== "admin" && user.role !== "vorstand") {
      throw createError({
        statusCode: 403,
        message: "Keine Berechtigung zum L\xF6schen von Mitgliedern."
      });
    }
    const body = await readBody(event);
    const { id } = body;
    if (!id) {
      throw createError({
        statusCode: 400,
        message: "Mitglieds-ID ist erforderlich."
      });
    }
    await deleteMember(id);
    return {
      success: true,
      message: "Mitglied erfolgreich gel\xF6scht."
    };
  } catch (error) {
    console.error("Fehler beim L\xF6schen des Mitglieds:", error);
    throw error;
  }
});

export { members_delete as default };
//# sourceMappingURL=members.delete.mjs.map
