"use strict";
const jsxRuntime = require("react/jsx-runtime");
const React = require("react");
const assert = require("assert");
const styles_lib_components_Box_Box_cjs = require("../Box/Box.cjs");
const styles_lib_components_Accordion_Accordion_cjs = require("../Accordion/Accordion.cjs");
const styles_lib_components_Accordion_AccordionItem_cjs = require("../Accordion/AccordionItem.cjs");
const styles_lib_components_Tabs_Tab_cjs = require("./Tab.cjs");
const styles_lib_components_Tabs_Tabs_css_cjs = require("./Tabs.css.cjs");
const _interopDefaultCompat = (e) => e && typeof e === "object" && "default" in e ? e : { default: e };
const assert__default = /* @__PURE__ */ _interopDefaultCompat(assert);
const TabPanelsContext = React.createContext(
  null
);
const TabPanel = ({
  children,
  data,
  item,
  ...restProps
}) => {
  const tabsContext = React.useContext(styles_lib_components_Tabs_Tab_cjs.TabsContext);
  const tabPanelsContext = React.useContext(TabPanelsContext);
  assert__default.default(
    tabsContext !== null,
    "A TabPanel must be rendered as a child of TabsProvider. See the documentation for correct usage: https://seek-oss.github.io/braid-design-system/components/Tabs"
  );
  if (!tabPanelsContext) {
    throw new Error("TabPanel rendered outside TabPanels");
  }
  if (!tabsContext) {
    throw new Error("TabPanel rendered outside TabsProvider");
  }
  const { a11y, selectedIndex, selectedItem } = tabsContext;
  const { panelIndex, renderInactive } = tabPanelsContext;
  const isSelected = selectedIndex > -1 ? panelIndex === selectedIndex : selectedItem === item;
  return /* @__PURE__ */ jsxRuntime.jsxs(
    styles_lib_components_Box_Box_cjs.Box,
    {
      ...a11y.tabPanelProps({ panelIndex, isSelected }),
      display: isSelected ? void 0 : "none",
      position: "relative",
      outline: "none",
      className: styles_lib_components_Tabs_Tabs_css_cjs.tabPanel,
      ...styles_lib_components_Accordion_Accordion_cjs.buildDataAttributes({ data, validateRestProps: restProps }),
      children: [
        isSelected || renderInactive ? children : void 0,
        /* @__PURE__ */ jsxRuntime.jsx(
          styles_lib_components_Accordion_AccordionItem_cjs.Overlay,
          {
            zIndex: 1,
            boxShadow: "outlineFocus",
            borderRadius: "large",
            className: styles_lib_components_Tabs_Tabs_css_cjs.tabPanelFocusRing,
            onlyVisibleForKeyboardNavigation: true
          }
        )
      ]
    }
  );
};
TabPanel.displayName = "TabPanel";
TabPanel.__isTabPanel__ = true;
exports.TabPanel = TabPanel;
exports.TabPanelsContext = TabPanelsContext;
