"use strict";

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

var _typeof = require("@babel/runtime/helpers/typeof");

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _Button = _interopRequireDefault(require("../../components/Button"));

var _Box = _interopRequireDefault(require("../../components/Box"));

var _Combine = _interopRequireDefault(require("../../components/Combine"));

var _useLocale = _interopRequireDefault(require("../../components/LocaleProvider/useLocale"));

var _zh_CN = _interopRequireDefault(require("./locale/zh_CN"));

var _style = require("./style");

var _this = void 0;

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var ShortcutWithoutMemo = function ShortcutWithoutMemo(_ref) {
  var _this2 = this;

  (0, _newArrowCheck2.default)(this, _this);
  var index = _ref.index,
      shortcut = _ref.shortcut,
      onShortcutClick = _ref.onShortcutClick,
      _locale = _ref.locale;
  var handleClick = (0, _react.useCallback)(function () {
    (0, _newArrowCheck2.default)(this, _this2);
    onShortcutClick(index);
  }.bind(this), [index, onShortcutClick]);
  var locale = (0, _useLocale.default)(_zh_CN.default, 'DatePicker', _locale);
  return /*#__PURE__*/_react.default.createElement("span", {
    className: _style.shortcutCls,
    onClick: handleClick
  }, shortcut.label ? shortcut.label : shortcut.locale ? locale[shortcut.locale] : 'shortcut');
}.bind(void 0);

var Shortcut = /*#__PURE__*/(0, _react.memo)(ShortcutWithoutMemo);

var Footer = function Footer(_ref2) {
  var _this3 = this;

  (0, _newArrowCheck2.default)(this, _this);
  var confirmAble = _ref2.confirmAble,
      onConfirm = _ref2.onConfirm,
      shortcuts = _ref2.shortcuts,
      onShortcut = _ref2.onShortcut,
      tip = _ref2.tip,
      _locale = _ref2.locale;
  if (shortcuts == null) shortcuts = [];
  var handleShortcutClick = (0, _react.useCallback)(function (i) {
    var _shortcuts;

    (0, _newArrowCheck2.default)(this, _this3);
    var shortcut = (_shortcuts = shortcuts) === null || _shortcuts === void 0 ? void 0 : _shortcuts[i];
    if (!shortcut) return;
    var d = shortcut.handle();
    onShortcut(d);
  }.bind(this), [onShortcut, shortcuts]);
  var handleConfirm = (0, _react.useCallback)(function () {
    (0, _newArrowCheck2.default)(this, _this3);
    return onConfirm();
  }.bind(this), [onConfirm]);
  var locale = (0, _useLocale.default)(_zh_CN.default, 'DatePicker', _locale);
  return /*#__PURE__*/_react.default.createElement(_Box.default, {
    className: _style.footerCls,
    container: true,
    justifyContent: "space-between",
    alignItems: "center"
  }, /*#__PURE__*/_react.default.createElement(_Combine.default, null, shortcuts.map(function (shortcut, i) {
    (0, _newArrowCheck2.default)(this, _this3);
    return /*#__PURE__*/_react.default.createElement(Shortcut, {
      index: i,
      key: i,
      shortcut: shortcut,
      onShortcutClick: handleShortcutClick
    });
  }.bind(this))), /*#__PURE__*/_react.default.createElement(_Combine.default, null, tip ? /*#__PURE__*/_react.default.createElement("span", {
    className: _style.tipCls
  }, tip) : null, /*#__PURE__*/_react.default.createElement(_Button.default, {
    styleType: "primary",
    disabled: !confirmAble,
    onClick: handleConfirm
  }, locale.confirm)));
}.bind(void 0);

Footer.propTypes = {
  mode: _propTypes.default.oneOf(['date', 'month']).isRequired,
  confirmAble: _propTypes.default.bool.isRequired,
  onConfirm: _propTypes.default.func.isRequired,
  shortcuts: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.shape({
    handle: _propTypes.default.func.isRequired,
    locale: _propTypes.default.any,
    label: _propTypes.default.node
  })), _propTypes.default.oneOf([null])]),
  onShortcut: _propTypes.default.func.isRequired,
  tip: _propTypes.default.node,
  locale: _propTypes.default.any
};

var _default = /*#__PURE__*/(0, _react.memo)(Footer);

exports.default = _default;