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

import React from 'react';
import PropTypes from 'prop-types';
import { Button } from "../..";
import { getDate, getMonth, isDayDisabled, isSameDay, now } from "../../utils/dateUtils";
import moment from 'moment';

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 !== getMonth(day);
    var isSelected = isSameDay(day, selected);
    var isToday = isSameDay(day, now());
    var disabled = isDayDisabled(day, this.props);
    var hasFocus = isSameDay(day, focus);
    return React.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: "" + getDate(day),
      "aria-selected": isSelected,
      tabIndex: -1
    }, getDate(day));
  };

  return DatePickerDay;
}(React.Component);

DatePickerDay.displayName = 'DatePickerDay';
DatePickerDay.contextTypes = {
  focus: PropTypes.instanceOf(moment),
  handleDayClick: PropTypes.func,
  selected: PropTypes.instanceOf(moment)
};
DatePickerDay.propTypes = {
  day: PropTypes.instanceOf(moment).isRequired,
  month: PropTypes.number.isRequired
};
export default DatePickerDay;