import { __ } from '@wordpress/i18n'; import Icon from '@/utils/Icon'; import { formatNumber } from '@/utils/formatting'; import type { BarColumn } from '@/components/DataTable/BarDataTable'; import type { SearchTermRow } from './useSearchTermsData'; /** * Returns the column definitions for the search-terms table. * * @param {Object} options - Options object. * @param {string} options.siteUrl - The WordPress site URL, used to build the search result links. * @return {BarColumn[]} The column definitions. */ export function getSearchTermsColumns({ siteUrl }: { siteUrl: string; }): BarColumn[] { return [ { key: 'term', label: __( 'Search term', 'burst-statistics' ), align: 'left', minWidth: 160, cell: ( row ) => ( { row.term } ) }, { key: 'volume', label: __( 'Volume', 'burst-statistics' ), align: 'right', minWidth: 80, cell: ( row ) => ( { formatNumber( row.volume ) } ) }, { key: 'results', label: __( 'Results', 'burst-statistics' ), align: 'right', minWidth: 80, cell: ( row ) => { const hasResults = 0 < row.results; const searchUrl = `${siteUrl.replace( /\/$/, '' )}/?s=${encodeURIComponent( row.term )}`; if ( ! hasResults ) { return ( { __( 'None', 'burst-statistics' ) } ); } return ( { formatNumber( row.results ) } ); } } ]; }