/**
 * ldesign v0.2.22
 * (c) 2022/12/7 16:21 built by 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 { SelectInput } from '../select-input/index.js';
import useVModel from '../../hooks/useVModel.js';
import { usePrefixClass } from '../../hooks/useConfig.js';
import { useGlobalIcon } from '../../hooks/useGlobalIcon.js';
import TTimePickerPanel from './panel/time-picker-panel.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-0f6442fd.js';
import '../../chunks/_commonjsHelpers-fe796db6.js';
import './panel/props.js';
import '../../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../../config.js';
import '../select-input/select-input.js';
import '../../chunks/helper.js';
import '../popup/index.js';
import '../../utils/map-props.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../../chunks/set-style.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../chunks/index.js';
import '../../chunks/log.js';
import '../../utils/easing.js';
import '../../utils/render-node.js';
import 'lodash';
import '../../utils/helper.js';
import 'lodash/camelCase';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../../chunks/zh_CN.js';
import '../config-provider/type.js';
import '../../utils/mixins.js';
import '../popup/props.js';
import '../popup/container.js';
import '../popup/style/css.js';
import '../popup/type.js';
import '../select-input/props.js';
import '../select-input/hooks/use-single.js';
import 'lodash/isObject';
import 'lodash/pick';
import '../input/index.js';
import '../input/input.js';
import 'lodash/kebabCase';
import '../../chunks/helper2.js';
import '../../chunks/defineProperty-19da3d4c.js';
import '../../utils/event.js';
import '../input/props.js';
import '../input/group.js';
import '../input/style/css.js';
import '../input/type.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../loading/style/css.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../../hooks/lnode.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../../hooks/render-lnode.js';
import '../../hooks/useDefaultValue.js';
import '../select-input/hooks/use-multiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../tag-input/props.js';
import '../tag-input/hooks/use-tag-scroll.js';
import '../tag-input/hooks/use-tag-list.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/style/css.js';
import '../tag/type.js';
import '../tag-input/hooks/use-hover.js';
import '../tag-input/hooks/use-drag-sorter.js';
import '../tag-input/style/css.js';
import '../tag-input/type.js';
import '../select-input/hooks/use-overlay-innerstyle.js';
import '../select-input/style/css.js';
import '../select-input/type.js';
import '../button/button.js';
import '../../utils/ripple.js';
import '../button/props.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) {
        props2.onOpen?.(context);
        ctx.emit("open", context);
      } else {
        props2.onClose?.(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) => {
      let {
        e
      } = _ref;
      if (props2.allowInput) {
        const isValidTime = validateInputValue(currentValue.value, props2.format);
        if (isValidTime) setInnerValue(formatInputValue(currentValue.value, props2.format));
      }
      props2.onBlur?.({
        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 => {
      props2.onFocus?.(context);
      ctx.emit("focus", context);
    };
    const handleOnPick = v => {
      props2.onPick?.(v);
      ctx.emit("pick", v);
    };
    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: 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,
          status: this.status,
          tips: this.tips,
          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
          }
        }
      }
    })]);
  }
});

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