'use strict';

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

var vue = require('vue');
require('../../../../utils/index.js');
var iconsVue = require('@element-plus/icons-vue');
var numberInterval = require('./numberInterval.js');
var is = require('../../../../utils/src/is.js');

const _withScopeId = (n) => (vue.pushScopeId("data-v-4e6f4d6f"), n = n(), vue.popScopeId(), n);
const _hoisted_1 = { class: "gm-flex gm-h-full gm-w-full gm-items-center gm-justify-center gm-text-[14px]" };
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{
    name: "GmNumberInterval"
  },
  __name: "NumberInterval",
  props: numberInterval.numIntervalProps,
  emits: numberInterval.numIntervalEmits,
  setup(__props, { expose: __expose, emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const defaultModelVal = props.modelValue;
    const newModelValue = vue.computed(() => {
      if (Array.isArray(props.modelValue)) {
        return props.modelValue;
      } else if (is.isString(props.modelValue)) {
        try {
          if (props.modelSeparator) {
            const modelVal = props.modelValue;
            const modelValArr = modelVal.split(props.modelSeparator);
            return modelValArr;
          } else {
            throw new Error("modelSeparator \u503C\u4E0D\u80FD\u4E3A\u7A7A");
          }
        } catch (error) {
          console.error(error);
        }
      }
      return props.modelValue || [];
    });
    const minVal = vue.computed({
      get() {
        if (newModelValue.value[0] || is.isNumber(newModelValue.value[0])) {
          return Number(newModelValue.value[0]);
        }
        return void 0;
      },
      set(val) {
        const modelVal = [val, maxVal.value];
        if (is.isString(props.modelValue) && props.modelSeparator) {
          const newVal = modelVal.join(props.modelSeparator);
          emit("update:modelValue", newVal);
        } else {
          emit("update:modelValue", modelVal);
        }
      }
    });
    const maxVal = vue.computed({
      get() {
        if (newModelValue.value[1] || is.isNumber(newModelValue.value[1])) {
          return Number(newModelValue.value[1]);
        }
        return void 0;
      },
      set(val) {
        const modelVal = [minVal.value, val];
        if (is.isString(props.modelValue) && props.modelSeparator) {
          const newVal = modelVal.join(props.modelSeparator);
          emit("update:modelValue", newVal);
        } else {
          emit("update:modelValue", modelVal);
        }
      }
    });
    const showClear = vue.computed(() => {
      if (!props.clearable) {
        return false;
      } else {
        if (is.isString(props.modelValue) && props.modelValue) {
          return true;
        } else if (Array.isArray(props.modelValue) && props.modelValue.length) {
          return true;
        } else {
          return false;
        }
      }
    });
    const updateHandle = () => {
      const modelVal = [minVal.value, maxVal.value];
      if (is.isString(props.modelValue) && props.modelSeparator) {
        const newVal = modelVal.join(props.modelSeparator);
        emit("change", newVal);
      } else {
        emit("change", modelVal);
      }
    };
    const changeHandle = () => {
      updateHandle();
    };
    const clear = () => {
      emit("update:modelValue", defaultModelVal);
      emit("change", defaultModelVal);
    };
    __expose({
      clear
    });
    return (_ctx, _cache) => {
      const _component_gm_icon = vue.resolveComponent("gm-icon");
      const _component_gm_input_number = vue.resolveComponent("gm-input-number");
      const _component_gm_col = vue.resolveComponent("gm-col");
      const _component_gm_row = vue.resolveComponent("gm-row");
      return vue.openBlock(), vue.createElementBlock(
        "div",
        {
          class: vue.normalizeClass(["gm-number-interval gm-w-full", !_ctx.multiple ? "gm-number-interval-single" : ""])
        },
        [
          vue.createVNode(_component_gm_row, { gutter: 5 }, {
            default: vue.withCtx(() => [
              vue.createVNode(_component_gm_col, { span: 11 }, {
                default: vue.withCtx(() => [
                  vue.createVNode(_component_gm_input_number, {
                    modelValue: minVal.value,
                    "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => minVal.value = $event),
                    class: "gm-w-full",
                    "controls-position": "right",
                    controls: _ctx.controls,
                    min: _ctx.min,
                    max: _ctx.max,
                    placeholder: _ctx.minPlaceholder,
                    disabled: _ctx.disabled || _ctx.disabledMin,
                    onChange: changeHandle
                  }, {
                    "decrease-icon": vue.withCtx(() => [
                      vue.createVNode(_component_gm_icon, null, {
                        default: vue.withCtx(() => [
                          vue.createVNode(vue.unref(iconsVue.ArrowDown))
                        ]),
                        _: 1
                        /* STABLE */
                      })
                    ]),
                    "increase-icon": vue.withCtx(() => [
                      vue.createVNode(_component_gm_icon, null, {
                        default: vue.withCtx(() => [
                          vue.createVNode(vue.unref(iconsVue.ArrowUp))
                        ]),
                        _: 1
                        /* STABLE */
                      })
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["modelValue", "controls", "min", "max", "placeholder", "disabled"])
                ]),
                _: 1
                /* STABLE */
              }),
              vue.createVNode(_component_gm_col, { span: 2 }, {
                default: vue.withCtx(() => [
                  vue.createElementVNode("div", _hoisted_1, [
                    vue.createElementVNode(
                      "span",
                      null,
                      vue.toDisplayString(_ctx.separator),
                      1
                      /* TEXT */
                    )
                  ])
                ]),
                _: 1
                /* STABLE */
              }),
              vue.createVNode(_component_gm_col, {
                span: 11,
                class: "gm-relative"
              }, {
                default: vue.withCtx(() => [
                  vue.createVNode(_component_gm_input_number, {
                    modelValue: maxVal.value,
                    "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => maxVal.value = $event),
                    class: "gm-w-full",
                    "controls-position": "right",
                    controls: _ctx.controls,
                    min: _ctx.min,
                    max: _ctx.max,
                    placeholder: _ctx.maxPlaceholder,
                    disabled: _ctx.disabled || _ctx.disabledMax,
                    onChange: changeHandle
                  }, {
                    "decrease-icon": vue.withCtx(() => [
                      vue.createVNode(_component_gm_icon, null, {
                        default: vue.withCtx(() => [
                          vue.createVNode(vue.unref(iconsVue.ArrowDown))
                        ]),
                        _: 1
                        /* STABLE */
                      })
                    ]),
                    "increase-icon": vue.withCtx(() => [
                      vue.createVNode(_component_gm_icon, null, {
                        default: vue.withCtx(() => [
                          vue.createVNode(vue.unref(iconsVue.ArrowUp))
                        ]),
                        _: 1
                        /* STABLE */
                      })
                    ]),
                    _: 1
                    /* STABLE */
                  }, 8, ["modelValue", "controls", "min", "max", "placeholder", "disabled"]),
                  showClear.value ? (vue.openBlock(), vue.createElementBlock("div", {
                    key: 0,
                    class: "gm-number-interval-close gm-absolute gm-right-2 gm-top-[50%] gm-translate-y-[-50%] gm-cursor-pointer gm-items-center",
                    onClick: clear
                  }, [
                    vue.createVNode(_component_gm_icon, null, {
                      default: vue.withCtx(() => [
                        vue.createVNode(vue.unref(iconsVue.CircleClose))
                      ]),
                      _: 1
                      /* STABLE */
                    })
                  ])) : vue.createCommentVNode("v-if", true)
                ]),
                _: 1
                /* STABLE */
              })
            ]),
            _: 1
            /* STABLE */
          })
        ],
        2
        /* CLASS */
      );
    };
  }
});

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