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

import { Provider } from 'react-redux';
import configureStore from './configureStore.js';

import App from './App.js';

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

if (page) {
  const store = configureStore();

  const settings = JSON.parse(document.getElementById('homepageSettings').textContent);
  const { feedUrl, categoriesUrl } = settings;

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

  const app = (
    <Provider store={store}>
      <App
        feedUrl={feedUrl.substring(1, feedUrl.length - 3)}
        categoriesUrl={categoriesUrl.substring(1, categoriesUrl.length - 3)}
        timezone={settings.timezone}
        autoMarking={settings.autoMarking}
        navLinks={navLinks}
      />
    </Provider>
  );

  ReactDOM.render(app, page);
}
