import React, { useCallback, useContext } from 'react';
import { ThemeContext } from "../../../lib/theming/ThemeContext";
import { InternalDateTransformer } from "../../../lib/date/InternalDateTransformer";
import { styles } from "../DayCellView.styles";
import { CalendarContext } from "../CalendarContext";
import * as CDS from "../CalendarDateShape";
import { CalendarDay } from "../CalendarDay";
export var DayCellView = function DayCellView(props) {
  var _isHoliday, _renderDay;
  var date = props.date;
  var _useContext = useContext(CalendarContext),
    value = _useContext.value,
    minDate = _useContext.minDate,
    maxDate = _useContext.maxDate,
    isHoliday = _useContext.isHoliday,
    renderDay = _useContext.renderDay,
    today = _useContext.today,
    onDateClick = _useContext.onDateClick;
  var theme = useContext(ThemeContext);
  var isDisabled = !CDS.isBetween(date, minDate, maxDate);
  var humanDateString = InternalDateTransformer.dateToHumanString(date);
  var dayClickHandler = useCallback(function () {
    onDateClick == null || onDateClick(date);
  }, [onDateClick, date]);
  var dayProps = {
    isToday: Boolean(today && CDS.isEqual(date, today)),
    isSelected: Boolean(value && CDS.isEqual(date, value)),
    isDisabled: isDisabled,
    isWeekend: (_isHoliday = isHoliday == null ? void 0 : isHoliday(humanDateString, date.isWeekend)) != null ? _isHoliday : date.isWeekend,
    date: humanDateString,
    onDayClick: dayClickHandler
  };
  var dayElement = (_renderDay = renderDay == null ? void 0 : renderDay(dayProps)) != null ? _renderDay : /*#__PURE__*/React.createElement(CalendarDay, dayProps);
  return /*#__PURE__*/React.createElement("div", {
    className: styles.cell(theme)
  }, dayElement);
};