'use client' import { FC, useState } from 'react'; import { type ApexOptions } from 'apexcharts'; import { useTheme } from 'next-themes'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'; import { Button } from '@/components/ui/button'; import ViewAvatar from '@/components/ViewAvatar'; import dynamic from 'next/dynamic'; import LazyLoading from '@/components/loader/LazyLoading'; const ReactApexChart = dynamic(() => import('react-apexcharts'), { loading: () => , ssr: false }); type Props = { data: any }; const PieChart: FC = ({ data }) => { const [selectedWorkingStatus, setSelectedWorkingStatus] = useState('') // const { windowWidth } = useMobileView() const { theme, systemTheme } = useTheme() const options: ApexOptions = { chart: { width: 1000, height: 1000, // width: windowWidth > 800 ? 1000 : 400, // height: windowWidth > 800 ? 1000 : 400, events: { click(e, chart, options) { const { selectedDataPoints, labels } = options.globals if (selectedDataPoints.length > 0) { const workingStatus = labels[selectedDataPoints[0]] setSelectedWorkingStatus(workingStatus?.toUpperCase()) } if (selectedDataPoints.length > 0) { chart.toggleDataPointSelection(selectedDataPoints[0]) } }, mounted: (chart) => { chart.windowResizeHandler(); } }, }, plotOptions: { pie: { expandOnClick: true, donut: { size: '55%', labels: { show: true, name: { show: true, color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000', fontSize: '20px', fontWeight: 'bold' }, value: { show: true, color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000', fontSize: '32px', fontWeight: 'bold' }, total: { show: true, showAlways: true, color: theme === 'dark' ? '#fff' : theme === 'system' && systemTheme === 'dark' ? '#fff' : '#000', label: 'Total', formatter: function (w) { return w.globals.seriesTotals.reduce((a: number, b: number) => { return a + b }, 0) }, }, }, }, } }, legend: { show: true, position: 'right', fontSize: '16px', // position: windowWidth > 800 ? 'right' : 'bottom', // fontSize: windowWidth > 800 ? '16px' : '12px', labels: { colors: theme === 'dark' ? '#fff' : theme === 'light' ? '#000' : '#a1a1aa', // useSeriesColors: true }, }, stroke: { width: 0 }, dataLabels: { enabled: true, formatter: function (val: any, opts) { // console.log(opts) return opts.w.globals.labels[opts.seriesIndex] + ': ' + opts.w.globals.series[opts.seriesIndex] // return opts.w.globals.series[opts.seriesIndex] }, }, fill: { type: 'gradient', }, labels: ['WFO', 'WFS', 'WFH', 'Cuti', 'Izin', 'Sakit', 'Belum Absen'], colors: ['#3b82f6', '#10b981', '#db2777', '#8b5cf6', '#06b6d4', '#f59e0b', '#84cc16'], responsive: [{ breakpoint: 800, options: { chart: { width: 400 }, legend: { fontSize: '12px', position: 'bottom' } } }] } const series = [data.total_wfo, data.total_wfs, data.total_wfh, data.total_ct01, data.total_iz01, data.total_skt, data.total_belum_absen] const handleGetListEmployee = () => { if (!selectedWorkingStatus) return [] if (selectedWorkingStatus === 'BELUM ABSEN') { return data.list.filter((item: any) => item.status_presence?.includes('Belum')) } else { return data.list.filter((item: any) => item.working_status?.toUpperCase().includes(selectedWorkingStatus)) } } return ( <> 800 ? 525 : 400} width={525} /> {selectedWorkingStatus && setSelectedWorkingStatus('')}> List Employee The following is a list of employees who are {selectedWorkingStatus}. {handleGetListEmployee().length > 0 ? handleGetListEmployee().map((item: any, key: number) => {item.fullname} {item.position_name || '--'} ) : No result } setSelectedWorkingStatus('')}>Close } > ); } export default PieChart;
{item.fullname}
{item.position_name || '--'}