import './print-share.scss';
import $ from 'jquery';
import {createElement} from "../../_global/scripts/helpers";
import {printShareListItems} from "./PrintShareData";
import {createSocialIcons} from "../../atoms/social-icons/SocialIconsComponent";
import {socialIconsBookmark} from "../../atoms/social-icons/SocialIconsData";
import IHKPrintShare from "./print-share";

export const createPrintShare =
  ({
    listItems = printShareListItems,
  }) => {
    const wrapper = createElement('div', ['print-share','variant-base']);

    const ul = createElement('ul', ['print-share-list'], null, wrapper);
    listItems.map((item, index) => {
      const li = createElement('li', [], null, ul);
      const a = createElement('a', [item.class], item.label, li);
      if (item.href && item.href.length > 0) {
        a.href = item.href;
      }
      if (item.onMouseDown && item.href.onMouseDown > 0) {
        a.onmousedown = item.onMouseDown;
      }
      if (item.title && item.title.length > 0) {
        a.title = item.title;
      }
      if (item.id && item.id.length > 0) {
        a.id = item.id;
      }
      if (item.target && item.target.length > 0) {
        a.target = item.target;
      }
    })

    const bookmarksWrapper = createElement('div', ['bookmarks'], null, wrapper);
    const iconsList = createSocialIcons({
      items: socialIconsBookmark,
      title: 'Bookmark setzen bei: ',
    })
    bookmarksWrapper.appendChild(iconsList);

    new IHKPrintShare($(wrapper));

    return wrapper;
  }