import './link-collection.scss';
import {createElement} from "../../_global/scripts/helpers";
import {linkListCopyData} from "../linklist/LinkListData";
import IHKLinkCollection from "./link-collection";
import {createLinkList} from "../linklist/LinkListComponent";
import {createButton} from "../../atoms/button/ButtonComponent";

export const createLinkCollection =
  ({
    headline = 'Meistgeklickt',
    linkListData = linkListCopyData,
    buttonText = 'Alle Pressemitteilungen anzeigen',
    addContainer = false,
  }) => {
    const wrapper = createElement('div', ['link-collection']);

    if (headline && headline.length > 0) {
      createElement('h2', [], headline, wrapper);
    }

    wrapper.appendChild(createLinkList({links: linkListData}));

    if (buttonText && buttonText.length > 0) {
      const btnWrapper = createElement('div', ['btn-wrapper'], null, wrapper);
      const btn = createButton({
        elementType: 'a',
        label: buttonText,
        icon: 'pfeil-rechts',
        iconPosition: 'icon-right',
      })
      btnWrapper.appendChild(btn);
    }

    new IHKLinkCollection(wrapper);

    if (addContainer) {
      const section = createElement('section', ['link-collection-wrapper']);
      const container = createElement('div', ['container'], null, section);
      const row = createElement('div', ['row'], null, container);
      const col = createElement('div', ['col'], null, row);
      col.appendChild(wrapper);
      return section;
    }

    return wrapper;
  }