import { d as defineEventHandler, g as getRouterParam, c as createError, P as Place, N as getEvents, Z as calculateEtag, h as handleCache, O as mapEvents, u as useLogger } 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 log = useLogger("events/place");
const _place_ = defineEventHandler(async (evt) => {
  const nameOrId = getRouterParam(evt, "place");
  if (!nameOrId) {
    throw createError({ statusCode: 400, message: `Invalid place parameter` });
  }
  const id = Number(nameOrId);
  const place = !isNaN(id) && Number.isInteger(id) ? await Place.findByPk(id) : await Place.findOne({ where: { name: nameOrId } });
  if (!place) {
    throw createError({ statusCode: 404, message: `Place not found` });
  }
  log.debug(`Events for place: ${place.name}`);
  const events = await getEvents({ places: [place.id], show_federated: true });
  const pastEvents = await getEvents({ places: [place.id], older: true, reverse: true, show_federated: true });
  const etag = calculateEtag([...events, ...pastEvents, place]);
  if (await handleCache(evt, etag)) return;
  return {
    events: mapEvents(events),
    pastEvents: mapEvents(pastEvents),
    place
  };
});

export { _place_ as default };
