import { d as defineEventHandler, u as useLogger, e as enableCors, n as getValidatedQuery, M as eventQuerySchema, h as handleCache, w as publicSettings, N as getEvents, O as mapEvents, E as Event } from '../../nitro/nitro.mjs';
import { g as getCollectionEvents } from '../../_/collections.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_get = defineEventHandler(async (event) => {
  const log = useLogger("get events");
  enableCors(event);
  const opt = await getValidatedQuery(event, eventQuerySchema.parse);
  let events;
  if (await handleCache(event, Event)) return;
  if (publicSettings.collection_in_home && !(opt.tags || opt.places || opt.query)) {
    log.debug("get collection events", publicSettings.collection_in_home);
    events = await getCollectionEvents({ name: publicSettings.collection_in_home, ...opt });
  } else {
    events = await getEvents(opt);
  }
  return mapEvents(events);
});

export { index_get as default };
