import { d as defineEventHandler, g as getQuery, c as createError } from '../../nitro/nitro.mjs';
import { readFile } from 'fs/promises';
import { join } from 'path';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'stream';
import 'events';
import 'http';
import 'crypto';
import 'buffer';
import 'zlib';
import 'https';
import 'net';
import 'tls';
import 'url';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'vue-router';
import '@prisma/client';
import '@prisma/adapter-better-sqlite3';
import 'fs';
import 'child_process';
import 'node:child_process';
import 'node:url';

function parseChangelog(content) {
  const entries = [];
  const versionBlocks = content.split(/(?=^## \[)/m).filter((b) => b.trim());
  for (const block of versionBlocks) {
    const versionMatch = block.match(/^## \[([^\]]+)\] - (\d{4}-\d{2}-\d{2})/);
    if (!versionMatch) continue;
    const rawTag = versionMatch[1];
    const date = versionMatch[2];
    if ((rawTag == null ? void 0 : rawTag.toLowerCase()) === "unreleased") continue;
    const tag = (rawTag == null ? void 0 : rawTag.startsWith("v")) ? rawTag : `v${rawTag}`;
    const sections = [];
    const sectionBlocks = block.split(/(?=^### )/m);
    for (const sectionBlock of sectionBlocks) {
      const sectionMatch = sectionBlock.match(/^### (.+)/);
      if (!sectionMatch) continue;
      const items = [];
      const itemMatches = sectionBlock.matchAll(/^- (.+)$/gm);
      for (const m of itemMatches) {
        if (m[1]) items.push(m[1]);
      }
      if (items.length > 0 && sectionMatch[1]) {
        sections.push({ title: sectionMatch[1].trim(), items });
      }
    }
    if (tag && date) {
      entries.push({ tag, date, sections });
    }
  }
  return entries;
}
const changelog_get = defineEventHandler(async (event) => {
  var _a;
  const query = getQuery(event);
  const lang = query["lang"] === "fr" ? "fr" : "en";
  const filename = lang === "fr" ? "CHANGELOG.fr.md" : "CHANGELOG.md";
  const changelogPath = join(process.cwd(), filename);
  try {
    const content = await readFile(changelogPath, "utf-8");
    const entries = parseChangelog(content);
    const topTag = ((_a = entries[0]) == null ? void 0 : _a.tag) || "";
    return {
      success: true,
      data: { lang, topTag, entries }
    };
  } catch (error) {
    console.error("Failed to read changelog:", error);
    throw createError({
      statusCode: 404,
      message: "Changelog not found"
    });
  }
});

export { changelog_get as default };
//# sourceMappingURL=changelog.get.mjs.map
