/**
 * ldesign v0.4.6
 * (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 VueCompositionAPI = require('@vue/composition-api');
var dayjs = require('dayjs');
var customParseFormat = require('../_chunks/dep-6e3fbdd7.js');
var iconsVue = require('@ldesign/icons-vue');
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 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-7c884501.js');
require('../utils/withInstall.js');
require('vue');
require('lodash/capitalize');
require('../range-input/range-input.js');
require('../input/index.js');
require('../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
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('../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('../hooks/tnode.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('../hooks/render-tnode.js');
require('lodash/isObject');
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('raf');
require('../utils/easing.js');
require('../_common/js/utils/set-style.js');
require('../popup/props.js');
require('../popup/container.js');
require('../popup/utils.js');
require('../popup/trigger.js');
require('../popup/plugin.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('lodash/mapKeys');
require('lodash/isEqual');
require('../loading/plugin.js');
require('../config.js');
require('../loading/loading.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../utils/ripple.js');
require('../button/props.js');
require('./panel/single-panel.js');
require('lodash/debounce');
require('lodash/range');
require('lodash/padStart');
require('./panel/props.js');
require('./props.js');

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 = VueCompositionAPI.defineComponent({
  name: "TTimeRangePicker",
  props: _objectSpread(_objectSpread({}, timePicker_timeRangePickerProps["default"]), {}, {
    rangeInputProps: Object,
    popupProps: Object
  }),
  setup: function setup(props2, ctx) {
    var componentName = hooks_useConfig.usePrefixClass("time-range-picker");
    var _useConfig = configProvider_useConfig.useConfig("timePicker"),
      global = _useConfig.global;
    var _useConfig2 = configProvider_useConfig.useConfig("classPrefix"),
      classPrefix = _useConfig2.classPrefix;
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        TimeIcon: iconsVue.TimeIcon
      }),
      TimeIcon = _useGlobalIcon.TimeIcon;
    var currentPanelIdx = VueCompositionAPI.ref(void 0);
    var currentValue = VueCompositionAPI.ref(_common_js_timePicker_const.TIME_PICKER_EMPTY);
    var isShowPanel = VueCompositionAPI.ref(false);
    var inputClasses = VueCompositionAPI.computed(function () {
      return ["".concat(componentName.value, "__group"), _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-is-focused"), isShowPanel.value)];
    });
    var _toRefs = VueCompositionAPI.toRefs(props2),
      value = _toRefs.value,
      format = _toRefs.format;
    var _useVModel = hooks_useVModel["default"](value, props2.defaultValue, props2.onChange, "change"),
      _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) {
      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];
    };
    var handleInputBlur = function handleInputBlur(value2, _ref3) {
      var _props2$onBlur;
      var e = _ref3.e;
      if (props2.allowInput) {
        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"
      });
      ctx.emit("input", {
        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"
      });
      ctx.emit("focus", {
        value: value2,
        e: e,
        position: position === "first" ? "start" : "end"
      });
    };
    var handleOnPick = function handleOnPick(pickValue, e) {
      var _props2$onPick;
      var pickedRangeValue = [];
      var context = {
        e: e
      };
      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 = {
          position: "start",
          e: e
        };
      } else {
        var _currentValue$value$6;
        pickedRangeValue = [(_currentValue$value$6 = currentValue.value[0]) !== null && _currentValue$value$6 !== void 0 ? _currentValue$value$6 : pickValue, pickValue];
        context = {
          position: "end",
          e: e
        };
      }
      (_props2$onPick = props2.onPick) === null || _props2$onPick === void 0 ? void 0 : _props2$onPick.call(props2, pickedRangeValue, context);
      ctx.emit("pick", pickedRangeValue, context);
    };
    VueCompositionAPI.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 {
      global: global,
      componentName: componentName,
      currentValue: currentValue,
      currentPanelIdx: currentPanelIdx,
      inputClasses: inputClasses,
      innerValue: innerValue,
      isShowPanel: isShowPanel,
      handleInputChange: handleInputChange,
      handleShowPopup: handleShowPopup,
      handleClear: handleClear,
      handleFocus: handleFocus,
      handleOnPick: handleOnPick,
      handleClickConfirm: handleClickConfirm,
      handleClick: handleClick,
      handleInputBlur: handleInputBlur,
      handleTimeChange: handleTimeChange,
      TimeIcon: TimeIcon
    };
  },
  render: function render() {
    var _this$innerValue,
      _this = this;
    var h = arguments[0];
    var TimeIcon = this.TimeIcon;
    return h("div", {
      "class": this.componentName
    }, [h(rangeInput_index.RangeInputPopup, {
      "props": _objectSpread({}, {
        onInputChange: this.handleInputChange,
        disabled: this.disabled,
        popupVisible: this.isShowPanel,
        inputValue: this.isShowPanel ? this.currentValue : (_this$innerValue = this.innerValue) !== null && _this$innerValue !== void 0 ? _this$innerValue : _common_js_timePicker_const.TIME_PICKER_EMPTY,
        popupProps: _objectSpread({
          overlayInnerStyle: {
            width: "auto",
            padding: 0
          },
          onVisibleChange: this.handleShowPopup
        }, this.popupProps),
        status: this.status,
        tips: this.tips,
        rangeInputProps: _objectSpread({
          size: this.size,
          clearable: this.clearable,
          "class": this.inputClasses,
          placeholder: this.placeholder || [this.global.placeholder, this.global.placeholder],
          suffixIcon: function suffixIcon() {
            return h(TimeIcon);
          },
          onClear: this.handleClear,
          onClick: this.handleClick,
          onFocus: this.handleFocus,
          onBlur: this.handleInputBlur,
          readonly: !this.allowInput,
          activeIndex: this.currentPanelIdx
        }, this.rangeInputProps),
        panel: function panel() {
          return h(timePicker_panel_timePickerPanel["default"], {
            "props": _objectSpread({}, {
              steps: _this.steps,
              format: _this.format,
              isShowPanel: _this.isShowPanel,
              disableTime: _this.disableTime,
              hideDisabledTime: _this.hideDisabledTime,
              isFooterDisplay: true,
              value: _this.currentValue[_this.currentPanelIdx || 0],
              onChange: _this.handleTimeChange,
              onPick: _this.handleOnPick,
              handleConfirmClick: _this.handleClickConfirm,
              position: _this.currentPanelIdx === 0 ? "start" : "end",
              activeIndex: _this.currentPanelIdx,
              presets: _this.presets
            })
          });
        }
      })
    })]);
  }
});

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