"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

var _react = _interopRequireWildcard(require("react"));

var _configProvider = require("../config-provider");

var _datePickerView = _interopRequireDefault(require("../date-picker-view"));

var _Container = _interopRequireDefault(require("../picker/Container"));

var DatePicker = function DatePicker(props) {
  var _locale$DatePicker, _locale$DatePicker2;

  var className = props.className,
      style = props.style,
      title = props.title,
      confirmText = props.confirmText,
      cancelText = props.cancelText,
      mountContainer = props.mountContainer,
      _props$maskClosable = props.maskClosable,
      maskClosable = _props$maskClosable === void 0 ? true : _props$maskClosable,
      safeArea = props.safeArea,
      onConfirm = props.onConfirm,
      onCancel = props.onCancel,
      onChange = props.onChange,
      afterOpen = props.afterOpen,
      afterClose = props.afterClose,
      visible = props.visible,
      rest = (0, _objectWithoutProperties2.default)(props, ["className", "style", "title", "confirmText", "cancelText", "mountContainer", "maskClosable", "safeArea", "onConfirm", "onCancel", "onChange", "afterOpen", "afterClose", "visible"]);

  var datePickerViewRef = _react.default.useRef(null);

  var handleChange = function handleChange(date, items, level) {
    visible && (onChange === null || onChange === void 0 ? void 0 : onChange(date, items, level));
  };

  var handleConfirm = function handleConfirm() {
    var _datePickerViewRef$cu, _datePickerViewRef$cu2;

    onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm((_datePickerViewRef$cu = datePickerViewRef.current) === null || _datePickerViewRef$cu === void 0 ? void 0 : _datePickerViewRef$cu.value, (_datePickerViewRef$cu2 = datePickerViewRef.current) === null || _datePickerViewRef$cu2 === void 0 ? void 0 : _datePickerViewRef$cu2.items);
  };

  var handleCancel = function handleCancel() {
    var _datePickerViewRef$cu3, _datePickerViewRef$cu4;

    (_datePickerViewRef$cu3 = datePickerViewRef.current) === null || _datePickerViewRef$cu3 === void 0 ? void 0 : (_datePickerViewRef$cu4 = _datePickerViewRef$cu3.reset) === null || _datePickerViewRef$cu4 === void 0 ? void 0 : _datePickerViewRef$cu4.call(_datePickerViewRef$cu3);
    onCancel === null || onCancel === void 0 ? void 0 : onCancel();
  };

  var _useContext = (0, _react.useContext)(_configProvider.ConfigContext),
      locale = _useContext.locale;

  return /*#__PURE__*/_react.default.createElement(_Container.default, {
    className: className,
    style: style,
    visible: visible,
    title: title,
    confirmText: confirmText || (locale === null || locale === void 0 ? void 0 : (_locale$DatePicker = locale.DatePicker) === null || _locale$DatePicker === void 0 ? void 0 : _locale$DatePicker.confirmText),
    cancelText: cancelText || (locale === null || locale === void 0 ? void 0 : (_locale$DatePicker2 = locale.DatePicker) === null || _locale$DatePicker2 === void 0 ? void 0 : _locale$DatePicker2.cancelText),
    maskClosable: maskClosable,
    mountContainer: mountContainer,
    safeArea: safeArea,
    onConfirm: handleConfirm,
    onCancel: handleCancel,
    onClose: handleCancel,
    afterOpen: afterOpen,
    afterClose: afterClose
  }, /*#__PURE__*/_react.default.createElement(_datePickerView.default, (0, _extends2.default)({}, rest, {
    ref: datePickerViewRef,
    value: props.value,
    onChange: handleChange
  })));
};

var _default = DatePicker;
exports.default = _default;