'use client' import { useMemo } from 'react' import { KriLineChart } from '@/components/chart' import { DataTable } from '@/components/data-table/DataTable' import type { DataTableColumn } from '@/components/data-table/DataTable.type' import type { ProgressDateResponse } from '@/types/progress' import type { ResultCodeColumn } from './resultCodeColumns' export type DateProgressSectionProps = { title: string subtitle: string rows: ProgressDateResponse[] resultCodeColumns: ResultCodeColumn[] } export function DateProgressSection({ title, subtitle, rows, resultCodeColumns }: DateProgressSectionProps) { const sortedRows = useMemo( () => [...rows].sort((a, b) => (a.contactDate ?? '').localeCompare(b.contactDate ?? '')), [rows], ) const categories = useMemo(() => sortedRows.map((row) => row.contactDate ?? ''), [sortedRows]) const series = useMemo(() => { const totalSeries = { name: 'Total', data: sortedRows.map((row) => row.totalCount ?? 0), option: { type: 'bar', barMaxWidth: 48 }, } const resultSeries = resultCodeColumns.map(({ resultCd, label }) => ({ name: label, data: sortedRows.map((row) => row.resultCodeCountMap?.[resultCd] ?? 0), })) return [totalSeries, ...resultSeries] }, [sortedRows, resultCodeColumns]) const columns = useMemo[]>(() => [ { id: 'contactDate', header: '일자', accessorFn: (row) => row.contactDate ?? '-', cell: ({ getValue }) =>
{getValue()}
, }, { id: 'startTime', header: '시작', accessorFn: (row) => row.startTime ?? '-', cell: ({ getValue }) =>
{getValue()}
, }, { id: 'endTime', header: '종료', accessorFn: (row) => row.endTime ?? '-', cell: ({ getValue }) =>
{getValue()}
, }, { id: 'totalCount', header: 'Total', accessorFn: (row) => row.totalCount ?? 0, cell: ({ getValue }) =>
{getValue().toLocaleString()}
, }, ...resultCodeColumns.map(({ resultCd, label }): DataTableColumn => ({ id: `rc-${resultCd}`, header: label, accessorFn: (row) => row.resultCodeCountMap?.[resultCd] ?? 0, cell: ({ getValue }) =>
{getValue().toLocaleString()}
, })), ], [resultCodeColumns]) return (

{title}

{subtitle}

columns={columns} data={sortedRows} getRowId={(row, index) => `${row.contactDate ?? ''}-${index}`} disablePagination maxBodyHeight="320px" />
) } export default DateProgressSection