<%
const isSSR = typeof ssrContext !== 'undefined';

function get(name, defaultValue) {
  if (typeof htmlWebpackPlugin !== 'undefined') {
    return htmlWebpackPlugin.options[name];
  } else {
    return ssrContext[name] || defaultValue;
  }
}
%>

<!DOCTYPE html>
<html>
<head>
  <title><%= get('appName', '')%></title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <meta name="format-detection" content="telephone=no">
  <meta name="msapplication-tap-highlight" content="no">
    <% if (isSSR) { %>
      <%-get('preHeading', '')%>
    <% } else { %>
      <%=get('preHeading', '')%>
    <% } %>

    <style>
    <% if (!get('noDefaultStyles') === true) { %>
      :focus { outline: none; }
      body {
        font-family: "Avenir Next",Nunito,"Helvetica Neue",Helvetica,sans-serif;
        font-size: 14px;
        color: #888888;
        font-weight: 400;
        overflow: hidden;
      }
      #root {
        position: absolute;
        top: 0; right: 0; bottom: 0; left: 0;
        display: flex;
      }
      .touchable {
        cursor: pointer;
        user-select: none;
      }
    <% } %>
  </style>

  <% if (isSSR) { %>
    <%-get('postHeading', '')%>
  <% } else { %>
    <%=get('postHeading', '')%>
  <% } %>
  <%- get('initialStyles', '')%>
</head>

<body>
  <div id="root"><%- get('initialHtml', '')%></div>
  <% if (isSSR) { %>
    <%-get('preContent', '')%>
  <% } else { %>
    <%=get('preContent', '')%>
  <% } %>

  <%if (isSSR) { %>
    <% if (get('initialProps')) { %>
      <script id="initialPropsInjector">
        ssrInitialProps = <%-JSON.stringify(get('initialProps'))%>
        var elem = document.getElementById("initialPropsInjector");
        elem.parentNode.removeChild(elem);
      </script>
    <% } %>

    <% if (get('isProduction') === true) { %>
      <script src="<%= get('publicPath') + get('buildId')%>.js"></script>
    <% } else { %>
      <script src="<%= get('publicPath')%>app.js"></script>
    <% } %>
  <% } %>

  <% if (isSSR) { %>
    <%-get('postContent', '')%>
  <% } else { %>
    <%=get('postContent', '')%>
  <% } %>
</body>
</html>
