'use client'; import * as React from 'react'; import Card from '@mui/material/Card'; import CardContent from '@mui/material/CardContent'; import CardHeader from '@mui/material/CardHeader'; import Stack from '@mui/material/Stack'; import { useTheme } from '@mui/material/styles'; import type { SxProps } from '@mui/material/styles'; import Typography from '@mui/material/Typography'; import type { Icon } from '@phosphor-icons/react/dist/lib/types'; import { DesktopIcon } from '@phosphor-icons/react/dist/ssr/Desktop'; import { DeviceTabletIcon } from '@phosphor-icons/react/dist/ssr/DeviceTablet'; import { PhoneIcon } from '@phosphor-icons/react/dist/ssr/Phone'; import type { ApexOptions } from 'apexcharts'; import { Chart } from '@/components/core/chart'; const iconMapping = { Desktop: DesktopIcon, Tablet: DeviceTabletIcon, Phone: PhoneIcon } as Record; export interface TrafficProps { chartSeries: number[]; labels: string[]; sx?: SxProps; } export function Traffic({ chartSeries, labels, sx }: TrafficProps): React.JSX.Element { const chartOptions = useChartOptions(labels); return ( {chartSeries.map((item, index) => { const label = labels[index]; const Icon = iconMapping[label]; return ( {Icon ? : null} {label} {item}% ); })} ); } function useChartOptions(labels: string[]): ApexOptions { const theme = useTheme(); return { chart: { background: 'transparent' }, colors: [theme.palette.primary.main, theme.palette.success.main, theme.palette.warning.main], dataLabels: { enabled: false }, labels, legend: { show: false }, plotOptions: { pie: { expandOnClick: false } }, states: { active: { filter: { type: 'none' } }, hover: { filter: { type: 'none' } } }, stroke: { width: 0 }, theme: { mode: theme.palette.mode }, tooltip: { fillSeriesColor: false }, }; }