import type { CardProps } from '@mui/material/Card';
import type { PaletteColorKey } from 'src/theme/core';
import type { ChartOptions } from 'src/components/chart';
import { varAlpha } from 'minimal-shared/utils';
import Box from '@mui/material/Box';
import Card from '@mui/material/Card';
import { useTheme } from '@mui/material/styles';
import { fNumber, fPercent, fShortenNumber } from 'src/utils/format-number';
import { Iconify } from 'src/components/iconify';
import { SvgColor } from 'src/components/svg-color';
import { Chart, useChart } from 'src/components/chart';
// ----------------------------------------------------------------------
type Props = CardProps & {
title: string;
total: number;
percent: number;
color?: PaletteColorKey;
icon: React.ReactNode;
chart: {
series: number[];
categories: string[];
options?: ChartOptions;
};
};
export function AnalyticsWidgetSummary({
sx,
icon,
title,
total,
chart,
percent,
color = 'primary',
...other
}: Props) {
const theme = useTheme();
const chartColors = [theme.palette[color].dark];
const chartOptions = useChart({
chart: { sparkline: { enabled: true } },
colors: chartColors,
xaxis: { categories: chart.categories },
grid: {
padding: {
top: 6,
left: 6,
right: 6,
bottom: 6,
},
},
tooltip: {
y: { formatter: (value: number) => fNumber(value), title: { formatter: () => '' } },
},
markers: {
strokeWidth: 0,
},
...chart.options,
});
const renderTrending = () => (
{percent > 0 && '+'}
{fPercent(percent)}
);
return (
({
p: 3,
boxShadow: 'none',
position: 'relative',
color: `${color}.darker`,
backgroundColor: 'common.white',
backgroundImage: `linear-gradient(135deg, ${varAlpha(theme.vars.palette[color].lighterChannel, 0.48)}, ${varAlpha(theme.vars.palette[color].lightChannel, 0.48)})`,
}),
...(Array.isArray(sx) ? sx : [sx]),
]}
{...other}
>
{icon}
{renderTrending()}
{title}
{fShortenNumber(total)}
);
}