import { d as defineEventHandler, c as createError, s as setResponseHeader } from '../nitro/nitro.mjs';
import { readFileSync, existsSync } from 'fs';
import { resolve } from 'path';
import 'node:crypto';
import 'jsonwebtoken';
import 'node:fs';
import 'node:module';
import 'node:path';
import 'node:url';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'pino';
import 'drizzle-orm/better-sqlite3';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/mysql2';
import 'better-sqlite3';
import 'pg';
import 'mysql2/promise';
import 'drizzle-orm';
import 'prom-client';
import 'bcryptjs';
import '@node-rs/argon2';
import 'node:async_hooks';
import 'crypto';
import 'node:dns';
import 'node:util';
import 'node:net';
import 'fs/promises';
import 'url';
import 'semver';

let cachedHtml = null;
let adminIndexPath = null;
function findAdminIndex() {
  const cwdPath = resolve(process.cwd(), "public/admin/index.html");
  if (existsSync(cwdPath)) {
    return cwdPath;
  }
  const cwdOutputPath = resolve(process.cwd(), ".output/public/admin/index.html");
  if (existsSync(cwdOutputPath)) {
    return cwdOutputPath;
  }
  const nodeModulesOutputPath = resolve(
    process.cwd(),
    "node_modules/@notty/server/.output/public/admin/index.html"
  );
  if (existsSync(nodeModulesOutputPath)) {
    return nodeModulesOutputPath;
  }
  const nodeModulesPublicPath = resolve(
    process.cwd(),
    "node_modules/@notty/server/public/admin/index.html"
  );
  if (existsSync(nodeModulesPublicPath)) {
    return nodeModulesPublicPath;
  }
  return "";
}
const index_get = defineEventHandler((event) => {
  if (adminIndexPath === null) {
    adminIndexPath = findAdminIndex();
    if (adminIndexPath) {
      console.log(`\u{1F4C1} Admin index.html found at: ${adminIndexPath}`);
    }
  }
  if (!adminIndexPath) {
    throw createError({
      statusCode: 404,
      statusMessage: "Not Found",
      message: "Admin panel not found. Ensure @notty/admin is built."
    });
  }
  if (!cachedHtml || false) {
    cachedHtml = readFileSync(adminIndexPath, "utf-8");
  }
  setResponseHeader(event, "Content-Type", "text/html; charset=utf-8");
  setResponseHeader(event, "Cache-Control", "no-store, no-cache, must-revalidate");
  setResponseHeader(event, "Pragma", "no-cache");
  setResponseHeader(event, "Expires", "0");
  return cachedHtml;
});

export { index_get as default };
//# sourceMappingURL=index.get.mjs.map
