"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _vue = require("vue");

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _generatePicker = _interopRequireDefault(require("../date-picker/generatePicker"));

var _props = require("../date-picker/generatePicker/props");

var _devWarning = _interopRequireDefault(require("../vc-util/devWarning"));

var _FormItemContext = require("../form/FormItemContext");

var _excluded = ["id"],
    _excluded2 = ["id"];
var timePickerProps = {
  format: String,
  showNow: {
    type: Boolean,
    default: undefined
  },
  showHour: {
    type: Boolean,
    default: undefined
  },
  showMinute: {
    type: Boolean,
    default: undefined
  },
  showSecond: {
    type: Boolean,
    default: undefined
  },
  use12Hours: {
    type: Boolean,
    default: undefined
  },
  hourStep: Number,
  minuteStep: Number,
  secondStep: Number,
  hideDisabledOptions: {
    type: Boolean,
    default: undefined
  },
  popupClassName: String
};

function createTimePicker(generateConfig) {
  var DatePicker = (0, _generatePicker.default)(generateConfig, (0, _objectSpread2.default)((0, _objectSpread2.default)({}, timePickerProps), {}, {
    order: {
      type: Boolean,
      default: true
    }
  }));
  var _ref = DatePicker,
      InternalTimePicker = _ref.TimePicker,
      InternalRangePicker = _ref.RangePicker;
  var TimePicker = (0, _vue.defineComponent)({
    name: 'ATimePicker',
    inheritAttrs: false,
    slot: ['addon', 'renderExtraFooter', 'suffixIcon', 'clearIcon'],
    emits: ['change', 'openChange', 'focus', 'blur', 'ok', 'update:value', 'update:open'],
    setup: function setup(props, _ref2) {
      var slots = _ref2.slots,
          expose = _ref2.expose,
          emit = _ref2.emit,
          attrs = _ref2.attrs;
      var formItemContext = (0, _FormItemContext.useInjectFormItemContext)();
      (0, _devWarning.default)(!(slots.addon || props.addon), 'TimePicker', '`addon` is deprecated. Please use `v-slot:renderExtraFooter` instead.');
      var pickerRef = (0, _vue.ref)();
      expose({
        focus: function focus() {
          var _pickerRef$value;

          (_pickerRef$value = pickerRef.value) === null || _pickerRef$value === void 0 ? void 0 : _pickerRef$value.focus();
        },
        blur: function blur() {
          var _pickerRef$value2;

          (_pickerRef$value2 = pickerRef.value) === null || _pickerRef$value2 === void 0 ? void 0 : _pickerRef$value2.blur();
        }
      });

      var onChange = function onChange(value, dateString) {
        emit('update:value', value);
        emit('change', value, dateString);
        formItemContext.onFieldChange();
      };

      var onOpenChange = function onOpenChange(open) {
        emit('update:open', open);
        emit('openChange', open);
      };

      var onFocus = function onFocus() {
        emit('focus');
      };

      var onBlur = function onBlur() {
        emit('blur');
        formItemContext.onFieldBlur();
      };

      var onOk = function onOk(value) {
        emit('ok', value);
      };

      return function () {
        var _props$id = props.id,
            id = _props$id === void 0 ? formItemContext.id.value : _props$id,
            restProps = (0, _objectWithoutProperties2.default)(props, _excluded);
        return (0, _vue.createVNode)(InternalTimePicker, (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, attrs), restProps), {}, {
          "id": id,
          "dropdownClassName": props.popupClassName,
          "mode": undefined,
          "ref": pickerRef,
          "renderExtraFooter": props.addon || slots.addon || props.renderExtraFooter || slots.renderExtraFooter,
          "onChange": onChange,
          "onOpenChange": onOpenChange,
          "onFocus": onFocus,
          "onBlur": onBlur,
          "onOk": onOk
        }), slots);
      };
    }
  });
  TimePicker.props = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _props.commonProps)()), (0, _props.datePickerProps)()), timePickerProps), {}, {
    addon: {
      type: Function
    }
  });
  var TimeRangePicker = (0, _vue.defineComponent)({
    name: 'ATimeRangePicker',
    inheritAttrs: false,
    slot: ['renderExtraFooter', 'suffixIcon', 'clearIcon'],
    emits: ['change', 'panelChange', 'ok', 'openChange', 'update:value', 'update:open', 'calendarChange', 'focus', 'blur'],
    setup: function setup(props, _ref3) {
      var slots = _ref3.slots,
          expose = _ref3.expose,
          emit = _ref3.emit,
          attrs = _ref3.attrs;
      var pickerRef = (0, _vue.ref)();
      var formItemContext = (0, _FormItemContext.useInjectFormItemContext)();
      expose({
        focus: function focus() {
          var _pickerRef$value3;

          (_pickerRef$value3 = pickerRef.value) === null || _pickerRef$value3 === void 0 ? void 0 : _pickerRef$value3.focus();
        },
        blur: function blur() {
          var _pickerRef$value4;

          (_pickerRef$value4 = pickerRef.value) === null || _pickerRef$value4 === void 0 ? void 0 : _pickerRef$value4.blur();
        }
      });

      var onChange = function onChange(values, dateStrings) {
        emit('update:value', values);
        emit('change', values, dateStrings);
        formItemContext.onFieldChange();
      };

      var onOpenChange = function onOpenChange(open) {
        emit('update:open', open);
        emit('openChange', open);
      };

      var onFocus = function onFocus() {
        emit('focus');
      };

      var onBlur = function onBlur() {
        emit('blur');
        formItemContext.onFieldBlur();
      };

      var onPanelChange = function onPanelChange(values, modes) {
        emit('panelChange', values, modes);
      };

      var onOk = function onOk(values) {
        emit('ok', values);
      };

      var onCalendarChange = function onCalendarChange(values, dateStrings, info) {
        emit('calendarChange', values, dateStrings, info);
      };

      return function () {
        var _props$id2 = props.id,
            id = _props$id2 === void 0 ? formItemContext.id.value : _props$id2,
            restProps = (0, _objectWithoutProperties2.default)(props, _excluded2);
        return (0, _vue.createVNode)(InternalRangePicker, (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, attrs), restProps), {}, {
          "id": id,
          "dropdownClassName": props.popupClassName,
          "picker": "time",
          "mode": undefined,
          "ref": pickerRef,
          "onChange": onChange,
          "onOpenChange": onOpenChange,
          "onFocus": onFocus,
          "onBlur": onBlur,
          "onPanelChange": onPanelChange,
          "onOk": onOk,
          "onCalendarChange": onCalendarChange
        }), slots);
      };
    }
  });
  TimeRangePicker.props = (0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)((0, _objectSpread2.default)({}, (0, _props.commonProps)()), (0, _props.rangePickerProps)()), timePickerProps), {}, {
    order: {
      type: Boolean,
      default: true
    }
  });
  return {
    TimePicker: TimePicker,
    TimeRangePicker: TimeRangePicker
  };
}

var _default = createTimePicker;
exports.default = _default;