import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Provider as ReduxProvider } from 'react-redux';

import Context from './Context';
import Name from './SiteName';
import Version from './SiteVersion';

/**
 * Defines a site for use by other components
 */
export class Site extends Component {
  static propTypes = {
    /** Content to render. */
    children: PropTypes.node.isRequired,

    /** Options for use with this library. */
    options: PropTypes.object,

    /** StoryShare `Site`. */
    site: PropTypes.object.isRequired,
  };

  static Name = Name;

  static Version = Version;

  render = () => {
    const { children, options, site } = this.props;
    return (
      <Context.Provider value={ { options, site } }>
        <ReduxProvider store={ site.store }>
          { children }
        </ReduxProvider>
      </Context.Provider>
    );
  };
}

export default Site;
