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

'use strict';

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

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var dayjs = require('dayjs');
var customParseFormat = require('../_chunks/dep-b7fa06da.js');
var iconsVueNext = require('@ldesign/icons-vue-next');
var rangeInput_index = require('../range-input/index.js');
var _common_js_timePicker_const = require('../_common/js/time-picker/const.js');
var _common_js_timePicker_utils = require('../_common/js/time-picker/utils.js');
var hooks_useVModel = require('../hooks/useVModel.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var form_hooks = require('../form/hooks.js');
var timePicker_timeRangePickerProps = require('./time-range-picker-props.js');
var timePicker_panel_timePickerPanel = require('./panel/time-picker-panel.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
require('../_chunks/dep-f4db2590.js');
require('../utils/withInstall.js');
require('../range-input/range-input.js');
require('lodash/isArray');
require('../input/index.js');
require('../input/input.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('lodash/isUndefined');
require('../hooks/tnode.js');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isString');
require('lodash/isObject');
require('../input/props.js');
require('../input/useInput.js');
require('../form/const.js');
require('../input/useLengthLimit.js');
require('lodash/isNumber');
require('../_common/js/log/log.js');
require('../_common/js/utils/helper.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/isNull');
require('../input/useInputEventHandler.js');
require('../input/useInputWidth.js');
require('lodash/cloneDeep');
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('../input/input-group.js');
require('../input/input-group-props.js');
require('../range-input/props.js');
require('../range-input/range-input-popup.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../utils/dom.js');
require('../utils/easing.js');
require('../_common/js/utils/set-style.js');
require('../popup/props.js');
require('../popup/container.js');
require('../hooks/useResizeObserver.js');
require('../select-input/useOverlayInnerStyle.js');
require('../range-input/range-input-popup-props.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('../loading/loading.js');
require('../hooks/useTeleport.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../hooks/useRipple.js');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.js');
require('../button/props.js');
require('./panel/props.js');
require('lodash/isBoolean');
require('./props.js');
require('./panel/single-panel.js');
require('lodash/debounce');
require('lodash/range');
require('lodash/padStart');

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

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

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; }
dayjs__default["default"].extend(customParseFormat.customParseFormat);
var _TimeRangePicker = vue.defineComponent({
  name: "TTimeRangePicker",
  props: _objectSpread(_objectSpread({}, timePicker_timeRangePickerProps["default"]), {}, {
    rangeInputProps: Object,
    popupProps: Object
  }),
  setup: function setup(props2) {
    var componentName = hooks_useConfig.usePrefixClass("time-range-picker");
    var _useConfig = configProvider_useConfig.useConfig("timePicker"),
      globalConfig = _useConfig.globalConfig;
    var _useConfig2 = configProvider_useConfig.useConfig("classPrefix"),
      classPrefix = _useConfig2.classPrefix;
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        TimeIcon: iconsVueNext.TimeIcon
      }),
      TimeIcon = _useGlobalIcon.TimeIcon;
    var disabled = form_hooks.useFormDisabled();
    var currentPanelIdx = vue.ref(void 0);
    var currentValue = vue.ref(_common_js_timePicker_const.TIME_PICKER_EMPTY);
    var isShowPanel = vue.ref(false);
    var inputClasses = vue.computed(function () {
      return ["".concat(componentName.value, "__group"), _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-is-focused"), isShowPanel.value)];
    });
    var _toRefs = vue.toRefs(props2),
      value = _toRefs.value,
      modelValue = _toRefs.modelValue,
      allowInput = _toRefs.allowInput,
      format = _toRefs.format;
    var _useVModel = hooks_useVModel["default"](value, modelValue, props2.defaultValue, props2.onChange),
      _useVModel2 = _slicedToArray__default["default"](_useVModel, 2),
      innerValue = _useVModel2[0],
      setInnerValue = _useVModel2[1];
    var handleShowPopup = function handleShowPopup(visible, context) {
      if (context.trigger === "trigger-element-click") {
        isShowPanel.value = true;
        return;
      }
      isShowPanel.value = visible;
    };
    var handleClear = function handleClear(context) {
      var e = context.e;
      e.stopPropagation();
      currentValue.value = _common_js_timePicker_const.TIME_PICKER_EMPTY;
      setInnerValue(null);
    };
    var handleClick = function handleClick(_ref2) {
      var position = _ref2.position;
      currentPanelIdx.value = position === "first" ? 0 : 1;
    };
    var handleTimeChange = function handleTimeChange(newValue, e) {
      var _currentValue$value$, _currentValue$value$2;
      if (currentPanelIdx.value === 0) currentValue.value = [newValue, (_currentValue$value$ = currentValue.value[1]) !== null && _currentValue$value$ !== void 0 ? _currentValue$value$ : newValue];else currentValue.value = [(_currentValue$value$2 = currentValue.value[0]) !== null && _currentValue$value$2 !== void 0 ? _currentValue$value$2 : newValue, newValue];
      handleOnPick(newValue, e);
    };
    var handleInputBlur = function handleInputBlur(value2, _ref3) {
      var _props2$onBlur;
      var e = _ref3.e;
      if (allowInput.value) {
        var isValidTime = _common_js_timePicker_utils.validateInputValue(currentValue.value[currentPanelIdx.value], format.value);
        if (isValidTime) {
          var _currentValue$value$3, _currentValue$value$4;
          var formattedVal = _common_js_timePicker_utils.formatInputValue(currentValue.value[currentPanelIdx.value], format.value);
          currentPanelIdx.value === 0 ? currentValue.value = [formattedVal, (_currentValue$value$3 = currentValue.value[1]) !== null && _currentValue$value$3 !== void 0 ? _currentValue$value$3 : formattedVal] : currentValue.value = [(_currentValue$value$4 = currentValue.value[0]) !== null && _currentValue$value$4 !== void 0 ? _currentValue$value$4 : formattedVal, formattedVal];
        }
      }
      (_props2$onBlur = props2.onBlur) === null || _props2$onBlur === void 0 ? void 0 : _props2$onBlur.call(props2, {
        value: value2,
        e: e
      });
    };
    var handleInputChange = function handleInputChange(inputVal, _ref4) {
      var _props2$onInput;
      var e = _ref4.e,
        position = _ref4.position;
      currentValue.value = inputVal;
      (_props2$onInput = props2.onInput) === null || _props2$onInput === void 0 ? void 0 : _props2$onInput.call(props2, {
        value: innerValue.value,
        e: e,
        position: position === "first" ? "start" : "end"
      });
    };
    var handleClickConfirm = function handleClickConfirm() {
      var isValidTime = !currentValue.value.find(function (v) {
        return !_common_js_timePicker_utils.validateInputValue(v, format.value);
      });
      if (isValidTime) setInnerValue(currentValue.value);
      isShowPanel.value = false;
    };
    var handleFocus = function handleFocus(value2, _ref5) {
      var _props2$onFocus;
      var e = _ref5.e,
        position = _ref5.position;
      (_props2$onFocus = props2.onFocus) === null || _props2$onFocus === void 0 ? void 0 : _props2$onFocus.call(props2, {
        value: value2,
        e: e,
        position: position === "first" ? "start" : "end"
      });
    };
    var handleOnPick = function handleOnPick(pickValue, e) {
      var _props2$onPick;
      var pickedRangeValue = [];
      var context;
      if (currentPanelIdx.value === 0) {
        var _currentValue$value$5;
        pickedRangeValue = [pickValue, (_currentValue$value$5 = currentValue.value[1]) !== null && _currentValue$value$5 !== void 0 ? _currentValue$value$5 : pickValue];
        context = {
          e: e,
          position: "start"
        };
      } else {
        var _currentValue$value$6;
        pickedRangeValue = [(_currentValue$value$6 = currentValue.value[0]) !== null && _currentValue$value$6 !== void 0 ? _currentValue$value$6 : pickValue, pickValue];
        context = {
          e: e,
          position: "end"
        };
      }
      (_props2$onPick = props2.onPick) === null || _props2$onPick === void 0 ? void 0 : _props2$onPick.call(props2, pickedRangeValue, context);
    };
    vue.watch(function () {
      return isShowPanel.value;
    }, function () {
      var _innerValue$value;
      currentValue.value = isShowPanel.value ? (_innerValue$value = innerValue.value) !== null && _innerValue$value !== void 0 ? _innerValue$value : _common_js_timePicker_const.TIME_PICKER_EMPTY : _common_js_timePicker_const.TIME_PICKER_EMPTY;
      if (!isShowPanel.value) currentPanelIdx.value = void 0;
    });
    return function () {
      var _innerValue$value2, _innerValue$value3;
      return vue.createVNode("div", {
        "class": componentName.value
      }, [vue.createVNode(rangeInput_index.RangeInputPopup, {
        "disabled": disabled.value,
        "popupVisible": isShowPanel.value,
        "popupProps": _objectSpread({
          overlayInnerStyle: {
            width: "auto",
            padding: 0
          },
          onVisibleChange: handleShowPopup
        }, props2.popupProps),
        "onInputChange": handleInputChange,
        "inputValue": isShowPanel.value ? currentValue.value : (_innerValue$value2 = innerValue.value) !== null && _innerValue$value2 !== void 0 ? _innerValue$value2 : _common_js_timePicker_const.TIME_PICKER_EMPTY,
        "rangeInputProps": _objectSpread({
          size: props2.size,
          clearable: props2.clearable,
          "class": inputClasses.value,
          value: isShowPanel.value ? currentValue.value : (_innerValue$value3 = innerValue.value) !== null && _innerValue$value3 !== void 0 ? _innerValue$value3 : void 0,
          placeholder: props2.placeholder || [globalConfig.value.placeholder, globalConfig.value.placeholder],
          suffixIcon: function suffixIcon() {
            return vue.createVNode(TimeIcon, null, null);
          },
          onClear: handleClear,
          onClick: handleClick,
          onFocus: handleFocus,
          onBlur: handleInputBlur,
          readonly: !allowInput.value,
          activeIndex: currentPanelIdx.value
        }, props2.rangeInputProps),
        "status": props2.status,
        "tips": props2.tips,
        "panel": function panel() {
          return vue.createVNode(timePicker_panel_timePickerPanel["default"], {
            "steps": props2.steps,
            "format": format.value,
            "isShowPanel": isShowPanel.value,
            "disableTime": props2.disableTime,
            "hideDisabledTime": props2.hideDisabledTime,
            "isFooterDisplay": true,
            "value": currentValue.value[currentPanelIdx.value || 0],
            "onChange": handleTimeChange,
            "onPick": handleOnPick,
            "handleConfirmClick": handleClickConfirm,
            "position": currentPanelIdx.value === 0 ? "start" : "end"
          }, null);
        }
      }, null)]);
    };
  }
});

exports["default"] = _TimeRangePicker;
//# sourceMappingURL=time-range-picker.js.map
