import React, { FC, ReactNode } from "react"; import { IconEdit, IconHistory } from "@tabler/icons-react"; import { motion } from "framer-motion"; import { Box, Tabs, Text } from "@mantine/core"; import TabsList from "@/app/deals/drawers/DealEditorDrawer/components/TabsList"; import DealStatusHistoryTab from "@/app/deals/drawers/DealEditorDrawer/tabs/DealStatusHistoryTab/DealStatusHistoryTab"; import GeneralTab from "@/app/deals/drawers/DealEditorDrawer/tabs/GeneralTab/GeneralTab"; import useIsMobile from "@/hooks/utils/useIsMobile"; import { DealSchema, ProjectSchema } from "@/lib/client"; import MODULES from "@/modules/modules"; import styles from "../DealEditorDrawer.module.css"; type Props = { value: DealSchema; onChange: (deal: DealSchema) => void; onDelete: (deal: DealSchema) => void; project: ProjectSchema | null; }; const DealEditorBody: FC = props => { const isMobile = useIsMobile(); const getTabPanel = (value: string, component: ReactNode): ReactNode => ( {component} ); const getTab = (key: string, label: string, icon: ReactNode) => ( {label} ); const getModuleTabs = (): ReactNode[] => { if (!props.project) return []; const tabs: ReactNode[] = []; for (const module of props.project.builtInModules) { const moduleInfo = MODULES[module.key]; for (const tab of moduleInfo.tabs) { if ( (tab.device === "desktop" && isMobile) || (tab.device === "mobile" && !isMobile) ) continue; tabs.push(getTab(tab.key, tab.label, tab.icon)); } } return tabs; }; const getModuleTabPanels = () => { if (!props.project) return []; const tabPanels: ReactNode[] = []; for (const module of props.project.builtInModules) { const moduleInfo = MODULES[module.key]; for (const tab of moduleInfo.tabs) { if ( (tab.device === "desktop" && isMobile) || (tab.device === "mobile" && !isMobile) ) continue; tabPanels.push(getTabPanel(tab.key, tab.tab(props))); } } return tabPanels; }; return ( {getTab("general", "Общая информация", )} {getTab("history", "История", )} {getModuleTabs()} {getTabPanel("general", )} {getTabPanel("history", )} {getModuleTabPanels()} ); }; export default DealEditorBody;