import { defineComponent, ref, withAsyncContext, withCtx, createTextVNode, toDisplayString, unref, isRef, createVNode, useSSRContext } from 'vue';
import { ssrRenderComponent, ssrInterpolate } from 'vue/server-renderer';
import { be as useNuxtApp, b4 as useFetch, V as VBtn } from './server.mjs';
import { S as Statuses } from '../nitro/nitro.mjs';
import { V as VCard, b as VCardTitle } from './VCard-D86CughW.mjs';
import { V as VCardText } from './VCardText-KkYigSmQ.mjs';
import { V as VForm } from './VForm-BuIr7lQn.mjs';
import { V as VAutocomplete } from './VAutocomplete-Jk9mR2K4.mjs';
import { V as VCardActions } from './VCardActions-B8o0qNQf.mjs';
import { V as VSpacer } from './VSpacer-D6kTsy1m.mjs';
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 '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 './createSimpleFunctional-D4PbVxKo.mjs';
import './VAvatar-DZc9zgUD.mjs';
import './form-Q_oG-_Ip.mjs';
import './forwardRefs-C3iWxc5z.mjs';
import './autofocus-BUnCw2TG.mjs';
import './index-0tjXFI7F.mjs';
import './animation-DMtpo1PO.mjs';
import './VSelect-BjfkSWhE.mjs';
import './VTextField-DFD0D30-.mjs';
import './VOverlay-Dlj-QQp0.mjs';
import './VDivider-akc4E5rx.mjs';
import './VMenu-I968mMci.mjs';
import './VSheet-DRep8U-I.mjs';
import './VChip-BLze6MCM.mjs';

