import { y as defineEventHandler, ac as getValidatedQuery, T as Tag, E as Event, ar as normalizeTag } from '../../nitro/nitro.mjs';
import { Op, fn, col } from '@sequelize/core';
import { z } from 'zod';
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().trim().optional().transform((q) => q && normalizeTag(q))
});
const index_get = defineEventHandler(async (event) => {
  const { query } = await getValidatedQuery(event, schema.parse);
  const tags = await Tag.findAll({
    order: [[fn("COUNT", col("tag")), "DESC"]],
    attributes: ["tag"],
    where: query ? { normalizedTag: { [Op.like]: `%${query}%` } } : void 0,
    include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
    group: ["tag"],
    limit: 10,
    raw: true,
    subQuery: false
  });
  return tags.map((t) => t.tag);
});

export { index_get as default };
