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

import App from './App.js';

const page = document.getElementById('categories--page');

if (page) {
  const dataScript = document.getElementById('categories-data');
  const categories = JSON.parse(dataScript.textContent);

  let createUrl = document.getElementById('createUrl').textContent;
  let updateUrl = document.getElementById('updateUrl').textContent;

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

  ReactDOM.render(
    <App
      categories={categories}
      createUrl={createUrl.substring(1, createUrl.length - 2)}
      updateUrl={updateUrl.substring(1, updateUrl.length - 4)}
      navLinks={navLinks}
    />,
    page
  );
}
