import { i as defineEventHandler, K as readBody, e as createError, t as getProvider } from '../../nitro/nitro.mjs';
import 'node:path';
import 'node:module';
import 'node:fs';
import 'node:os';
import 'dotenv';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:crypto';
import 'node:async_hooks';
import 'node:url';
import 'node:net';
import '@iconify/utils';
import 'consola';

const tasks_post = defineEventHandler(async (event) => {
  var _a;
  const body = (_a = await readBody(event)) != null ? _a : {};
  const title = typeof body.title === "string" ? body.title.trim() : "";
  if (!title) {
    throw createError({ statusCode: 400, statusMessage: "title is required" });
  }
  const description = typeof body.description === "string" ? body.description : "";
  const tags = Array.isArray(body.tags) ? body.tags.filter((t) => typeof t === "string" && t.length > 0) : [];
  const priority = typeof body.priority === "number" ? body.priority : void 0;
  const dueDate = typeof body.dueDate === "number" ? body.dueDate : void 0;
  const listId = typeof body.listId === "string" ? body.listId.trim() || void 0 : void 0;
  const { provider, nonCodeProvider, config } = getProvider(event);
  const nonCodeTag = config.nonCodeTag || "";
  const useNonCode = nonCodeTag.length > 0 && nonCodeProvider !== void 0 && tags.some((t) => t.toLowerCase() === nonCodeTag.toLowerCase());
  const target = useNonCode ? nonCodeProvider : provider;
  if (typeof target.createTask !== "function") {
    throw createError({
      statusCode: 501,
      statusMessage: `${config.provider} provider does not support task creation`
    });
  }
  const result = await target.createTask({ title, description, tags, priority, dueDate, listId });
  return { id: result.id, url: result.url };
});

export { tasks_post as default };
//# sourceMappingURL=tasks.post.mjs.map
