/**
 * ldesign v0.4.2
 * (c) 2023 ldesign
 * @license MIT
 */

import { _ as _defineProperty } from '../_chunks/dep-eb20e23f.mjs';
import { _ as _typeof } from '../_chunks/dep-b4041200.mjs';
import { defineComponent, ref, onMounted, computed, createVNode, Fragment, createTextVNode } from 'vue';
import { BacktopIcon } from '@ldesign/icons-vue-next';
import { scrollTo } from '../utils/dom.mjs';
import '../hooks/index.mjs';
import { useGlobalIcon } from '../hooks/useGlobalIcon.mjs';
import props from './props.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import { useConfig } from '../config-provider/useConfig.mjs';
import { useContent } from '../hooks/tnode.mjs';
import { useChildSlots } from '../hooks/slot.mjs';
import '../_chunks/dep-a0b4a044.mjs';
import '../_chunks/dep-1cf2b129.mjs';
import '../_chunks/dep-c959a6fb.mjs';
import '../_chunks/dep-e3b14d70.mjs';
import '../_chunks/dep-66d6733b.mjs';
import '../_chunks/dep-c31e1d9e.mjs';
import '../_chunks/dep-6b22dd27.mjs';
import '../_chunks/dep-0f0c89ff.mjs';
import '../utils/easing.mjs';
import '../hooks/icon.mjs';
import '../hooks/useCommonClassName.mjs';
import '../hooks/useDefaultValue.mjs';
import '../_chunks/dep-c4e1a112.mjs';
import '../_chunks/dep-74848b92.mjs';
import '../_chunks/dep-37ba476d.mjs';
import '../_chunks/dep-be27d184.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../_chunks/dep-99920870.mjs';
import '../_chunks/dep-79821ff2.mjs';
import '../_chunks/dep-0bfbf721.mjs';
import '../_chunks/dep-39cc276d.mjs';
import '../_chunks/dep-8f777748.mjs';
import '../_chunks/dep-ae357f26.mjs';
import '../_chunks/dep-352691c2.mjs';
import '../_chunks/dep-2cfd5b3a.mjs';
import '../_chunks/dep-05fa17c9.mjs';
import '../_chunks/dep-a9c8a5d5.mjs';
import '../_chunks/dep-10085c61.mjs';
import '../_chunks/dep-1b058de3.mjs';
import '../_chunks/dep-c852a61a.mjs';
import '../_chunks/dep-92e7085e.mjs';
import '../_chunks/dep-c7e9ce16.mjs';
import '../_chunks/dep-3afa94cf.mjs';
import '../_chunks/dep-ba3c0b2e.mjs';
import '../_chunks/dep-ee57d235.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-6b4aa943.mjs';
import '../_chunks/dep-d52291a9.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useVirtualScroll.mjs';
import '../hooks/useVModel.mjs';
import '../_chunks/dep-44417261.mjs';
import '../_chunks/dep-bf74f1c2.mjs';
import '../_chunks/dep-44f056cd.mjs';
import '../_chunks/dep-23a0f453.mjs';
import '../config-provider/type.mjs';
import '../_chunks/dep-f6649a46.mjs';
import '../_chunks/dep-1fe0ad42.mjs';
import '../_chunks/dep-d54f2690.mjs';
import '../_chunks/dep-59c8420d.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-bd03960e.mjs';

var _BackTop = defineComponent({
  name: "TBackTop",
  props: props,
  setup: function setup(props2) {
    var visible = ref(false);
    var containerRef = ref(null);
    var componentName = usePrefixClass("back-top");
    var _useConfig = useConfig("alert"),
      classPrefix = _useConfig.classPrefix;
    var _useGlobalIcon = useGlobalIcon({
        BacktopIcon: BacktopIcon
      }),
      BacktopIcon$1 = _useGlobalIcon.BacktopIcon;
    var renderContent = useContent();
    var getContainer = function getContainer(container) {
      if (typeof container === "string" && (typeof document === "undefined" ? "undefined" : _typeof(document)) !== void 0) {
        if (container === "body") return document;
        return document.querySelector(container);
      }
      if (typeof container === "function") return container();
      return null;
    };
    onMounted(function () {
      containerRef.value = getContainer(props2.container);
      var visibleHeight;
      if (typeof props2.visibleHeight === "string") visibleHeight = Number(props2.visibleHeight.replace("px", ""));else visibleHeight = props2.visibleHeight;
      if (visibleHeight === 0) {
        visible.value = true;
        return;
      }
      var scrollDOM;
      if (containerRef.value.scrollTop === void 0) scrollDOM = document.documentElement;else scrollDOM = containerRef.value;
      containerRef.value.onscroll = function () {
        var scrollTop = scrollDOM.scrollTop;
        if (scrollTop >= visibleHeight) {
          visible.value = true;
          containerRef.value.onscroll = null;
        }
      };
    });
    return function () {
      var theme = props2.theme,
        shape = props2.shape,
        size = props2.size,
        target = props2.target,
        duration = props2.duration,
        offset = props2.offset,
        container = props2.container;
      var getChild = useChildSlots();
      var children = getChild();
      if (children.length < 1) children = null;
      var cls = computed(function () {
        var _ref;
        return _ref = {}, _defineProperty(_ref, componentName.value, true), _defineProperty(_ref, "".concat(componentName.value, "--theme-").concat(theme), true), _defineProperty(_ref, "".concat(componentName.value, "--").concat(shape), true), _defineProperty(_ref, "".concat(componentName.value, "--show"), visible.value), _defineProperty(_ref, "".concat(classPrefix.value, "-size-s"), size === "small"), _defineProperty(_ref, "".concat(classPrefix.value, "-size-m"), size === "medium"), _ref;
      });
      var defaultContent = createVNode(Fragment, null, [createVNode(BacktopIcon$1, {
        "class": "".concat(componentName.value, "__icon"),
        "size": "24"
      }, null), createVNode("span", {
        "class": "".concat(componentName.value, "__text")
      }, [createTextVNode("TOP")])]);
      var getBackTo = function getBackTo() {
        if (target === container) return 0;
        if (target === "body") return 0;
        if (!target) return 0;
        var targetNode = getContainer(target);
        if (!targetNode) return 0;
        var y = targetNode.getBoundingClientRect().y;
        return y;
      };
      var handleClick = function handleClick(e) {
        var _props2$onClick;
        var y = getBackTo();
        scrollTo(y, {
          container: containerRef.value,
          duration: duration
        });
        (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, {
          e: e
        });
      };
      var positionStyle = computed(function () {
        return {
          insetInlineEnd: offset[0],
          insetBlockEnd: offset[1]
        };
      });
      return createVNode("button", {
        "type": "button",
        "class": cls.value,
        "style": positionStyle.value,
        "onClick": handleClick
      }, [renderContent("content", "default", defaultContent)]);
    };
  }
});

export { _BackTop as default };
//# sourceMappingURL=back-top.mjs.map
