import { defineComponent, ref, computed, createVNode } from 'vue';
import '../../../utils/index.mjs';
import '../../../vue-components/index.mjs';
import { useInjectFormItemContext } from '../../form/src/FormItemContext.mjs';
import useConfigInject from '../../config-provider/src/hooks/useConfigInject.mjs';
import useStyle from '../style/index.mjs';
import SliderTooltip from './SliderTooltip.mjs';
import { sliderProps } from './props.mjs';
import { devWarning } from '../../../utils/log.mjs';
import VcHandle from '../../../vue-components/vc-slider/src/Handle.mjs';
import { classNames } from '../../../utils/dom/class.mjs';
import VcRange from '../../../vue-components/vc-slider/src/Range.mjs';
import VcSlider from '../../../vue-components/vc-slider/src/Slider.mjs';

var ASlider = /* @__PURE__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ASlider",
  inheritAttrs: false,
  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]) => {
        devWarning(props.tooltipVisible === void 0, "Slider", `\`${deprecatedName}\` is deprecated, please use \`${newName}\` instead.`);
      });
    }
    const {
      prefixCls,
      rootPrefixCls,
      direction,
      getPopupContainer,
      configProvider
    } = useConfigInject("slider", props);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    const formItemContext = useInjectFormItemContext();
    const sliderRef = ref();
    const visibles = ref({});
    const toggleTooltipOpen = (index, visible) => {
      visibles.value[index] = visible;
    };
    const tooltipPlacement = 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 createVNode(SliderTooltip, {
        "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: () => [createVNode(VcHandle, {
          ...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 = 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(createVNode(VcRange, {
          ...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(createVNode(VcSlider, {
        ...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
      }));
    };
  }
});

export { ASlider as default };
//# sourceMappingURL=Slider.mjs.map
