<%- await include('@/meta') %>

<%
const maintenance = _.cms('maintenance') || {}
if (maintenance.active) {
  // redirect to maintenance page
  %>
  <script>
    var unlockKey
    <% if (maintenance.unlock_key) { %>
      unlockKey = '<%= maintenance.unlock_key %>'
      if (location.hash === '#' + unlockKey) {
        sessionStorage.setItem('unlockKey', unlockKey)
      }
    <% } %>
    if (!location.pathname.startsWith('/maintenance/') && sessionStorage.getItem('unlockKey') !== unlockKey) {
      location.href = '/maintenance/'
    }
  </script>
  <%
}
%>

<script>
  if ('serviceWorker' in navigator) {
    navigator.serviceWorker.register('/sw.js').then(registration => {
      console.log('SW registered: ', registration)
    }).catch(registrationError => {
      console.log('SW registration failed: ', registrationError)
    })
  }
</script>
<link rel="stylesheet" type="text/css" href="<%= _.assetsPrefix || '' %>/storefront.css">

<%
// inject custom code
const customCode = _.cms('code') || {}
if (customCode.css) {
  %>
  <style>
    <%- customCode.css %>
  </style>
  <%
}
%>
<%- customCode.html_head %>
