var _excluded = ["children", "variant"],
  _excluded2 = ["children"],
  _excluded3 = ["children", "expanded", "expandableContentMaxHeight"],
  _excluded4 = ["children"],
  _excluded5 = ["children"],
  _excluded6 = ["children"],
  _excluded7 = ["children"],
  _excluded8 = ["children"],
  _excluded9 = ["children", "icon"],
  _excluded10 = ["children"],
  _excluded11 = ["children"],
  _excluded12 = ["children"],
  _excluded13 = ["children"],
  _excluded14 = ["children"],
  _excluded15 = ["children", "variant"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { Check, Clear, EllipsisVertical, Error, Info, Warning } from '@procore/core-icons/dist';
import { partition } from 'ramda';
import React from 'react';
import { Button } from '../Button/Button';
import { Card } from '../Card/Card';
import { Menu, useMenu } from '../Menu/Menu';
import { OverlayTrigger } from '../OverlayTrigger/OverlayTrigger';
import { useI18nContext } from '../_hooks/I18n';
import { OverflowObserver } from '../_hooks/OverflowObserver';
import { addSubcomponents } from '../_utils/addSubcomponents';
import { mergeRefs } from '../_utils/mergeRefs';
import { StyledAction, StyledActionsTrigger, StyledBannerContainer, StyledBody, StyledContent, StyledExpandableContent, StyledExpandableContentContainer, StyledIconContainer, StyledMiniBannerContainer, StyledTitle } from './Banner.styles';
/**


 We use banners to contextually convey complicated or supplemental information
 to a user. Depending on the type of banner, we can provide more information
 about a feature or page the user is on, an action the user needs to perform,
 or an error the user has encountered.

 Procore banners are informative and actionable. Always explain what the user
 needs to know (and in some cases, why they’re seeing the banner), and provide
 an actionable next step.

 @since 10.19.0

 @see [Storybook](https://procore.github.io/core/core-react/latest/?path=/story/demos-banner--demo)

 @see [Design Guidelines](https://design.procore.com/banner)

 */
var Banner_ = /*#__PURE__*/React.forwardRef(function Banner(_ref, ref) {
  var children = _ref.children,
    variant = _ref.variant,
    props = _objectWithoutProperties(_ref, _excluded);
  var _ref2 = partition(function (element) {
      return /*#__PURE__*/React.isValidElement(element) && element.type === ExpandableContent;
    }, React.Children.toArray(children)),
    _ref3 = _slicedToArray(_ref2, 2),
    expandableContentNodes = _ref3[0],
    content = _ref3[1];
  var isExpandable = expandableContentNodes.length !== 0;
  return /*#__PURE__*/React.createElement(StyledBannerContainer, _extends({
    ref: ref,
    isExpandable: isExpandable,
    variant: variant
  }, props), isExpandable ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StyledExpandableContentContainer, {
    justifyContent: "space-between",
    alignItems: "center"
  }, content), expandableContentNodes) : content);
});
var Content = /*#__PURE__*/React.forwardRef(function Content(_ref4, ref) {
  var children = _ref4.children,
    props = _objectWithoutProperties(_ref4, _excluded2);
  return /*#__PURE__*/React.createElement(StyledContent, _extends({}, props, {
    ref: ref
  }), children);
});
var ExpandableContent = /*#__PURE__*/React.forwardRef(function ExpandableContent(_ref5, ref) {
  var children = _ref5.children,
    _ref5$expanded = _ref5.expanded,
    expanded = _ref5$expanded === void 0 ? false : _ref5$expanded,
    _ref5$expandableConte = _ref5.expandableContentMaxHeight,
    expandableContentMaxHeight = _ref5$expandableConte === void 0 ? 120 : _ref5$expandableConte,
    props = _objectWithoutProperties(_ref5, _excluded3);
  var containerRef = React.useRef(null);
  return expanded ? /*#__PURE__*/React.createElement(OverflowObserver, null, function (_ref6) {
    var overflowRef = _ref6.ref,
      isOverflowingY = _ref6.isOverflowingY;
    return /*#__PURE__*/React.createElement(StyledExpandableContent, _extends({
      ref: mergeRefs(ref, containerRef),
      "data-qa": "core-banner-expandable-content",
      onAnimationEnd: function onAnimationEnd() {
        return overflowRef(containerRef.current);
      },
      isOverflowingY: isOverflowingY,
      expandableContentMaxHeight: expandableContentMaxHeight
    }, props, isOverflowingY && {
      tabIndex: 0
    }), children);
  }) : null;
});
var Title = /*#__PURE__*/React.forwardRef(function Title(_ref7, ref) {
  var children = _ref7.children,
    props = _objectWithoutProperties(_ref7, _excluded4);
  return /*#__PURE__*/React.createElement(StyledTitle, _extends({}, props, {
    ref: ref
  }), children);
});
var Body = /*#__PURE__*/React.forwardRef(function Body(_ref8, ref) {
  var children = _ref8.children,
    props = _objectWithoutProperties(_ref8, _excluded5);
  return /*#__PURE__*/React.createElement(StyledBody, _extends({}, props, {
    ref: ref
  }), children);
});
var Action = /*#__PURE__*/React.forwardRef(function Action(_ref9, ref) {
  var children = _ref9.children,
    props = _objectWithoutProperties(_ref9, _excluded6);
  return /*#__PURE__*/React.createElement(StyledAction, _extends({}, props, {
    ref: ref
  }), children);
});
var DropdownAction = /*#__PURE__*/React.forwardRef(function DropdownAction(_ref10, ref) {
  var children = _ref10.children,
    props = _objectWithoutProperties(_ref10, _excluded7);
  return /*#__PURE__*/React.createElement(Menu.Item, _extends({
    ref: ref,
    item: null
  }, props), children);
});
var Actions = /*#__PURE__*/React.forwardRef(function Actions(_ref11, ref) {
  var children = _ref11.children,
    props = _objectWithoutProperties(_ref11, _excluded8);
  var actionButtons = React.Children.toArray(children).filter(function (element) {
    return /*#__PURE__*/React.isValidElement(element) && element.type === Action;
  });
  return /*#__PURE__*/React.createElement(OverlayTrigger, {
    overlay: /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(Menu, {
      ref: function ref(node) {
        return node === null || node === void 0 ? void 0 : node.focus();
      },
      usingHook: useMenu({
        isSelectable: function isSelectable(_ref12) {
          var type = _ref12.type;
          return type === DropdownAction;
        }
      })
    }, /*#__PURE__*/React.createElement(Menu.Options, null, actionButtons.map(function (_ref13, idx) {
      var actionButtonProps = _ref13.props;
      return /*#__PURE__*/React.createElement(DropdownAction, _extends({
        key: idx
      }, actionButtonProps));
    })))),
    ref: ref,
    placement: "bottom-right"
  }, /*#__PURE__*/React.createElement(StyledActionsTrigger, _extends({
    "data-qa": "core-banner-actions-trigger",
    variant: "tertiary",
    arrow: false,
    icon: /*#__PURE__*/React.createElement(EllipsisVertical, null)
  }, props)));
});
var Icon = /*#__PURE__*/React.forwardRef(function Icon(_ref14, ref) {
  var children = _ref14.children,
    icon = _ref14.icon,
    props = _objectWithoutProperties(_ref14, _excluded9);
  return /*#__PURE__*/React.createElement(StyledIconContainer, _extends({
    ref: ref,
    "aria-hidden": "true"
  }, props), icon);
});
var Dismiss = /*#__PURE__*/React.forwardRef(function Dismiss(_ref15, ref) {
  var children = _ref15.children,
    props = _objectWithoutProperties(_ref15, _excluded10);
  var I18n = useI18nContext();
  return /*#__PURE__*/React.createElement(Button, _extends({
    "aria-label": I18n.t('core.banner.dismissAlert'),
    ref: ref
  }, props, {
    icon: /*#__PURE__*/React.createElement(Clear, null),
    variant: "tertiary"
  }));
});
export var ErrorBanner = /*#__PURE__*/React.forwardRef(function ErrorBanner(_ref16, ref) {
  var children = _ref16.children,
    props = _objectWithoutProperties(_ref16, _excluded11);
  return /*#__PURE__*/React.createElement(Banner, _extends({
    ref: ref,
    variant: "error"
  }, props), /*#__PURE__*/React.createElement(Icon, {
    icon: /*#__PURE__*/React.createElement(Error, {
      size: "lg"
    })
  }), children);
});

