/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

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_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_panel_timePickerPanel = require('./panel/time-picker-panel.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-c4f4ce86.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('./panel/props.js');
require('../../utils/with-install.js');
require('vue');
require('lodash');
require('../../config.js');
require('../select-input/select-input.js');
require('../../chunks/helper.js');
require('../popup/index.js');
require('../../utils/map-props.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../../chunks/set-style.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../utils/easing.js');
require('../../utils/render-node.js');
require('../../utils/helper.js');
require('lodash/camelCase');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/mixins.js');
require('../popup/props.js');
require('../popup/container.js');
require('../select-input/props.js');
require('../select-input/hooks/use-single.js');
require('lodash/isObject');
require('lodash/pick');
require('../input/index.js');
require('../input/input.js');
require('lodash/kebabCase');
require('../../chunks/helper2.js');
require('../../utils/event.js');
require('../input/props.js');
require('../input/group.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../../chunks/defineProperty-838e4192.js');
require('../loading/plugin.js');
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('../tag-input/index.js');
require('../tag-input/tag-input.js');
require('../tag-input/props.js');
require('../tag-input/hooks/use-tag-scroll.js');
require('../tag-input/hooks/use-tag-list.js');
require('../tag/index.js');
require('../tag/tag.js');
require('../tag/props.js');
require('../tag/check-tag.js');
require('../tag-input/hooks/use-hover.js');
require('../tag-input/hooks/use-drag-sorter.js');
require('../select-input/hooks/use-overlay-innerstyle.js');
require('../button/button.js');
require('../../utils/ripple.js');
require('../button/props.js');

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

var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);

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: {
    ...components_timePicker_props.TimePickerProps
  },
  setup(props2, ctx) {
    const {
      classPrefix
    } = components_configProvider_useConfig.useConfig("classPrefix");
    const componentName = hooks_useConfig.usePrefixClass("time-picker");
    const {
      TimeIcon
    } = hooks_useGlobalIcon.useGlobalIcon({
      TimeIcon: iconsVue.TimeIcon
    });
    const currentValue = VueCompositionAPI.ref("");
    const isShowPanel = VueCompositionAPI.ref(false);
    const {
      global
    } = components_configProvider_useConfig.useConfig("timePicker");
    const {
      value
    } = VueCompositionAPI.toRefs(props2);
    const [innerValue, setInnerValue] = hooks_useVmodel["default"](value, props2.defaultValue, props2.onChange, "change");
    const inputClasses = VueCompositionAPI.computed(() => [`${componentName.value}__group`, {
      [`${classPrefix.value}-is-focused`]: isShowPanel.value
    }]);
    const 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);
      }
    };
    const handleClear = context => {
      const {
        e
      } = context;
      e.stopPropagation();
      currentValue.value = null;
      setInnerValue(null);
    };
    const handleInputChange = value2 => {
      currentValue.value = value2;
    };
    const handleInputBlur = (value2, _ref) => {
      var _props2$onBlur;
      let {
        e
      } = _ref;
      if (props2.allowInput) {
        const 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
      });
      ctx.emit("blur", {
        value: value2,
        e
      });
    };
    const handleClickConfirm = () => {
      const isValidTime = components_timePicker_panel_singlePanel.validateInputValue(currentValue.value, props2.format);
      if (isValidTime) setInnerValue(currentValue.value);
      isShowPanel.value = false;
    };
    const handlePanelChange = v => {
      currentValue.value = v;
    };
    const 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);
    };
    const handleOnPick = v => {
      var _props2$onPick;
      (_props2$onPick = props2.onPick) === null || _props2$onPick === void 0 ? void 0 : _props2$onPick.call(props2, v);
      ctx.emit("pick", v);
    };
    VueCompositionAPI.watch(() => isShowPanel.value, () => {
      currentValue.value = isShowPanel.value ? innerValue.value ?? "" : "";
    });
    return {
      handleClickConfirm,
      handlePanelChange,
      handleInputBlur,
      handleInputChange,
      handleClear,
      handleShowPopup,
      handleOnFocus,
      handleOnPick,
      inputClasses,
      componentName,
      innerValue,
      isShowPanel,
      global,
      currentValue,
      TimeIcon
    };
  },
  render() {
    const h = arguments[0];
    const {
      TimeIcon
    } = this;
    return h("div", {
      "class": this.componentName
    }, [h("l-select-input", {
      "props": {
        ...{
          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: () => h(TimeIcon),
          popupVisible: this.isShowPanel,
          placeholder: !this.innerValue ? this.placeholder || this.global.placeholder : void 0,
          value: this.isShowPanel ? this.currentValue : this.innerValue ?? void 0,
          inputValue: this.isShowPanel ? this.currentValue : this.innerValue ?? void 0,
          inputProps: this.inputProps,
          panel: () => h("l-time-picker-panel", {
            "props": {
              ...{
                steps: this.steps,
                format: this.format,
                value: this.currentValue,
                isFooterDisplay: true,
                isShowPanel: this.isShowPanel,
                disableTime: this.disableTime,
                onChange: this.handlePanelChange,
                onPick: this.handleOnPick,
                hideDisabledTime: this.hideDisabledTime,
                handleConfirmClick: this.handleClickConfirm,
                presets: this.presets
              }
            }
          }),
          popupProps: {
            overlayInnerStyle: {
              width: "auto",
              padding: 0
            },
            onVisibleChange: this.handleShowPopup,
            ...this.popupProps
          }
        }
      }
    })]);
  }
});

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