"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const types = require("../../../utils/types.js");
const index$1 = require("../../../hooks/use-locale/index.js");
const index = require("../../../hooks/use-namespace/index.js");
const useFormCommonProps = require("../../form/src/hooks/use-form-common-props.js");
const useFormItem = require("../../form/src/hooks/use-form-item.js");
const index$3 = require("../../input-number/index.js");
const constants = require("./constants.js");
const slider = require("./slider.js");
const useLifecycle = require("./composables/use-lifecycle.js");
const useMarks = require("./composables/use-marks.js");
const useSlide = require("./composables/use-slide.js");
const useStops = require("./composables/use-stops.js");
const useWatch = require("./composables/use-watch.js");
const button2 = require("./button2.js");
const marker = require("./marker.js");
const index$2 = require("../../../../node_modules/@vueuse/core/index.js");
const Vue = require("vue");
const _hoisted_1 = [
  "id",
  "role",
  "aria-label",
  "aria-labelledby"
];
const _hoisted_2 = { key: 1 };
var slider_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  name: "ElSlider",
  __name: "slider",
  props: slider.sliderProps,
  emits: slider.sliderEmits,
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const ns = index.useNamespace("slider");
    const { t } = index$1.useLocale();
    const initData = Vue.reactive({
      firstValue: 0,
      secondValue: 0,
      oldValue: 0,
      dragging: false,
      sliderSize: 1
    });
    const { elFormItem, slider: slider2, firstButton, secondButton, sliderDisabled, minValue, maxValue, runwayStyle, barStyle, resetSize, emitChange, onSliderWrapperPrevent, onSliderClick, onSliderDown, onSliderMarkerDown, setFirstValue, setSecondValue } = useSlide.useSlide(props, initData, emit);
    const { stops, getStopStyle } = useStops.useStops(props, initData, minValue, maxValue);
    const { inputId, isLabeledByFormItem } = useFormItem.useFormItemInputId(props, { formItemContext: elFormItem });
    const sliderWrapperSize = useFormCommonProps.useFormSize();
    const sliderInputSize = Vue.computed(() => props.inputSize || sliderWrapperSize.value);
    const renderInput = Vue.computed(() => {
      return props.showInput && !props.range && props.step !== "mark";
    });
    const groupLabel = Vue.computed(() => {
      return props.ariaLabel || t("el.slider.defaultLabel", {
        min: props.min,
        max: props.max
      });
    });
    const firstButtonLabel = Vue.computed(() => {
      if (props.range) return props.rangeStartLabel || t("el.slider.defaultRangeStartLabel");
      else return groupLabel.value;
    });
    const firstValueText = Vue.computed(() => {
      return props.formatValueText ? props.formatValueText(firstValue.value) : `${firstValue.value}`;
    });
    const secondButtonLabel = Vue.computed(() => {
      return props.rangeEndLabel || t("el.slider.defaultRangeEndLabel");
    });
    const secondValueText = Vue.computed(() => {
      return props.formatValueText ? props.formatValueText(secondValue.value) : `${secondValue.value}`;
    });
    const sliderKls = Vue.computed(() => [
      ns.b(),
      ns.m(sliderWrapperSize.value),
      ns.is("vertical", props.vertical),
      { [ns.m("with-input")]: renderInput.value }
    ]);
    const markList = useMarks.useMarks(props);
    useWatch.useWatch(props, initData, minValue, maxValue, emit, elFormItem);
    const sliderInputStep = Vue.computed(() => {
      return types.isNumber(props.step) ? props.step : 1;
    });
    const precision = Vue.computed(() => {
      const stepValue = types.isNumber(props.step) ? props.step : 1;
      const precisions = [
        props.min,
        props.max,
        stepValue
      ].map((item) => {
        const decimal = `${item}`.split(".")[1];
        return decimal ? decimal.length : 0;
      });
      return Math.max.apply(null, precisions);
    });
    const { sliderWrapper } = useLifecycle.useLifecycle(props, initData, resetSize);
    const { firstValue, secondValue, sliderSize } = Vue.toRefs(initData);
    const updateDragging = (val) => {
      initData.dragging = val;
    };
    index$2.useEventListener(sliderWrapper, "touchstart", onSliderWrapperPrevent, { passive: false });
    index$2.useEventListener(sliderWrapper, "touchmove", onSliderWrapperPrevent, { passive: false });
    Vue.provide(constants.sliderContextKey, {
      ...Vue.toRefs(props),
      sliderSize,
      disabled: sliderDisabled,
      precision,
      markList,
      emitChange,
      resetSize,
      updateDragging
    });
    __expose({ onSliderClick });
    return (_ctx, _cache) => {
      var _a, _b;
      return Vue.openBlock(), Vue.createElementBlock("div", {
        id: _ctx.range ? Vue.unref(inputId) : void 0,
        ref_key: "sliderWrapper",
        ref: sliderWrapper,
        class: Vue.normalizeClass(sliderKls.value),
        role: _ctx.range ? "group" : void 0,
        "aria-label": _ctx.range && !Vue.unref(isLabeledByFormItem) ? groupLabel.value : void 0,
        "aria-labelledby": _ctx.range && Vue.unref(isLabeledByFormItem) ? (_a = Vue.unref(elFormItem)) == null ? void 0 : _a.labelId : void 0
      }, [Vue.createElementVNode("div", {
        ref_key: "slider",
        ref: slider2,
        class: Vue.normalizeClass([
          Vue.unref(ns).e("runway"),
          { "show-input": renderInput.value },
          Vue.unref(ns).is("disabled", Vue.unref(sliderDisabled))
        ]),
        style: Vue.normalizeStyle(Vue.unref(runwayStyle)),
        onMousedown: _cache[0] || (_cache[0] = (...args) => Vue.unref(onSliderDown) && Vue.unref(onSliderDown)(...args)),
        onTouchstartPassive: _cache[1] || (_cache[1] = (...args) => Vue.unref(onSliderDown) && Vue.unref(onSliderDown)(...args))
      }, [
        Vue.createElementVNode("div", {
          class: Vue.normalizeClass(Vue.unref(ns).e("bar")),
          style: Vue.normalizeStyle(Vue.unref(barStyle))
        }, null, 6),
        Vue.createVNode(button2.default, {
          id: !_ctx.range ? Vue.unref(inputId) : void 0,
          ref_key: "firstButton",
          ref: firstButton,
          "model-value": Vue.unref(firstValue),
          vertical: _ctx.vertical,
          "tooltip-class": _ctx.tooltipClass,
          placement: _ctx.placement,
          role: "slider",
          "aria-label": _ctx.range || !Vue.unref(isLabeledByFormItem) ? firstButtonLabel.value : void 0,
          "aria-labelledby": !_ctx.range && Vue.unref(isLabeledByFormItem) ? (_b = Vue.unref(elFormItem)) == null ? void 0 : _b.labelId : void 0,
          "aria-valuemin": _ctx.min,
          "aria-valuemax": _ctx.range ? Vue.unref(secondValue) : _ctx.max,
          "aria-valuenow": Vue.unref(firstValue),
          "aria-valuetext": firstValueText.value,
          "aria-orientation": _ctx.vertical ? "vertical" : "horizontal",
          "aria-disabled": Vue.unref(sliderDisabled),
          "onUpdate:modelValue": Vue.unref(setFirstValue)
        }, null, 8, [
          "id",
          "model-value",
          "vertical",
          "tooltip-class",
          "placement",
          "aria-label",
          "aria-labelledby",
          "aria-valuemin",
          "aria-valuemax",
          "aria-valuenow",
          "aria-valuetext",
          "aria-orientation",
          "aria-disabled",
          "onUpdate:modelValue"
        ]),
        _ctx.range ? (Vue.openBlock(), Vue.createBlock(button2.default, {
          key: 0,
          ref_key: "secondButton",
          ref: secondButton,
          "model-value": Vue.unref(secondValue),
          vertical: _ctx.vertical,
          "tooltip-class": _ctx.tooltipClass,
          placement: _ctx.placement,
          role: "slider",
          "aria-label": secondButtonLabel.value,
          "aria-valuemin": Vue.unref(firstValue),
          "aria-valuemax": _ctx.max,
          "aria-valuenow": Vue.unref(secondValue),
          "aria-valuetext": secondValueText.value,
          "aria-orientation": _ctx.vertical ? "vertical" : "horizontal",
          "aria-disabled": Vue.unref(sliderDisabled),
          "onUpdate:modelValue": Vue.unref(setSecondValue)
        }, null, 8, [
          "model-value",
          "vertical",
          "tooltip-class",
          "placement",
          "aria-label",
          "aria-valuemin",
          "aria-valuemax",
          "aria-valuenow",
          "aria-valuetext",
          "aria-orientation",
          "aria-disabled",
          "onUpdate:modelValue"
        ])) : Vue.createCommentVNode("v-if", true),
        _ctx.showStops ? (Vue.openBlock(), Vue.createElementBlock("div", _hoisted_2, [(Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(stops), (item, key) => {
          return Vue.openBlock(), Vue.createElementBlock("div", {
            key,
            class: Vue.normalizeClass(Vue.unref(ns).e("stop")),
            style: Vue.normalizeStyle(Vue.unref(getStopStyle)(item))
          }, null, 6);
        }), 128))])) : Vue.createCommentVNode("v-if", true),
        Vue.unref(markList).length > 0 ? (Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, { key: 2 }, [Vue.createElementVNode("div", null, [(Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(markList), (item, key) => {
          return Vue.openBlock(), Vue.createElementBlock("div", {
            key,
            style: Vue.normalizeStyle(Vue.unref(getStopStyle)(item.position)),
            class: Vue.normalizeClass([Vue.unref(ns).e("stop"), Vue.unref(ns).e("marks-stop")])
          }, null, 6);
        }), 128))]), Vue.createElementVNode("div", { class: Vue.normalizeClass(Vue.unref(ns).e("marks")) }, [(Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(markList), (item, key) => {
          return Vue.openBlock(), Vue.createBlock(Vue.unref(marker.default), {
            key,
            mark: item.mark,
            style: Vue.normalizeStyle(Vue.unref(getStopStyle)(item.position)),
            onMousedown: Vue.withModifiers(($event) => Vue.unref(onSliderMarkerDown)(item.position), ["stop"])
          }, null, 8, [
            "mark",
            "style",
            "onMousedown"
          ]);
        }), 128))], 2)], 64)) : Vue.createCommentVNode("v-if", true)
      ], 38), renderInput.value ? (Vue.openBlock(), Vue.createBlock(Vue.unref(index$3.ElInputNumber), {
        key: 0,
        ref: "input",
        "model-value": Vue.unref(firstValue),
        class: Vue.normalizeClass(Vue.unref(ns).e("input")),
        step: sliderInputStep.value,
        disabled: Vue.unref(sliderDisabled),
        controls: _ctx.showInputControls,
        min: _ctx.min,
        max: _ctx.max,
        precision: precision.value,
        size: sliderInputSize.value,
        "onUpdate:modelValue": Vue.unref(setFirstValue),
        onChange: Vue.unref(emitChange)
      }, null, 8, [
        "model-value",
        "class",
        "step",
        "disabled",
        "controls",
        "min",
        "max",
        "precision",
        "size",
        "onUpdate:modelValue",
        "onChange"
      ])) : Vue.createCommentVNode("v-if", true)], 10, _hoisted_1);
    };
  }
});
exports.default = slider_vue_vue_type_script_setup_true_lang_default;
