/* tslint:disable */

// _document is only rendered on the server side and not on the client side
// Event handlers like onClick can't be added to this file

// ./pages/_document.js
import React from 'react';
import getConfig from 'next/config';

import Document, { Html, Head, Main, NextScript } from 'next/document';

const { serverRuntimeConfig } = getConfig();

class MyDocument extends Document {
  static async getInitialProps(ctx: any) {
    const initialProps = await Document.getInitialProps(ctx);
    serverRuntimeConfig;
    return { ...initialProps };
  }

  render() {
    const script: any = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
    new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
    j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','${serverRuntimeConfig.GTM_ID}');`;

    return (
      <Html>
        <Head>
          {serverRuntimeConfig.GTM_ID && (
            <script
              dangerouslySetInnerHTML={{
                __html: script,
              }}
            />
          )}

          <meta name="apple-itunes-app" content="app-id=544945754" />
          <meta name="google-play-app" content="app-id=is.nova.app" />
          <link rel="apple-touch-icon" href="/assets/nova-app-icon.png" />
          <link rel="android-touch-icon" href="/assets/nova-app-icon.png" />
        </Head>
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

export default MyDocument;
