import { _ as __nuxt_component_0 } from './nuxt-link-Cq8xZgFP.mjs';
import { defineComponent, ref, withAsyncContext, watch, nextTick, mergeProps, withCtx, createTextVNode, toDisplayString, unref, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrInterpolate, ssrRenderComponent, ssrRenderStyle, ssrRenderList, ssrRenderClass } from 'vue/server-renderer';
import { _ as _export_sfc, b as useRouter, u as useI18n, a as useHead } from './server.mjs';
import { u as useNotification } from './useNotification-BqDqaGnC.mjs';
import { u as useApiError } from './useApiError-BSStUojq.mjs';
import { u as useFetch } from './fetch-B5NxMLIO.mjs';
import { u as useWebSocket } from './useWebSocket-UbMCn0vY.mjs';
import '../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';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'unhead/server';
import 'devalue';
import 'unhead/utils';
import '@vue/shared';

const ISSUES_PER_PAGE = 5;
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "kanban",
  __ssrInlineRender: true,
  async setup(__props) {
    let __temp, __restore;
    useRouter();
    const { t } = useI18n();
    useNotification();
    useApiError();
    ref(null);
    const boardRef = ref(null);
    const boardWidth = ref(0);
    const updateBoardWidth = () => {
      if (boardRef.value) {
        boardWidth.value = boardRef.value.scrollWidth;
      }
    };
    const visibleCounts = ref({});
    const draggedIssue = ref(null);
    const dragOverColumn = ref(null);
    ref(false);
    ref(0);
    const processingIssues = ref(/* @__PURE__ */ new Set());
    const contextMenu = ref({
      visible: false,
      x: 0,
      y: 0,
      issue: null
    });
    const {
      data: columns,
      status: columnsStatus,
      error: columnsError
    } = ([__temp, __restore] = withAsyncContext(() => useFetch("/api/columns", "$35IWyimU8j")), __temp = await __temp, __restore(), __temp);
    const {
      data: issues,
      status: issuesStatus,
      error: issuesError,
      refresh: refreshIssues
    } = ([__temp, __restore] = withAsyncContext(() => useFetch("/api/issues", "$0eQrGqHYDa")), __temp = await __temp, __restore(), __temp);
    watch(
      () => columns.value,
      () => nextTick(updateBoardWidth)
    );
    const getColumnIssues = (columnSlug) => {
      if (!issues.value) return [];
      return issues.value.filter((i) => i.column_slug === columnSlug);
    };
    const getVisibleCount = (columnSlug) => {
      return visibleCounts.value[columnSlug] ?? ISSUES_PER_PAGE;
    };
    const getVisibleIssues = (columnSlug) => {
      const allIssues = getColumnIssues(columnSlug);
      const count = getVisibleCount(columnSlug);
      return allIssues.slice(0, count);
    };
    const hasMoreIssues = (columnSlug) => {
      const allIssues = getColumnIssues(columnSlug);
      const visibleCount = getVisibleCount(columnSlug);
      return allIssues.length > visibleCount;
    };
    const getRemainingCount = (columnSlug) => {
      const allIssues = getColumnIssues(columnSlug);
      const visibleCount = getVisibleCount(columnSlug);
      return Math.max(0, allIssues.length - visibleCount);
    };
    const { lastMessage } = useWebSocket();
    const silentRefresh = async () => {
      try {
        const newIssues = await $fetch("/api/issues");
        if (issues.value && newIssues) {
          const currentJson = JSON.stringify(issues.value);
          const newJson = JSON.stringify(newIssues);
          if (currentJson !== newJson) {
            issues.value = newIssues;
          }
        }
      } catch {
      }
    };
    const isProcessing = (issueKey) => {
      if (!processingIssues.value.has(issueKey)) return false;
      if (!columns.value || columns.value.length < 2) return false;
      const issue = issues.value?.find((i) => i.key === issueKey);
      if (!issue) return false;
      const columnIndex = columns.value.findIndex((c) => c.slug === issue.column_slug);
      if (columnIndex === 0 || columnIndex === columns.value.length - 1) return false;
      return true;
    };
    watch(lastMessage, (message) => {
      if (message?.type === "refresh" || message?.type === "issue-update") {
        silentRefresh();
      }
      if (message?.type === "claude_start" && message["issue"]) {
        const issueKey = message["issue"];
        processingIssues.value = /* @__PURE__ */ new Set([...processingIssues.value, issueKey]);
      }
      if (message?.type === "claude_end" && message["issue"]) {
        const issueKey = message["issue"];
        const newSet = new Set(processingIssues.value);
        newSet.delete(issueKey);
        processingIssues.value = newSet;
        silentRefresh();
      }
    });
    useHead({
      title: "Kanban - AutoCode"
    });
    return (_ctx, _push, _parent, _attrs) => {
      const _component_NuxtLink = __nuxt_component_0;
      _push(`<div${ssrRenderAttrs(mergeProps({ class: "kanban-page" }, _attrs))} data-v-a660ac78><header class="page-header" data-v-a660ac78><h1 data-v-a660ac78>${ssrInterpolate(_ctx.$t("kanban.title"))}</h1><div class="header-actions" data-v-a660ac78>`);
      _push(ssrRenderComponent(_component_NuxtLink, {
        to: "/issues/graph",
        class: "btn btn-secondary"
      }, {
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            _push2(`${ssrInterpolate(_ctx.$t("graph.title"))}`);
          } else {
            return [
              createTextVNode(toDisplayString(_ctx.$t("graph.title")), 1)
            ];
          }
        }),
        _: 1
      }, _parent));
      _push(`</div></header>`);
      if (unref(columnsStatus) === "pending" || unref(issuesStatus) === "pending") {
        _push(`<div class="loading" data-v-a660ac78>${ssrInterpolate(_ctx.$t("kanban.loading"))}</div>`);
      } else if (unref(columnsError) || unref(issuesError)) {
        _push(`<div class="error-message" data-v-a660ac78>${ssrInterpolate(unref(columnsError)?.message || unref(issuesError)?.message)}</div>`);
      } else {
        _push(`<div class="board-wrapper" data-v-a660ac78><div class="scroll-top" data-v-a660ac78><div class="scroll-spacer" style="${ssrRenderStyle({ width: unref(boardWidth) + "px" })}" data-v-a660ac78></div></div><div class="board" data-v-a660ac78><!--[-->`);
        ssrRenderList(unref(columns), (column) => {
          _push(`<div class="${ssrRenderClass([{ "drag-over": unref(dragOverColumn) === column.slug }, "board-column"])}" data-v-a660ac78><div class="column-header" data-v-a660ac78><div class="column-header-top" data-v-a660ac78><h2 class="column-title" data-v-a660ac78>${ssrInterpolate(column.name)} <span class="column-count" data-v-a660ac78>${ssrInterpolate(getColumnIssues(column.slug).length)}</span></h2>`);
          _push(ssrRenderComponent(_component_NuxtLink, {
            to: `/column/${column.slug}/prompt?name=${encodeURIComponent(column.name)}`,
            class: "column-action",
            title: "View prompt"
          }, {
            default: withCtx((_, _push2, _parent2, _scopeId) => {
              if (_push2) {
                _push2(` 👁 `);
              } else {
                return [
                  createTextVNode(" 👁 ")
                ];
              }
            }),
            _: 2
          }, _parent));
          _push(`</div>`);
          if (column.wip_limit) {
            _push(`<span class="wip-limit" data-v-a660ac78>${ssrInterpolate(_ctx.$t("kanban.wipLimit"))}: ${ssrInterpolate(column.wip_limit)}</span>`);
          } else {
            _push(`<!---->`);
          }
          _push(`</div><div class="column-content" data-v-a660ac78>`);
          if (getColumnIssues(column.slug).length === 0) {
            _push(`<div class="column-empty" data-v-a660ac78>${ssrInterpolate(_ctx.$t("kanban.noIssues"))}</div>`);
          } else {
            _push(`<!---->`);
          }
          _push(`<!--[-->`);
          ssrRenderList(getVisibleIssues(column.slug), (issue) => {
            _push(`<div class="${ssrRenderClass([{
              dragging: unref(draggedIssue) === issue.key,
              processing: isProcessing(issue.key)
            }, "issue-card"])}" draggable="true" data-v-a660ac78><div class="issue-header" data-v-a660ac78><div class="issue-key" data-v-a660ac78>`);
            if (isProcessing(issue.key)) {
              _push(`<span class="processing-indicator" title="Claude is working..." data-v-a660ac78>⚙️</span>`);
            } else {
              _push(`<!---->`);
            }
            _push(` ${ssrInterpolate(issue.key)}</div><button class="issue-menu-btn" title="Menu" data-v-a660ac78> ☰ </button></div><div class="issue-title" data-v-a660ac78>${ssrInterpolate(issue.title)}</div><div class="issue-meta" data-v-a660ac78>`);
            if (issue.priority) {
              _push(`<span class="${ssrRenderClass([`badge-${issue.priority}`, "badge"])}" data-v-a660ac78>${ssrInterpolate(issue.priority)}</span>`);
            } else {
              _push(`<!---->`);
            }
            if (issue.parent_key) {
              _push(`<span class="parent-indicator" title="Has parent" data-v-a660ac78> ^ </span>`);
            } else {
              _push(`<!---->`);
            }
            _push(`</div></div>`);
          });
          _push(`<!--]-->`);
          if (hasMoreIssues(column.slug)) {
            _push(`<button class="load-more-btn" data-v-a660ac78>${ssrInterpolate(_ctx.$t("kanban.loadMore"))} (${ssrInterpolate(getRemainingCount(column.slug))}) </button>`);
          } else {
            _push(`<!---->`);
          }
          _push(`</div></div>`);
        });
        _push(`<!--]--></div></div>`);
      }
      if (unref(contextMenu).visible) {
        _push(`<div style="${ssrRenderStyle({
          position: "fixed",
          inset: "0",
          zIndex: 99998
        })}" data-v-a660ac78></div>`);
      } else {
        _push(`<!---->`);
      }
      if (unref(contextMenu).visible) {
        _push(`<div style="${ssrRenderStyle({
          position: "fixed",
          top: unref(contextMenu).y + "px",
          left: unref(contextMenu).x + "px",
          zIndex: 99999,
          background: "white",
          border: "1px solid #ddd",
          borderRadius: "8px",
          boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
          padding: "4px 0",
          minWidth: "140px"
        })}" data-v-a660ac78>`);
        if (unref(contextMenu).issue && unref(columns) && unref(contextMenu).issue.column_slug !== unref(columns)[unref(columns).length - 1]?.slug) {
          _push(`<button style="${ssrRenderStyle({
            display: "block",
            width: "100%",
            padding: "10px 16px",
            textAlign: "left",
            background: "none",
            border: "none",
            cursor: "pointer",
            fontSize: "14px"
          })}" data-v-a660ac78>${ssrInterpolate(_ctx.$t("issue.archive"))}</button>`);
        } else {
          _push(`<!---->`);
        }
        _push(`<button style="${ssrRenderStyle({
          display: "block",
          width: "100%",
          padding: "10px 16px",
          textAlign: "left",
          background: "none",
          border: "none",
          cursor: "pointer",
          fontSize: "14px",
          color: "#ef4444"
        })}" data-v-a660ac78>${ssrInterpolate(_ctx.$t("common.delete"))}</button></div>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div>`);
    };
  }
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/kanban.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const kanban = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a660ac78"]]);

export { kanban as default };
//# sourceMappingURL=kanban-CMVmXpCA.mjs.map
