import { Children, type PropsWithChildren, useEffect, useState } from 'react'; import { Tab, Tabs } from '@mui/material'; import { TabContext, TabPanel } from '@mui/lab'; import { getTransientTabs, getVisibleTabs, tabClick } from '@pega/react-sdk-components/lib/components/template/SubTabs/tabUtils'; import type { PConnProps } from '@pega/react-sdk-components/lib/types/PConnProps'; interface DetailsSubTabsProps extends PConnProps { // If any, enter additional props that only exist on this component showLabel: boolean; label: string; } export default function DetailsSubTabs(props: PropsWithChildren) { const { children = [], label, showLabel = true, getPConnect } = props; // Get the inherited props from the parent to determine label settings const propsToUse = { label, showLabel, ...getPConnect().getInheritedProps() }; const defaultTabIndex = 0; const deferLoadedTabs = Children.toArray(children)[0]; let availableTabs = []; useEffect(() => { availableTabs = getVisibleTabs(deferLoadedTabs, 'detailsSubTabs'); }, [availableTabs]); const [currentTabId, setCurrentTabId] = useState(defaultTabIndex.toString()); const [tabItems, setTabitem] = useState([]); useEffect(() => { const tempTabItems = getTransientTabs(availableTabs, currentTabId, tabItems); setTabitem(tempTabItems); }, [currentTabId]); const handleTabClick = (id, index: string) => { setCurrentTabId(index); tabClick(index, availableTabs, currentTabId, setCurrentTabId, tabItems); }; return ( <> {propsToUse.showLabel &&

{propsToUse.label}

} {tabItems.map((tab: any) => ( ))} {tabItems.map((tab: any) => (
{tab.content ? tab.content : 'No content exists'}
))}
); }