import { d as defineEventHandler, c as createError, w as publicSettings, t as setHeader, a3 as runtimeResolve, u as useLogger } from '../nitro/nitro.mjs';
import fs from 'fs';
import pug from 'pug';
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/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("Open Search");
const openSearchTemplate = loadOpenSearchTemplate();
const opensearch_xml = defineEventHandler(async (event) => {
  if (!openSearchTemplate) {
    throw createError({ statusCode: 500 });
  }
  const longName = publicSettings.title.includes("Gancio") ? publicSettings.title : publicSettings.title + " - Gancio";
  const response = openSearchTemplate({
    settings: publicSettings,
    longName
  });
  setHeader(event, "Content-Type", "text/xml");
  setHeader(event, "Cache-Control", "public, max-age=2592000, immutable");
  return response;
});
function loadOpenSearchTemplate() {
  try {
    const templateStr = fs.readFileSync(runtimeResolve("./static/opensearch.pug"), "utf-8");
    return pug.compile(templateStr);
  } catch (err) {
    log.error("Unable to load opensearch template.", err);
    return null;
  }
}

export { opensearch_xml as default, openSearchTemplate };
