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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, createVNode, resolveComponent, mergeProps } from 'vue';
import isObject from 'lodash/isObject';
import { usePrefixClass } from '../hooks/useConfig.js';
import TdStickyToolProps from './props.js';
import baseProps from './sticky-item-props.js';
import { useChildComponentSlots } from '../hooks/slot.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import 'lodash/isFunction';
import 'lodash/isString';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-c9c789a8.js';
import 'dayjs';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var _StickyTool = defineComponent({
  name: "TStickyTool",
  props: _objectSpread({}, TdStickyToolProps),
  setup: function setup(props2) {
    var COMPONENT_NAME = usePrefixClass("sticky-tool");
    var classes = computed(function () {
      return [COMPONENT_NAME.value, "".concat(COMPONENT_NAME.value, "--").concat(props2.shape)];
    });
    var styles = computed(function () {
      var styles2 = getOffset();
      if (props2.width) styles2.width = typeof props2.width === "number" ? "".concat(props2.width, "px") : props2.width;
      return styles2;
    });
    var getChildComponentByName = useChildComponentSlots();
    var getList = function getList() {
      var _props2$list;
      var list;
      if ((_props2$list = props2.list) !== null && _props2$list !== void 0 && _props2$list.length) {
        list = props2.list;
      } else {
        var nodes = getChildComponentByName("StickyItem");
        list = getListBySlots(nodes);
      }
      return list;
    };
    var getListBySlots = function getListBySlots(nodes) {
      var arr = [];
      nodes === null || nodes === void 0 ? void 0 : nodes.forEach(function (node) {
        var list = (node === null || node === void 0 ? void 0 : node.props) || {};
        var children = node === null || node === void 0 ? void 0 : node.children;
        if (!list && !children) return;
        if (children && isObject(children)) {
          for (var key in children) {
            if (key in baseProps && !list[key]) list[key] = children[key];
          }
        }
        arr.push(list);
      });
      return arr;
    };
    var getOffset = function getOffset() {
      var _props2$offset;
      var position = props2.offset ? [80, 24] : ["80px", "24px"];
      (_props2$offset = props2.offset) === null || _props2$offset === void 0 ? void 0 : _props2$offset.forEach(function (item, index) {
        position[index] = isNaN(Number(item)) ? "calc( ".concat(position[index], "px + ").concat(item, ")") : "".concat(position[index] + item, "px");
      });
      var offsetStyle = {};
      props2.placement.split("-").forEach(function (item, index) {
        if (item !== "center") {
          offsetStyle[item] = position[index];
        } else {
          offsetStyle.top = "50%";
          offsetStyle.transform = "translate(0, -50%)";
        }
      });
      return offsetStyle;
    };
    var handleClick = function handleClick(context) {
      var _props2$onClick;
      (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, context);
    };
    var handleHover = function handleHover(context) {
      var _props2$onHover;
      (_props2$onHover = props2.onHover) === null || _props2$onHover === void 0 ? void 0 : _props2$onHover.call(props2, context);
    };
    var renderContent = function renderContent() {
      var list = getList();
      var content = list.map(function (item, index) {
        var type = props2.type,
          shape = props2.shape,
          placement = props2.placement,
          popupProps = props2.popupProps;
        var itemProps = _objectSpread(_objectSpread({}, item), {}, {
          type: type,
          shape: shape,
          placement: placement,
          basePopupProps: popupProps,
          baseWidth: styles.value.width,
          onClick: handleClick,
          onHover: handleHover
        });
        return createVNode(resolveComponent("l-sticky-item"), mergeProps(itemProps, {
          "key": index
        }), null);
      });
      return content;
    };
    return function () {
      return createVNode("div", {
        "class": classes.value,
        "style": styles.value
      }, [renderContent()]);
    };
  }
});

export { _StickyTool as default };
//# sourceMappingURL=sticky-tool.js.map
