/**
 *
 * {{properCase name }}
 *
 */

import * as React from 'react';
import { connect } from 'react-redux';
{{#if wantHeaders}}
import { Helmet } from 'react-helmet';
{{/if}}
{{#if wantMessages}}
import { FormattedMessage } from 'react-intl';
{{/if}}
{{#if wantActionsAndReducer}}
import { createStructuredSelector } from 'reselect';
{{/if}}
import { compose, Dispatch } from 'redux';

{{#if wantSaga}}
import injectSaga from 'utils/injectSaga';
{{/if}}
{{#if wantActionsAndReducer}}
import injectReducer from 'utils/injectReducer';
import select{{properCase name}} from './selectors';
import reducer from './reducer';
{{/if}}
{{#if wantSaga}}
import saga from './saga';
{{/if}}
{{#if wantMessages}}
import messages from './messages';
{{/if}}

import { RootState } from './types';


interface OwnProps {}

interface StateProps {}

interface DispatchProps {}

type Props = StateProps & DispatchProps & OwnProps;

export class {{ properCase name }} extends {{{ type }}}<Props> {
  public render() {
    return (
      <div>
      {{#if wantHeaders}}
        <Helmet>
          <title>{{properCase name}}</title>
          <meta name="description" content="Description of {{properCase name}}" />
        </Helmet>
      {{/if}}
      {{#if wantMessages}}
        <FormattedMessage {...messages.header} />
      {{/if}}
      </div>
    );
  }
}

{{#if wantActionsAndReducer}}
const mapStateToProps = createStructuredSelector<RootState, StateProps>({
  {{ lowerCase name }}: select{{properCase name}}(),
});
{{/if}}

function mapDispatchToProps(dispatch: Dispatch, ownProps: OwnProps): DispatchProps {
  return {
    dispatch: dispatch,
  };
}

{{#if wantActionsAndReducer}}
const withConnect = connect(
  mapStateToProps,
  mapDispatchToProps,
);

// <OwnProps> restricts access to the HOC's other props. This component must not do anything with reducer hoc
const withReducer = injectReducer<OwnProps>({ key: '{{ camelCase name }}', reducer: reducer });
{{else}}
const withConnect = connect(null, mapDispatchToProps);
{{/if}}
{{#if wantSaga}}
// <OwnProps> restricts access to the HOC's other props. This component must not do anything with saga hoc
const withSaga = injectSaga<OwnProps>({ key: '{{ camelCase name }}', saga: saga });
{{/if}}

export default compose(
{{#if wantActionsAndReducer}}
  withReducer,
{{/if}}
{{#if wantSaga}}
  withSaga,
{{/if}}
  withConnect,
)({{ properCase name }});
