'use strict';

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

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var IconClose = require('../_Icon/Icons/IconClose.js');
var index = require('../../utils/index.js');
var index$1 = require('./utils/index.js');
var BottomSheet_tokens = require('./BottomSheet.tokens.js');
var useBottomSheet = require('./hooks/useBottomSheet.js');
var base = require('./variations/_view/base.js');
var base$1 = require('./variations/_size/base.js');
var BottomSheet_styles = require('./BottomSheet.styles.js');
var Overlay = require('../Overlay/Overlay.js');

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

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

var _IconClose;
var _excluded = ["opened", "children", "contentBeforeHeader", "contentHeader", "contentFooter", "handlePlacement", "hasClose", "hasHandle", "withOverlay", "withBlur", "withTransition", "maxHeight", "zIndex", "onClose", "className", "view", "size"];
var noop = function noop() {};
var bottomSheetRoot = function bottomSheetRoot(Root) {
  return /*#__PURE__*/React.forwardRef(function (_ref, ref) {
    var _ref$opened = _ref.opened,
      opened = _ref$opened === void 0 ? false : _ref$opened,
      children = _ref.children,
      contentBeforeHeader = _ref.contentBeforeHeader,
      contentHeader = _ref.contentHeader,
      contentFooter = _ref.contentFooter,
      _ref$handlePlacement = _ref.handlePlacement,
      handlePlacement = _ref$handlePlacement === void 0 ? 'inner' : _ref$handlePlacement,
      _ref$hasClose = _ref.hasClose,
      hasClose = _ref$hasClose === void 0 ? true : _ref$hasClose,
      _ref$hasHandle = _ref.hasHandle,
      hasHandle = _ref$hasHandle === void 0 ? true : _ref$hasHandle,
      _ref$withOverlay = _ref.withOverlay,
      withOverlay = _ref$withOverlay === void 0 ? true : _ref$withOverlay,
      _ref$withBlur = _ref.withBlur,
      withBlur = _ref$withBlur === void 0 ? true : _ref$withBlur,
      _ref$withTransition = _ref.withTransition,
      withTransition = _ref$withTransition === void 0 ? true : _ref$withTransition,
      _ref$maxHeight = _ref.maxHeight,
      maxHeight = _ref$maxHeight === void 0 ? '66dvh' : _ref$maxHeight,
      _ref$zIndex = _ref.zIndex,
      zIndex = _ref$zIndex === void 0 ? 1000 : _ref$zIndex,
      _ref$onClose = _ref.onClose,
      onClose = _ref$onClose === void 0 ? noop : _ref$onClose,
      className = _ref.className,
      view = _ref.view,
      size = _ref.size,
      rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
    var content = React.useMemo(function () {
      return [contentBeforeHeader, contentHeader, children, contentFooter];
    }, [contentBeforeHeader, contentHeader, children, contentFooter]);
    var _useBottomSheet = useBottomSheet.useBottomSheet({
        opened: opened,
        content: content,
        onClose: onClose,
        hasHandle: hasHandle
      }),
      panelRef = _useBottomSheet.panelRef,
      bodyRef = _useBottomSheet.bodyRef,
      handleRef = _useBottomSheet.handleRef,
      overflows = _useBottomSheet.overflows,
      headerDivider = _useBottomSheet.headerDivider,
      footerDivider = _useBottomSheet.footerDivider;
    var panelClassName = index.cx(BottomSheet_tokens.classes.panel, withTransition && BottomSheet_tokens.classes.animated, !opened && BottomSheet_tokens.classes.closed);
    return /*#__PURE__*/React__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      ref: ref,
      className: className,
      view: view,
      size: size
    }, rest), withOverlay && opened && /*#__PURE__*/React__default.default.createElement(Overlay.Overlay, {
      zIndex: String(zIndex),
      backgroundColorProperty: withBlur ? "var(".concat(BottomSheet_tokens.tokens.overlayWithBlurColor, ")") : "var(".concat(BottomSheet_tokens.tokens.overlayColor, ")"),
      withBlur: withBlur,
      isClickable: true,
      onOverlayClick: onClose
    }), /*#__PURE__*/React__default.default.createElement(BottomSheet_styles.Panel, {
      ref: panelRef,
      className: panelClassName,
      style: {
        maxHeight: maxHeight,
        zIndex: index$1.getPanelZIndex(zIndex)
      }
    }, hasHandle && /*#__PURE__*/React__default.default.createElement(BottomSheet_styles.Handler, {
      ref: handleRef,
      $placement: handlePlacement,
      className: BottomSheet_tokens.classes.hasHandle
    }), hasClose && /*#__PURE__*/React__default.default.createElement(BottomSheet_styles.CloseButton, {
      view: "clear",
      onClick: onClose,
      "aria-label": "\u0417\u0430\u043A\u0440\u044B\u0442\u044C"
    }, _IconClose || (_IconClose = /*#__PURE__*/React__default.default.createElement(IconClose.IconClose, {
      size: "s",
      color: "inherit"
    }))), /*#__PURE__*/React__default.default.createElement(BottomSheet_styles.PanelContent, null, contentBeforeHeader && /*#__PURE__*/React__default.default.createElement(BottomSheet_styles.BeforeHeader, {
      className: BottomSheet_tokens.classes.beforeHeaderSlot
    }, contentBeforeHeader), contentHeader && /*#__PURE__*/React__default.default.createElement(BottomSheet_styles.Header, {
      className: index.cx(BottomSheet_tokens.classes.headerSlot, headerDivider && BottomSheet_tokens.classes.headerDividerVisible)
    }, contentHeader), children && /*#__PURE__*/React__default.default.createElement(BottomSheet_styles.StyledBody, {
      ref: bodyRef,
      className: index.cx(BottomSheet_tokens.classes.bodySlot, overflows && BottomSheet_tokens.classes.scrollable)
    }, children), contentFooter && /*#__PURE__*/React__default.default.createElement(BottomSheet_styles.Footer, {
      className: index.cx(BottomSheet_tokens.classes.footerSlot, footerDivider && BottomSheet_tokens.classes.footerDividerVisible)
    }, contentFooter))));
  });
};
var bottomSheetConfig = {
  name: 'BottomSheet',
  tag: 'div',
  layout: bottomSheetRoot,
  base: '',
  variations: {
    view: {
      css: base.base
    },
    size: {
      css: base$1.base
    }
  },
  defaults: {
    view: 'default',
    size: 'm'
  }
};

exports.bottomSheetConfig = bottomSheetConfig;
exports.bottomSheetRoot = bottomSheetRoot;
