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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var isObject = require('lodash/isObject');
var hooks_useConfig = require('../hooks/useConfig.js');
var stickyTool_props = require('./props.js');
var stickyTool_stickyItemProps = require('./sticky-item-props.js');
var hooks_slot = require('../hooks/slot.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('lodash/isString');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-7f0559c3.js');
require('dayjs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);

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__default["default"](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 = vue.defineComponent({
  name: "TStickyTool",
  props: _objectSpread({}, stickyTool_props["default"]),
  setup: function setup(props2) {
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("sticky-tool");
    var classes = vue.computed(function () {
      return [COMPONENT_NAME.value, "".concat(COMPONENT_NAME.value, "--").concat(props2.shape)];
    });
    var styles = vue.computed(function () {
      var styles2 = getOffset();
      if (props2.width) styles2.width = typeof props2.width === "number" ? "".concat(props2.width, "px") : props2.width;
      return styles2;
    });
    var getChildComponentByName = hooks_slot.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__default["default"](children)) {
          for (var key in children) {
            if (key in stickyTool_stickyItemProps["default"] && !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 vue.createVNode(vue.resolveComponent("l-sticky-item"), vue.mergeProps(itemProps, {
          "key": index
        }), null);
      });
      return content;
    };
    return function () {
      return vue.createVNode("div", {
        "class": classes.value,
        "style": styles.value
      }, [renderContent()]);
    };
  }
});

exports["default"] = _StickyTool;
//# sourceMappingURL=sticky-tool.js.map
