// import $ from 'jquery';
import {EtrackerUtils} from "../utils/EtrackerUtils";

const $ = require('jquery');
class Bookmarks{
  constructor(list) {
    this.wrap = list.closest('.print-share');
    this.bookmarks = $('#socialbookmarks').addClass('bookmarks').removeAttr('id');


    if ($('.has-sidebar').length) {
      this.initMobileClone();
    }
    else if ($('.document-number').length) {
      this.initMobileDocNumber();
    }

    $(document).find('.print-share-list .share-mail').on('click', function (e) {
      e.preventDefault();
      $('.bookmarks').addClass('show-bookmarks');
    });
    this.initEtrackerClickEvents();
  }

  initMobileClone() {
    const docNumber = $('.document-number');
    const documentNrClone = docNumber.clone().attr("id", "gfi-document-id-mobil").removeClass("desktopOnly");

    this.mobileClone = $('<div class="mobile-footer" />');

    this.mobileClone.append( this.wrap.clone() );
    this.mobileClone.append( this.bookmarks.clone() )
    this.mobileClone.prepend( documentNrClone );

    this.mobileClone.insertAfter($('aside'));
  }

  initMobileDocNumber() {
    const docNumber = $('.document-number').removeClass('desktopOnly');
    const wrapper = $('<div class="bookmarks-wrapper" />');

    this.wrap.wrap(wrapper);
    docNumber.clone().insertBefore(this.wrap);
  }

  initEtrackerClickEvents(){
    $(document).find(".social-share").on('click', function (e) {
      const category = 'Socialbookmark';
      const object = $(this).attr("href");
      const action = 'Link';
      EtrackerUtils.fireETrackerEvent(category,object,action,'');
    });
  }
}


  const docNumber = $('.document-number');
  const printShareList = $('.print-share-list');

  if (printShareList.length === 0 && docNumber.length > 0) {
    const documentNrClone = docNumber.clone().attr("id", "gfi-document-id-mobil").removeClass("desktopOnly");
    const mobileWrapperElem = $('<div class="mobile-footer" />').append(documentNrClone);
    const pageContent = $('.page-content');

    if(pageContent.length){
      pageContent.append(mobileWrapperElem);
    } else {
      $('.page-wrapper').append(mobileWrapperElem);
    }
  }

  printShareList.each(function(i) {
    new Bookmarks($(this));
  });

