import { d as defineEventHandler, I as findAll } from '../../../nitro/nitro.mjs';
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 'path';
import 'fs/promises';
import 'child_process';
import 'node:child_process';
import 'node:url';

const graph_get = defineEventHandler(async () => {
  const issues = await findAll({ includeColumn: true });
  const issueMap = /* @__PURE__ */ new Map();
  for (const issue of issues) {
    issueMap.set(issue.key, issue);
  }
  const roots = [];
  const childrenMap = /* @__PURE__ */ new Map();
  for (const issue of issues) {
    if (!issue.parentKey || !issueMap.has(issue.parentKey)) {
      roots.push(issue);
    } else {
      const siblings = childrenMap.get(issue.parentKey) || [];
      siblings.push(issue);
      childrenMap.set(issue.parentKey, siblings);
    }
  }
  const buildNode = (issue) => {
    var _a, _b;
    const children = childrenMap.get(issue.key) || [];
    const node = {
      id: issue.key,
      title: issue.title,
      column: (_b = (_a = issue.column) == null ? void 0 : _a.slug) != null ? _b : ""
    };
    if (issue.priority) node.priority = issue.priority;
    if (children.length > 0) node.children = children.map(buildNode);
    return node;
  };
  const rootNode = {
    id: "root",
    title: "Issues"
  };
  if (roots.length > 0) rootNode.children = roots.map(buildNode);
  return rootNode;
});

export { graph_get as default };
//# sourceMappingURL=graph.get.mjs.map
