import { d as defineEventHandler, u as useLogger, a as readBody, c as createError, a1 as parseIcsData } from '../../nitro/nitro.mjs';
import 'luxon';
import '@sequelize/core';
import 'html-to-text';
import 'zod';
import 'crypto';
import 'node:fs';
import 'sharp';
import 'path';
import 'node:stream';
import 'jsdom';
import 'dompurify';
import 'mime-types';
import 'fs';
import 'fs/promises';
import 'linkify-html';
import '@peertube/http-signature';
import 'jsonld';
import 'lodash.intersection';
import 'email-templates';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'node:events';
import 'node:buffer';
import 'node:path';
import 'vue';
import 'vue-router';
import 'dotenv';
import 'url';
import 'bcryptjs';
import 'slugify';
import 'umzug';
import 'consola';
import '@sequelize/core/decorators-legacy';
import 'util';
import 'mitt';
import 'ical.js';
import 'node:url';
import 'fast-xml-parser';

const index_post = defineEventHandler(async (event) => {
  const log = useLogger("ics");
  const { icsText, includePastEvents = false } = await readBody(event);
  if (!icsText) {
    log.warn("No ICS text received");
    throw createError({ status: 400, message: "No ICS text received" });
  }
  try {
    const events = parseIcsData(icsText, includePastEvents);
    log.info(`Found ${events.length} event(s)`);
    return { success: true, events };
  } catch (e) {
    log.error("ICS error", e);
    throw createError({ status: 500, message: "Error while parsing ics text" });
  }
});

export { index_post as default };
