import { d as defineEventHandler, r as readBody, c as createError } from '../../../../nitro/nitro.mjs';
import { mkdir, writeFile } from 'fs/promises';
import { join } from 'path';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'stream';
import 'events';
import 'http';
import 'crypto';
import 'buffer';
import 'zlib';
import 'https';
import 'net';
import 'tls';
import 'url';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'vue-router';
import '@prisma/client';
import '@prisma/adapter-better-sqlite3';
import 'fs';
import 'child_process';
import 'node:child_process';
import 'node:url';

const apply_post = defineEventHandler(async (event) => {
  const body = await readBody(event);
  if (!body.proposals || !Array.isArray(body.proposals)) {
    throw createError({
      statusCode: 400,
      message: "Proposals array required"
    });
  }
  const catalogPath = join(process.cwd(), "catalog");
  const results = [];
  for (const proposal of body.proposals) {
    try {
      const slug = proposal.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
      const columnPath = join(catalogPath, slug);
      await mkdir(columnPath, { recursive: true });
      const configContent = {
        name: proposal.name,
        description: proposal.description,
        type: proposal.type,
        ...proposal.config
      };
      await writeFile(join(columnPath, "config.json"), JSON.stringify(configContent, null, 2));
      await writeFile(join(columnPath, "prompt.txt"), "");
      await writeFile(join(columnPath, "actions.yml"), "");
      results.push({ name: proposal.name, success: true });
    } catch (err) {
      const result = {
        name: proposal.name,
        success: false
      };
      if (err instanceof Error) result.error = err.message;
      results.push(result);
    }
  }
  return results;
});

export { apply_post as default };
//# sourceMappingURL=apply.post.mjs.map
