import './tile-grid.scss';
import {createElement, createImage} from "../../_global/scripts/helpers";
import {TileGridData} from "./TileGridData";

export const createTileGrid = ({
  headline = 'Daten und Fakten auf einen Blick',
  tiles = TileGridData,
}) => {
  const section = createElement('section', ['tile-grid']);
  const container = createElement('div', ['container'], null, section);
  createElement('h2', [], headline, container);
  const row = createElement('div', ['row'], null, container);

  tiles.map((group) => {
    const col = createElement('div', ['col'], null, row);
    const head = createElement('div', ['tile-head'], null, col);
    const tileLink = createElement('a', ['tile-head-outer'], null, head);
    tileLink.href = group.titleUrl;
    createElement('h3', ['like-h4'], group.title, tileLink);

    group.tiles.map((item) => {
      const tile = createElement('div', ['tile'], null, col);
      const tileLink = createElement('a', ['tile-outer'], null, tile);
      tileLink.href = item.url;
      const iconBox = createElement('div', ['icon'], null, tileLink);
      createImage(item.icon, 220, 220, ['icon'], [], iconBox);
      const p = createElement('p', [], null, tileLink);
      const num = createElement('span', ['number'], item.number, p);
      if (item.unit) {
        createElement('small', [], item.unit, num);
      }
      createElement('span', ['label'], item.label, p);
    })
  })

  return section;
}