import { abbreviateNumber } from '@/modules/@common/helpers/number';

const createTopSearches = ({ topSearches }) => {
  const head = ['Keyword', 'Search %', 'Total Searches'];

  const body = [];
  topSearches.forEach(({ query, rate, count }) => {
    body.push([`"${query.replace(/"/g, "'")}"`, `${Math.round(rate * 100)}%`, abbreviateNumber(count, 2)]);
  });

  const rows = [head, ...body];

  const csvContent = rows.map((e) => e.join(',')).join('\n');

  return csvContent;
};

export default createTopSearches;