const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "AssignAuthor",
  __ssrInlineRender: true,
  props: { event: { type: Object, default: () => ({}) } },
  emits: ["close", "update"],
  async setup(__props, { emit: __emit }) {
    let __temp, __restore;
    const props = __props;
    const { $notify } = useNuxtApp();
    const emit = __emit;
    const loading = ref(false);
    const selectedUser = ref();
    const { data: users } = ([__temp, __restore] = withAsyncContext(() => useFetch(
      "/api/users",
      "$JDsH0ifUd5"
      /* nuxt-injected */
    )), __temp = await __temp, __restore(), __temp);
    async function assign() {
      try {
        loading.value = true;
        await $fetch(`/api/events/${props.event.id}/assign_to_author`, { method: "PUT", body: { userId: selectedUser.value } });
        loading.value = false;
        emit("update");
        emit("close");
        $notify("event.saved");
      } catch (e) {
        loading.value = false;
        $notify(e, Statuses.ERROR);
      }
    }
    return (_ctx, _push, _parent, _attrs) => {
      _push(ssrRenderComponent(VCard, _attrs, {
        default: withCtx((_, _push2, _parent2, _scopeId) => {
          if (_push2) {
            _push2(ssrRenderComponent(VCardTitle, { class: "bg-primary" }, {
              default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  _push3(`${ssrInterpolate(_ctx.$t("event.assign_to_user"))}`);
                } else {
                  return [
                    createTextVNode(toDisplayString(_ctx.$t("event.assign_to_user")), 1)
                  ];
                }
              }),
              _: 1
            }, _parent2, _scopeId));
            _push2(ssrRenderComponent(VCardText, null, {
              default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  _push3(`<p class="mb-2"${_scopeId2}>${ssrInterpolate(_ctx.$t("event.assign_to_user_description"))}</p>`);
                  _push3(ssrRenderComponent(VForm, null, {
                    default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                      if (_push4) {
                        _push4(ssrRenderComponent(VAutocomplete, {
                          modelValue: unref(selectedUser),
                          "onUpdate:modelValue": ($event) => isRef(selectedUser) ? selectedUser.value = $event : null,
                          items: unref(users),
                          "prepend-inner-icon": "mdi-account",
                          "hide-no-data": "",
                          "item-title": "email",
                          "item-value": "id",
                          placeholder: "Choose user",
                          label: _ctx.$t("common.user")
                        }, null, _parent4, _scopeId3));
                      } else {
                        return [
                          createVNode(VAutocomplete, {
                            modelValue: unref(selectedUser),
                            "onUpdate:modelValue": ($event) => isRef(selectedUser) ? selectedUser.value = $event : null,
                            items: unref(users),
                            "prepend-inner-icon": "mdi-account",
                            "hide-no-data": "",
                            "item-title": "email",
                            "item-value": "id",
                            placeholder: "Choose user",
                            label: _ctx.$t("common.user")
                          }, null, 8, ["modelValue", "onUpdate:modelValue", "items", "label"])
                        ];
                      }
                    }),
                    _: 1
                  }, _parent3, _scopeId2));
                } else {
                  return [
                    createVNode("p", { class: "mb-2" }, toDisplayString(_ctx.$t("event.assign_to_user_description")), 1),
                    createVNode(VForm, null, {
                      default: withCtx(() => [
                        createVNode(VAutocomplete, {
                          modelValue: unref(selectedUser),
                          "onUpdate:modelValue": ($event) => isRef(selectedUser) ? selectedUser.value = $event : null,
                          items: unref(users),
                          "prepend-inner-icon": "mdi-account",
                          "hide-no-data": "",
                          "item-title": "email",
                          "item-value": "id",
                          placeholder: "Choose user",
                          label: _ctx.$t("common.user")
                        }, null, 8, ["modelValue", "onUpdate:modelValue", "items", "label"])
                      ]),
                      _: 1
                    })
                  ];
                }
              }),
              _: 1
            }, _parent2, _scopeId));
            _push2(ssrRenderComponent(VCardActions, null, {
              default: withCtx((_2, _push3, _parent3, _scopeId2) => {
                if (_push3) {
                  _push3(ssrRenderComponent(VSpacer, null, null, _parent3, _scopeId2));
                  _push3(ssrRenderComponent(VBtn, {
                    color: "primary",
                    variant: "outlined",
                    disabled: !unref(selectedUser) || unref(loading),
                    loading: unref(loading),
                    onClick: assign
                  }, {
                    default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                      if (_push4) {
                        _push4(`${ssrInterpolate(_ctx.$t("event.assign_to_user"))}`);
                      } else {
                        return [
                          createTextVNode(toDisplayString(_ctx.$t("event.assign_to_user")), 1)
                        ];
                      }
                    }),
                    _: 1
                  }, _parent3, _scopeId2));
                  _push3(ssrRenderComponent(VBtn, {
                    color: "warning",
                    variant: "outlined",
                    onClick: ($event) => _ctx.$emit("close")
                  }, {
                    default: withCtx((_3, _push4, _parent4, _scopeId3) => {
                      if (_push4) {
                        _push4(`${ssrInterpolate(_ctx.$t("common.close"))}`);
                      } else {
                        return [
                          createTextVNode(toDisplayString(_ctx.$t("common.close")), 1)
                        ];
                      }
                    }),
                    _: 1
                  }, _parent3, _scopeId2));
                } else {
                  return [
                    createVNode(VSpacer),
                    createVNode(VBtn, {
                      color: "primary",
                      variant: "outlined",
                      disabled: !unref(selectedUser) || unref(loading),
                      loading: unref(loading),
                      onClick: assign
                    }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(_ctx.$t("event.assign_to_user")), 1)
                      ]),
                      _: 1
                    }, 8, ["disabled", "loading"]),
                    createVNode(VBtn, {
                      color: "warning",
                      variant: "outlined",
                      onClick: ($event) => _ctx.$emit("close")
                    }, {
                      default: withCtx(() => [
                        createTextVNode(toDisplayString(_ctx.$t("common.close")), 1)
                      ]),
                      _: 1
                    }, 8, ["onClick"])
                  ];
                }
              }),
              _: 1
            }, _parent2, _scopeId));
          } else {
            return [
              createVNode(VCardTitle, { class: "bg-primary" }, {
                default: withCtx(() => [
                  createTextVNode(toDisplayString(_ctx.$t("event.assign_to_user")), 1)
                ]),
                _: 1
              }),
              createVNode(VCardText, null, {
                default: withCtx(() => [
                  createVNode("p", { class: "mb-2" }, toDisplayString(_ctx.$t("event.assign_to_user_description")), 1),
                  createVNode(VForm, null, {
                    default: withCtx(() => [
                      createVNode(VAutocomplete, {
                        modelValue: unref(selectedUser),
                        "onUpdate:modelValue": ($event) => isRef(selectedUser) ? selectedUser.value = $event : null,
                        items: unref(users),
                        "prepend-inner-icon": "mdi-account",
                        "hide-no-data": "",
                        "item-title": "email",
                        "item-value": "id",
                        placeholder: "Choose user",
                        label: _ctx.$t("common.user")
                      }, null, 8, ["modelValue", "onUpdate:modelValue", "items", "label"])
                    ]),
                    _: 1
                  })
                ]),
                _: 1
              }),
              createVNode(VCardActions, null, {
                default: withCtx(() => [
                  createVNode(VSpacer),
                  createVNode(VBtn, {
                    color: "primary",
                    variant: "outlined",
                    disabled: !unref(selectedUser) || unref(loading),
                    loading: unref(loading),
                    onClick: assign
                  }, {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(_ctx.$t("event.assign_to_user")), 1)
                    ]),
                    _: 1
                  }, 8, ["disabled", "loading"]),
                  createVNode(VBtn, {
                    color: "warning",
                    variant: "outlined",
                    onClick: ($event) => _ctx.$emit("close")
                  }, {
                    default: withCtx(() => [
                      createTextVNode(toDisplayString(_ctx.$t("common.close")), 1)
                    ]),
                    _: 1
                  }, 8, ["onClick"])
                ]),
                _: 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("components/Event/AssignAuthor.vue");
  return _sfc_setup ? _sfc_setup(props, ctx) : void 0;
};
const AssignAuthor = Object.assign(_sfc_main, { __name: "EventAssignAuthor" });

export { AssignAuthor as default };
