/**
 * 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 slider_util_common = require('../util/common.js');
require('lodash/isString');

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

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

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 initialProps = {
  visible: false,
  trigger: "hover",
  showArrow: true,
  overlayInnerStyle: void 0,
  overlayClassName: void 0,
  attach: "body",
  theme: "default"
};
var useSliderTooltip = function useSliderTooltip(tooltipConfig) {
  var tooltipRef = vue.ref();
  var showTooltip = vue.computed({
    get: function get() {
      return !tooltipConfig.value.tooltipProps === false;
    },
    set: function set(val) {
      return val;
    }
  });
  var normalizeProps = vue.ref(_objectSpread({}, initialProps));
  var toggleTooltip = function toggleTooltip(toState) {
    if (!showTooltip.value) return;
    normalizeProps.value.visible = toState;
  };
  var validProps = vue.computed(function () {
    var _tooltipConfig$value = tooltipConfig.value,
      vertical = _tooltipConfig$value.vertical,
      tooltipProps = _tooltipConfig$value.tooltipProps,
      label = _tooltipConfig$value.label,
      value = _tooltipConfig$value.value;
    var placement = vertical ? "right" : "top";
    var content = slider_util_common.formatLabel(label, value);
    if (tooltipProps instanceof Object) {
      if (!(tooltipProps !== null && tooltipProps !== void 0 && tooltipProps.placement)) normalizeProps.value.placement = placement;
      if (tooltipProps.content) content = tooltipProps.content;
      return _objectSpread(_objectSpread(_objectSpread({}, normalizeProps.value), tooltipProps), {}, {
        content: content
      });
    }
    return _objectSpread(_objectSpread({}, normalizeProps.value), {}, {
      placement: placement,
      content: content
    });
  });
  return {
    tooltipRef: tooltipRef,
    tooltipProps: validProps,
    toggleTooltip: toggleTooltip,
    showTooltip: showTooltip
  };
};

exports.useSliderTooltip = useSliderTooltip;
//# sourceMappingURL=useSliderTooltip.js.map
