import { d as defineEventHandler, c as createError, dL as optionalAuth, bT as requirePermission, G as createContentManager, bN as dbQueryOne } from '../../../nitro/nitro.mjs';
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 'fs';
import 'path';
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';

const _id__get = defineEventHandler(async (event) => {
  var _a;
  try {
    const id = parseInt(((_a = event.context.params) == null ? void 0 : _a.id) || "0");
    if (!id || isNaN(id)) {
      throw createError({
        statusCode: 400,
        statusMessage: "Bad Request",
        message: "Invalid folder ID"
      });
    }
    await optionalAuth(event);
    await requirePermission(
      event.context.user,
      "media",
      "read",
      event.context.adminUser,
      event.context.apiToken
    );
    const folderManager = createContentManager("media-folder");
    const folder = await folderManager.findOne(id);
    if (!folder) {
      throw createError({
        statusCode: 404,
        statusMessage: "Not Found",
        message: "Folder not found"
      });
    }
    const childResult = await dbQueryOne(
      `SELECT COUNT(*) as count FROM media_folders WHERE parent_id = ?`,
      [id]
    );
    const fileResult = await dbQueryOne(
      `SELECT COUNT(*) as count FROM media WHERE folder_id = ?`,
      [id]
    );
    const breadcrumb = [];
    let currentParentId = folder.parent;
    while (currentParentId !== null && currentParentId !== void 0) {
      const parentFolder = await dbQueryOne(
        `SELECT id, name, parent_id FROM media_folders WHERE id = ?`,
        [currentParentId]
      );
      if (!parentFolder) {
        break;
      }
      breadcrumb.unshift({ id: parentFolder.id, name: parentFolder.name });
      currentParentId = parentFolder.parent_id;
    }
    return {
      success: true,
      data: {
        ...folder,
        childCount: Number((childResult == null ? void 0 : childResult.count) || 0),
        fileCount: Number((fileResult == null ? void 0 : fileResult.count) || 0),
        breadcrumb
      }
    };
  } catch (error) {
    const err = error;
    if (err.statusCode) {
      throw error;
    }
    console.error("Get media folder error:", error);
    throw createError({
      statusCode: 500,
      statusMessage: "Internal Server Error",
      message: err.message || "Failed to get media folder"
    });
  }
});

export { _id__get as default };
//# sourceMappingURL=_id_.get.mjs.map
