import { _ as __nuxt_component_0 } from './IssueHeader-BKlqeUoH.mjs';
import { defineComponent, ref, withAsyncContext, computed, watch, nextTick, mergeProps, unref, 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 { u as useWebSocket } from './useWebSocket-UbMCn0vY.mjs';
import './nuxt-link-Cq8xZgFP.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: "terminal",
  __ssrInlineRender: true,
  async setup(__props) {
    let __temp, __restore;
    const route = useRoute();
    const issueId = route.params["id"];
    const terminalRef = ref(null);
    const autoScroll = ref(true);
    const { data: issue } = ([__temp, __restore] = withAsyncContext(() => useFetch(`/api/issues/${issueId}`, "$s3Vbd9k-VO")), __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: terminalData, refresh } = ([__temp, __restore] = withAsyncContext(() => useFetch(
      `/api/issues/${issueId}/full-terminal`,
      "$XMztO43Pyz"
    )), __temp = await __temp, __restore(), __temp);
    const { lastMessage } = useWebSocket();
    watch(lastMessage, (message) => {
      if (message?.type === "claude_end" && message["issue"] === issueId) {
        refresh();
      }
      if (autoScroll.value) {
        nextTick(() => {
          if (terminalRef.value) {
            terminalRef.value.scrollTop = terminalRef.value.scrollHeight;
          }
        });
      }
    });
    const formatTime = (timestamp) => {
      if (!timestamp) return "";
      try {
        return new Date(timestamp).toLocaleTimeString();
      } catch {
        return timestamp;
      }
    };
    const getSectionIcon = (index) => {
      if (index === 0) return "1";
      return String(index + 1);
    };
    useHead({
      title: `Terminal - ${issueId} - AutoCode`
    });
    return (_ctx, _push, _parent, _attrs) => {
      const _component_IssueHeader = __nuxt_component_0;
      _push(`<div${ssrRenderAttrs(mergeProps({ class: "issue-terminal-page" }, _attrs))} data-v-3b499d2c>`);
      _push(ssrRenderComponent(_component_IssueHeader, {
        issue: unref(issueForHeader),
        "active-tab": "terminal"
      }, null, _parent));
      _push(`<div class="terminal-content card" data-v-3b499d2c><div class="terminal-header" data-v-3b499d2c><h2 data-v-3b499d2c>${ssrInterpolate(_ctx.$t("issue.terminal"))} (${ssrInterpolate(_ctx.$t("terminal.fullHistory"))})</h2><div class="terminal-actions" data-v-3b499d2c><button class="btn btn-secondary btn-sm" data-v-3b499d2c>${ssrInterpolate(unref(autoScroll) ? "Pause" : "Resume")} Auto-scroll </button><button class="btn btn-secondary btn-sm" data-v-3b499d2c>${ssrInterpolate(_ctx.$t("btn.refresh"))}</button></div></div><div class="terminal-output" data-v-3b499d2c>`);
      if (!unref(terminalData)?.logFiles?.length) {
        _push(`<div class="terminal-empty" data-v-3b499d2c>${ssrInterpolate(_ctx.$t("terminal.noLogs"))}</div>`);
      } else {
        _push(`<!---->`);
      }
      _push(`<!--[-->`);
      ssrRenderList(unref(terminalData)?.logFiles, (logFile, fileIndex) => {
        _push(`<!--[--><div class="section-header" data-v-3b499d2c><span class="section-icon" data-v-3b499d2c>${ssrInterpolate(getSectionIcon(fileIndex))}</span><span class="section-column" data-v-3b499d2c>${ssrInterpolate(logFile.column)}</span><span class="section-session" data-v-3b499d2c>${ssrInterpolate(logFile.sessionId)}</span></div><!--[-->`);
        ssrRenderList(logFile.logs, (log, logIndex) => {
          _push(`<div class="${ssrRenderClass([`log-${log.level}`, "log-line"])}" data-v-3b499d2c>`);
          if (log.timestamp) {
            _push(`<span class="log-time" data-v-3b499d2c>${ssrInterpolate(formatTime(log.timestamp))}</span>`);
          } else {
            _push(`<!---->`);
          }
          _push(`<span class="log-message" data-v-3b499d2c>${ssrInterpolate(log.message)}</span></div>`);
        });
        _push(`<!--]--><!--]-->`);
      });
      _push(`<!--]--></div></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]/terminal.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const terminal = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-3b499d2c"]]);

export { terminal as default };
//# sourceMappingURL=terminal-D_WbT8Ri.mjs.map