/**
 * @deprecated Component will be removed in a future version. Instead, please consider using "success" variant of Toast component.
 * @deprecatedSince 10.7.0
 */
export var SuccessBanner = /*#__PURE__*/React.forwardRef(function SuccessBanner(_ref17, ref) {
  var children = _ref17.children,
    props = _objectWithoutProperties(_ref17, _excluded12);
  return /*#__PURE__*/React.createElement(Banner, _extends({
    ref: ref,
    variant: "success"
  }, props), /*#__PURE__*/React.createElement(Icon, {
    icon: /*#__PURE__*/React.createElement(Check, {
      size: "lg"
    })
  }), children);
});
export var InfoBanner = /*#__PURE__*/React.forwardRef(function InfoBanner(_ref18, ref) {
  var children = _ref18.children,
    props = _objectWithoutProperties(_ref18, _excluded13);
  return /*#__PURE__*/React.createElement(Banner, _extends({
    ref: ref,
    variant: "info"
  }, props), /*#__PURE__*/React.createElement(Icon, {
    icon: /*#__PURE__*/React.createElement(Info, {
      size: "lg"
    })
  }), children);
});

/**
 * @since 11.26.0
 */
export var AttentionBanner = /*#__PURE__*/React.forwardRef(function AttentionBanner(_ref19, ref) {
  var children = _ref19.children,
    props = _objectWithoutProperties(_ref19, _excluded14);
  return /*#__PURE__*/React.createElement(Banner, _extends({
    ref: ref,
    variant: "attention"
  }, props), /*#__PURE__*/React.createElement(Icon, {
    icon: /*#__PURE__*/React.createElement(Warning, {
      size: "lg"
    })
  }), children);
});

