import { __ } from '@wordpress/i18n'; import Icon from '@/utils/Icon'; import { formatNumber, getChangePercentage, truncateMiddle } from '@/utils/formatting'; import type { BarColumn } from '@/components/DataTable/BarDataTable'; import type { OutgoingLinkRow } from './useOutgoingLinksData'; /** * Returns the column definitions for the outgoing links table. * * @return {BarColumn[]} The column definitions. */ export function getOutgoingLinksColumns(): BarColumn[] { return [ { key: 'url', label: __( 'URL', 'burst-statistics' ), align: 'left', minWidth: 160, cell: ( row ) => { let display = row.url; try { const parsed = new URL( row.url ); display = parsed.hostname + ( '/' !== parsed.pathname ? parsed.pathname : '' ); } catch { // Fall back to the raw URL if parsing fails. } return ( { truncateMiddle( display, 30 ) } ); } }, { key: 'clicks', label: __( 'Clicks', 'burst-statistics' ), align: 'right', minWidth: 64, cell: ( row ) => ( { formatNumber( row.clicks ) } ) }, { key: 'change', label: __( 'Change', 'burst-statistics' ), align: 'right', minWidth: 96, cell: ( row ) => { if ( 0 === row.previousClicks ) { return ( { __( 'N/A', 'burst-statistics' ) } ); } const { val, status } = getChangePercentage( row.clicks, row.previousClicks ); return ( { val } ); } } ]; }