'use strict';

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

var vue = require('vue');
var rangeNumber = require('./rangeNumber.js');

const _withScopeId = (n) => (vue.pushScopeId("data-v-1ae16d96"), n = n(), vue.popScopeId(), n);
const _hoisted_1 = { class: "gm-flex" };
const _hoisted_2 = /* @__PURE__ */ _withScopeId(() => /* @__PURE__ */ vue.createElementVNode(
  "span",
  null,
  "~",
  -1
  /* HOISTED */
));
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "GmRangeNumber"
  },
  __name: "rangeNumber",
  props: rangeNumber.rangeNumberProp,
  emits: rangeNumber.rangeEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const formData = vue.ref({});
    const updateValue = (type) => {
      switch (type) {
        case "start":
          if (formData.value.startValue) {
            formData.value.startValue = Math.min(props.max || Number.MAX_VALUE, Math.max(props.min || Number.MIN_VALUE, formData.value.startValue));
          }
          break;
        case "end":
          if (formData.value.endValue) {
            formData.value.endValue = Math.min(props.max || Number.MAX_VALUE, Math.max(props.min || Number.MIN_VALUE, formData.value.endValue));
          }
      }
      emit("change", [formData.value.startValue, formData.value.endValue]);
      emit("update:value", [formData.value.startValue, formData.value.endValue]);
    };
    vue.watch(
      () => props.value,
      () => {
        if (Array.isArray(props.value)) {
          formData.value.startValue = props.value[0];
          formData.value.endValue = props.value[1];
        }
      },
      {
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      const _component_gm_input = vue.resolveComponent("gm-input");
      return vue.openBlock(), vue.createElementBlock("div", _hoisted_1, [
        vue.createVNode(_component_gm_input, {
          modelValue: formData.value.startValue,
          "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => formData.value.startValue = $event),
          type: "number",
          placeholder: props.startPlaceholder,
          onChange: _cache[1] || (_cache[1] = ($event) => updateValue("start"))
        }, null, 8, ["modelValue", "placeholder"]),
        _hoisted_2,
        vue.createVNode(_component_gm_input, {
          modelValue: formData.value.endValue,
          "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => formData.value.endValue = $event),
          type: "number",
          placeholder: props.endPlaceholder,
          onChange: _cache[3] || (_cache[3] = ($event) => updateValue("end"))
        }, null, 8, ["modelValue", "placeholder"])
      ]);
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=rangeNumber.vue2.js.map
