import { _ as __nuxt_component_0 } from './IssueHeader-BKlqeUoH.mjs';
import { defineComponent, ref, withAsyncContext, computed, watch, mergeProps, unref, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrRenderComponent, ssrInterpolate, ssrRenderAttr, ssrIncludeBooleanAttr, ssrRenderList } from 'vue/server-renderer';
import { marked } from 'marked';
import { _ as _export_sfc, j as useRoute, 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 { 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: "comments",
  __ssrInlineRender: true,
  async setup(__props) {
    let __temp, __restore;
    const route = useRoute();
    useNotification();
    useApiError();
    const issueId = route.params["id"];
    const newComment = ref("");
    const submitting = ref(false);
    const { data: issue } = ([__temp, __restore] = withAsyncContext(() => useFetch(`/api/issues/${issueId}`, "$sHdW2Rruhz")), __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: comments2,
      status: commentsStatus,
      refresh
    } = ([__temp, __restore] = withAsyncContext(() => useFetch(`/api/issues/${issueId}/comments`, "$2TYRtwuSoA")), __temp = await __temp, __restore(), __temp);
    const { lastMessage } = useWebSocket();
    watch(lastMessage, (message) => {
      if (message?.type === "comment" && message["issueId"] === issueId) {
        refresh();
      }
    });
    const formatDate = (date) => {
      return new Date(date).toLocaleString();
    };
    const renderMarkdown = (content) => {
      return marked(content);
    };
    useHead({
      title: `Comments - ${issueId} - AutoCode`
    });
    return (_ctx, _push, _parent, _attrs) => {
      const _component_IssueHeader = __nuxt_component_0;
      _push(`<div${ssrRenderAttrs(mergeProps({ class: "issue-comments-page" }, _attrs))} data-v-b988772a>`);
      _push(ssrRenderComponent(_component_IssueHeader, {
        issue: unref(issueForHeader),
        "active-tab": "comments"
      }, null, _parent));
      _push(`<div class="comments-content card" data-v-b988772a><h2 data-v-b988772a>${ssrInterpolate(_ctx.$t("issue.comments"))}</h2><form class="comment-form" data-v-b988772a><textarea class="form-input comment-input"${ssrRenderAttr("placeholder", _ctx.$t("issue.addComment"))} rows="3" data-v-b988772a>${ssrInterpolate(unref(newComment))}</textarea><button type="submit" class="btn btn-primary"${ssrIncludeBooleanAttr(!unref(newComment).trim() || unref(submitting)) ? " disabled" : ""} data-v-b988772a>${ssrInterpolate(_ctx.$t("form.save"))}</button></form>`);
      if (unref(commentsStatus) === "pending") {
        _push(`<div class="loading" data-v-b988772a>${ssrInterpolate(_ctx.$t("app.loading"))}</div>`);
      } else if (!unref(comments2)?.length) {
        _push(`<div class="empty" data-v-b988772a>${ssrInterpolate(_ctx.$t("issue.noComments"))}</div>`);
      } else {
        _push(`<ul class="comments-list" data-v-b988772a><!--[-->`);
        ssrRenderList(unref(comments2), (comment) => {
          _push(`<li class="comment" data-v-b988772a><div class="comment-header" data-v-b988772a><span class="comment-author" data-v-b988772a>${ssrInterpolate(comment.author || "User")}</span><time class="comment-date" data-v-b988772a>${ssrInterpolate(formatDate(comment.createdAt))}</time></div><div class="comment-body" data-v-b988772a>${renderMarkdown(comment.content) ?? ""}</div></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]/comments.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const comments = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-b988772a"]]);

export { comments as default };
//# sourceMappingURL=comments-CZn-fPmX.mjs.map
