import { useContext } from 'react';
import { GridTable, GridColumn } from 'react-basics';
import classNames from 'classnames';
import { ReportContext } from '../Report';
import EmptyPlaceholder from 'components/common/EmptyPlaceholder';
import { useMessages } from 'hooks';
import { formatDate } from 'lib/date';
import styles from './RetentionTable.module.css';
export function RetentionTable() {
const { formatMessage, labels } = useMessages();
const { report } = useContext(ReportContext);
const { data } = report || {};
if (!data) {
return ;
}
const rows = data.reduce((arr, { date, visitors }) => {
if (!arr.find(a => a.date === date)) {
return arr.concat({ date, visitors });
}
return arr;
}, []);
const days = [1, 2, 3, 4, 5, 6, 7, 14, 21, 30];
return (
<>
{formatMessage(labels.date)}
{formatMessage(labels.visitors)}
{days.map(n => (
{formatMessage(labels.day)} {n}
))}
{rows.map(({ date, visitors }, i) => {
return (
{formatDate(`${date} 00:00:00`, 'PP')}
{visitors}
{days.map((n, day) => {
return (
{data.find(row => row.date === date && row.day === day)?.percentage.toFixed(2)}
);
})}
);
})}
>
);
}
function DataTable({ data }) {
return (
{row => row.date}
{row => row.day}
{row => row.visitors}
{row => row.returnVisitors}
{row => row.percentage}
);
}
export default RetentionTable;