"use strict";

exports.__esModule = true;
exports.default = void 0;

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

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

var _ = require("../..");

var _dateUtils = require("../../utils/dateUtils");

var _moment = _interopRequireDefault(require("moment"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }

var DatePickerDay =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(DatePickerDay, _React$Component);

  function DatePickerDay() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;

    _this.handleClick = function (e) {
      var handleDayClick = _this.context.handleDayClick;
      var day = _this.props.day;
      return handleDayClick && handleDayClick(e, day);
    };

    return _this;
  }

  var _proto = DatePickerDay.prototype;

  _proto.render = function render() {
    var _this$props = this.props,
        day = _this$props.day,
        month = _this$props.month;
    var _this$context = this.context,
        selected = _this$context.selected,
        focus = _this$context.focus;
    var isOutsideMonth = month !== (0, _dateUtils.getMonth)(day);
    var isSelected = (0, _dateUtils.isSameDay)(day, selected);
    var isToday = (0, _dateUtils.isSameDay)(day, (0, _dateUtils.now)());
    var disabled = (0, _dateUtils.isDayDisabled)(day, this.props);
    var hasFocus = (0, _dateUtils.isSameDay)(day, focus);
    return _react.default.createElement(_.Button, {
      circle: true,
      size: 28,
      disabled: disabled,
      className: 'cui-datepicker__day' + ("" + (isSelected && " cui-datepicker__day--selected" || '')) + ("" + (hasFocus && " cui-datepicker__day--focus" || '')) + ("" + (isToday && " cui-datepicker__day--today" || '')) + ("" + (isOutsideMonth && " cui-datepicker__day--outside-month" || '')),
      onClick: this.handleClick,
      ariaLabel: "" + (0, _dateUtils.getDate)(day),
      "aria-selected": isSelected,
      tabIndex: -1
    }, (0, _dateUtils.getDate)(day));
  };

  return DatePickerDay;
}(_react.default.Component);

DatePickerDay.displayName = 'DatePickerDay';
DatePickerDay.contextTypes = {
  focus: _propTypes.default.instanceOf(_moment.default),
  handleDayClick: _propTypes.default.func,
  selected: _propTypes.default.instanceOf(_moment.default)
};
DatePickerDay.propTypes = {
  /** @prop Required day that the DatePickerDay displays */
  day: _propTypes.default.instanceOf(_moment.default).isRequired,

  /** @prop Required month that the DatePickerDay displays */
  month: _propTypes.default.number.isRequired
};
var _default = DatePickerDay;
exports.default = _default;