import { defineComponent, computed, ref, withAsyncContext, mergeProps, unref, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrInterpolate, ssrRenderClass, ssrIncludeBooleanAttr } from 'vue/server-renderer';
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 usePipeline } from './usePipeline-ZPHbtOs6.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: "prompt",
  __ssrInlineRender: true,
  async setup(__props) {
    let __temp, __restore;
    const route = useRoute();
    useRouter();
    useNotification();
    const {
      pipelineConfig,
      isColumnInPipeline
    } = usePipeline();
    const slug = computed(() => route.params["slug"]);
    const pipelineName = computed(() => route.query["pipeline"] || "");
    const columnName = computed(() => route.query["name"] || "");
    const displayName = computed(() => columnName.value || slug.value);
    const copied = ref(false);
    const editMode = ref(false);
    const editContent = ref("");
    const isDirty = ref(false);
    const saving = ref(false);
    const toggling = ref(false);
    const {
      data: rawPrompt,
      status,
      error,
      refresh
    } = ([__temp, __restore] = withAsyncContext(() => useFetch(() => {
      const params = new URLSearchParams();
      if (pipelineName.value) params.set("pipeline", pipelineName.value);
      const queryString = params.toString();
      return `/api/columns/${slug.value}/prompt${queryString ? `?${queryString}` : ""}`;
    }, "$jZPB4J8e0r")), __temp = await __temp, __restore(), __temp);
    const promptContent = computed(() => {
      if (!rawPrompt.value) return "";
      if (typeof rawPrompt.value === "string") return rawPrompt.value;
      return rawPrompt.value.content || "";
    });
    const currentContent = computed(() => editMode.value ? editContent.value : promptContent.value);
    const lineCount = computed(() => {
      const content = currentContent.value;
      if (!content || typeof content !== "string") return 0;
      return content.split("\n").length;
    });
    const charCount = computed(() => {
      const content = currentContent.value;
      if (!content || typeof content !== "string") return 0;
      return content.length;
    });
    const { t: $t } = useI18n();
    const { data: catalog } = ([__temp, __restore] = withAsyncContext(() => useFetch("/api/catalog", "$8GjW2wVST-")), __temp = await __temp, __restore(), __temp);
    const columnInfo = computed(() => {
      if (!catalog.value) return null;
      const baseSlug = slug.value.replace(/^\d+_/, "");
      for (const segmentName of ["definition", "action", "finish"]) {
        const segment = catalog.value.segments[segmentName];
        const found = segment.columns.find((c) => c.slug.replace(/^\d+_/, "") === baseSlug);
        if (found) {
          return { ...found, segment: segmentName };
        }
      }
      return null;
    });
    const pipelineStatus = computed(() => {
      return isColumnInPipeline(slug.value);
    });
    const isInPipeline = computed(() => pipelineStatus.value.inPipeline);
    useHead({
      title: computed(() => `${slug.value} - AutoCode`)
    });
    return (_ctx, _push, _parent, _attrs) => {
      _push(`<div${ssrRenderAttrs(mergeProps({ class: "column-prompt-page" }, _attrs))} data-v-bf4ee782><header class="page-header card" data-v-bf4ee782><div class="header-left" data-v-bf4ee782><button class="back-link" data-v-bf4ee782>← ${ssrInterpolate(unref($t)("nav.back"))}</button><span class="header-separator" data-v-bf4ee782>/</span><h1 data-v-bf4ee782>${ssrInterpolate(unref(displayName))}</h1>`);
      if (unref(pipelineName)) {
        _push(`<span class="pipeline-badge" data-v-bf4ee782>${ssrInterpolate(unref(pipelineName))}</span>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div><div class="header-right" data-v-bf4ee782>`);
      if (!unref(editMode) && unref(columnInfo) && unref(pipelineConfig)) {
        _push(`<button class="${ssrRenderClass([unref(isInPipeline) ? "btn-danger" : "btn-success", "btn btn-sm"])}"${ssrIncludeBooleanAttr(unref(toggling)) ? " disabled" : ""} data-v-bf4ee782>${ssrInterpolate(unref(toggling) ? "..." : unref(isInPipeline) ? unref($t)("column.deactivate") : unref($t)("column.activate"))}</button>`);
      } else {
        _push(`<!---->`);
      }
      if (!unref(editMode)) {
        _push(`<button class="btn btn-secondary btn-sm" data-v-bf4ee782>${ssrInterpolate(unref(copied) ? unref($t)("form.copied") : unref($t)("form.copy"))}</button>`);
      } else {
        _push(`<!---->`);
      }
      if (!unref(editMode)) {
        _push(`<button class="btn btn-primary btn-sm" data-v-bf4ee782>${ssrInterpolate(unref($t)("column.edit"))}</button>`);
      } else {
        _push(`<!--[--><button class="btn btn-secondary btn-sm" data-v-bf4ee782>${ssrInterpolate(unref($t)("modal.cancel"))}</button><button class="btn btn-primary btn-sm"${ssrIncludeBooleanAttr(unref(saving) || !unref(isDirty)) ? " disabled" : ""} data-v-bf4ee782>${ssrInterpolate(unref(saving) ? unref($t)("form.saving") : unref($t)("form.save"))}</button><!--]-->`);
      }
      _push(`</div></header>`);
      if (unref(status) === "pending") {
        _push(`<div class="loading card" data-v-bf4ee782>${ssrInterpolate(unref($t)("app.loading"))}</div>`);
      } else if (unref(error)) {
        _push(`<div class="error-message card" data-v-bf4ee782>${ssrInterpolate(unref(error).message)}</div>`);
      } else {
        _push(`<div class="prompt-container card" data-v-bf4ee782>`);
        if (!unref(editMode)) {
          _push(`<pre class="prompt-content" data-v-bf4ee782><code data-v-bf4ee782>${ssrInterpolate(unref(promptContent))}</code></pre>`);
        } else {
          _push(`<textarea class="code-editor" spellcheck="false" data-v-bf4ee782>${ssrInterpolate(unref(editContent))}</textarea>`);
        }
        _push(`<div class="prompt-meta" data-v-bf4ee782><span class="meta-item" data-v-bf4ee782><strong data-v-bf4ee782>${ssrInterpolate(unref($t)("column.lines"))}:</strong> ${ssrInterpolate(unref(lineCount))}</span><span class="meta-item" data-v-bf4ee782><strong data-v-bf4ee782>${ssrInterpolate(unref($t)("column.chars"))}:</strong> ${ssrInterpolate(unref(charCount))}</span>`);
        if (unref(editMode) && unref(isDirty)) {
          _push(`<span class="meta-item meta-dirty" data-v-bf4ee782>${ssrInterpolate(unref($t)("form.unsavedChanges"))}</span>`);
        } else {
          _push(`<!---->`);
        }
        _push(`</div></div>`);
      }
      _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/column/[slug]/prompt.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const prompt = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-bf4ee782"]]);

export { prompt as default };
//# sourceMappingURL=prompt-BD-UncOd.mjs.map
