/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var input_index = require('../input/index.js');
var hooks_useVModel = require('../hooks/useVModel.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var rangeInput_props = require('./props.js');
require('../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('vue');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../input/input.js');
require('../_chunks/dep-c3e1ffac.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@babel/runtime/helpers/typeof');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../_common/js/utils/helper.js');
require('lodash/isString');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('../utils/helper.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/mixins.js');
require('../utils/event.js');
require('../utils/render-tnode.js');
require('../_common/js/log/log.js');
require('../input/props.js');
require('../input/input-group.js');
require('../config-provider/useConfig.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('../hooks/render-tnode.js');
require('lodash/isObject');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);

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__default["default"](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 = VueCompositionAPI.defineComponent({
  name: "TRangeInput",
  props: rangeInput_props["default"],
  setup: function setup(props2) {
    var instance = VueCompositionAPI.getCurrentInstance();
    var _toRefs = VueCompositionAPI.toRefs(props2),
      value = _toRefs.value;
    var _useCommonClassName = hooks_useConfig.useCommonClassName(),
      STATUS = _useCommonClassName.STATUS,
      SIZE = _useCommonClassName.SIZE;
    var classPrefix = hooks_useConfig.usePrefixClass();
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        CloseCircleFilledIcon: iconsVue.CloseCircleFilledIcon
      }),
      CloseCircleFilledIcon = _useGlobalIcon.CloseCircleFilledIcon;
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("range-input");
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var focused = VueCompositionAPI.ref(false);
    var isHover = VueCompositionAPI.ref(false);
    var calcFormat = VueCompositionAPI.computed(function () {
      return calcArrayValue(props2.format);
    });
    var calcInputProps = VueCompositionAPI.computed(function () {
      return calcArrayValue(props2.inputProps);
    });
    var calcPlaceholder = VueCompositionAPI.computed(function () {
      return calcArrayValue(props2.placeholder);
    });
    var _useVModel = hooks_useVModel["default"](value, props2.defaultValue, props2.onChange, "change"),
      _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
      innerValue = _useVModel2[0],
      setInnerValue = _useVModel2[1];
    var isShowClearIcon = VueCompositionAPI.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: VueCompositionAPI.ref(),
      secondInputRef: VueCompositionAPI.ref()
    };
    function handleClear(context) {
      var _props2$onClear;
      (_props2$onClear = props2.onClear) === null || _props2$onClear === void 0 ? void 0 : _props2$onClear.call(props2, context);
    }
    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
    });
  },
  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");
    var tips = renderTNodeJSX("tips");
    return h("div", {
      "class": [COMPONENT_NAME, (_ref4 = {}, _defineProperty__default["default"](_ref4, SIZE[this.size], this.size !== "medium"), _defineProperty__default["default"](_ref4, STATUS.disabled, this.disabled), _defineProperty__default["default"](_ref4, STATUS.focused, focused), _defineProperty__default["default"](_ref4, STATUS.success, this.status === "success"), _defineProperty__default["default"](_ref4, STATUS.warning, this.status === "warning"), _defineProperty__default["default"](_ref4, STATUS.error, this.status === "error"), _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_index.Input, {
      "ref": inputRefs.firstInputRef,
      "class": "".concat(COMPONENT_NAME, "__inner-left"),
      "attrs": {
        "inputClass": _defineProperty__default["default"]({}, "".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_index.Input, {
      "ref": inputRefs.secondInputRef,
      "class": "".concat(COMPONENT_NAME, "__inner-right"),
      "attrs": {
        "inputClass": _defineProperty__default["default"]({}, "".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])]), tips && h("div", {
      "class": "".concat(COMPONENT_NAME, "__tips")
    }, [tips])]);
  }
});

exports["default"] = _RangeInput;
//# sourceMappingURL=range-input.js.map
