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: "terminal",
  __ssrInlineRender: true,
  async setup(__props) {
    let __temp, __restore;
    const route = useRoute();
    const issueId = route.params["id"];
    const columnSlug = route.params["column"];
    const { data: issue } = ([__temp, __restore] = withAsyncContext(() => useFetch(`/api/issues/${issueId}`, "$kO2jumUF-U")), __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: logs,
      status: logsStatus,
      error: logsError
    } = ([__temp, __restore] = withAsyncContext(() => useFetch(`/api/issues/${issueId}/${columnSlug}/log`, "$kN3ufMrA3g")), __temp = await __temp, __restore(), __temp);
    const formatTime = (timestamp) => {
      const date = new Date(timestamp);
      if (isNaN(date.getTime())) return timestamp;
      return date.toLocaleTimeString("fr-FR", {
        hour: "2-digit",
        minute: "2-digit",
        second: "2-digit"
      });
    };
    useHead({
      title: `Terminal ${columnSlug} - ${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: "terminal-page" }, _attrs))} data-v-8427ea96>`);
      _push(ssrRenderComponent(_component_IssueHeader, {
        issue: unref(issueForHeader),
        "active-tab": "history"
      }, null, _parent));
      _push(`<div class="card" data-v-8427ea96><div class="section-header" data-v-8427ea96><h2 data-v-8427ea96>${ssrInterpolate(_ctx.$t("history.viewTerminal"))}</h2><span class="column-badge" data-v-8427ea96>${ssrInterpolate(unref(columnSlug))}</span></div>`);
      if (unref(logsStatus) === "pending") {
        _push(`<div class="loading" data-v-8427ea96>${ssrInterpolate(_ctx.$t("app.loading"))}</div>`);
      } else if (unref(logsError)) {
        _push(`<div class="error-message" data-v-8427ea96>${ssrInterpolate(unref(logsError).message)}</div>`);
      } else if (!unref(logs)?.length) {
        _push(`<div class="empty" data-v-8427ea96>${ssrInterpolate(_ctx.$t("terminal.noLogs"))}</div>`);
      } else {
        _push(`<div class="terminal-content" data-v-8427ea96><!--[-->`);
        ssrRenderList(unref(logs), (log, index) => {
          _push(`<div class="${ssrRenderClass([`log-${log.level}`, "log-entry"])}" data-v-8427ea96><span class="log-time" data-v-8427ea96>${ssrInterpolate(formatTime(log.timestamp))}</span><span class="log-level" data-v-8427ea96>${ssrInterpolate(log.level)}</span><span class="log-message" data-v-8427ea96>${ssrInterpolate(log.message)}</span></div>`);
        });
        _push(`<!--]--></div>`);
      }
      _push(`</div><div class="actions" data-v-8427ea96>`);
      _push(ssrRenderComponent(_component_NuxtLink, {
        to: `/issue/${unref(issueId)}/history`,
        class: "btn-secondary"
      }, {
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            _push2(`${ssrInterpolate(_ctx.$t("nav.back"))}`);
          } else {
            return [
              createTextVNode(toDisplayString(_ctx.$t("nav.back")), 1)
            ];
          }
        }),
        _: 1
      }, _parent));
      _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]/[column]/terminal.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const terminal = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-8427ea96"]]);

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