import { beauty } from "./beauty";

const certificates = [
  "SBA-WOSB1.webp",
  "VOSB.webp",
  "SBA8a2.webp",
  "HUBZone-circle.webp",
  null,
  "WBE1.webp",
  "MBE1.webp",
  "DBE.webp",
  "SDVOSB.webp",
  "EDWOSB.webp",
  "GSA.webp",
  "CMMC.webp",
  "NMSDC.webp",
  "SBE.webp",
];

export function getCertificates(template: string, certifications: number[]) {
  const certListRegex = /certificates:\s*{\s*title:\s*`Certifications`,\s*attributes:\s*{\s*backgroundColor:\s*COLORS\.light_1,\s*},\s*list:\s*\[([\s\S]*?)\],/;
  const emptyCertList = "/** certificate list **/"

  const _certs = certifications.filter(Boolean);

  const match = template.match(certListRegex);

  if (!match) {
    return { template, certs: [] };
  }

  if (_certs.length === 0) {
    template = template.replace(match[1], emptyCertList);
    return { template, certs: [] };
  }

  const certs = _certs.map((cert) => {
    return { src: certificates[cert - 1] };
  });

  template = template.replace(`[${match[1]}]`, beauty(certs));

  return { template, certs };
}
