import { __ } from '@wordpress/i18n'; import Icon from '@/utils/Icon'; import { formatTime, truncateMiddle } from '@/utils/formatting'; import { safeDecodeURI } from '@/utils/lib'; import type { BarColumn } from '@/components/DataTable/BarDataTable'; import type { ReadingEngagementRow } from './useReadingEngagementData'; /** * Returns the column definitions for the reading engagement table. * * @param {Object} options - Options object. * @param {string} options.siteUrl - The WordPress site URL, used to build the page links. * @return {BarColumn[]} The column definitions. */ export function getReadingEngagementColumns({ siteUrl }: { siteUrl: string; }): BarColumn[] { return [ { key: 'page_url', label: __( 'Page', 'burst-statistics' ), align: 'left', minWidth: 160, cell: ( row ) => { const pageUrl = `${siteUrl.replace( /\/$/, '' )}${row.page_url}`; const decoded = safeDecodeURI( row.page_url ); return ( { truncateMiddle( decoded, 30 ) } ); } }, { key: 'avg_time_on_page', label: __( 'Avg. time on page', 'burst-statistics' ), align: 'right', minWidth: 100, cell: ( row ) => ( { formatTime( row.avg_time_on_page ) } ) } ]; }