import { _ as __nuxt_component_0 } from './IssueHeader-BKlqeUoH.mjs';
import { _ as __nuxt_component_0$1 } from './nuxt-link-Cq8xZgFP.mjs';
import { defineComponent, withAsyncContext, computed, mergeProps, unref, withCtx, createTextVNode, toDisplayString, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrRenderComponent, ssrInterpolate, ssrRenderList, ssrRenderClass } from 'vue/server-renderer';
import { _ as _export_sfc, j as useRoute, a as useHead } from './server.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();
    const issueId = route.params["id"];
    const { data: issue } = ([__temp, __restore] = withAsyncContext(() => useFetch(`/api/issues/${issueId}`, "$Rocr4faAHy")), __temp = await __temp, __restore(), __temp);
    const issueForHeader = computed(() => {
      if (!issue.value) return null;
      const header = {
        id: issue.value.key,
        title: issue.value.title,
        column: issue.value.column_slug
      };
      if (issue.value.priority) header.priority = issue.value.priority;
      return header;
    });
    const {
      data: history,
      status: historyStatus,
      error: historyError
    } = ([__temp, __restore] = withAsyncContext(() => useFetch(`/api/issues/${issueId}/history`, "$bELPvGg345")), __temp = await __temp, __restore(), __temp);
    const sortedHistory = computed(() => {
      if (!history.value) return [];
      return [...history.value].reverse();
    });
    const formatTime = (timestamp) => {
      const date = new Date(timestamp);
      return date.toLocaleDateString("fr-FR", {
        day: "2-digit",
        month: "2-digit",
        year: "numeric",
        hour: "2-digit",
        minute: "2-digit"
      });
    };
    const formatValue = (value) => {
      if (!value) return "";
      return value;
    };
    useHead({
      title: `History - ${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-history-page" }, _attrs))} data-v-e79c602e>`);
      _push(ssrRenderComponent(_component_IssueHeader, {
        issue: unref(issueForHeader),
        "active-tab": "history"
      }, null, _parent));
      _push(`<div class="card" data-v-e79c602e><div class="section-header" data-v-e79c602e><h2 data-v-e79c602e>${ssrInterpolate(_ctx.$t("issue.history"))}</h2><span class="count" data-v-e79c602e>(${ssrInterpolate(unref(history)?.length || 0)})</span></div>`);
      if (unref(historyStatus) === "pending") {
        _push(`<div class="loading" data-v-e79c602e>${ssrInterpolate(_ctx.$t("app.loading"))}</div>`);
      } else if (unref(historyError)) {
        _push(`<div class="error-message" data-v-e79c602e>${ssrInterpolate(unref(historyError).message)}</div>`);
      } else if (!unref(history)?.length) {
        _push(`<div class="empty" data-v-e79c602e>${ssrInterpolate(_ctx.$t("issue.noHistory"))}</div>`);
      } else {
        _push(`<ul class="history-list" data-v-e79c602e><!--[-->`);
        ssrRenderList(unref(sortedHistory), (event, index2) => {
          _push(`<li class="history-item" data-v-e79c602e><div class="history-main" data-v-e79c602e><span class="${ssrRenderClass([`history-action-${event.action}`, "history-action"])}" data-v-e79c602e>${ssrInterpolate(_ctx.$t(`history.action.${event.action}`))}</span>`);
          if (event.action !== "edited") {
            _push(`<!--[-->`);
            if (event.from) {
              _push(`<span class="history-from" data-v-e79c602e>${ssrInterpolate(event.from)}</span>`);
            } else {
              _push(`<!---->`);
            }
            if (event.from) {
              _push(`<span class="history-arrow" data-v-e79c602e>→</span>`);
            } else {
              _push(`<!---->`);
            }
            _push(`<span class="history-to" data-v-e79c602e>${ssrInterpolate(event.to)}</span><!--]-->`);
          } else if (event.changes?.length) {
            _push(`<div class="history-changes" data-v-e79c602e><!--[-->`);
            ssrRenderList(event.changes, (change, ci) => {
              _push(`<div class="history-change-item" data-v-e79c602e><span class="change-field" data-v-e79c602e>${ssrInterpolate(_ctx.$t(`history.field.${change.field}`))}</span><span class="change-from" data-v-e79c602e>${ssrInterpolate(formatValue(change.from) || "∅")}</span><span class="history-arrow" data-v-e79c602e>→</span><span class="change-to" data-v-e79c602e>${ssrInterpolate(formatValue(change.to) || "∅")}</span></div>`);
            });
            _push(`<!--]--></div>`);
          } else {
            _push(`<!---->`);
          }
          _push(`</div>`);
          if (event.artifactsAvailable?.prompt || event.artifactsAvailable?.terminal) {
            _push(`<div class="history-actions" data-v-e79c602e>`);
            if (event.artifactsAvailable?.prompt) {
              _push(ssrRenderComponent(_component_NuxtLink, {
                to: `/issue/${unref(issueId)}/history/${event.sessionId}/prompt`,
                class: "btn-action"
              }, {
                default: withCtx((_, _push2, _parent2, _scopeId) => {
                  if (_push2) {
                    _push2(`${ssrInterpolate(_ctx.$t("history.viewPrompt"))}`);
                  } else {
                    return [
                      createTextVNode(toDisplayString(_ctx.$t("history.viewPrompt")), 1)
                    ];
                  }
                }),
                _: 2
              }, _parent));
            } else {
              _push(`<!---->`);
            }
            if (event.artifactsAvailable?.terminal) {
              _push(ssrRenderComponent(_component_NuxtLink, {
                to: `/issue/${unref(issueId)}/history/${event.sessionId}/terminal`,
                class: "btn-action"
              }, {
                default: withCtx((_, _push2, _parent2, _scopeId) => {
                  if (_push2) {
                    _push2(`${ssrInterpolate(_ctx.$t("history.viewTerminal"))}`);
                  } else {
                    return [
                      createTextVNode(toDisplayString(_ctx.$t("history.viewTerminal")), 1)
                    ];
                  }
                }),
                _: 2
              }, _parent));
            } else {
              _push(`<!---->`);
            }
            _push(`</div>`);
          } else {
            _push(`<!---->`);
          }
          if (event.sessionId) {
            _push(`<span class="session-badge" data-v-e79c602e>${ssrInterpolate(event.sessionId)}</span>`);
          } else {
            _push(`<!---->`);
          }
          _push(`<time class="history-date" data-v-e79c602e>${ssrInterpolate(formatTime(event.at))}</time></li>`);
        });
        _push(`<!--]--></ul>`);
      }
      _push(`</div></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]/history/index.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const index = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-e79c602e"]]);

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