'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var index = require('../../utils/index.js');
var Sheet_tokens = require('./Sheet.tokens.js');
var Sheet_styles = require('./Sheet.styles.js');
var base = require('./variations/_view/base.js');
var base$1 = require('./variations/_handlePlacement/base.js');
var index$1 = require('./utils/index.js');
var useOverflow = require('./hooks/useOverflow.js');
var useSheetSwipe = require('./hooks/useSheetSwipe.js');
var Overlay = require('../Overlay/Overlay.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

var _excluded = ["opened", "children", "onClose", "hasHandle", "handlePlacement", "contentHeader", "isHeaderFixed", "contentFooter", "isFooterFixed", "withOverlay", "withBlur", "withTransition", "hasScrollEvents", "throttleMs", "className", "view"];

/**
 * Открывает окно-шторку поверх основного экрана.
 */

var sheetRoot = function sheetRoot(Root) {
  return /*#__PURE__*/React.forwardRef(function (_ref, rootRef) {
    var opened = _ref.opened,
      children = _ref.children,
      onClose = _ref.onClose,
      _ref$hasHandle = _ref.hasHandle,
      hasHandle = _ref$hasHandle === void 0 ? true : _ref$hasHandle,
      handlePlacement = _ref.handlePlacement,
      contentHeader = _ref.contentHeader,
      _ref$isHeaderFixed = _ref.isHeaderFixed,
      isHeaderFixed = _ref$isHeaderFixed === void 0 ? false : _ref$isHeaderFixed,
      contentFooter = _ref.contentFooter,
      _ref$isFooterFixed = _ref.isFooterFixed,
      isFooterFixed = _ref$isFooterFixed === void 0 ? false : _ref$isFooterFixed,
      _ref$withOverlay = _ref.withOverlay,
      withOverlay = _ref$withOverlay === void 0 ? true : _ref$withOverlay,
      _ref$withBlur = _ref.withBlur,
      withBlur = _ref$withBlur === void 0 ? false : _ref$withBlur,
      _ref$withTransition = _ref.withTransition,
      withTransition = _ref$withTransition === void 0 ? true : _ref$withTransition,
      _ref$hasScrollEvents = _ref.hasScrollEvents,
      hasScrollEvents = _ref$hasScrollEvents === void 0 ? true : _ref$hasScrollEvents,
      throttleMs = _ref.throttleMs,
      className = _ref.className,
      view = _ref.view,
      restProps = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
    var contentWrapperRef = React.useRef(null);
    var contentRef = React.useRef(null);
    var handleRef = React.useRef(null);
    useOverflow.useOverflow({
      opened: opened
    });
    useSheetSwipe.useSheetSwipe({
      contentWrapperRef: contentWrapperRef,
      contentRef: contentRef,
      handleRef: handleRef,
      throttleMs: throttleMs,
      hasScrollEvents: hasScrollEvents,
      onClose: onClose
    });
    var hasHeader = Boolean(contentHeader);
    var hasFooter = Boolean(contentFooter);
    var closedClass = opened ? undefined : "".concat(Sheet_tokens.classes.closed);
    var overlayBackgroundToken = withBlur ? "var(".concat(Sheet_tokens.tokens.sheetOverlayWithBlurColor, ")") : "var(".concat(Sheet_tokens.tokens.sheetOverlayColor, ")");
    return /*#__PURE__*/React__default.default.createElement(Root, {
      opened: opened,
      onClose: onClose,
      view: view,
      handlePlacement: handlePlacement,
      ref: rootRef
    }, /*#__PURE__*/React__default.default.createElement(Sheet_styles.StyledContentWrapper, _rollupPluginBabelHelpers.extends({
      opened: opened,
      withTransition: withTransition,
      className: index.cx(closedClass, className),
      ref: contentWrapperRef
    }, restProps), hasHandle && /*#__PURE__*/React__default.default.createElement(Sheet_styles.StyledSheetHandle, {
      ref: handleRef
    }), /*#__PURE__*/React__default.default.createElement(Sheet_styles.StyledSheetContent, {
      hasHeader: hasHeader,
      hasFooter: hasFooter,
      ref: contentRef
    }, hasHeader && /*#__PURE__*/React__default.default.createElement(Sheet_styles.StyledSheetHeader, {
      isHeaderFixed: isHeaderFixed
    }, contentHeader), /*#__PURE__*/React__default.default.createElement(Sheet_styles.StyledSheetBody, null, children), hasFooter && /*#__PURE__*/React__default.default.createElement(Sheet_styles.StyledSheetFooter, {
      isFooterFixed: isFooterFixed
    }, contentFooter))), withOverlay && opened && /*#__PURE__*/React__default.default.createElement(Overlay.Overlay, {
      zIndex: index$1.DEFAULT_Z_INDEX,
      backgroundColorProperty: overlayBackgroundToken,
      withBlur: withBlur,
      isClickable: true,
      onOverlayClick: onClose
    }));
  });
};
var sheetConfig = {
  name: 'Sheet',
  tag: 'div',
  layout: sheetRoot,
  base: '',
  variations: {
    view: {
      css: base.base
    },
    handlePlacement: {
      css: base$1.base
    }
  },
  defaults: {
    view: 'default',
    handlePlacement: 'outer'
  }
};

exports.sheetConfig = sheetConfig;
exports.sheetRoot = sheetRoot;
