"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;exports.__esModule = true;exports.CalendarDay = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _react = _interopRequireWildcard(require("react"));

var _useLocaleForControl = require("../../lib/locale/useLocaleForControl");
var _ThemeContext = require("../../lib/theming/ThemeContext");
var _Emotion = require("../../lib/theming/Emotion");
var _locale = require("../DatePicker/locale");
var _InternalDate = require("../../lib/date/InternalDate");
var _locale2 = require("../../lib/locale");
var _getVisualStateDataAttributes = require("../../internal/CommonWrapper/utils/getVisualStateDataAttributes");
var _forwardRefAndName = require("../../lib/forwardRefAndName");

var _DayCellView = require("./DayCellView.styles");
var _Calendar = require("./Calendar");var _excluded = ["isToday", "isSelected", "isDisabled", "isWeekend", "date", "onDayClick", "onClick", "children", "className"];























/**
 * Компонент дня `CalendarDay` из Calendar.
 *
 * @visibleName Calendar.Day
 */
var CalendarDay = exports.CalendarDay = /*#__PURE__*/(0, _react.memo)(
  (0, _forwardRefAndName.forwardRefAndName)(
    'CalendarDay',
    function CalendarDay(_ref,












    ref)
    {var _cx, _cx2;var isToday = _ref.isToday,isSelected = _ref.isSelected,isDisabled = _ref.isDisabled,isWeekend = _ref.isWeekend,date = _ref.date,onDayClick = _ref.onDayClick,onClick = _ref.onClick,children = _ref.children,className = _ref.className,rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
      var theme = (0, _react.useContext)(_ThemeContext.ThemeContext);

      var _useContext = (0, _react.useContext)(_locale2.LocaleContext),langCode = _useContext.langCode;
      var internalDate = new _InternalDate.InternalDate({ langCode: langCode, value: date });

      var locale = (0, _useLocaleForControl.useLocaleForControl)('Calendar', _locale.DatePickerLocaleHelper);
      var ariaLabel = locale.dayCellChooseDateAriaLabel + ": " + internalDate.toA11YFormat();

      var handleClick = (0, _react.useCallback)(
        function (e) {
          onDayClick();
          onClick == null || onClick(e);
        },
        [onDayClick, onClick]
      );

      var _internalDate$getComp = internalDate.getComponentsLikeNumber(),day = _internalDate$getComp.date;
      var caption = children != null ? children : day;

      return /*#__PURE__*/(
        _react.default.createElement("button", (0, _extends2.default)({
          ref: ref,
          "data-tid": _Calendar.CalendarDataTids.dayCell,
          "aria-label": ariaLabel,
          tabIndex: -1,
          disabled: isDisabled,
          onClick: handleClick,
          className: (0, _Emotion.cx)((_cx = {}, _cx[

          _DayCellView.styles.day(theme)] = true, _cx[
          _DayCellView.styles.selected(theme)] = isSelected, _cx[
          _DayCellView.styles.weekend(theme)] = isWeekend, _cx),

          className
          ) },
        (0, _getVisualStateDataAttributes.getVisualStateDataAttributes)({ selected: isSelected }),
        rest), /*#__PURE__*/

        _react.default.createElement("span", { className: (0, _Emotion.cx)((_cx2 = {}, _cx2[_DayCellView.styles.todayCaption(theme)] = isToday, _cx2)) }, caption)
        ));

    }
  )
);