import { defineComponent, withAsyncContext, computed, ref, mergeProps, unref, readonly, useSSRContext } from 'vue';
import { ssrRenderAttrs, ssrInterpolate, ssrRenderList } from 'vue/server-renderer';
import { u as useFetch } from './fetch-B5NxMLIO.mjs';
import { _ as _export_sfc, u as useI18n, a as useHead } from './server.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 '@vue/shared';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'unhead/server';
import 'devalue';
import 'unhead/utils';

const STORAGE_KEYS = {
  CHANGELOG_LAST_SEEN: "autocode-changelog-lastSeen"
};
function useChangelog() {
  const lastSeenVersion = ref(null);
  const hasNewChanges = ref(false);
  const markAsSeen = (version) => {
    lastSeenVersion.value = version;
    localStorage.setItem(STORAGE_KEYS.CHANGELOG_LAST_SEEN, version);
    hasNewChanges.value = false;
  };
  const checkForUpdates = (currentVersion) => {
    if (!lastSeenVersion.value) {
      markAsSeen(currentVersion);
      return false;
    }
    if (lastSeenVersion.value !== currentVersion) {
      hasNewChanges.value = true;
      return true;
    }
    return false;
  };
  return {
    lastSeenVersion: readonly(lastSeenVersion),
    hasNewChanges: readonly(hasNewChanges),
    markAsSeen,
    checkForUpdates
  };
}
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "changelog",
  __ssrInlineRender: true,
  async setup(__props) {
    let __temp, __restore;
    const { locale } = useI18n();
    const {
      data: response,
      status,
      error
    } = ([__temp, __restore] = withAsyncContext(() => useFetch("/api/changelog", {
      query: { lang: locale.value }
    }, "$j1EO-12DBP")), __temp = await __temp, __restore(), __temp);
    const entries = computed(() => response.value?.data?.entries || []);
    computed(() => response.value?.data?.topTag || "");
    const { lastSeenVersion } = useChangelog();
    const summary = ref(null);
    const summaryLoading = ref(false);
    const isNew = (tag) => {
      if (!lastSeenVersion.value) return false;
      return tag > lastSeenVersion.value;
    };
    const formatDate = (dateStr) => {
      const date = new Date(dateStr);
      return date.toLocaleDateString(locale.value === "fr" ? "fr-FR" : "en-US", {
        year: "numeric",
        month: "long",
        day: "numeric"
      });
    };
    useHead({
      title: "Changelog - AutoCode"
    });
    return (_ctx, _push, _parent, _attrs) => {
      _push(`<div${ssrRenderAttrs(mergeProps({ class: "changelog-page" }, _attrs))} data-v-03a0ef3e><header class="page-header" data-v-03a0ef3e><h1 data-v-03a0ef3e>${ssrInterpolate(_ctx.$t("changelog.title"))}</h1></header><div class="summary-section" data-v-03a0ef3e>`);
      if (!unref(summary) && !unref(summaryLoading)) {
        _push(`<button class="btn btn-secondary summary-btn" data-v-03a0ef3e><span class="btn-icon" data-v-03a0ef3e>✨</span> ${ssrInterpolate(_ctx.$t("changelog.generateSummary"))}</button>`);
      } else {
        _push(`<!---->`);
      }
      if (unref(summaryLoading)) {
        _push(`<div class="summary-loading" data-v-03a0ef3e><span class="spinner" data-v-03a0ef3e></span> ${ssrInterpolate(_ctx.$t("changelog.generatingSummary"))}</div>`);
      } else {
        _push(`<!---->`);
      }
      if (unref(summary) && !unref(summaryLoading)) {
        _push(`<div class="summary-banner" data-v-03a0ef3e><div class="summary-icon" data-v-03a0ef3e><span class="icon" data-v-03a0ef3e>✨</span></div><p class="summary-text" data-v-03a0ef3e>${ssrInterpolate(unref(summary))}</p></div>`);
      } else {
        _push(`<!---->`);
      }
      _push(`</div>`);
      if (unref(status) === "pending") {
        _push(`<div class="loading" data-v-03a0ef3e>${ssrInterpolate(_ctx.$t("app.loading"))}</div>`);
      } else if (unref(error)) {
        _push(`<div class="error-message" data-v-03a0ef3e>${ssrInterpolate(unref(error).message)}</div>`);
      } else if (!unref(entries)?.length) {
        _push(`<div class="empty" data-v-03a0ef3e>${ssrInterpolate(_ctx.$t("changelog.noChanges"))}</div>`);
      } else {
        _push(`<div class="changelog-list" data-v-03a0ef3e><!--[-->`);
        ssrRenderList(unref(entries), (entry) => {
          _push(`<article class="changelog-entry card" data-v-03a0ef3e><header class="entry-header" data-v-03a0ef3e><h2 class="entry-version" data-v-03a0ef3e>${ssrInterpolate(entry.tag)} `);
          if (isNew(entry.tag)) {
            _push(`<span class="badge badge-success" data-v-03a0ef3e>${ssrInterpolate(_ctx.$t("changelog.new"))}</span>`);
          } else {
            _push(`<!---->`);
          }
          _push(`</h2><time class="entry-date" data-v-03a0ef3e>${ssrInterpolate(formatDate(entry.date))}</time></header><div class="entry-content" data-v-03a0ef3e><!--[-->`);
          ssrRenderList(entry.sections, (section) => {
            _push(`<div class="entry-section" data-v-03a0ef3e><h3 data-v-03a0ef3e>${ssrInterpolate(section.title)}</h3><ul data-v-03a0ef3e><!--[-->`);
            ssrRenderList(section.items, (item, idx) => {
              _push(`<li data-v-03a0ef3e>${ssrInterpolate(item)}</li>`);
            });
            _push(`<!--]--></ul></div>`);
          });
          _push(`<!--]--></div></article>`);
        });
        _push(`<!--]--></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/changelog.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const changelog = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-03a0ef3e"]]);

export { changelog as default };
//# sourceMappingURL=changelog-CVp1u2jo.mjs.map
