import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/app.jsx'
import { NitroSdk } from '../nitro.sdk'

window.sdk = NitroSdk

// polyfills
import 'intersection-observer'
import smoothscroll from 'smoothscroll-polyfill'
smoothscroll.polyfill()

// css
import './external-css/fonts.css'
import './external-css/daypicker.css'
import './external-css/extras.css'
import './external-css/root.css'

document.addEventListener('DOMContentLoaded', () => {
  if (process.env.NODE_ENV === 'production') {
    const Runtime = require('offline-plugin/runtime')
    Runtime.install()
  } else {
    console.info('Service Worker is disabled in development.')
  }

  const shell = document.getElementById('app-shell')
  NitroSdk.loadData()
    .then(() => {
      ReactDOM.render(<App />, shell)
    })
    .catch(err => {
      const fixBtn = `
      <h2>fatal error!</h2>
      <p>Sign out,
      and hopefully your issue will be fixed
      when you sign back in.</p>
      <button onclick="window.sdk.signOut()">sign out</button>
      <h3>error message</h3>`
      console.error(err)
      shell.innerHTML = fixBtn + err
    })
})

// we have fancy single page routing that does this for us
if ('scrollRestoration' in history) {
  history.scrollRestoration = 'manual'
}

@@ -849,38 +849,67 @@
 cons
-t fixBtn = %60%0A      %3Ch2%3Ef
+ole.error(err)%0A      const headerText = '%3Ch2%3ENitro: F
 atal 
-e
+E
 rror
@@ -918,18 +918,55 @@
 /h2%3E
+'
 %0A      
-%3Cp%3E
+let bodyText = %60%0A        %3Cp%3E%0A          
 Sign
@@ -970,22 +970,16 @@
 ign out,
-%0A     
  and hop
@@ -1009,22 +1009,16 @@
 be fixed
-%0A     
  when yo
@@ -1036,13 +1036,24 @@
  in.
+%0A        
 %3C/p%3E%0A
+  
     
@@ -1097,14 +1097,14 @@
 ()%22%3E
-s
+S
 ign 
-o
+O
 ut%3C/
@@ -1121,19 +1121,21 @@
     
+  
 %3Ch3%3E
-e
+E
 rror 
-m
+M
 essa
@@ -1145,71 +1145,625 @@
 /h3%3E
-%60%0A      console.error(err)%0A      shell.innerHTML = fixBtn + err
+%0A        $%7Berr.message%7D%0A      %60%0A      if (%0A        err.message.toLowerCase().match('indexeddb') %7C%7C%0A        err.message.match('database')%0A      ) %7B%0A        bodyText = %60%0A          %3Cp%3EIndexedDB is not supported in this browser! The most likely reasons for this are either:%3C/p%3E%0A          %3Cul%3E%0A            %3Cli%3EYou are currently private browsing%3C/li%3E%0A            %3Cli%3EYour browser is outdated%3C/li%3E%0A          %3C/ul%3E%0A          %3Cp%3EPlease contact support if you have further issues.%3C/p%3E%0A        %60%0A      %7D%0A      shell.innerHTML = headerText + bodyText%0A      shell.style.fontFamily = 'sans-serif'%0A      shell.style.padding = '25px'
 %0A   

Add Custom Error for IndexedDB Failures