import { y as defineEventHandler, b0 as useLogger, aa as getRouterParam, C as Collection, v as createError, aQ as sendNoContent } from '../../../../nitro/nitro.mjs';
import { Op } from '@sequelize/core';
import { r as requireAdminSession } from '../../../../_/session.mjs';
import 'luxon';
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 _index__put = defineEventHandler(async (event) => {
  await requireAdminSession(event);
  const log = useLogger("collection moveup");
  const sortIndex = Number(getRouterParam(event, "index"));
  try {
    const collections = await Collection.findAll({ where: { sortIndex: { [Op.lte]: sortIndex } }, limit: 2, order: [["sortIndex", "desc"]] });
    if (collections.length !== 2) {
      throw createError({ status: 404 });
    }
    const tmpSortIndex = collections[0].sortIndex;
    await collections[0].update({ sortIndex: collections[1].sortIndex });
    await collections[1].update({ sortIndex: tmpSortIndex });
    return sendNoContent(event, 200);
  } catch (e) {
    log.error(e);
    throw createError({ status: 404 });
  }
});

export { _index__put as default };
