/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, toRefs, computed, watch, createVNode } from 'vue';
import dayjs from 'dayjs';
import { c as customParseFormat } from '../_chunks/dep-e86e320e.js';
import { TimeIcon } from '@ldesign/icons-vue-next';
import { SelectInput } from '../select-input/index.js';
import { validateInputValue, formatInputValue } from '../_common/js/time-picker/utils.js';
import useVModel from '../hooks/useVModel.js';
import { useFormDisabled } from '../form/hooks.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import { useGlobalIcon } from '../hooks/useGlobalIcon.js';
import props from './props.js';
import _TimePickerPanel from './panel/time-picker-panel.js';
import { useConfig } from '../config-provider/useConfig.js';
import '../_chunks/dep-e041f5b0.js';
import '../utils/withInstall.js';
import '../select-input/select-input.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import 'lodash/isString';
import 'lodash/isFunction';
import 'lodash/isObject';
import '../utils/dom.js';
import 'lodash/isArray';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../_common/js/utils/set-style.js';
import '../popup/props.js';
import '../popup/container.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/isUndefined';
import '../hooks/useResizeObserver.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import 'lodash/pick';
import '../input/index.js';
import '../input/input.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../hooks/tnode.js';
import '../input/props.js';
import '../input/useInput.js';
import '../form/const.js';
import '../input/useLengthLimit.js';
import 'lodash/isNumber';
import '../_common/js/log/log.js';
import '../_common/js/utils/helper.js';
import 'lodash/isNull';
import '../input/useInputEventHandler.js';
import '../input/useInputWidth.js';
import '../input/input-group.js';
import '../input/input-group-props.js';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../loading/loading.js';
import '../hooks/useTeleport.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../hooks/useDefaultValue.js';
import '../select-input/useMultiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../tag-input/props.js';
import '../tag-input/hooks/useTagScroll.js';
import '../tag-input/useTagList.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../select-input/useOverlayInnerStyle.js';
import '../_common/js/time-picker/const.js';
import '../button/button.js';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useKeepAnimation.js';
import '../button/props.js';
import './panel/props.js';
import 'lodash/isBoolean';
import './panel/single-panel.js';
import 'lodash/debounce';
import 'lodash/range';
import 'lodash/padStart';

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(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.extend(customParseFormat);
var _TimePicker = defineComponent({
  name: "TTimePicker",
  props: _objectSpread({}, props),
  setup: function setup(props2) {
    var currentValue = ref("");
    var isShowPanel = ref(false);
    var _useConfig = useConfig("timePicker"),
      globalConfig = _useConfig.globalConfig;
    var _useGlobalIcon = useGlobalIcon({
        TimeIcon: TimeIcon
      }),
      TimeIcon$1 = _useGlobalIcon.TimeIcon;
    var _toRefs = toRefs(props2),
      value = _toRefs.value,
      modelValue = _toRefs.modelValue;
    var _useVModel = useVModel(value, modelValue, props2.defaultValue, props2.onChange),
      _useVModel2 = _slicedToArray(_useVModel, 2),
      innerValue = _useVModel2[0],
      setInnerValue = _useVModel2[1];
    var disabled = useFormDisabled();
    var _toRefs2 = toRefs(props2),
      allowInput = _toRefs2.allowInput,
      format = _toRefs2.format;
    var _useConfig2 = useConfig("classPrefix"),
      classPrefix = _useConfig2.classPrefix;
    var componentName = usePrefixClass("time-picker");
    var inputClasses = computed(function () {
      return ["".concat(componentName.value, "__group"), _defineProperty({}, "".concat(classPrefix.value, "-is-focused"), isShowPanel.value)];
    });
    var handleShowPopup = function handleShowPopup(visible, context) {
      var _props2$onOpen, _props2$onClose;
      isShowPanel.value = visible;
      visible ? (_props2$onOpen = props2.onOpen) === null || _props2$onOpen === void 0 ? void 0 : _props2$onOpen.call(props2, context) : (_props2$onClose = props2.onClose) === null || _props2$onClose === void 0 ? void 0 : _props2$onClose.call(props2, 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 (allowInput.value) {
        var isValidTime = validateInputValue(currentValue.value, format.value);
        if (isValidTime) setInnerValue(formatInputValue(currentValue.value, format.value));
      }
      (_props2$onBlur = props2.onBlur) === null || _props2$onBlur === void 0 ? void 0 : _props2$onBlur.call(props2, {
        value: String(value2),
        e: e
      });
    };
    var handleClickConfirm = function handleClickConfirm() {
      var isValidTime = validateInputValue(currentValue.value, format.value);
      if (isValidTime) setInnerValue(currentValue.value);
      isShowPanel.value = false;
    };
    var handlePanelChange = function handlePanelChange(v, e) {
      var _props2$onPick;
      currentValue.value = v;
      (_props2$onPick = props2.onPick) === null || _props2$onPick === void 0 ? void 0 : _props2$onPick.call(props2, v, {
        e: e
      });
    };
    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 function () {
      var _innerValue$value2, _innerValue$value3;
      return createVNode("div", {
        "class": componentName.value
      }, [createVNode(SelectInput, {
        "onFocus": props2.onFocus,
        "onClear": handleClear,
        "disabled": disabled.value,
        "clearable": props2.clearable,
        "allowInput": allowInput.value,
        "className": inputClasses.value,
        "suffixIcon": function suffixIcon() {
          return createVNode(TimeIcon$1, null, null);
        },
        "popupVisible": isShowPanel.value,
        "onInputChange": handleInputChange,
        "onBlur": handleInputBlur,
        "onPopupVisibleChange": handleShowPopup,
        "placeholder": !innerValue.value ? props2.placeholder || globalConfig.value.placeholder : void 0,
        "value": isShowPanel.value ? currentValue.value : (_innerValue$value2 = innerValue.value) !== null && _innerValue$value2 !== void 0 ? _innerValue$value2 : void 0,
        "inputValue": isShowPanel.value ? currentValue.value : (_innerValue$value3 = innerValue.value) !== null && _innerValue$value3 !== void 0 ? _innerValue$value3 : void 0,
        "inputProps": props2.inputProps,
        "popupProps": _objectSpread({
          overlayInnerStyle: {
            width: "auto",
            padding: 0
          }
        }, props2.popupProps),
        "status": props2.status,
        "tips": props2.tips,
        "panel": function panel() {
          return createVNode(_TimePickerPanel, {
            "steps": props2.steps,
            "format": format.value,
            "value": currentValue.value,
            "isFooterDisplay": true,
            "isShowPanel": isShowPanel.value,
            "disableTime": props2.disableTime,
            "onChange": handlePanelChange,
            "hideDisabledTime": props2.hideDisabledTime,
            "handleConfirmClick": handleClickConfirm
          }, null);
        }
      }, null)]);
    };
  }
});

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