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

const createTopVideos = ({ videos }) => {
  const head = ['Video Name', 'No. of Views', 'Attention Span', 'Eng. Score '];

  const body = [];
  videos.forEach(({ name, numOfViews, attentionSpan, engScore }) => {
    body.push([
      `"${name.replace(/"/g, "'")}"`,
      abbreviateNumber(numOfViews, 2),
      attentionSpan.toFixed(1),
      engScore.toFixed(1),
    ]);
  });

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

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

  return csvContent;
};

export default createTopVideos;
