'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var pinia = require('pinia');
require('../../../stores/index.js');
require('../../../utils/index.js');
require('../../../hooks/index.js');
var mitt = require('../../../utils/mitt.js');
var themeConfig = require('../../../stores/themeConfig.js');
var useDialogEvents = require('../../../hooks/composables/useDialogEvents.js');
var storage = require('../../../utils/storage.js');

var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "FLayout"
  },
  __name: "index",
  emits: ["layoutChangePassword", "layoutOnlineUsers", "layoutSearchMenu", "layoutSetBrowserTitle", "layoutSetOpenLink"],
  setup(__props, { emit: __emit }) {
    const layouts = {
      defaults: vue.defineAsyncComponent(() => Promise.resolve().then(function () { return require('./main/defaults.vue.js'); })),
      classic: vue.defineAsyncComponent(() => Promise.resolve().then(function () { return require('./main/classic.vue.js'); })),
      transverse: vue.defineAsyncComponent(() => Promise.resolve().then(function () { return require('./main/transverse.vue.js'); })),
      columns: vue.defineAsyncComponent(() => Promise.resolve().then(function () { return require('./main/columns.vue.js'); }))
    };
    const storesThemeConfig = themeConfig.useThemeConfig();
    const { themeConfig: themeConfig$1 } = pinia.storeToRefs(storesThemeConfig);
    let maxClientWidth = document.body.clientWidth;
    const curMyEmit = __emit;
    useDialogEvents.provideFormEvents({
      onFormDialogOpen: (data) => {
        if (data.name == "changePassword") {
          curMyEmit("layoutChangePassword");
        } else if (data.name == "onlineUsers") {
          curMyEmit("layoutOnlineUsers");
        } else if (data.name == "searchFormMenu") {
          curMyEmit("layoutSearchMenu");
        } else if (data.name == "setFBrowserTitle") {
          curMyEmit("layoutSetBrowserTitle");
        } else if (data.name == "setFOpenLink") {
          curMyEmit("layoutSetOpenLink", data);
        }
      }
    });
    const onLayoutResize = () => {
      if (!storage.Local.get("oldLayout")) storage.Local.set("oldLayout", themeConfig$1.value.layout);
      const clientWidth = document.body.clientWidth;
      if (maxClientWidth > clientWidth) return;
      maxClientWidth = clientWidth;
      if (clientWidth < 1e3) {
        themeConfig$1.value.isCollapse = false;
        mitt.default.emit("layoutMobileResize", {
          layout: "defaults",
          clientWidth
        });
      } else {
        mitt.default.emit("layoutMobileResize", {
          layout: storage.Local.get("oldLayout") ? storage.Local.get("oldLayout") : themeConfig$1.value.layout,
          clientWidth
        });
      }
    };
    vue.onBeforeMount(() => {
      onLayoutResize();
      window.addEventListener("resize", onLayoutResize);
    });
    vue.onUnmounted(() => {
      window.removeEventListener("resize", onLayoutResize);
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(
        vue.resolveDynamicComponent(layouts[vue.unref(themeConfig$1).layout]),
        vue.normalizeProps(vue.guardReactiveProps(_ctx.$attrs)),
        {
          default: vue.withCtx(() => [
            (vue.openBlock(true), vue.createElementBlock(
              vue.Fragment,
              null,
              vue.renderList(_ctx.$slots, (_, name) => {
                return vue.renderSlot(_ctx.$slots, name, vue.mergeProps({
                  key: name,
                  ref_for: true
                }, _ctx.$slots[name].props || {}));
              }),
              128
              /* KEYED_FRAGMENT */
            ))
          ]),
          _: 3
          /* FORWARDED */
        },
        16
        /* FULL_PROPS */
      );
    };
  }
});

exports.default = _sfc_main;
