import { y as defineEventHandler, ac as getValidatedQuery, d as Place, E as Event, az as placeToJSON, aC as publicSettings } from '../../nitro/nitro.mjs';
import { z } from 'zod';
import { Op, where, fn, col } from '@sequelize/core';
import 'luxon';
import 'html-to-text';
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 schema = z.object({
  query: z.string().optional().transform((q) => q?.toLocaleLowerCase(publicSettings.instance_locale)),
  limit: z.number().min(1).max(100).default(10)
});
const index_get = defineEventHandler(async (event) => {
  const { query, limit } = await getValidatedQuery(event, schema.parse);
  const condition = query ? {
    [Op.or]: [
      where(fn("LOWER", col("name")), Op.like, "%" + query + "%"),
      where(fn("LOWER", col("address")), Op.like, "%" + query + "%")
    ]
  } : void 0;
  const places = await Place.findAll({
    order: [[fn("COUNT", col("events.placeId")), "DESC"]],
    where: condition,
    attributes: ["name", "address", "latitude", "longitude", "id", "ap_id"],
    include: [{ model: Event, where: { is_visible: true }, required: true, attributes: [] }],
    group: ["Place.id"],
    limit,
    subQuery: false
  });
  return places.map(placeToJSON);
});

export { index_get as default };
