|  |  | 
 |  |  | import React, { useState, useRef, useEffect } from 'react'; | 
 |  |  | import { useTranslate } from "react-admin"; | 
 |  |  | import { Box, Typography, Tabs, Tab, Stack, useTheme, Divider } from '@mui/material'; | 
 |  |  | import ShelfMain from './ShelfMain'; | 
 |  |  | import JsonShow from '../../JsonShow'; | 
 |  |  | import { getLocGroup } from '../../http'; | 
 |  |  |  | 
 |  |  | const ShelfInsight = (props) => { | 
 |  |  |     const { } = props; | 
 |  |  |     const { sprite, setTitle } = props; | 
 |  |  |     const theme = useTheme(); | 
 |  |  |     const themeMode = theme.palette.mode; | 
 |  |  |     const translate = useTranslate(); | 
 |  |  |  | 
 |  |  |     const [activeTab, setActiveTab] = useState(0); | 
 |  |  |     const [curShelfInfo, setCurShelfInfo] = useState(null); | 
 |  |  |     const [curLocNo, setCurLocNo] = useState(null); | 
 |  |  |  | 
 |  |  |     const fetchShelfInfo = (row, bay) => { | 
 |  |  |         getLocGroup(row, bay, (response) => { | 
 |  |  |             setCurShelfInfo(response); | 
 |  |  |             const defaultLocNo = response[0]?.locNo; | 
 |  |  |             setCurLocNo(defaultLocNo); | 
 |  |  |         }); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     useEffect(() => { | 
 |  |  |         if (sprite) { | 
 |  |  |             const { row, bay } = sprite.data; | 
 |  |  |             if (row && bay) { | 
 |  |  |                 fetchShelfInfo(row, bay); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return () => { | 
 |  |  |             setCurLocNo(null); | 
 |  |  |             setCurShelfInfo(null); | 
 |  |  |         } | 
 |  |  |     }, [sprite]); | 
 |  |  |  | 
 |  |  |     useEffect(() => { | 
 |  |  |         if (curLocNo) { | 
 |  |  |             setTitle(translate('page.map.devices.shelf') + ' - ' + curLocNo); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return () => { | 
 |  |  |             setTitle(null); | 
 |  |  |         } | 
 |  |  |     }, [curLocNo]) | 
 |  |  |  | 
 |  |  |     const handleTabChange = (event, newValue) => { | 
 |  |  |         setActiveTab(newValue); | 
 |  |  |     }; | 
 |  |  |  | 
 |  |  |     return ( | 
 |  |  |         <> | 
 |  |  |         <Box sx={{ height: '100%', display: 'flex', flexDirection: 'column' }}> | 
 |  |  |             <Tabs | 
 |  |  |                 value={activeTab} | 
 |  |  |                 onChange={handleTabChange} | 
 |  |  |                 indicatorColor="primary" | 
 |  |  |                 textColor="primary" | 
 |  |  |                 centered | 
 |  |  |                 sx={{ mb: 0 }} | 
 |  |  |             > | 
 |  |  |                 <Tab label={translate('page.map.settings.map.title')} /> | 
 |  |  |                 <Tab label={translate('page.map.settings.config.title')} /> | 
 |  |  |                 <Tab label={translate('page.map.insight.title')} /> | 
 |  |  |                 <Tab label={'JSON'} /> | 
 |  |  |             </Tabs> | 
 |  |  |  | 
 |  |  |             <Divider /> | 
 |  |  |  | 
 |  |  |             <Box p={3}> | 
 |  |  |             <Box flex={1} pt={2}> | 
 |  |  |                 {activeTab === 0 && ( | 
 |  |  |                     <Box> | 
 |  |  |                         <h1>1</h1> | 
 |  |  |                     </Box> | 
 |  |  |                     <ShelfMain | 
 |  |  |                         row={sprite?.data?.row} | 
 |  |  |                         bay={sprite?.data?.bay} | 
 |  |  |                         curLocNo={curLocNo} | 
 |  |  |                         curShelfInfo={curShelfInfo} | 
 |  |  |                         setCurLocNo={setCurLocNo} | 
 |  |  |                     /> | 
 |  |  |                 )} | 
 |  |  |                 {activeTab === 1 && ( | 
 |  |  |                     <Box> | 
 |  |  |                         <h1>2</h1> | 
 |  |  |                     </Box> | 
 |  |  |                     <JsonShow | 
 |  |  |                         data={curShelfInfo || sprite?.data} | 
 |  |  |                         height={550} | 
 |  |  |                     /> | 
 |  |  |                 )} | 
 |  |  |             </Box> | 
 |  |  |         </> | 
 |  |  |         </Box> | 
 |  |  |     ) | 
 |  |  | } | 
 |  |  |  |