import React__default from 'react';
import { Wrapper, DayNum, Event } from './styles.js';
import { getIsToday } from '../../dateUtils.js';
import { getPrevMonth, getNextMonth } from '../calendar/utils.js';

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

export { Day };
