'use client' // React Imports import { useState } from 'react' import type { SyntheticEvent } from 'react' // Next Imports import dynamic from 'next/dynamic' // MUI Imports import Card from '@mui/material/Card' import CardHeader from '@mui/material/CardHeader' import CardContent from '@mui/material/CardContent' import Tab from '@mui/material/Tab' import TabList from '@mui/lab/TabList' import TabPanel from '@mui/lab/TabPanel' import TabContext from '@mui/lab/TabContext' import Typography from '@mui/material/Typography' import type { Theme } from '@mui/material/styles' import { useTheme } from '@mui/material/styles' // Third Party Imports import classnames from 'classnames' import type { ApexOptions } from 'apexcharts' // Components Imports import OptionMenu from '@core/components/option-menu' import CustomAvatar from '@core/components/mui/Avatar' // Styled Component Imports const AppReactApexCharts = dynamic(() => import('@/libs/styles/AppReactApexCharts')) type ApexChartSeries = NonNullable type ApexChartSeriesData = Exclude type TabCategory = 'orders' | 'sales' | 'profit' | 'income' type TabType = { type: TabCategory avatarIcon: string series: ApexChartSeries } // Vars const tabData: TabType[] = [ { type: 'orders', avatarIcon: 'tabler-shopping-cart', series: [{ data: [28, 10, 46, 38, 15, 30, 35, 28, 8] }] }, { type: 'sales', avatarIcon: 'tabler-chart-bar', series: [{ data: [35, 25, 15, 40, 42, 25, 48, 8, 30] }] }, { type: 'profit', avatarIcon: 'tabler-currency-dollar', series: [{ data: [10, 22, 27, 33, 42, 32, 27, 22, 8] }] }, { type: 'income', avatarIcon: 'tabler-chart-pie-2', series: [{ data: [5, 9, 12, 18, 20, 25, 30, 36, 48] }] } ] const renderTabs = (value: TabCategory) => { return tabData.map((item, index) => ( {item.type} } /> )) } const renderTabPanels = (value: TabCategory, theme: Theme, options: ApexOptions, colors: string[]) => { return tabData.map((item, index) => { const max = Math.max(...((item.series[0] as ApexChartSeriesData).data as number[])) const seriesIndex = ((item.series[0] as ApexChartSeriesData).data as number[]).indexOf(max) const finalColors = colors.map((color, i) => (seriesIndex === i ? 'var(--mui-palette-primary-main)' : color)) return ( ) }) } const EarningReportsWithTabs = () => { // States const [value, setValue] = useState('orders') // Hooks const theme = useTheme() // Vars const disabledText = 'var(--mui-palette-text-disabled)' const handleChange = (event: SyntheticEvent, newValue: TabCategory) => { setValue(newValue) } const colors = Array(9).fill('var(--mui-palette-primary-lightOpacity)') const options: ApexOptions = { chart: { parentHeightOffset: 0, toolbar: { show: false } }, plotOptions: { bar: { borderRadius: 6, distributed: true, columnWidth: '33%', borderRadiusApplication: 'end', dataLabels: { position: 'top' } } }, legend: { show: false }, tooltip: { enabled: false }, dataLabels: { offsetY: -11, formatter: val => `${val}k`, style: { fontWeight: 500, colors: ['var(--mui-palette-text-primary)'], fontSize: theme.typography.body1.fontSize as string } }, colors, states: { hover: { filter: { type: 'none' } }, active: { filter: { type: 'none' } } }, grid: { show: false, padding: { top: -19, left: -4, right: 0, bottom: -11 } }, xaxis: { axisTicks: { show: false }, axisBorder: { color: 'var(--mui-palette-divider)' }, categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep'], labels: { style: { colors: disabledText, fontFamily: theme.typography.fontFamily, fontSize: theme.typography.body2.fontSize as string } } }, yaxis: { labels: { offsetX: -18, formatter: val => `$${val}k`, style: { colors: disabledText, fontFamily: theme.typography.fontFamily, fontSize: theme.typography.body2.fontSize as string } } }, responsive: [ { breakpoint: 1450, options: { plotOptions: { bar: { columnWidth: '45%' } } } }, { breakpoint: 600, options: { dataLabels: { style: { fontSize: theme.typography.body2.fontSize as string } }, plotOptions: { bar: { columnWidth: '58%' } } } }, { breakpoint: 500, options: { plotOptions: { bar: { columnWidth: '70%' } } } } ] } return ( } /> {renderTabs(value)} } /> {renderTabPanels(value, theme, options, colors)} ) } export default EarningReportsWithTabs