/**
 * ldesign v0.2.3
 * (c) 2022年9月24日 swimly
 * @license MIT
 */

import { defineComponent, ref, toRefs, computed, watch } from '@vue/composition-api';
import dayjs from 'dayjs';
import { c as customParseFormat, v as validateInputValue, f as formatInputValue } from '../../chunks/single-panel.js';
import { TimeIcon } from '@ldesign/icons-vue';
import TTimePickerPanel from './panel/time-picker-panel.js';
import { SelectInput } from '../select-input/index.js';
import useVModel from '../../hooks/use-vmodel.js';
import { usePrefixClass } from '../../hooks/use-config.js';
import { useGlobalIcon } from '../../hooks/use-global-icon.js';
import { TimePickerProps } from './props.js';
import { useConfig } from '../config-provider/useConfig.js';
import 'lodash/debounce';
import 'lodash/range';
import 'lodash/padStart';
import '../../chunks/_commonjsHelpers.js';
import '../../chunks/dayjs.min-be98bc0e.js';
import '../../chunks/_commonjsHelpers-8b4be15a.js';
import './panel/props.js';
import '../../chunks/index.js';
import '../../chunks/log.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import 'vue';
import '../../chunks/defineProperty-56324511.js';
import '../../chunks/set-style.js';
import '../../chunks/helper2.js';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../utils/render-node.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../../utils/mixins.js';
import '../../utils/with-install.js';
import '../loading/style';
import '../loading/type.js';
import '../loading/plugin.js';
import '../button/props.js';
import '../../utils/ripple.js';
import '../select-input/select-input.js';
import '../../chunks/helper.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../../utils/helper.js';
import '../popup/props.js';
import '../popup/container.js';
import '../../utils/map-props.js';
import '../popup/style';
import '../popup/type.js';
import '../select-input/props.js';
import '../select-input/hooks/use-single.js';
import 'lodash/isObject';
import 'lodash/pick';
import '../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../../hooks/render-lnode.js';
import '../../hooks/use-default-value.js';
import '../select-input/hooks/use-multiple.js';
import '../select-input/hooks/use-overlay-innerstyle.js';
import '../select-input/style';
import '../select-input/type.js';

dayjs.extend(customParseFormat);
var _TimePicker = defineComponent({
  name: "LTimePicker",
  components: {
    LTimePickerPanel: TTimePickerPanel,
    LSelectInput: SelectInput
  },
  props: { ...TimePickerProps
  },

  setup(props2, ctx) {
    const {
      classPrefix
    } = useConfig("classPrefix");
    const componentName = usePrefixClass("time-picker");
    const {
      TimeIcon: TimeIcon$1
    } = useGlobalIcon({
      TimeIcon: TimeIcon
    });
    const currentValue = ref("");
    const isShowPanel = ref(false);
    const {
      global
    } = useConfig("timePicker");
    const {
      value
    } = toRefs(props2);
    const [innerValue, setInnerValue] = useVModel(value, props2.defaultValue, props2.onChange, "change");
    const inputClasses = 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 = validateInputValue(currentValue.value, props2.format);

        if (isValidTime) {
          setInnerValue(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 = 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);
    };

    watch(() => isShowPanel.value, () => {
      currentValue.value = isShowPanel.value ? innerValue.value ?? "" : "";
    });
    return {
      handleClickConfirm,
      handlePanelChange,
      handleInputBlur,
      handleInputChange,
      handleClear,
      handleShowPopup,
      handleOnFocus,
      inputClasses,
      componentName,
      innerValue,
      isShowPanel,
      global,
      currentValue,
      TimeIcon: TimeIcon$1
    };
  },

  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,
                hideDisabledTime: this.hideDisabledTime,
                handleConfirmClick: this.handleClickConfirm,
                presets: this.presets
              }
            }
          }),
          popupProps: {
            overlayInnerStyle: {
              width: "auto"
            },
            onVisibleChange: this.handleShowPopup,
            ...this.popupProps
          }
        }
      }
    })]);
  }

});

export { _TimePicker as default };
//# sourceMappingURL=time-picker.js.map
