import './a-z.scss';
import $ from 'jquery';
import {createElement} from "../../_global/scripts/helpers";
import {alphabet} from "./AZData";
import IHKIndex from "./a-z";

export const createAZ =
  ({
    items = alphabet,
  }) => {
    const section = createElement('section', ['a-z', 'variant-base']);
    const list = createElement('ul', ['letters'], null, section);
    items.map((item) => {
      const hasUrl = item.url && item.url.length > 0;
      const li = createElement('li', [], null, list);
      const letter = createElement(hasUrl ? 'a' : 'span', ['letter'], item.letter, li);
      if (hasUrl) {
        letter.href = item.url;
      } else {
        li.classList.add('disabled');
      }
    })

    new IHKIndex($(section));

    return section;
  }