import React, { PropTypes } from 'react';
import { Map } from 'immutable';
import ImmutableTypes from 'react-immutable-proptypes';
import { isString, isPlainObject } from 'lodash';


const propTypes = {
  appcache: PropTypes.string,
  assets: PropTypes.object.isRequired,
  children: PropTypes.node,
  js: PropTypes.array.isRequired,
  css: PropTypes.array.isRequired,
  state: ImmutableTypes.map.isRequired,
  manifest: PropTypes.string.isRequired,
  meta: PropTypes.arrayOf((p, k, c, l, n) => (
    (p[k].length === 2 && isString(p[k][0]) && isPlainObject(p[k][1])) ?
      undefined : new Error(`Invalid prop \`${n}\` supplied to \`${c}\`.`)
  )),
  title: PropTypes.string,
};


const defaultProps = {
  assets: {},
  state: Map(),
  manifest: '/manifest.json',
  meta: [],
  title: 'Lawly',
};


const AppHtml = ({
  appcache,
  assets,
  children,
  css,
  js,
  state,
  manifest,
  meta,
  title,
}) => (
  <html lang='de-DE' manifest={appcache}>
    <head>
      <title>{title}</title>
      <meta charSet='utf-8' />
      <meta name='viewport' content='width=device-width, minimum-scale=1.0' />
      {meta.map(([tag, props], idx) =>
        React.createElement(tag, { ...props, key: idx })
      )}
      <link rel='manifest' href={manifest} />
      <link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto:400,400i,700,700i' />
      {css.map(src =>
        <link rel='stylesheet' href={src} key={src} />
      )}
    </head>
    <body>
      <div id='app'>{children}</div>
      <script
        dangerouslySetInnerHTML={{
          __html: `window.__assets=${JSON.stringify(assets)}`,
        }}
      />
      <script
        dangerouslySetInnerHTML={{
          __html: `window.__state=${JSON.stringify(state.toJS())}`,
        }}
      />
      {js.map(src =>
        <script src={src} key={src} />
      )}
    </body>
  </html>
);


AppHtml.propTypes = propTypes;
AppHtml.defaultProps = defaultProps;


export default AppHtml;

@@ -790,24 +790,53 @@
 awly',%0A%7D;%0A%0A%0A
+/* eslint-disable max-len */%0A
 const AppHtm
@@ -1123,24 +1123,171 @@
 ale=1.0' /%3E%0A
+      %3Clink rel='manifest' href=%7Bmanifest%7D /%3E%0A      %3Clink rel='shortcut icon' sizes='16x16 24x24 32x32 48x48 64x64' href='/static/img/icon.ico' /%3E%0A
       %7Bmeta.
@@ -1309,24 +1309,24 @@
 s%5D, idx) =%3E%0A
-
         Reac
@@ -1370,16 +1370,16 @@
  idx %7D)%0A
+
       )%7D
@@ -1383,54 +1383,8 @@
  )%7D%0A
-      %3Clink rel='manifest' href=%7Bmanifest%7D /%3E%0A
     

Add favicon.