/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 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/dep-2af9ce5e.js';
import { TimeIcon } from '@ldesign/icons-vue';
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 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/dep-74554e14.js';
import '../../_chunks/dep-f38f4c93.js';
import '../../_chunks/dep-5210251b.js';
import './panel/props.js';
import '../../utils/with-install.js';
import 'vue';
import 'lodash';
import '../../config.js';
import '../select-input/select-input.js';
import '../../_chunks/dep-29915b8e.js';
import '../popup/index.js';
import '../../utils/map-props.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../../_chunks/dep-cf772670.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../_chunks/dep-70c789e5.js';
import '../../utils/easing.js';
import '../../utils/render-node.js';
import '../../utils/helper.js';
import 'lodash/camelCase';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../_chunks/dep-def4c2ce.js';
import '../../utils/mixins.js';
import '../popup/props.js';
import '../popup/container.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/dep-47d77fc8.js';
import '../../utils/event.js';
import '../input/props.js';
import '../input/group.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../../_chunks/dep-eb467ddf.js';
import '../loading/plugin.js';
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 '../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-input/hooks/use-hover.js';
import '../tag-input/hooks/use-drag-sorter.js';
import '../select-input/hooks/use-overlay-innerstyle.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) {
        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);
    };
    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);
    };
    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,
          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
