'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var styles = require('./styles.js');
var dateUtils = require('../../dateUtils.js');
var utils = require('../calendar/utils.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var React__default = /*#__PURE__*/_interopDefaultLegacy(React);

const Day = React__default['default'].forwardRef((props, ref) => {
    const { disabled = false } = props;
    function handleClick() {
        if (!disabled) {
            const prevMonth = utils.getPrevMonth(props.currentMonth);
            const nextMonth = utils.getNextMonth(props.currentMonth);
            if (props.day.getMonth() === prevMonth) {
                props.onChange(props.day, prevMonth);
            }
            else if (props.day.getMonth() === nextMonth) {
                props.onChange(props.day, nextMonth);
            }
            else {
                props.onChange(props.day);
            }
        }
    }
    function isStartAndEnd() {
        return props.isStartDay && props.isEndDay;
    }
    return (React__default['default'].createElement(styles.Wrapper, { isInRange: props.isInRange &&
            props.selection !== 'single-date' &&
            !isStartAndEnd(), isStartDay: props.isStartDay, isEndDay: props.isEndDay, onClick: handleClick, disabled: disabled },
        React__default['default'].createElement(styles.DayNum, { ref: ref || undefined, isStartEndDay: props.isStartDay || props.isEndDay, isToday: dateUtils.getIsToday(props.day), isCurrentMonth: props.day.getMonth() === props.currentMonth ||
                props.currentMonth === 12, disabled: disabled, width: props.width, tabIndex: props.hasFocus ? 0 : -1 },
            React__default['default'].createElement("span", null, props.day.getDate()),
            props.hasEvent && (React__default['default'].createElement(styles.Event, { isStartEnd: props.isStartDay || props.isEndDay })))));
});

exports.Day = Day;
