import * as React from "react";
import Tabs from "@mui/material/Tabs";
import Tab from "@mui/material/Tab";
import isEmpty from "lodash/isEmpty";
import { ArrayControlProps, UISchemaElement } from "@jsonforms/core";
import Box from "@mui/material/Box";
import { JsonFormsDispatch, useJsonForms } from "@jsonforms/react";
import { DataContext } from "../context/Context";
import { Divider, Typography } from "@mui/material";
interface TabPanelProps {
children: any;
index: number;
value: number;
id: number | string;
theme: any;
uischema: any;
}
function TabPanel(props: TabPanelProps) {
const { children, value, index, id, theme, uischema, ...other } = props;
return (
{children}
);
}
function a11yProps(index: number) {
return {
id: `simple-tab-${index}`,
"aria-controls": `simple-tabpanel-${index}`,
};
}
export default function TabLayout({
elements,
path,
schema,
uischema,
renderers,
enabled,
cells,
}: ArrayControlProps & any) {
const [value, setValue] = React.useState(0);
const { pageName } = React.useContext(DataContext);
const MainVariables = uischema.config?.main;
const ConfigStyles = uischema.config?.style;
const isVertical = MainVariables?.orientation === "vertical";
const tabLength = MainVariables?.tabLabels.length;
React.useEffect(() => {
setValue(0);
}, [MainVariables?.id, path, pageName]);
const { theme } = React.useContext(DataContext);
const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
const getTabStyles = (index: number) => ({
...theme.TabStyle,
borderBottom: isVertical ? "1px solid rgba(0, 0, 0, 0.12)" : undefined,
marginLeft: "24px",
position: "relative",
overflow: "visible",
minWidth: "0px",
textTransform: "none",
...(index !== tabLength - 1 && {
"&::after": {
content: '""',
position: "absolute",
top: 15,
right: "-12px",
height: "calc(70% - 8px)",
width: "3px",
backgroundColor: "#707070",
opacity: 0.26,
},
}),
...ConfigStyles?.TabsHeaderStyle,
});
const tabsAndPanels = (
<>
{uischema.tabLabelElements?.length > 0
? uischema.tabLabelElements.map((elem: any, index: number) => (
}
{...a11yProps(index)}
/>
))
: MainVariables?.tabLabels.map((elem: string, index: number) => {
return (
);
})}
{!isEmpty(elements) && uischema?.config?.main?.lazyLoad ? (
) : (
elements.map((e, i) => {
return (
);
})
)}
>
);
return (
{uischema?.config?.main?.label && (
{uischema.config?.main?.label}
{uischema?.config?.main?.divider && (
)}
)}
{isVertical ? tabsAndPanels : {tabsAndPanels}}
);
}
export const CustomTabLayout = React.memo(TabLayout);