import { _ as __nuxt_component_0 } from './IssueHeader-BKlqeUoH.mjs';
import { _ as __nuxt_component_0$1 } from './nuxt-link-Cq8xZgFP.mjs';
import { defineComponent, ref, withAsyncContext, computed, watch, mergeProps, unref, withCtx, createTextVNode, toDisplayString, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrRenderComponent, ssrRenderAttr, ssrIncludeBooleanAttr, ssrInterpolate, ssrLooseContain, ssrLooseEqual, ssrRenderList, ssrRenderClass } from 'vue/server-renderer';
import { marked } from 'marked';
import { _ as _export_sfc, j as useRoute, 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 '../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 _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "index",
  __ssrInlineRender: true,
  async setup(__props) {
    let __temp, __restore;
    const route = useRoute();
    useRouter();
    const { t, locale } = useI18n();
    useNotification();
    useApiError();
    const issueId = route.params["id"];
    const showMoveModal = ref(false);
    const targetColumn = ref("");
    const moving = ref(false);
    const saving = ref(false);
    const autocompleting = ref(false);
    const isEditingDescription = ref(false);
    const isEditingCriteria = ref(false);
    const editedCriteria = ref([]);
    const { data: issue, refresh } = ([__temp, __restore] = withAsyncContext(() => useFetch(`/api/issues/${issueId}`, "$IXIJsCSqf0")), __temp = await __temp, __restore(), __temp);
    const { data: columns } = ([__temp, __restore] = withAsyncContext(() => useFetch("/api/columns", "$xdX8vE_27c")), __temp = await __temp, __restore(), __temp);
    const { data: allIssues } = ([__temp, __restore] = withAsyncContext(() => useFetch("/api/issues", "$81nxEVnLdN")), __temp = await __temp, __restore(), __temp);
    const parentSuggestions = computed(() => {
      return (allIssues.value || []).filter((i) => i.key !== issueId).slice(0, 10);
    });
    const editedTitle = ref(issue.value?.title || "");
    const editedDescription = ref(issue.value?.description || "");
    const editedPriority = ref(issue.value?.priority || "");
    const editedParent = ref(issue.value?.parent_key || "");
    watch(issue, (newIssue) => {
      if (newIssue) {
        editedTitle.value = newIssue.title;
        editedDescription.value = newIssue.description || "";
        editedPriority.value = newIssue.priority || "";
        editedParent.value = newIssue.parent_key || "";
      }
    });
    const columnName = computed(() => {
      if (!issue.value || !columns.value) return issue.value?.column_slug || "";
      const col = columns.value.find((c) => c.slug === issue.value?.column_slug);
      return col?.name || issue.value.column_slug;
    });
    const isInLastColumn = computed(() => {
      if (!issue.value || !columns.value || columns.value.length === 0) return false;
      const lastColumn = columns.value[columns.value.length - 1];
      return issue.value.column_slug === lastColumn?.slug;
    });
    const issueForHeader = computed(() => {
      if (!issue.value) return null;
      const header = {
        id: issue.value.key,
        title: editedTitle.value,
        column: issue.value.column_slug
      };
      if (issue.value.priority) header.priority = issue.value.priority;
      return header;
    });
    const hasChanges = computed(() => {
      if (!issue.value) return false;
      const titleChanged = editedTitle.value !== issue.value.title;
      const descChanged = editedDescription.value !== (issue.value.description || "");
      const priorityChanged = editedPriority.value !== (issue.value.priority || "");
      const parentChanged = editedParent.value !== (issue.value.parent_key || "");
      const criteriaChanged = isEditingCriteria.value && JSON.stringify(editedCriteria.value.filter((c) => c.trim())) !== JSON.stringify(issue.value.acceptance_criteria || []);
      return titleChanged || descChanged || priorityChanged || parentChanged || criteriaChanged;
    });
    const renderedDescription = computed(() => {
      const desc = isEditingDescription.value ? editedDescription.value : issue.value?.description || "";
      if (!desc) return `<span style="color: var(--text-muted)">${t("issue.noDescription")}</span>`;
      return marked(desc);
    });
    const formatDate = (date) => {
      if (!date) return "-";
      return new Date(date).toLocaleDateString();
    };
    useHead({
      title: `${issueId} - AutoCode`
    });
    return (_ctx, _push, _parent, _attrs) => {
      const _component_IssueHeader = __nuxt_component_0;
      const _component_NuxtLink = __nuxt_component_0$1;
      _push(`<div${ssrRenderAttrs(mergeProps({ class: "issue-view-page" }, _attrs))} data-v-07b1c9a3>`);
      _push(ssrRenderComponent(_component_IssueHeader, {
        issue: unref(issueForHeader),
        "active-tab": "details"
      }, null, _parent));
      _push(`<div class="issue-content" data-v-07b1c9a3><div class="main-section" data-v-07b1c9a3><div class="card title-card" data-v-07b1c9a3><div class="title-row" data-v-07b1c9a3><input${ssrRenderAttr("value", unref(editedTitle))} type="text" class="title-input"${ssrRenderAttr("placeholder", _ctx.$t("issue.title"))} data-v-07b1c9a3><button type="button" class="btn-autocomplete"${ssrIncludeBooleanAttr(unref(autocompleting) || !unref(editedTitle).trim()) ? " disabled" : ""}${ssrRenderAttr("title", _ctx.$t("autocomplete.tooltip"))} data-v-07b1c9a3>`);
      if (unref(autocompleting)) {
        _push(`<span class="spinner" data-v-07b1c9a3></span>`);
      } else {
        _push(`<span class="sparkle" data-v-07b1c9a3>✨</span>`);
      }
      _push(` ${ssrInterpolate(unref(autocompleting) ? _ctx.$t("autocomplete.loading") : _ctx.$t("autocomplete.button"))}</button></div></div><div class="card" data-v-07b1c9a3><h2 data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.metadata"))}</h2><div class="form-row" data-v-07b1c9a3><div class="form-group" data-v-07b1c9a3><label class="form-label" for="edit-priority" data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.priority"))}</label><select id="edit-priority" class="form-input" data-v-07b1c9a3><option value="" data-v-07b1c9a3${ssrIncludeBooleanAttr(Array.isArray(unref(editedPriority)) ? ssrLooseContain(unref(editedPriority), "") : ssrLooseEqual(unref(editedPriority), "")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("form.select"))}</option><option value="low" data-v-07b1c9a3${ssrIncludeBooleanAttr(Array.isArray(unref(editedPriority)) ? ssrLooseContain(unref(editedPriority), "low") : ssrLooseEqual(unref(editedPriority), "low")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("priority.low"))}</option><option value="medium" data-v-07b1c9a3${ssrIncludeBooleanAttr(Array.isArray(unref(editedPriority)) ? ssrLooseContain(unref(editedPriority), "medium") : ssrLooseEqual(unref(editedPriority), "medium")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("priority.medium"))}</option><option value="high" data-v-07b1c9a3${ssrIncludeBooleanAttr(Array.isArray(unref(editedPriority)) ? ssrLooseContain(unref(editedPriority), "high") : ssrLooseEqual(unref(editedPriority), "high")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("priority.high"))}</option><option value="critical" data-v-07b1c9a3${ssrIncludeBooleanAttr(Array.isArray(unref(editedPriority)) ? ssrLooseContain(unref(editedPriority), "critical") : ssrLooseEqual(unref(editedPriority), "critical")) ? " selected" : ""}>${ssrInterpolate(_ctx.$t("priority.critical"))}</option></select></div><div class="form-group" data-v-07b1c9a3><label class="form-label" for="edit-parent" data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.parent"))}</label><input id="edit-parent"${ssrRenderAttr("value", unref(editedParent))} type="text" class="form-input"${ssrRenderAttr("placeholder", _ctx.$t("form.parentPlaceholder"))} list="parent-suggestions" data-v-07b1c9a3><datalist id="parent-suggestions" data-v-07b1c9a3><!--[-->`);
      ssrRenderList(unref(parentSuggestions), (parentIssue) => {
        _push(`<option${ssrRenderAttr("value", parentIssue.key)} data-v-07b1c9a3>${ssrInterpolate(parentIssue.title)}</option>`);
      });
      _push(`<!--]--></datalist></div></div><div class="meta-badges" data-v-07b1c9a3><span class="meta-badge column-badge" data-v-07b1c9a3>${ssrInterpolate(unref(columnName))}</span>`);
      if (unref(issue)?.semver) {
        _push(`<span class="meta-badge semver-badge" data-v-07b1c9a3>${ssrInterpolate(unref(issue).semver)}</span>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div></div>`);
      if (unref(issue)?.labels?.length) {
        _push(`<div class="card" data-v-07b1c9a3><h2 data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.labels"))}</h2><div class="labels-list" data-v-07b1c9a3><!--[-->`);
        ssrRenderList(unref(issue).labels, (label, index2) => {
          _push(`<span class="label-tag" data-v-07b1c9a3>${ssrInterpolate(label)}</span>`);
        });
        _push(`<!--]--></div></div>`);
      } else {
        _push(`<!---->`);
      }
      _push(`<div class="card" data-v-07b1c9a3><div class="section-header" data-v-07b1c9a3><h2 data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.description"))}</h2><button class="${ssrRenderClass([{ active: unref(isEditingDescription) }, "btn-edit-toggle"])}" data-v-07b1c9a3>${ssrInterpolate(unref(isEditingDescription) ? "✓" : "✏️")}</button></div>`);
      if (!unref(isEditingDescription)) {
        _push(`<div class="description" data-v-07b1c9a3>${unref(renderedDescription) ?? ""}</div>`);
      } else {
        _push(`<textarea class="description-edit"${ssrRenderAttr("placeholder", _ctx.$t("issue.description"))} rows="10" data-v-07b1c9a3>${ssrInterpolate(unref(editedDescription))}</textarea>`);
      }
      _push(`</div><div class="card" data-v-07b1c9a3><div class="section-header" data-v-07b1c9a3><h2 data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.acceptanceCriteria"))}</h2><button class="${ssrRenderClass([{ active: unref(isEditingCriteria) }, "btn-edit-toggle"])}" data-v-07b1c9a3>${ssrInterpolate(unref(isEditingCriteria) ? "✓" : "✏️")}</button></div>`);
      if (!unref(isEditingCriteria) && unref(issue)?.acceptance_criteria?.length) {
        _push(`<ul class="criteria-list" data-v-07b1c9a3><!--[-->`);
        ssrRenderList(unref(issue).acceptance_criteria, (criteria, index2) => {
          _push(`<li class="criteria-item" data-v-07b1c9a3>${ssrInterpolate(criteria)}</li>`);
        });
        _push(`<!--]--></ul>`);
      } else if (!unref(isEditingCriteria)) {
        _push(`<p class="empty-criteria" data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.noCriteria"))}</p>`);
      } else {
        _push(`<div class="criteria-edit" data-v-07b1c9a3><!--[-->`);
        ssrRenderList(unref(editedCriteria), (_, index2) => {
          _push(`<div class="criteria-input-row" data-v-07b1c9a3><input${ssrRenderAttr("value", unref(editedCriteria)[index2])} type="text" class="form-input"${ssrRenderAttr("placeholder", _ctx.$t("form.criteriaPlaceholder"))} data-v-07b1c9a3><button class="btn-icon" type="button" data-v-07b1c9a3>×</button></div>`);
        });
        _push(`<!--]--><button class="btn btn-secondary btn-sm" type="button" data-v-07b1c9a3> + ${ssrInterpolate(_ctx.$t("form.addCriteria"))}</button></div>`);
      }
      _push(`</div><div class="actions-bar" data-v-07b1c9a3><button class="btn btn-primary"${ssrIncludeBooleanAttr(unref(saving) || !unref(hasChanges)) ? " disabled" : ""} data-v-07b1c9a3>${ssrInterpolate(unref(saving) ? _ctx.$t("form.saving") : _ctx.$t("form.save"))}</button>`);
      if (!unref(isInLastColumn)) {
        _push(`<button class="btn btn-secondary"${ssrIncludeBooleanAttr(unref(moving)) ? " disabled" : ""} data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.next"))} → </button>`);
      } else {
        _push(`<!---->`);
      }
      if (!unref(isInLastColumn)) {
        _push(`<button class="btn btn-danger" data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.archive"))}</button>`);
      } else {
        _push(`<!---->`);
      }
      if (unref(isInLastColumn)) {
        _push(`<span class="done-badge" data-v-07b1c9a3> ✓ ${ssrInterpolate(_ctx.$t("issue.done"))}</span>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div></div><aside class="sidebar" data-v-07b1c9a3><div class="card" data-v-07b1c9a3><h3 data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.actions"))}</h3><div class="action-buttons" data-v-07b1c9a3><button class="btn btn-secondary" data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.move"))}</button></div></div><div class="card" data-v-07b1c9a3><h3 data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.details"))}</h3><dl class="metadata-list" data-v-07b1c9a3><div class="metadata-item" data-v-07b1c9a3><dt data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.status"))}</dt><dd data-v-07b1c9a3>${ssrInterpolate(unref(columnName))}</dd></div><div class="metadata-item" data-v-07b1c9a3><dt data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.created"))}</dt><dd data-v-07b1c9a3>${ssrInterpolate(formatDate(unref(issue)?.created_at))}</dd></div><div class="metadata-item" data-v-07b1c9a3><dt data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.updated"))}</dt><dd data-v-07b1c9a3>${ssrInterpolate(formatDate(unref(issue)?.updated_at))}</dd></div></dl></div>`);
      if (unref(issue)?.parent_key) {
        _push(`<div class="card" data-v-07b1c9a3><h3 data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.parent"))}</h3>`);
        _push(ssrRenderComponent(_component_NuxtLink, {
          to: `/issue/${unref(issue).parent_key}`,
          class: "parent-link"
        }, {
          default: withCtx((_, _push2, _parent2, _scopeId) => {
            if (_push2) {
              _push2(`${ssrInterpolate(unref(issue).parent_key)}`);
            } else {
              return [
                createTextVNode(toDisplayString(unref(issue).parent_key), 1)
              ];
            }
          }),
          _: 1
        }, _parent));
        _push(`</div>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</aside></div>`);
      if (unref(showMoveModal)) {
        _push(`<div class="modal-overlay active" data-v-07b1c9a3><div class="modal" data-v-07b1c9a3><div class="modal-header" data-v-07b1c9a3><h3 class="modal-title" data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("issue.move"))}</h3><button class="modal-close" data-v-07b1c9a3>×</button></div><div class="modal-body" data-v-07b1c9a3><select class="form-input" data-v-07b1c9a3><!--[-->`);
        ssrRenderList(unref(columns), (col) => {
          _push(`<option${ssrRenderAttr("value", col.slug)} data-v-07b1c9a3${ssrIncludeBooleanAttr(Array.isArray(unref(targetColumn)) ? ssrLooseContain(unref(targetColumn), col.slug) : ssrLooseEqual(unref(targetColumn), col.slug)) ? " selected" : ""}>${ssrInterpolate(col.name)}</option>`);
        });
        _push(`<!--]--></select></div><div class="modal-footer" data-v-07b1c9a3><button class="btn btn-secondary" data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("modal.cancel"))}</button><button class="btn btn-primary" data-v-07b1c9a3>${ssrInterpolate(_ctx.$t("modal.confirm"))}</button></div></div></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/issue/[id]/index.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-07b1c9a3"]]);

export { index as default };
//# sourceMappingURL=index-Bm8ROtfk.mjs.map
