"use strict";var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;exports.__esModule = true;exports.SidePageCloseButton = void 0;var _react = _interopRequireWildcard(require("react"));
var _globalObject = require("@skbkontur/global-object");

var _ThemeContext = require("../../lib/theming/ThemeContext");
var _useLocaleForControl = require("../../lib/locale/useLocaleForControl");
var _XIcon20Regular = require("../../internal/icons2022/XIcon/XIcon20Regular");
var _Emotion = require("../../lib/theming/Emotion");
var _keyListener = require("../../lib/events/keyListener");

var _ThemeHelpers = require("../../lib/theming/ThemeHelpers");

var _SidePage = require("./SidePage.styles");
var _locale = require("./locale");
var _SidePageHeader = require("./SidePageHeader");
var _SidePageContext = require("./SidePageContext");






var SidePageCloseButton = exports.SidePageCloseButton = function SidePageCloseButton(_ref) {var _cx;var isHeaderFixed = _ref.isHeaderFixed,isMobile = _ref.isMobile;
  var _useState = (0, _react.useState)(false),isFocusedByTab = _useState[0],setIsFocusedByTab = _useState[1];

  var locale = (0, _useLocaleForControl.useLocaleForControl)('SidePage', _locale.SidePageLocaleHelper);
  var theme = (0, _react.useContext)(_ThemeContext.ThemeContext);
  var sidePageContext = (0, _react.useContext)(_SidePageContext.SidePageContext);

  var handleFocus = function handleFocus() {
    _globalObject.globalObject.requestAnimationFrame == null || _globalObject.globalObject.requestAnimationFrame(function () {
      if (_keyListener.keyListener.isTabPressed) {
        setIsFocusedByTab(true);
      }
    });
  };

  var handleBlur = function handleBlur() {
    setIsFocusedByTab(false);
  };

  var icon = /*#__PURE__*/_react.default.createElement(_XIcon20Regular.XIcon20Regular, { align: "none" });
  var versionGTE5_1 = (0, _ThemeHelpers.isThemeGTE)(theme, '5.1');
  return /*#__PURE__*/(
    _react.default.createElement("button", {
      "aria-label": locale == null ? void 0 : locale.closeButtonAriaLabel,
      className: (0, _Emotion.cx)(_SidePage.styles.close(theme), (_cx = {}, _cx[
      _SidePage.styles.close5_1(theme)] = versionGTE5_1, _cx[
      _SidePage.styles.closeFocus(theme)] = isFocusedByTab && !versionGTE5_1, _cx[
      _SidePage.styles.closeFocus5_1(theme)] = isFocusedByTab && versionGTE5_1, _cx[
      _SidePage.styles.closeSticky(theme)] = isHeaderFixed && versionGTE5_1, _cx[
      _SidePage.styles.closeMobile(theme)] = isMobile && versionGTE5_1, _cx)
      ),
      onFocus: handleFocus,
      onBlur: handleBlur,
      onClick: sidePageContext.requestClose,
      "data-tid": _SidePageHeader.SidePageHeaderDataTids.close },

    icon
    ));

};

SidePageCloseButton.__KONTUR_REACT_UI__ = 'SidePageCloseButton';
SidePageCloseButton.displayName = 'SidePageCloseButton';