import React from 'react';
import ReactDOM from 'react-dom';

import Sidebar from '../../components/Sidebar';

const mainElements = [...document.getElementsByClassName('main')];
const mainElement = mainElements.find(element => element.dataset.renderSidebar);

if (mainElement) {
  let linkScript = document.getElementById('Links');
  let navLinks = JSON.parse(linkScript.textContent);

  ReactDOM.render(
    ReactDOM.createPortal(<Sidebar navLinks={navLinks} />, mainElement),
    document.createElement('div')
  );
}
