<% include ./main.ejs %>
<%let preview = false;
let withQueries = false;
ampStory.cuts.map(currentSlide => { %>
<amp-story-page auto-advance-after="<%=currentSlide ? currentSlide.duration : 10%>s" id="<%= currentSlide.position %>" style="background: #eeeeee">
  <amp-story-grid-layer template="fill"><div class="bg-wrapper" style="background: <%=getBgColor(currentSlide)%>;"></div></amp-story-grid-layer>
  <% currentSlide.layers.sort((first, second) => {
    var keyA = first.position,
      keyB = second.position;
    if (keyA < keyB) return -1;
    if (keyA > keyB) return 1;
    return 0;
  }) %>
  <% currentSlide && currentSlide.layers && currentSlide.layers.map(layer => { %>
    <% switch (layer.type) {
    	case 'text':
      case 'html': %>
        <amp-story-grid-layer template="horizontal">
          <%- include('./components/text-layer.ejs', {withEvent: false, withAnimations: true, layer, currentSlide, preview})%>
        </amp-story-grid-layer>
        <% break;

      case 'shape': %>
        <amp-story-grid-layer template="horizontal">
          <%- include('./components/shape-layer.ejs', {withEvent: false, withAnimations: true, layer, currentSlide, preview})%>
        </amp-story-grid-layer>
        <% break;

      case 'image':
      case 'gifs': %>
        <% if (layer.content.image && layer.content.image) { %>
          <% if (((!['pan-left', 'pan-right', 'pan-up', 'pan-down'].includes(layer.settings.animateIn) || !layer.settings.animateIn) && (!layer.content.compressed && !zipExport)) ||
            (((layer.content.compressed || zipExport) && !layer.settings.layerSettings.fullscreen)) ||
            ['rotate-in-right', 'rotate-in-left', 'twirl-in'].includes(layer.settings.animateIn) && (layer.content.compressed || zipExport)) { %>
            <amp-story-grid-layer template="horizontal">
              <%- include('./components/image-layer.ejs', {layer, currentSlide, preview})%>
            </amp-story-grid-layer>
          <% } else { %>
            <amp-story-grid-layer template="fill">
              <%- include('layers/image.ejs', {withAnimations: true, layer, zipExport }); %>
            </amp-story-grid-layer>
          <% } %>
        <% } %>
        <% break

      case 'video': %>
        <% if (layer.content.video && layer.content.video) { %>
          <% if (((!['pan-left', 'pan-right', 'pan-up', 'pan-down'].includes(layer.settings.animateIn) || !layer.settings.animateIn) && (!layer.content.compressed && !zipExport)) ||
            (((layer.content.compressed || zipExport) && !layer.settings.layerSettings.fullscreen)) ||
            ['rotate-in-right', 'rotate-in-left', 'twirl-in'].includes(layer.settings.animateIn) && (layer.content.compressed || zipExport)) { %>
            <amp-story-grid-layer template="horizontal">
              <%- include('./components/video-layer.ejs', {layer, currentSlide, preview})%>
            </amp-story-grid-layer>
          <% } else { %>
            <amp-story-grid-layer template="fill">
              <%- include('layers/video.ejs', {withAnimations: true, layer, duration: currentSlide.duration, zipExport }); %>
            </amp-story-grid-layer>
          <% } %>
        <% } %>
        <% break
        } %>
  <% }) %>
  <% currentSlide && currentSlide.layers && currentSlide.layers.map((layer, layerIndex) => { %>
  <%if (currentSlide.position >= 1 && ampStory.type !== 'amp-template' && layer.settings.ctaLayerSettings && layer.type === 'cta-link' && (layer.settings.ctaLayerSettings.link || layer.settings.ctaLayerSettings.withQueries)) {%>
    <% if (layer.settings.ctaLayerSettings.withQueries) { withQueries = true }%>
    <%- include('components/cta-layer.ejs', {layer, currentSlide}); %>
  <% } else if (ampStory.type === 'amp-template' && layer.settings.ctaLayerSettings && layer.type === 'cta-link' && layer.settings.ctaLayerSettings.link) {%>
    <%- include('./components/dirty-cta-layer.ejs', {withEvent: false, layer, currentSlide})%>
  <% } %>
  <% }) %>
</amp-story-page>
<% }) %>
<%if (ampStory.googleAnalytics && ampStory.googleAnalytics.trackingAccountId) {%>
  <%- include('analytics.ejs', {analyticsKey: ampStory.googleAnalytics.trackingAccountId})%>
<% } %>
<%if (ampStory.customerAnalyticsKey) {%>
  <%- include('customerAnalytics.ejs', {analyticsKey: ampStory.customerAnalyticsKey})%>
<% } %>
<% snippets.map(snippet => { %>
  <%- Buffer.from(snippet.bodyCode || '', 'base64').toString() %>
<% })%>
<%if (withQueries) { %>
  <%- include('cta-queries.ejs')%>
<% } %>

