var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { useContext, memo, useCallback } from 'react';
import { useEmotion, useStyles } from '../../lib/renderEnvironment/index.js';
import { useLocaleForControl } from '../../lib/locale/useLocaleForControl.js';
import { ThemeContext } from '../../lib/theming/ThemeContext.js';
import { DatePickerLocaleHelper } from '../DatePicker/locale/index.js';
import { InternalDate } from '../../lib/date/InternalDate.js';
import { LocaleContext } from '../../lib/locale/index.js';
import { getVisualStateDataAttributes } from '../../internal/CommonWrapper/utils/getVisualStateDataAttributes.js';
import { forwardRefAndName } from '../../lib/forwardRefAndName.js';
import { getStyles } from './DayCellView.styles.js';
import { CalendarDataTids } from './Calendar.js';
/**
 * Компонент дня `CalendarDay` из Calendar.
 *
 * @visibleName Calendar.Day
 */
export var CalendarDay = memo(forwardRefAndName('CalendarDay', function CalendarDay(_a, ref) {
    var _b, _c;
    var isToday = _a.isToday, isSelected = _a.isSelected, isDisabled = _a.isDisabled, isWeekend = _a.isWeekend, date = _a.date, onDayClick = _a.onDayClick, onClick = _a.onClick, children = _a.children, className = _a.className, rest = __rest(_a, ["isToday", "isSelected", "isDisabled", "isWeekend", "date", "onDayClick", "onClick", "children", "className"]);
    var theme = useContext(ThemeContext);
    var cx = useEmotion().cx;
    var styles = useStyles(getStyles);
    var langCode = useContext(LocaleContext).langCode;
    var internalDate = new InternalDate({ langCode: langCode, value: date });
    var locale = useLocaleForControl('Calendar', DatePickerLocaleHelper);
    var ariaLabel = "".concat(locale.dayCellChooseDateAriaLabel, ": ").concat(internalDate.toA11YFormat());
    var handleClick = useCallback(function (e) {
        onDayClick();
        onClick === null || onClick === void 0 ? void 0 : onClick(e);
    }, [onDayClick, onClick]);
    var day = internalDate.getComponentsLikeNumber().date;
    var caption = children !== null && children !== void 0 ? children : day;
    return (React.createElement("button", __assign({ ref: ref, "data-tid": CalendarDataTids.dayCell, "aria-label": ariaLabel, tabIndex: -1, disabled: isDisabled, onClick: handleClick, className: cx((_b = {},
            _b[styles.day(theme)] = true,
            _b[styles.weekend(theme)] = isWeekend,
            _b[styles.selected(theme)] = isSelected,
            _b), className) }, getVisualStateDataAttributes({ selected: isSelected }), rest),
        React.createElement("span", { className: cx((_c = {}, _c[styles.todayCaption(theme)] = isToday, _c)) }, caption)));
}));
//# sourceMappingURL=CalendarDay.js.map