import { f as defineAdminEventHandler, h as requireAdminRole, q as readBody, c as createError, br as getComponentRegistry, bs as SchemaValidationError } 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 index_post = defineAdminEventHandler("admin:components:create", async (event) => {
  try {
    await requireAdminRole(event, ["super-admin", "admin"]);
    const body = await readBody(event);
    if (!body.uid || !body.category || !body.info || !body.attributes) {
      throw createError({
        statusCode: 400,
        statusMessage: "Missing required fields",
        message: "Component must have uid, category, info, and attributes"
      });
    }
    const component = {
      uid: body.uid,
      category: body.category,
      info: {
        displayName: body.info.displayName || "",
        description: body.info.description,
        icon: body.info.icon
      },
      attributes: body.attributes
    };
    const registry = getComponentRegistry();
    if (registry.has(component.uid)) {
      throw createError({
        statusCode: 409,
        statusMessage: "Component already exists",
        message: `Component '${component.uid}' already exists`
      });
    }
    registry.save(component);
    return {
      success: true,
      data: component
    };
  } catch (error) {
    if (error instanceof SchemaValidationError) {
      throw createError({
        statusCode: 400,
        statusMessage: "Validation failed",
        message: "Component schema validation failed",
        data: error.result.errors
      });
    }
    if (error && typeof error === "object" && "statusCode" in error) {
      throw error;
    }
    console.error("[POST /api/admin/components] Error:", error);
    throw createError({
      statusCode: 500,
      statusMessage: "Failed to create component",
      message: error instanceof Error ? error.message : "Unknown error"
    });
  }
});

export { index_post as default };
//# sourceMappingURL=index.post3.mjs.map
