import { defineComponent, withAsyncContext, withCtx, unref, createVNode, toDisplayString, createTextVNode, openBlock, createBlock, createCommentVNode, useSSRContext } from 'vue';
import { ssrRenderComponent, ssrInterpolate } from 'vue/server-renderer';
import { b9 as useI18n, be as useNuxtApp, br as useState, bl as useRoute$2, b4 as useFetch, y as createError, b8 as useHead, j as VContainer, V as VBtn } from './server.mjs';
import { V as VAlert } from './VAlert-B_mtyJh1.mjs';
import { V as VCard, b as VCardTitle } from './VCard-D86CughW.mjs';
import { V as VCardText } from './VCardText-KkYigSmQ.mjs';
import '../nitro/nitro.mjs';
import 'luxon';
import '@sequelize/core';
import 'html-to-text';
import 'zod';
import 'crypto';
import 'node:fs';
import 'sharp';
import 'path';
import 'node:stream';
import 'jsdom';
import 'dompurify';
import 'mime-types';
import 'fs';
import 'fs/promises';
import 'linkify-html';
import '@peertube/http-signature';
import 'jsonld';
import 'lodash.intersection';
import 'email-templates';
import 'node:http';
import 'node:https';
import 'node:crypto';
import 'node:events';
import 'node:buffer';
import 'node:path';
import 'vue-router';
import 'dotenv';
import 'url';
import 'bcryptjs';
import 'slugify';
import 'umzug';
import 'consola';
import '@sequelize/core/decorators-legacy';
import 'util';
import 'mitt';
import 'ical.js';
import 'node:url';
import 'fast-xml-parser';
import 'perfect-debounce';
import 'v-calendar';
import 'linkifyjs';
import '../routes/renderer.mjs';
import 'vue-bundle-renderer/runtime';
import 'unhead/server';
import 'devalue';
import 'unhead/utils';
import './createSimpleFunctional-D4PbVxKo.mjs';
import './VCardActions-B8o0qNQf.mjs';
import './VAvatar-DZc9zgUD.mjs';

const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "[slug]",
  __ssrInlineRender: true,
  async setup(__props) {
    let __temp, __restore;
    const { t: $t } = useI18n();
    const { $notify } = useNuxtApp();
    const settings = useState("settings");
    const route = useRoute$2();
    const { data: page, refresh } = ([__temp, __restore] = withAsyncContext(() => useFetch(
      `/api/pages/${route.params.slug}`,
      "$HgIisT4fpk"
      /* nuxt-injected */
    )), __temp = await __temp, __restore(), __temp);
    if (!page.value) {
      throw createError({ status: 404, statusMessage: "Page not found" });
    }
    useHead(() => {
      const title = `${settings.value.title} - ${page.value?.title}`;
      return {
        title
      };
    });
    async function toggleVisibility() {
      if (!page.value) {
        return;
      }
      try {
        await $fetch(`/api/pages/${page.value.id}`, {
          method: "PUT",
          body: { ...page.value, visible: true }
        });
        refresh();
        $notify($t("common.enabled"));
      } catch (e) {
        $notify(String(e));
      }
    }
    return (_ctx, _push, _parent, _attrs) => {
      _push(ssrRenderComponent(VContainer, _attrs, {
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            if (!unref(page)?.visible) {
              _push2(ssrRenderComponent(VAlert, {
                type: "warning",
                rounded: "",
                class: "mb-4"
              }, {
                append: withCtx((_2, _push3, _parent3, _scopeId2) => {
                  if (_push3) {
                    _push3(ssrRenderComponent(VBtn, {
                      color: "warning",
                      onClick: toggleVisibility
                    }, {
                      default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                        if (_push4) {
                          _push4(`${ssrInterpolate(unref($t)("common.enable"))}`);
                        } else {
                          return [
                            createTextVNode(toDisplayString(unref($t)("common.enable")), 1)
                          ];
                        }
                      }),
                      _: 1
                    }, _parent3, _scopeId2));
                  } else {
                    return [
                      createVNode(VBtn, {
                        color: "warning",
                        onClick: toggleVisibility
                      }, {
                        default: withCtx(() => [
                          createTextVNode(toDisplayString(unref($t)("common.enable")), 1)
                        ]),
                        _: 1
                      })
                    ];
                  }
                }),
                default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                  if (_push3) {
                    _push3(`<span class="font-weight-semibold"${_scopeId2}>${ssrInterpolate(unref($t)("admin.page_is_disabled"))}</span>`);
                  } else {
                    return [
                      createVNode("span", { class: "font-weight-semibold" }, toDisplayString(unref($t)("admin.page_is_disabled")), 1)
                    ];
                  }
                }),
                _: 1
              }, _parent2, _scopeId));
            } else {
              _push2(`<!---->`);
            }
            _push2(ssrRenderComponent(VCard, null, {
              default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  _push3(ssrRenderComponent(VCardTitle, { class: "text-h4 font-weight-bold" }, {
                    default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                      if (_push4) {
                        _push4(`${ssrInterpolate(unref(page)?.title)}`);
                      } else {
                        return [
                          createTextVNode(toDisplayString(unref(page)?.title), 1)
                        ];
                      }
                    }),
                    _: 1
                  }, _parent3, _scopeId2));
                  _push3(ssrRenderComponent(VCardText, null, null, _parent3, _scopeId2));
                } else {
                  return [
                    createVNode(VCardTitle, { class: "text-h4 font-weight-bold" }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(unref(page)?.title), 1)
                      ]),
                      _: 1
                    }),
                    createVNode(VCardText, {
                      innerHTML: unref(page)?.content
                    }, null, 8, ["innerHTML"])
                  ];
                }
              }),
              _: 1
            }, _parent2, _scopeId));
          } else {
            return [
              !unref(page)?.visible ? (openBlock(), createBlock(VAlert, {
                key: 0,
                type: "warning",
                rounded: "",
                class: "mb-4"
              }, {
                append: withCtx(() => [
                  createVNode(VBtn, {
                    color: "warning",
                    onClick: toggleVisibility
                  }, {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(unref($t)("common.enable")), 1)
                    ]),
                    _: 1
                  })
                ]),
                default: withCtx(() => [
                  createVNode("span", { class: "font-weight-semibold" }, toDisplayString(unref($t)("admin.page_is_disabled")), 1)
                ]),
                _: 1
              })) : createCommentVNode("", true),
              createVNode(VCard, null, {
                default: withCtx(() => [
                  createVNode(VCardTitle, { class: "text-h4 font-weight-bold" }, {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(unref(page)?.title), 1)
                    ]),
                    _: 1
                  }),
                  createVNode(VCardText, {
                    innerHTML: unref(page)?.content
                  }, null, 8, ["innerHTML"])
                ]),
                _: 1
              })
            ];
          }
        }),
        _: 1
      }, _parent));
    };
  }
});
const _sfc_setup = _sfc_main.setup;
_sfc_main.setup = (props, ctx) => {
  const ssrContext = useSSRContext();
  (ssrContext.modules || (ssrContext.modules = /* @__PURE__ */ new Set())).add("pages/p/[slug].vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};

export { _sfc_main as default };
