import { y as defineEventHandler, b0 as useLogger, E as Event, d as Place, M as Message, v as createError } from '../../../nitro/nitro.mjs';
import { DateTime } from 'luxon';
import { b as requireUser } from '../../../_/session.mjs';
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';
import '../../../_/getUser.mjs';
import '../../../_/jwt.mjs';
import 'jose';

const unconfirmed = defineEventHandler(async (event) => {
  await requireUser(event);
  const log = useLogger("event/unconfirmed");
  try {
    const events = await Event.findAll({
      where: {
        parentId: null,
        is_visible: false
      },
      // attributes: {
      //   include: [
      //     [ sql.cast( sql.fn('COUNT', sql.col('messages.id')), 'INTEGER' ), 'n_messages' ]
      //   ],
      // },
      order: [["start_datetime", "ASC"]],
      include: [
        Place,
        { model: Message, required: false, attributes: [] }
      ]
      // group: [col('event', 'id'), col('place.id')],
    });
    const now = DateTime.local().toUnixInteger();
    return { events: events.filter((e) => e.start_datetime >= now), oldEvents: events.filter((e) => e.start_datetime < now) };
  } catch (e) {
    log.info(String(e));
    throw createError({ statusCode: 400, statusMessage: String(e) });
  }
});

export { unconfirmed as default };
