var _excluded = ["aria-labelledby", "children", "isClosable", "isInitiallyOpen", "onClose"],
  _excluded2 = ["children"],
  _excluded3 = ["children"],
  _excluded4 = ["children"],
  _excluded5 = ["children"],
  _excluded6 = ["children"],
  _excluded7 = ["children"],
  _excluded8 = ["children"];
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
import { Clear } from '@procore/core-icons';
import { useId } from '@react-aria/utils';
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';
import { SplitViewCardInternalContextProvider, useSplitViewCardInternal } from './SplitViewCardInternal.context';
var SplitViewCard_ = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
  var ariaLabelledBy = _ref['aria-labelledby'],
    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);
  var defaultLabelId = useId();
  return /*#__PURE__*/React.createElement(SplitViewCardContextProvider, {
    isInitiallyOpen: isInitiallyOpen
  }, /*#__PURE__*/React.createElement(SplitViewCardInternalContextProvider, {
    ariaLabelledBy: ariaLabelledBy !== null && ariaLabelledBy !== void 0 ? ariaLabelledBy : defaultLabelId,
    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(),
    isOpen = _useSplitViewCard.isOpen;
  return /*#__PURE__*/React.createElement(StyledSplitViewCardMain, _extends({
    $open: isOpen,
    ref: ref
  }, props), children);
});
export var Panel = /*#__PURE__*/React.forwardRef(function (_ref3, ref) {
  var children = _ref3.children,
    props = _objectWithoutProperties(_ref3, _excluded3);
  var _useSplitViewCard2 = useSplitViewCard(),
    isOpen = _useSplitViewCard2.isOpen;
  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: isOpen,
    $hasShadow: hasShadow,
    ref: mergeRefs(ref, mainRef)
  }, props), children);
});
export var PanelTitle = /*#__PURE__*/React.forwardRef(function (_ref4, ref) {
  var children = _ref4.children,
    props = _objectWithoutProperties(_ref4, _excluded4);
  var I18n = useI18nContext();
  var _useSplitViewCardInte = useSplitViewCardInternal(),
    ariaLabelledBy = _useSplitViewCardInte.ariaLabelledBy,
    isClosable = _useSplitViewCardInte.isClosable;
  var _useSplitViewCard3 = useSplitViewCard(),
    hide = _useSplitViewCard3.hide;
  return /*#__PURE__*/React.createElement(StyledSplitViewCardTitle, _extends({
    ref: ref
  }, props), /*#__PURE__*/React.createElement(StyledSplitViewCardHeading, {
    id: ariaLabelledBy
  }, children), isClosable && /*#__PURE__*/React.createElement(Button, {
    "aria-label": I18n.t('core.splitViewCard.a11y.close'),
    icon: /*#__PURE__*/React.createElement(Clear, null),
    variant: "tertiary",
    onClick: hide
  }));
});
export var PanelHeader = /*#__PURE__*/React.forwardRef(function (_ref5, ref) {
  var children = _ref5.children,
    props = _objectWithoutProperties(_ref5, _excluded5);
  return /*#__PURE__*/React.createElement(StyledSplitViewCardHeader, _extends({
    ref: ref
  }, props), children);
});
export var PanelBody = /*#__PURE__*/React.forwardRef(function (_ref6, ref) {
  var children = _ref6.children,
    props = _objectWithoutProperties(_ref6, _excluded6);
  var _useSplitViewCardInte2 = useSplitViewCardInternal(),
    ariaLabelledBy = _useSplitViewCardInte2.ariaLabelledBy,
    setIsScrolling = _useSplitViewCardInte2.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,
    role: "region",
    "aria-labelledby": ariaLabelledBy
  }), children);
});
export var PanelFooter = /*#__PURE__*/React.forwardRef(function (_ref7, ref) {
  var children = _ref7.children,
    props = _objectWithoutProperties(_ref7, _excluded7);
  var _useSplitViewCardInte3 = useSplitViewCardInternal(),
    isScrolling = _useSplitViewCardInte3.isScrolling;
  return /*#__PURE__*/React.createElement(StyledSplitViewCardFooter, _extends({
    $hasShadow: isScrolling,
    ref: ref
  }, props), children);
});
var Actions = /*#__PURE__*/React.forwardRef(function Actions(_ref8, ref) {
  var children = _ref8.children,
    props = _objectWithoutProperties(_ref8, _excluded8);
  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