/**
 * ldesign v0.4.6
 * (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 } from '@vue/composition-api';
import dayjs from 'dayjs';
import { c as customParseFormat } from '../_chunks/dep-2de45821.js';
import { TimeIcon } from '@ldesign/icons-vue';
import { SelectInput } from '../select-input/index.js';
import { validateInputValue, formatInputValue } from '../_common/js/time-picker/utils.js';
import useVModel from '../hooks/useVModel.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import { useGlobalIcon } from '../hooks/useGlobalIcon.js';
import _TimePickerPanel from './panel/time-picker-panel.js';
import props from './props.js';
import { useConfig } from '../config-provider/useConfig.js';
import '../_chunks/dep-be599ec8.js';
import '../utils/withInstall.js';
import 'vue';
import 'lodash/capitalize';
import '../select-input/select-input.js';
import '../_chunks/dep-c89aafbb.js';
import '../popup/index.js';
import '../utils/map-props.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../popup/popup.js';
import '@babel/runtime/helpers/typeof';
import '@popperjs/core';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/helper.js';
import '../_common/js/utils/set-style.js';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-67ff4010.js';
import '../config-provider/type.js';
import '../utils/mixins.js';
import '../utils/event.js';
import '../popup/props.js';
import '../popup/container.js';
import 'lodash/isFunction';
import '../popup/utils.js';
import '../popup/trigger.js';
import '../popup/style';
import '../popup/type.js';
import '../popup/plugin.js';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import 'lodash/isObject';
import 'lodash/pick';
import '../input/index.js';
import '../input/input.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../_common/js/utils/helper.js';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import 'lodash/isArray';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import '../input/props.js';
import '../input/input-group.js';
import '../input/style';
import '../input/type.js';
import '../loading/index.js';
import '../loading/directive.js';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../loading/plugin.js';
import '../config.js';
import '../loading/loading.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../loading/style';
import '../loading/type.js';
import '../hooks/tnode.js';
import 'lodash/isEmpty';
import '../hooks/render-tnode.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/style';
import '../tag/type.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../tag-input/style';
import '../tag-input/type.js';
import '../tag-input/interface.js';
import '../select-input/useOverlayInnerStyle.js';
import '../select-input/style';
import '../select-input/type.js';
import '../_common/js/time-picker/const.js';
import '../button/button.js';
import '../utils/ripple.js';
import '../button/props.js';
import './panel/single-panel.js';
import 'lodash/debounce';
import 'lodash/range';
import 'lodash/padStart';
import './panel/props.js';

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, ctx) {
    var _useConfig = useConfig("classPrefix"),
      classPrefix = _useConfig.classPrefix;
    var componentName = usePrefixClass("time-picker");
    var _useGlobalIcon = useGlobalIcon({
        TimeIcon: TimeIcon
      }),
      TimeIcon$1 = _useGlobalIcon.TimeIcon;
    var currentValue = ref("");
    var isShowPanel = ref(false);
    var _useConfig2 = useConfig("timePicker"),
      global = _useConfig2.global;
    var _toRefs = toRefs(props2),
      value = _toRefs.value;
    var _useVModel = useVModel(value, props2.defaultValue, props2.onChange, "change"),
      _useVModel2 = _slicedToArray(_useVModel, 2),
      innerValue = _useVModel2[0],
      setInnerValue = _useVModel2[1];
    var inputClasses = computed(function () {
      return ["".concat(componentName.value, "__group"), _defineProperty({}, "".concat(classPrefix.value, "-is-focused"), isShowPanel.value)];
    });
    var handleShowPopup = function 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);
      }
    };
    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 (props2.allowInput) {
        var 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: e
      });
      ctx.emit("blur", {
        value: value2,
        e: e
      });
    };
    var handleClickConfirm = function handleClickConfirm() {
      var isValidTime = validateInputValue(currentValue.value, props2.format);
      if (isValidTime) setInnerValue(currentValue.value);
      isShowPanel.value = false;
    };
    var handlePanelChange = function handlePanelChange(v) {
      currentValue.value = v;
    };
    var handleOnFocus = function 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);
    };
    var handleOnPick = function handleOnPick(v, e) {
      var _props2$onPick;
      (_props2$onPick = props2.onPick) === null || _props2$onPick === void 0 ? void 0 : _props2$onPick.call(props2, v, {
        e: e
      });
      ctx.emit("pick", 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 {
      handleClickConfirm: handleClickConfirm,
      handlePanelChange: handlePanelChange,
      handleInputBlur: handleInputBlur,
      handleInputChange: handleInputChange,
      handleClear: handleClear,
      handleShowPopup: handleShowPopup,
      handleOnFocus: handleOnFocus,
      handleOnPick: handleOnPick,
      inputClasses: inputClasses,
      componentName: componentName,
      innerValue: innerValue,
      isShowPanel: isShowPanel,
      global: global,
      currentValue: currentValue,
      TimeIcon: TimeIcon$1
    };
  },
  render: function render() {
    var _this$innerValue,
      _this$innerValue2,
      _this = this;
    var h = arguments[0];
    var TimeIcon = this.TimeIcon;
    return h("div", {
      "class": this.componentName
    }, [h(SelectInput, {
      "props": _objectSpread({}, {
        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: function suffixIcon() {
          return h(TimeIcon);
        },
        popupVisible: this.isShowPanel,
        placeholder: !this.innerValue ? this.placeholder || this.global.placeholder : void 0,
        value: this.isShowPanel ? this.currentValue : (_this$innerValue = this.innerValue) !== null && _this$innerValue !== void 0 ? _this$innerValue : void 0,
        inputValue: this.isShowPanel ? this.currentValue : (_this$innerValue2 = this.innerValue) !== null && _this$innerValue2 !== void 0 ? _this$innerValue2 : void 0,
        inputProps: _objectSpread(_objectSpread({}, this.inputProps), {}, {
          size: this.size
        }),
        status: this.status,
        tips: this.tips,
        panel: function panel() {
          return h(_TimePickerPanel, {
            "props": _objectSpread({}, {
              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: _objectSpread({
          overlayInnerStyle: {
            width: "auto",
            padding: 0
          },
          onVisibleChange: this.handleShowPopup
        }, this.popupProps)
      })
    })]);
  }
});

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