'use strict';

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

var vue = require('vue');
var svg = require('@element-plus/icons-vue');

const _hoisted_1 = {
  key: 0,
  class: "back_to_top"
};
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "FLayoutPage"
  },
  __name: "index",
  props: {
    keepScrollDisabled: { type: Boolean, default: false },
    isNoMargin: { type: Boolean, default: false },
    showGoTopButton: { type: Boolean, default: true },
    scrollToTop: { default: 100 }
  },
  setup(__props) {
    const props = __props;
    const isShowGoTopButton = vue.ref(false);
    const FLayoutPageRef = vue.ref(null);
    const scrollTop = vue.ref(0);
    vue.watch(
      () => scrollTop.value,
      (newVal) => {
        if (newVal > props.scrollToTop) {
          isShowGoTopButton.value = true;
        } else {
          isShowGoTopButton.value = false;
        }
      }
    );
    const backToTop = () => {
      scrollTop.value = 0;
      FLayoutPageRef.value.scrollTo({
        top: 0,
        behavior: "smooth"
      });
    };
    vue.onMounted(() => {
      const pageItems = FLayoutPageRef.value.querySelectorAll(".f_layout_page_item");
      if (pageItems.length === 2) {
        pageItems[0].style.marginBottom = "8px";
      }
      if (pageItems.length > 2) {
        pageItems.forEach((item) => {
          item.style.marginBottom = "8px";
        });
        pageItems[pageItems.length - 1].style.marginBottom = "0";
      }
    });
    vue.onActivated(() => {
      if (!props.keepScrollDisabled) {
        ;
        FLayoutPageRef.value.scrollTop = scrollTop;
      }
    });
    return (_ctx, _cache) => {
      const _component_el_icon = vue.resolveComponent("el-icon");
      return vue.openBlock(), vue.createElementBlock(
        "div",
        {
          ref_key: "FLayoutPageRef",
          ref: FLayoutPageRef,
          class: vue.normalizeClass(["f_layout_page", { layout_page_no_margin: __props.isNoMargin }]),
          onScroll: _cache[0] || (_cache[0] = (e) => scrollTop.value = e.target.scrollTop)
        },
        [
          vue.renderSlot(_ctx.$slots, "default"),
          __props.showGoTopButton ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
            isShowGoTopButton.value ? (vue.openBlock(), vue.createElementBlock("div", {
              key: 0,
              onClick: backToTop
            }, [
              vue.createVNode(
                _component_el_icon,
                vue.normalizeProps(vue.guardReactiveProps({ size: 24, ..._ctx.$attrs })),
                {
                  default: vue.withCtx(() => [
                    vue.createVNode(vue.unref(svg.CaretTop))
                  ]),
                  _: 1
                  /* STABLE */
                },
                16
                /* FULL_PROPS */
              )
            ])) : vue.createCommentVNode("v-if", true)
          ])) : vue.createCommentVNode("v-if", true)
        ],
        34
        /* CLASS, NEED_HYDRATION */
      );
    };
  }
});

exports.default = _sfc_main;
