'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
require('../../../vue-components/index.cjs');
var FormItemContext = require('../../form/src/FormItemContext.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var SliderTooltip = require('./SliderTooltip.cjs');
var props = require('./props.cjs');
var log = require('../../../utils/log.cjs');
var Handle = require('../../../vue-components/vc-slider/src/Handle.cjs');
var _class = require('../../../utils/dom/class.cjs');
var Range = require('../../../vue-components/vc-slider/src/Range.cjs');
var Slider = require('../../../vue-components/vc-slider/src/Slider.cjs');

var ASlider = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ASlider",
  inheritAttrs: false,
  props: props.sliderProps(),
  // emits: ['update:value', 'change', 'afterChange', 'blur'],
  slots: Object,
  setup(props, {
    attrs,
    slots,
    emit,
    expose
  }) {
    if (process.env.NODE_ENV !== "production") {
      [["tooltipVisible", "tooltipOpen"]].forEach(([deprecatedName, newName]) => {
        log.devWarning(props.tooltipVisible === void 0, "Slider", `\`${deprecatedName}\` is deprecated, please use \`${newName}\` instead.`);
      });
    }
    const {
      prefixCls,
      rootPrefixCls,
      direction,
      getPopupContainer,
      configProvider
    } = useConfigInject.default("slider", props);
    const [wrapSSR, hashId] = index.default(prefixCls);
    const formItemContext = FormItemContext.useInjectFormItemContext();
    const sliderRef = vue.ref();
    const visibles = vue.ref({});
    const toggleTooltipOpen = (index, visible) => {
      visibles.value[index] = visible;
    };
    const tooltipPlacement = vue.computed(() => {
      if (props.tooltipPlacement)
        return props.tooltipPlacement;
      if (!props.vertical)
        return "top";
      return direction.value === "rtl" ? "left" : "right";
    });
    const focus = () => {
      var _a;
      (_a = sliderRef.value) == null ? void 0 : _a.focus();
    };
    const blur = () => {
      var _a;
      (_a = sliderRef.value) == null ? void 0 : _a.blur();
    };
    const handleChange = (val) => {
      emit("update:value", val);
      emit("change", val);
      formItemContext.onFieldChange();
    };
    const handleBlur = (e) => {
      emit("blur", e);
    };
    expose({
      focus,
      blur
    });
    const handleWithTooltip = ({
      tooltipPrefixCls,
      info: {
        value,
        dragging,
        index,
        ...restProps
      }
    }) => {
      const {
        tipFormatter,
        tooltipOpen = props.tooltipVisible,
        getTooltipPopupContainer
      } = props;
      const isTipFormatter = tipFormatter ? visibles.value[index] || dragging : false;
      const open = tooltipOpen || tooltipOpen === void 0 && isTipFormatter;
      return vue.createVNode(SliderTooltip.default, {
        "prefixCls": tooltipPrefixCls,
        "title": tipFormatter ? tipFormatter(value) : "",
        "open": open,
        "placement": tooltipPlacement.value,
        "transitionName": `${rootPrefixCls.value}-zoom-down`,
        "key": index,
        "overlayClassName": `${prefixCls.value}-tooltip`,
        "getPopupContainer": getTooltipPopupContainer || (getPopupContainer == null ? void 0 : getPopupContainer.value)
      }, {
        default: () => [vue.createVNode(Handle.default, {
          ...restProps,
          "value": value,
          "onMouseenter": () => toggleTooltipOpen(index, true),
          "onMouseleave": () => toggleTooltipOpen(index, false)
        }, null)]
      });
    };
    return () => {
      const {
        tooltipPrefixCls: customizeTooltipPrefixCls,
        range,
        id = formItemContext.id.value,
        ...restProps
      } = props;
      const tooltipPrefixCls = configProvider.getPrefixCls("tooltip", customizeTooltipPrefixCls);
      const cls = _class.classNames(attrs.class, {
        [`${prefixCls.value}-rtl`]: direction.value === "rtl"
      }, hashId.value);
      if (direction.value === "rtl" && !restProps.vertical)
        restProps.reverse = !restProps.reverse;
      let draggableTrack;
      if (typeof range === "object")
        draggableTrack = range.draggableTrack;
      if (range) {
        return wrapSSR(vue.createVNode(Range.default, {
          ...attrs,
          ...restProps,
          "step": restProps.step,
          "draggableTrack": draggableTrack,
          "class": cls,
          "ref": sliderRef,
          "handle": (info) => handleWithTooltip({
            tooltipPrefixCls,
            prefixCls: prefixCls.value,
            info
          }),
          "prefixCls": prefixCls.value,
          "onChange": handleChange,
          "onBlur": handleBlur
        }, {
          mark: slots.mark
        }));
      }
      return wrapSSR(vue.createVNode(Slider.default, {
        ...attrs,
        ...restProps,
        "id": id,
        "step": restProps.step,
        "class": cls,
        "ref": sliderRef,
        "handle": (info) => handleWithTooltip({
          tooltipPrefixCls,
          prefixCls: prefixCls.value,
          info
        }),
        "prefixCls": prefixCls.value,
        "onChange": handleChange,
        "onBlur": handleBlur
      }, {
        mark: slots.mark
      }));
    };
  }
});

exports.default = ASlider;
//# sourceMappingURL=Slider.cjs.map
