import { d as defineEventHandler } from '../../nitro/nitro.mjs';
import { r as readNews } from '../../_/news.mjs';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
import 'fs';
import 'path';
import 'crypto';

const newsPublic_get = defineEventHandler(async (event) => {
  try {
    const allNews = await readNews();
    const now = /* @__PURE__ */ new Date();
    const publicNews = allNews.filter((item) => {
      if (!item.isPublic) return false;
      if (item.isHidden) return false;
      if (item.expiresAt) {
        const expiresAt = new Date(item.expiresAt);
        if (expiresAt <= now) return false;
      }
      return true;
    });
    publicNews.sort((a, b) => new Date(b.created) - new Date(a.created));
    const latestNews = publicNews.slice(0, 3);
    return {
      success: true,
      news: latestNews
    };
  } catch (error) {
    console.error("Fehler beim Abrufen der \xF6ffentlichen News:", error);
    throw error;
  }
});

export { newsPublic_get as default };
//# sourceMappingURL=news-public.get.mjs.map
