/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @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 components_timePicker_panel_singlePanel = require('../../chunks/single-panel.js');
var iconsVue = require('@ldesign/icons-vue');
var components_timePicker_panel_timePickerPanel = require('./panel/time-picker-panel.js');
var components_selectInput_index = require('../select-input/index.js');
var hooks_useVmodel = require('../../hooks/use-vmodel.js');
var hooks_useConfig = require('../../hooks/use-config.js');
var hooks_useGlobalIcon = require('../../hooks/use-global-icon.js');
var components_timePicker_props = require('./props.js');
var components_configProvider_useConfig = require('../config-provider/useConfig.js');
require('lodash/debounce');
require('lodash/range');
require('lodash/padStart');
require('../../chunks/_commonjsHelpers.js');
require('../../chunks/dayjs.min-12eb376c.js');
require('@babel/runtime/helpers/typeof');
require('../../chunks/_commonjsHelpers-ea2bee21.js');
require('./panel/props.js');
require('../../chunks/log.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('vue');
require('../../chunks/defineProperty-28395935.js');
require('../../chunks/set-style.js');
require('../../chunks/helper2.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/render-node.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/mixins.js');
require('../../utils/with-install.js');
require('../loading/plugin.js');
require('../button/props.js');
require('../../utils/ripple.js');
require('../select-input/select-input.js');
require('../../chunks/helper.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../popup/props.js');
require('../popup/container.js');
require('../../utils/map-props.js');
require('../select-input/props.js');
require('../select-input/hooks/use-single.js');
require('lodash/isObject');
require('lodash/pick');
require('../../hooks/lnode.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('../../hooks/render-lnode.js');
require('../../hooks/use-default-value.js');
require('../select-input/hooks/use-multiple.js');
require('../select-input/hooks/use-overlay-innerstyle.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(components_timePicker_panel_singlePanel.customParseFormat);
var _TimePicker = VueCompositionAPI.defineComponent({
  name: "LTimePicker",
  components: {
    LTimePickerPanel: components_timePicker_panel_timePickerPanel["default"],
    LSelectInput: components_selectInput_index.SelectInput
  },
  props: _objectSpread({}, components_timePicker_props.TimePickerProps),
  setup: function setup(props2, ctx) {
    var _useConfig = components_configProvider_useConfig.useConfig("classPrefix"),
        classPrefix = _useConfig.classPrefix;

    var componentName = hooks_useConfig.usePrefixClass("time-picker");

    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
      TimeIcon: iconsVue.TimeIcon
    }),
        TimeIcon = _useGlobalIcon.TimeIcon;

    var currentValue = VueCompositionAPI.ref("");
    var isShowPanel = VueCompositionAPI.ref(false);

    var _useConfig2 = components_configProvider_useConfig.useConfig("timePicker"),
        global = _useConfig2.global;

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

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

    var inputClasses = VueCompositionAPI.computed(function () {
      return ["".concat(componentName.value, "__group"), _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-is-focused"), isShowPanel.value)];
    });

    var handleShowPopup = function handleShowPopup(visible, context) {
      isShowPanel.value = visible;

      if (visible) {
        var _props2$onOpen;

        (_props2$onOpen = props2.onOpen) === null || _props2$onOpen === void 0 ? void 0 : _props2$onOpen.call(props2, context);
        ctx.emit("open", context);
      } else {
        var _props2$onClose;

        (_props2$onClose = props2.onClose) === null || _props2$onClose === void 0 ? void 0 : _props2$onClose.call(props2, context);
        ctx.emit("close", context);
      }
    };

    var handleClear = function handleClear(context) {
      var e = context.e;
      e.stopPropagation();
      currentValue.value = null;
      setInnerValue(null);
    };

    var handleInputChange = function handleInputChange(value2) {
      currentValue.value = value2;
    };

    var handleInputBlur = function handleInputBlur(value2, _ref2) {
      var _props2$onBlur;

      var e = _ref2.e;

      if (props2.allowInput) {
        var isValidTime = components_timePicker_panel_singlePanel.validateInputValue(currentValue.value, props2.format);

        if (isValidTime) {
          setInnerValue(components_timePicker_panel_singlePanel.formatInputValue(currentValue.value, props2.format));
        }
      }

      (_props2$onBlur = props2.onBlur) === null || _props2$onBlur === void 0 ? void 0 : _props2$onBlur.call(props2, {
        value: value2,
        e: e
      });
      ctx.emit("blur", {
        value: value2,
        e: e
      });
    };

    var handleClickConfirm = function handleClickConfirm() {
      var isValidTime = components_timePicker_panel_singlePanel.validateInputValue(currentValue.value, props2.format);
      if (isValidTime) setInnerValue(currentValue.value);
      isShowPanel.value = false;
    };

    var handlePanelChange = function handlePanelChange(v) {
      currentValue.value = v;
    };

    var handleOnFocus = function handleOnFocus(context) {
      var _props2$onFocus;

      (_props2$onFocus = props2.onFocus) === null || _props2$onFocus === void 0 ? void 0 : _props2$onFocus.call(props2, context);
      ctx.emit("focus", 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 : "" : "";
    });
    return {
      handleClickConfirm: handleClickConfirm,
      handlePanelChange: handlePanelChange,
      handleInputBlur: handleInputBlur,
      handleInputChange: handleInputChange,
      handleClear: handleClear,
      handleShowPopup: handleShowPopup,
      handleOnFocus: handleOnFocus,
      inputClasses: inputClasses,
      componentName: componentName,
      innerValue: innerValue,
      isShowPanel: isShowPanel,
      global: global,
      currentValue: currentValue,
      TimeIcon: TimeIcon
    };
  },
  render: function render() {
    var _this$innerValue,
        _this$innerValue2,
        _this = this;

    var h = arguments[0];
    var TimeIcon = this.TimeIcon;
    return h("div", {
      "class": this.componentName
    }, [h("l-select-input", {
      "props": _objectSpread({}, {
        onFocus: this.handleOnFocus,
        onClear: this.handleClear,
        onBlur: this.handleInputBlur,
        onInputChange: this.handleInputChange,
        disabled: this.disabled,
        clearable: this.clearable,
        allowInput: this.allowInput,
        "class": this.inputClasses,
        suffixIcon: function suffixIcon() {
          return h(TimeIcon);
        },
        popupVisible: this.isShowPanel,
        placeholder: !this.innerValue ? this.placeholder || this.global.placeholder : void 0,
        value: this.isShowPanel ? this.currentValue : (_this$innerValue = this.innerValue) !== null && _this$innerValue !== void 0 ? _this$innerValue : void 0,
        inputValue: this.isShowPanel ? this.currentValue : (_this$innerValue2 = this.innerValue) !== null && _this$innerValue2 !== void 0 ? _this$innerValue2 : void 0,
        inputProps: this.inputProps,
        panel: function panel() {
          return h("l-time-picker-panel", {
            "props": _objectSpread({}, {
              steps: _this.steps,
              format: _this.format,
              value: _this.currentValue,
              isFooterDisplay: true,
              isShowPanel: _this.isShowPanel,
              disableTime: _this.disableTime,
              onChange: _this.handlePanelChange,
              hideDisabledTime: _this.hideDisabledTime,
              handleConfirmClick: _this.handleClickConfirm,
              presets: _this.presets
            })
          });
        },
        popupProps: _objectSpread({
          overlayInnerStyle: {
            width: "auto"
          },
          onVisibleChange: this.handleShowPopup
        }, this.popupProps)
      })
    })]);
  }
});

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