var _excluded = ["children", "isClosable", "isInitiallyOpen", "onClose"],
  _excluded2 = ["children"],
  _excluded3 = ["children"],
  _excluded4 = ["children"],
  _excluded5 = ["children"],
  _excluded6 = ["children"],
  _excluded7 = ["children"],
  _excluded8 = ["children"],
  _excluded9 = ["children"];
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 _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 _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 { Clear } from '@procore/core-icons';
import React from 'react';
import { Button } from '../Button';
import { StyledActions } from '../Content/Content.styles';
import { Section } from '../Section';
import { useI18nContext } from '../_hooks/I18n';
import { useResizeObserver } from '../_hooks/ResizeObserver';
import { addSubcomponents } from '../_utils/addSubcomponents';
import { mergeRefs } from '../_utils/mergeRefs';
import { SplitViewCardContextProvider, useSplitViewCard } from './SplitViewCard.context';
import { StyledSplitViewCardAside, StyledSplitViewCardBody, StyledSplitViewCardContainer, StyledSplitViewCardFooter, StyledSplitViewCardHeader, StyledSplitViewCardHeading, StyledSplitViewCardMain, StyledSplitViewCardTitle } from './SplitViewCard.styles';
var SplitViewCard_ = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var children = _ref.children,
    _ref$isClosable = _ref.isClosable,
    isClosable = _ref$isClosable === void 0 ? true : _ref$isClosable,
    isInitiallyOpen = _ref.isInitiallyOpen,
    onClose = _ref.onClose,
    props = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/React.createElement(SplitViewCardContextProvider, {
    isInitiallyOpen: isInitiallyOpen,
    onClose: onClose,
    isClosable: isClosable
  }, /*#__PURE__*/React.createElement(StyledSplitViewCardContainer, _extends({
    ref: ref
  }, props), children));
});
export var Main = /*#__PURE__*/React.forwardRef(function (_ref2, ref) {
  var children = _ref2.children,
    props = _objectWithoutProperties(_ref2, _excluded2);
  var _useSplitViewCard = useSplitViewCard(),
    open = _useSplitViewCard.open;
  return /*#__PURE__*/React.createElement(StyledSplitViewCardMain, _extends({
    $open: open,
    ref: ref
  }, props), children);
});
export var Panel = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
  var children = _ref3.children,
    props = _objectWithoutProperties(_ref3, _excluded3);
  var _useSplitViewCard2 = useSplitViewCard(),
    open = _useSplitViewCard2.open;
  var _React$useState = React.useState(false),
    _React$useState2 = _slicedToArray(_React$useState, 2),
    hasShadow = _React$useState2[0],
    setHasShadow = _React$useState2[1];
  var mainRef = React.useRef(null);
  var handleResize = React.useCallback(function (entries) {
    var element = entries[0];
    if (element && element.target.clientWidth <= 400) {
      setHasShadow(true);
      return;
    }
    setHasShadow(false);
  }, []);
  var setResize = useResizeObserver(handleResize);
  React.useEffect(function () {
    setResize(mainRef.current);
  }, [setResize]);
  return /*#__PURE__*/React.createElement(StyledSplitViewCardAside, _extends({
    $open: open,
    $hasShadow: hasShadow,
    ref: mergeRefs(ref, mainRef)
  }, props), children);
});
export var PanelHeading = /*#__PURE__*/React.forwardRef(function (_ref4, ref) {
  var children = _ref4.children,
    props = _objectWithoutProperties(_ref4, _excluded4);
  return /*#__PURE__*/React.createElement(StyledSplitViewCardHeading, _extends({
    ref: ref
  }, props), children);
});
export var PanelTitle = /*#__PURE__*/React.forwardRef(function (_ref5, ref) {
  var children = _ref5.children,
    props = _objectWithoutProperties(_ref5, _excluded5);
  var I18n = useI18nContext();
  var _useSplitViewCard3 = useSplitViewCard(),
    isClosable = _useSplitViewCard3.isClosable,
    onClose = _useSplitViewCard3.onClose;
  return /*#__PURE__*/React.createElement(StyledSplitViewCardTitle, _extends({
    ref: ref
  }, props), /*#__PURE__*/React.createElement(StyledSplitViewCardHeading, null, children), isClosable && /*#__PURE__*/React.createElement(Button, {
    "aria-label": I18n.t('core.splitViewCard.a11y.close'),
    icon: /*#__PURE__*/React.createElement(Clear, null),
    variant: "tertiary",
    onClick: onClose
  }));
});
export var PanelHeader = /*#__PURE__*/React.forwardRef(function (_ref6, ref) {
  var children = _ref6.children,
    props = _objectWithoutProperties(_ref6, _excluded6);
  return /*#__PURE__*/React.createElement(StyledSplitViewCardHeader, _extends({
    ref: ref
  }, props), children);
});
export var PanelBody = /*#__PURE__*/React.forwardRef(function (_ref7, ref) {
  var children = _ref7.children,
    props = _objectWithoutProperties(_ref7, _excluded7);
  var _useSplitViewCard4 = useSplitViewCard(),
    setIsScrolling = _useSplitViewCard4.setIsScrolling;
  var timer = React.useRef(null);
  var handleScroll = React.useCallback(function () {
    setIsScrolling(true);
    if (timer.current) {
      clearTimeout(timer.current);
    }
    timer.current = setTimeout(function () {
      setIsScrolling(false);
    }, 100);
  }, [setIsScrolling]);
  return /*#__PURE__*/React.createElement(StyledSplitViewCardBody, _extends({
    ref: ref
  }, props, {
    onScroll: handleScroll,
    tabIndex: 0
  }), children);
});
export var PanelFooter = /*#__PURE__*/React.forwardRef(function (_ref8, ref) {
  var children = _ref8.children,
    props = _objectWithoutProperties(_ref8, _excluded8);
  var _useSplitViewCard5 = useSplitViewCard(),
    isScrolling = _useSplitViewCard5.isScrolling;
  return /*#__PURE__*/React.createElement(StyledSplitViewCardFooter, _extends({
    $hasShadow: isScrolling,
    ref: ref
  }, props), children);
});
var Actions = /*#__PURE__*/React.forwardRef(function Actions(_ref9, ref) {
  var children = _ref9.children,
    props = _objectWithoutProperties(_ref9, _excluded9);
  return /*#__PURE__*/React.createElement(StyledActions, _extends({
    ref: ref
  }, props), children);
});
SplitViewCard_.displayName = 'SplitViewCard';
Main.displayName = 'SplitViewCard.Main';
Panel.displayName = 'SplitViewCard.Panel';
PanelTitle.displayName = 'SplitViewCard.PanelTitle';
PanelHeader.displayName = 'SplitViewCard.PanelHeader';
PanelBody.displayName = 'SplitViewCard.PanelBody';
PanelFooter.displayName = 'SplitViewCard.PanelFooter';
Actions.displayName = 'SplitViewCard.Actions';

/**

 A SplitViewCard component is used to display additional details
 of an item from a collection inside a panel of a card.

 - SplitViewCard
   - SplitViewCard.Main
     - SplitViewCard.Section
       - Table or some other main content
   - SplitViewCard.Panel
     - SplitViewCard.PanelHeader
       - SplitViewCard.PanelTitle
         - text
       - Tabs
     - SplitViewCard.PanelBody
       - Content
     - SplitViewCard.PanelFooter
       - SplitViewCard.Actions

 @since 12.9.0

 @see [Storybook](https://stories.core.procore.com/?path=/story/demos-splitviewcard--demo)

 */

export var SplitViewCard = addSubcomponents({
  Actions: Actions,
  Main: Main,
  Section: Section,
  Panel: Panel,
  PanelTitle: PanelTitle,
  PanelHeader: PanelHeader,
  PanelBody: PanelBody,
  PanelFooter: PanelFooter
}, SplitViewCard_);
//# sourceMappingURL=SplitViewCard.js.map