import process from 'node:process';globalThis._importMeta_=globalThis._importMeta_||{url:"file:///_entry.js",env:process.env};import { d as defineEventHandler, c as createError, s as setResponseHeader } from '../../nitro/nitro.mjs';
import { existsSync, readFileSync } from 'fs';
import { extname, resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
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 'semver';

const __filename$1 = fileURLToPath(globalThis._importMeta_.url);
const __dirname$1 = dirname(__filename$1);
function findAdminDir() {
  const devPath = resolve(__dirname$1, "../../../../public/admin");
  if (existsSync(devPath)) {
    return devPath;
  }
  const prodPath = resolve(__dirname$1, "../../../public/admin");
  if (existsSync(prodPath)) {
    return prodPath;
  }
  const chunksPath = resolve(__dirname$1, "../../public/admin");
  if (existsSync(chunksPath)) {
    return chunksPath;
  }
  const cwdPath = resolve(process.cwd(), "public/admin");
  if (existsSync(cwdPath)) {
    return cwdPath;
  }
  const cwdOutputPath = resolve(process.cwd(), ".output/public/admin");
  if (existsSync(cwdOutputPath)) {
    return cwdOutputPath;
  }
  const nodeModulesOutputPath = resolve(
    process.cwd(),
    "node_modules/@notty/server/.output/public/admin"
  );
  if (existsSync(nodeModulesOutputPath)) {
    return nodeModulesOutputPath;
  }
  const nodeModulesPublicPath = resolve(process.cwd(), "node_modules/@notty/server/public/admin");
  if (existsSync(nodeModulesPublicPath)) {
    return nodeModulesPublicPath;
  }
  return "";
}
const MIME_TYPES = {
  ".js": "application/javascript",
  ".css": "text/css",
  ".svg": "image/svg+xml",
  ".png": "image/png",
  ".jpg": "image/jpeg",
  ".jpeg": "image/jpeg",
  ".gif": "image/gif",
  ".ico": "image/x-icon",
  ".woff": "font/woff",
  ".woff2": "font/woff2",
  ".ttf": "font/ttf",
  ".eot": "application/vnd.ms-fontobject",
  ".map": "application/json"
};
const fileCache = /* @__PURE__ */ new Map();
let indexHtmlCache = null;
let adminDir = null;
const ____path__get = defineEventHandler((event) => {
  var _a;
  if (adminDir === null) {
    adminDir = findAdminDir();
    if (adminDir) {
      console.log(`\u{1F4C1} Admin panel found at: ${adminDir}`);
    }
  }
  if (!adminDir) {
    throw createError({
      statusCode: 404,
      statusMessage: "Not Found",
      message: "Admin panel not found. Ensure @notty/admin is built."
    });
  }
  const path = ((_a = event.context.params) == null ? void 0 : _a.path) || "";
  const ext = extname(path).toLowerCase();
  if (MIME_TYPES[ext]) {
    const filePath = resolve(adminDir, path);
    if (!existsSync(filePath)) {
      throw createError({
        statusCode: 404,
        statusMessage: "Not Found",
        message: `Asset not found: ${path}`
      });
    }
    let content;
    const cachedContent = fileCache.get(filePath);
    if (cachedContent) {
      content = cachedContent;
    } else {
      content = readFileSync(filePath);
      {
        fileCache.set(filePath, content);
      }
    }
    setResponseHeader(event, "Content-Type", MIME_TYPES[ext]);
    setResponseHeader(event, "Cache-Control", "public, max-age=31536000, immutable");
    return content;
  }
  const indexPath = resolve(adminDir, "index.html");
  if (!existsSync(indexPath)) {
    throw createError({
      statusCode: 404,
      statusMessage: "Not Found",
      message: "Admin panel index.html not found."
    });
  }
  if (!indexHtmlCache || false) {
    indexHtmlCache = readFileSync(indexPath, "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 indexHtmlCache;
});

export { ____path__get as default };
//# sourceMappingURL=_...path_.get.mjs.map