/**
 * @deprecated ActionBanner was renamed to AttentionBanner.
 * @deprecatedSince 11.26.0
 */
export var ActionBanner = AttentionBanner;
export var UNSAFE_MiniBanner = /*#__PURE__*/React.forwardRef(function MiniBanner(_ref20, ref) {
  var children = _ref20.children,
    _ref20$variant = _ref20.variant,
    variant = _ref20$variant === void 0 ? 'info' : _ref20$variant,
    props = _objectWithoutProperties(_ref20, _excluded15);
  return /*#__PURE__*/React.createElement(StyledMiniBannerContainer, _extends({
    ref: ref,
    variant: variant
  }, props), children);
});
Banner_.displayName = 'Banner';
Body.displayName = 'Banner.Body';
Content.displayName = 'Banner.Content';
ExpandableContent.displayName = 'Banner.ExpandableContent';
Title.displayName = 'Banner.Title';
Action.displayName = 'Banner.Action';
Actions.displayName = 'Banner.Actions';
DropdownAction.displayName = 'Banner.DropdownAction';
Icon.displayName = 'Banner.Icon';
Dismiss.displayName = 'Banner.Dismiss';
ErrorBanner.displayName = 'ErrorBanner';
SuccessBanner.displayName = 'SuccessBanner';
InfoBanner.displayName = 'InfoBanner';
AttentionBanner.displayName = 'AttentionBanner';
ActionBanner.displayName = 'ActionBanner';
UNSAFE_MiniBanner.displayName = 'MiniBanner';
export var Banner = addSubcomponents({
  Body: Body,
  Content: Content,
  ExpandableContent: ExpandableContent,
  Title: Title,
  Action: Action,
  Actions: Actions,
  Icon: Icon,
  Dismiss: Dismiss
}, Banner_);
//# sourceMappingURL=Banner.js.map