/**
 * ldesign v0.3.13
 * (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 vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
var isArray = require('lodash/isArray');
var input_index = require('../input/index.js');
var hooks_useVModel = require('../hooks/useVModel.js');
var form_hooks = require('../form/hooks.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/withInstall.js');
require('../input/input.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isUndefined');
require('../input/props.js');
require('../input/useInput.js');
require('../form/const.js');
require('../input/useLengthLimit.js');
require('lodash/isNumber');
require('lodash/isObject');
require('../_common/js/log/log.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/isString');
require('lodash/isNull');
require('../input/useInputEventHandler.js');
require('../input/useInputWidth.js');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('lodash/isFunction');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('../input/input-group.js');
require('../input/input-group-props.js');

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);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

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 (isArray__default["default"](value)) return value;
  return [value, value];
}
var _RangeInput = vue.defineComponent({
  name: "TRangeInput",
  props: rangeInput_props["default"],
  setup: function setup(props2, _ref) {
    var expose = _ref.expose;
    var _toRefs = vue.toRefs(props2),
      value = _toRefs.value,
      modelValue = _toRefs.modelValue;
    var _useCommonClassName = hooks_useConfig.useCommonClassName(),
      STATUS = _useCommonClassName.STATUS,
      SIZE = _useCommonClassName.SIZE;
    var classPrefix = hooks_useConfig.usePrefixClass();
    var disabled = form_hooks.useFormDisabled();
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("range-input");
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        CloseCircleFilledIcon: iconsVueNext.CloseCircleFilledIcon
      }),
      CloseCircleFilledIcon = _useGlobalIcon.CloseCircleFilledIcon;
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var focused = vue.ref(false);
    var isHover = vue.ref(false);
    var format = vue.computed(function () {
      return calcArrayValue(props2.format);
    });
    var inputProps = vue.computed(function () {
      return calcArrayValue(props2.inputProps);
    });
    var placeholder = vue.computed(function () {
      return calcArrayValue(props2.placeholder);
    });
    var _useVModel = hooks_useVModel["default"](value, modelValue, props2.defaultValue, props2.onChange),
      _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
      innerValue = _useVModel2[0],
      setInnerValue = _useVModel2[1];
    var isShowClearIcon = vue.computed(function () {
      var _props2$value;
      return (props2.clearable && ((_props2$value = props2.value) === null || _props2$value === void 0 ? void 0 : _props2$value.length) && !disabled.value || props2.showClearIconOnEmpty) && isHover.value;
    });
    var labelContent = renderTNodeJSX("label");
    var prefixIconContent = renderTNodeJSX("prefixIcon");
    var suffixContent = renderTNodeJSX("suffix");
    var suffixIconContent = renderTNodeJSX("suffixIcon");
    var tips = renderTNodeJSX("tips");
    var inputRefs = {
      firstInputRef: vue.ref(),
      secondInputRef: vue.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);
    }
    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);
    }
    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);
    }
    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
      });
    }
    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
      });
    }
    expose({
      firstInputElement: inputRefs.firstInputRef.value,
      secondInputElement: inputRefs.secondInputRef.value,
      focus: function focus(options) {
        var _inputRefs$value;
        var _ref2 = options || {},
          _ref2$position = _ref2.position,
          position = _ref2$position === void 0 ? "first" : _ref2$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 _ref3 = options || {},
          _ref3$position = _ref3.position,
          position = _ref3$position === void 0 ? "first" : _ref3$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 _ref4 = options || {},
          _ref4$position = _ref4.position,
          position = _ref4$position === void 0 ? "first" : _ref4$position;
        (_inputRefs$value3 = inputRefs["".concat(position, "InputRef")].value) === null || _inputRefs$value3 === void 0 ? void 0 : _inputRefs$value3.select();
      }
    });
    return function () {
      var _ref5, _innerValue$value, _innerValue$value6;
      return vue.createVNode("div", {
        "class": [COMPONENT_NAME.value, (_ref5 = {}, _defineProperty__default["default"](_ref5, SIZE.value[props2.size], props2.size !== "medium"), _defineProperty__default["default"](_ref5, STATUS.value.disabled, disabled.value), _defineProperty__default["default"](_ref5, STATUS.value.focused, focused.value), _defineProperty__default["default"](_ref5, STATUS.value.success, props2.status === "success"), _defineProperty__default["default"](_ref5, STATUS.value.warning, props2.status === "warning"), _defineProperty__default["default"](_ref5, STATUS.value.error, props2.status === "error"), _defineProperty__default["default"](_ref5, "".concat(COMPONENT_NAME.value, "--prefix"), prefixIconContent || labelContent), _defineProperty__default["default"](_ref5, "".concat(COMPONENT_NAME.value, "--suffix"), suffixContent || suffixIconContent), _ref5)],
        "onMouseenter": handleMouseEnter,
        "onMouseleave": handleMouseLeave
      }, [vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__inner")
      }, [prefixIconContent && vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__prefix")
      }, [prefixIconContent]), labelContent ? vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__prefix")
      }, [labelContent]) : null, vue.createVNode(input_index.Input, vue.mergeProps({
        "ref": inputRefs.firstInputRef,
        "class": "".concat(COMPONENT_NAME.value, "__inner-left"),
        "inputClass": _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-is-focused"), props2.activeIndex === 0),
        "placeholder": placeholder.value[0],
        "disabled": disabled.value,
        "readonly": props2.readonly,
        "format": format.value[0],
        "value": (_innerValue$value = innerValue.value) === null || _innerValue$value === void 0 ? void 0 : _innerValue$value[0],
        "onClick": function onClick(_ref7) {
          var _props2$onClick;
          var e = _ref7.e;
          return (_props2$onClick = props2.onClick) === null || _props2$onClick === void 0 ? void 0 : _props2$onClick.call(props2, {
            e: e,
            position: "first"
          });
        },
        "onClear": function onClear() {
          return setInnerValue([], {
            position: "first",
            trigger: "input"
          });
        },
        "onEnter": function onEnter(val, _ref8) {
          var _innerValue$value2;
          var e = _ref8.e;
          return handleEnter([val, (_innerValue$value2 = innerValue.value) === null || _innerValue$value2 === void 0 ? void 0 : _innerValue$value2[1]], {
            e: e,
            position: "first"
          });
        },
        "onFocus": function onFocus(val, _ref9) {
          var _innerValue$value3;
          var e = _ref9.e;
          return handleFocus([val, (_innerValue$value3 = innerValue.value) === null || _innerValue$value3 === void 0 ? void 0 : _innerValue$value3[1]], {
            e: e,
            position: "first"
          });
        },
        "onBlur": function onBlur(val, _ref10) {
          var _innerValue$value4;
          var e = _ref10.e;
          return handleBlur([val, (_innerValue$value4 = innerValue.value) === null || _innerValue$value4 === void 0 ? void 0 : _innerValue$value4[1]], {
            e: e,
            position: "first"
          });
        },
        "onChange": function onChange(val, _ref11) {
          var _innerValue$value5;
          var e = _ref11.e;
          return setInnerValue([val, (_innerValue$value5 = innerValue.value) === null || _innerValue$value5 === void 0 ? void 0 : _innerValue$value5[1]], {
            e: e,
            position: "first",
            trigger: "input"
          });
        }
      }, inputProps.value[0]), null), vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__inner-separator")
      }, [props2.separator]), vue.createVNode(input_index.Input, vue.mergeProps({
        "ref": inputRefs.secondInputRef,
        "class": "".concat(COMPONENT_NAME.value, "__inner-right"),
        "inputClass": _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-is-focused"), props2.activeIndex === 1),
        "placeholder": placeholder.value[1],
        "disabled": disabled.value,
        "readonly": props2.readonly,
        "format": format.value[1],
        "value": (_innerValue$value6 = innerValue.value) === null || _innerValue$value6 === void 0 ? void 0 : _innerValue$value6[1],
        "onClick": function onClick(_ref13) {
          var _props2$onClick2;
          var e = _ref13.e;
          return (_props2$onClick2 = props2.onClick) === null || _props2$onClick2 === void 0 ? void 0 : _props2$onClick2.call(props2, {
            e: e,
            position: "second"
          });
        },
        "onClear": function onClear() {
          return setInnerValue([], {
            position: "second",
            trigger: "input"
          });
        },
        "onEnter": function onEnter(val, _ref14) {
          var _innerValue$value7;
          var e = _ref14.e;
          return handleEnter([(_innerValue$value7 = innerValue.value) === null || _innerValue$value7 === void 0 ? void 0 : _innerValue$value7[0], val], {
            e: e,
            position: "second"
          });
        },
        "onFocus": function onFocus(val, _ref15) {
          var _innerValue$value8;
          var e = _ref15.e;
          return handleFocus([(_innerValue$value8 = innerValue.value) === null || _innerValue$value8 === void 0 ? void 0 : _innerValue$value8[0], val], {
            e: e,
            position: "second"
          });
        },
        "onBlur": function onBlur(val, _ref16) {
          var _innerValue$value9;
          var e = _ref16.e;
          return handleBlur([(_innerValue$value9 = innerValue.value) === null || _innerValue$value9 === void 0 ? void 0 : _innerValue$value9[0], val], {
            e: e,
            position: "second"
          });
        },
        "onChange": function onChange(val, _ref17) {
          var _innerValue$value10;
          var e = _ref17.e;
          return setInnerValue([(_innerValue$value10 = innerValue.value) === null || _innerValue$value10 === void 0 ? void 0 : _innerValue$value10[0], val], {
            e: e,
            position: "second",
            trigger: "input"
          });
        }
      }, inputProps.value[1]), null), suffixContent ? vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__suffix")
      }, [suffixContent]) : null, suffixIconContent && vue.createVNode("span", {
        "class": "".concat(COMPONENT_NAME.value, "__suffix ").concat(COMPONENT_NAME.value, "__suffix-icon")
      }, [isShowClearIcon.value ? vue.createVNode(CloseCircleFilledIcon, {
        "class": "".concat(COMPONENT_NAME.value, "__suffix-clear"),
        "onClick": handleClear
      }, null) : suffixIconContent])]), tips && vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__tips")
      }, [tips])]);
    };
  }
});

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