/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { defineComponent, getCurrentInstance, toRefs, ref, computed } from '@vue/composition-api';
import { CloseCircleFilledIcon } from 'tdesign-icons-vue';
import { Input } from '../input/index.js';
import props from './props.js';
import useVModel from '../hooks/useVModel.js';
import { useGlobalIcon } from '../hooks/useGlobalIcon.js';
import { useCommonClassName, usePrefixClass } from '../hooks/useConfig.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/typeof';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../utils/helper.js';
import '../config-provider/config-receiver.js';
import 'vue';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import '../utils/mixins.js';
import '../utils/event.js';
import '../input/props.js';
import '../utils/render-tnode.js';
import '../input/input-group.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../input/type.js';
import '../config-provider/useConfig.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../hooks/render-tnode.js';
import 'lodash/isString';
import 'lodash/isObject';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

function calcArrayValue(value) {
  if (Array.isArray(value)) {
    return value;
  }

  return [value, value];
}

var _RangeInput = defineComponent({
  name: "TRangeInput",
  props: props,
  setup: function setup(props2) {
    var instance = getCurrentInstance();

    var _toRefs = toRefs(props2),
        value = _toRefs.value;

    var _useCommonClassName = useCommonClassName(),
        STATUS = _useCommonClassName.STATUS,
        SIZE = _useCommonClassName.SIZE;

    var classPrefix = usePrefixClass();

    var _useGlobalIcon = useGlobalIcon({
      CloseCircleFilledIcon: CloseCircleFilledIcon
    }),
        CloseCircleFilledIcon$1 = _useGlobalIcon.CloseCircleFilledIcon;

    var COMPONENT_NAME = usePrefixClass("range-input");
    var renderTNodeJSX = useTNodeJSX();
    var focused = ref(false);
    var isHover = ref(false);
    var calcFormat = computed(function () {
      return calcArrayValue(props2.format);
    });
    var calcInputProps = computed(function () {
      return calcArrayValue(props2.inputProps);
    });
    var calcPlaceholder = computed(function () {
      return calcArrayValue(props2.placeholder);
    });

    var _useVModel = useVModel(value, props2.defaultValue, props2.onChange, "change"),
        _useVModel2 = _slicedToArray(_useVModel, 2),
        innerValue = _useVModel2[0],
        setInnerValue = _useVModel2[1];

    var isShowClearIcon = computed(function () {
      var _props2$value;

      return (props2.clearable && ((_props2$value = props2.value) === null || _props2$value === void 0 ? void 0 : _props2$value.length) && !props2.disabled || props2.showClearIconOnEmpty) && isHover.value;
    });
    var inputRefs = {
      firstInputRef: ref(),
      secondInputRef: ref()
    };

    function handleClear(context) {
      var _props2$onClear;

      (_props2$onClear = props2.onClear) === null || _props2$onClear === void 0 ? void 0 : _props2$onClear.call(props2, context);
      setInnerValue(["", ""], _objectSpread(_objectSpread({}, context), {}, {
        trigger: "clear",
        position: "all"
      }));
    }

    function handleEnter(rangeValue, context) {
      var _props2$onEnter;

      (_props2$onEnter = props2.onEnter) === null || _props2$onEnter === void 0 ? void 0 : _props2$onEnter.call(props2, rangeValue, context);
      instance.emit("enter", rangeValue, context);
    }

    function handleFocus(rangeValue, context) {
      var _props2$onFocus;

      focused.value = true;
      (_props2$onFocus = props2.onFocus) === null || _props2$onFocus === void 0 ? void 0 : _props2$onFocus.call(props2, rangeValue, context);
      instance.emit("focus", rangeValue, context);
    }

    function handleBlur(rangeValue, context) {
      var _props2$onBlur;

      focused.value = false;
      (_props2$onBlur = props2.onBlur) === null || _props2$onBlur === void 0 ? void 0 : _props2$onBlur.call(props2, rangeValue, context);
      instance.emit("blur", rangeValue, context);
    }

    function handleMouseEnter(e) {
      var _props2$onMouseenter;

      isHover.value = true;
      props2 === null || props2 === void 0 ? void 0 : (_props2$onMouseenter = props2.onMouseenter) === null || _props2$onMouseenter === void 0 ? void 0 : _props2$onMouseenter.call(props2, {
        e: e
      });
      instance.emit("monseenter", {
        e: e
      });
    }

    function handleMouseLeave(e) {
      var _props2$onMouseleave;

      isHover.value = false;
      props2 === null || props2 === void 0 ? void 0 : (_props2$onMouseleave = props2.onMouseleave) === null || _props2$onMouseleave === void 0 ? void 0 : _props2$onMouseleave.call(props2, {
        e: e
      });
      instance.emit("monseleave", {
        e: e
      });
    }

    var exposeObj = {
      firstInputElement: inputRefs.firstInputRef.value,
      secondInputElement: inputRefs.secondInputRef.value,
      focus: function focus(options) {
        var _inputRefs$value;

        var _ref = options || {},
            _ref$position = _ref.position,
            position = _ref$position === void 0 ? "first" : _ref$position;

        (_inputRefs$value = inputRefs["".concat(position, "InputRef")].value) === null || _inputRefs$value === void 0 ? void 0 : _inputRefs$value.focus();
      },
      blur: function blur(options) {
        var _inputRefs$value2;

        var _ref2 = options || {},
            _ref2$position = _ref2.position,
            position = _ref2$position === void 0 ? "first" : _ref2$position;

        (_inputRefs$value2 = inputRefs["".concat(position, "InputRef")].value) === null || _inputRefs$value2 === void 0 ? void 0 : _inputRefs$value2.blur();
      },
      select: function select(options) {
        var _inputRefs$value3;

        var _ref3 = options || {},
            _ref3$position = _ref3.position,
            position = _ref3$position === void 0 ? "first" : _ref3$position;

        (_inputRefs$value3 = inputRefs["".concat(position, "InputRef")].value) === null || _inputRefs$value3 === void 0 ? void 0 : _inputRefs$value3.select();
      }
    };
    return _objectSpread(_objectSpread({}, exposeObj), {}, {
      COMPONENT_NAME: COMPONENT_NAME,
      SIZE: SIZE,
      STATUS: STATUS,
      focused: focused,
      classPrefix: classPrefix,
      inputRefs: inputRefs,
      calcInputProps: calcInputProps,
      calcFormat: calcFormat,
      calcPlaceholder: calcPlaceholder,
      innerValue: innerValue,
      isShowClearIcon: isShowClearIcon,
      handleMouseEnter: handleMouseEnter,
      handleMouseLeave: handleMouseLeave,
      handleEnter: handleEnter,
      handleFocus: handleFocus,
      handleBlur: handleBlur,
      setInnerValue: setInnerValue,
      renderTNodeJSX: renderTNodeJSX,
      handleClear: handleClear,
      CloseCircleFilledIcon: CloseCircleFilledIcon$1
    });
  },
  render: function render() {
    var _ref4,
        _this = this;

    var h = arguments[0];
    var COMPONENT_NAME = this.COMPONENT_NAME,
        SIZE = this.SIZE,
        STATUS = this.STATUS,
        focused = this.focused,
        handleMouseEnter = this.handleMouseEnter,
        handleMouseLeave = this.handleMouseLeave,
        handleEnter = this.handleEnter,
        handleFocus = this.handleFocus,
        handleBlur = this.handleBlur,
        setInnerValue = this.setInnerValue,
        renderTNodeJSX = this.renderTNodeJSX,
        handleClear = this.handleClear,
        classPrefix = this.classPrefix,
        inputRefs = this.inputRefs,
        calcInputProps = this.calcInputProps,
        calcFormat = this.calcFormat,
        calcPlaceholder = this.calcPlaceholder,
        innerValue = this.innerValue,
        isShowClearIcon = this.isShowClearIcon,
        CloseCircleFilledIcon = this.CloseCircleFilledIcon;
    var labelContent = renderTNodeJSX("label");
    var prefixIconContent = renderTNodeJSX("prefixIcon");
    var suffixContent = renderTNodeJSX("suffix");
    var suffixIconContent = renderTNodeJSX("suffixIcon");
    return h("div", {
      "class": [COMPONENT_NAME, (_ref4 = {}, _defineProperty(_ref4, SIZE[this.size], this.size !== "medium"), _defineProperty(_ref4, STATUS.disabled, this.disabled), _defineProperty(_ref4, STATUS.focused, focused), _ref4)],
      "on": {
        "mouseenter": handleMouseEnter,
        "mouseleave": handleMouseLeave
      }
    }, [h("div", {
      "class": "".concat(COMPONENT_NAME, "__inner")
    }, [prefixIconContent, labelContent ? h("div", {
      "class": "".concat(classPrefix, "-input__prefix")
    }, [labelContent]) : null, h(Input, {
      "ref": inputRefs.firstInputRef,
      "class": "".concat(COMPONENT_NAME, "__inner-left"),
      "attrs": {
        "inputClass": _defineProperty({}, "".concat(classPrefix, "-is-focused"), this.activeIndex === 0),
        "placeholder": calcPlaceholder[0],
        "disabled": this.disabled,
        "readonly": this.readonly,
        "format": calcFormat[0],
        "value": innerValue === null || innerValue === void 0 ? void 0 : innerValue[0]
      },
      "on": {
        "click": function click(_ref6) {
          var _this$onClick;

          var e = _ref6.e;
          return (_this$onClick = _this.onClick) === null || _this$onClick === void 0 ? void 0 : _this$onClick.call(_this, {
            e: e,
            position: "first"
          });
        },
        "clear": function clear() {
          return setInnerValue([], {
            position: "first",
            trigger: "input"
          });
        },
        "enter": function enter(val, _ref7) {
          var e = _ref7.e;
          return handleEnter([val, innerValue === null || innerValue === void 0 ? void 0 : innerValue[1]], {
            e: e,
            position: "first"
          });
        },
        "focus": function focus(val, _ref8) {
          var e = _ref8.e;
          return handleFocus([val, innerValue === null || innerValue === void 0 ? void 0 : innerValue[1]], {
            e: e,
            position: "first"
          });
        },
        "blur": function blur(val, _ref9) {
          var e = _ref9.e;
          return handleBlur([val, innerValue === null || innerValue === void 0 ? void 0 : innerValue[1]], {
            e: e,
            position: "first"
          });
        },
        "change": function change(val, _ref10) {
          var e = _ref10.e;
          return setInnerValue([val, innerValue === null || innerValue === void 0 ? void 0 : innerValue[1]], {
            e: e,
            position: "first",
            trigger: "input"
          });
        }
      },
      "props": _objectSpread({}, calcInputProps[0])
    }), h("div", {
      "class": "".concat(COMPONENT_NAME, "__inner-separator")
    }, [this.separator]), h(Input, {
      "ref": inputRefs.secondInputRef,
      "class": "".concat(COMPONENT_NAME, "__inner-right"),
      "attrs": {
        "inputClass": _defineProperty({}, "".concat(classPrefix, "-is-focused"), this.activeIndex === 1),
        "placeholder": calcPlaceholder[1],
        "disabled": this.disabled,
        "readonly": this.readonly,
        "format": calcFormat[1],
        "value": innerValue === null || innerValue === void 0 ? void 0 : innerValue[1]
      },
      "on": {
        "click": function click(_ref12) {
          var _this$onClick2;

          var e = _ref12.e;
          return (_this$onClick2 = _this.onClick) === null || _this$onClick2 === void 0 ? void 0 : _this$onClick2.call(_this, {
            e: e,
            position: "second"
          });
        },
        "clear": function clear() {
          return setInnerValue([], {
            position: "second",
            trigger: "input"
          });
        },
        "enter": function enter(val, _ref13) {
          var e = _ref13.e;
          return handleEnter([innerValue === null || innerValue === void 0 ? void 0 : innerValue[0], val], {
            e: e,
            position: "second"
          });
        },
        "focus": function focus(val, _ref14) {
          var e = _ref14.e;
          return handleFocus([innerValue === null || innerValue === void 0 ? void 0 : innerValue[0], val], {
            e: e,
            position: "second"
          });
        },
        "blur": function blur(val, _ref15) {
          var e = _ref15.e;
          return handleBlur([innerValue === null || innerValue === void 0 ? void 0 : innerValue[0], val], {
            e: e,
            position: "second"
          });
        },
        "change": function change(val, _ref16) {
          var e = _ref16.e;
          return setInnerValue([innerValue === null || innerValue === void 0 ? void 0 : innerValue[0], val], {
            e: e,
            position: "second",
            trigger: "input"
          });
        }
      },
      "props": _objectSpread({}, calcInputProps[1])
    }), suffixContent ? h("div", {
      "class": "".concat(COMPONENT_NAME, "__suffix")
    }, [suffixContent]) : null, suffixIconContent && h("span", {
      "class": "".concat(COMPONENT_NAME, "__suffix ").concat(COMPONENT_NAME, "__suffix-icon")
    }, [isShowClearIcon ? h(CloseCircleFilledIcon, {
      "class": "".concat(COMPONENT_NAME, "__suffix-clear"),
      "on": {
        "click": handleClear
      }
    }) : suffixIconContent])]), this.tips && h("div", {
      "class": "".concat(COMPONENT_NAME, "__tips")
    }, [this.tips])]);
  }
});

export { _RangeInput as default };
//# sourceMappingURL=range-input.js.map
