<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js" integrity="sha384-I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.min.js" integrity="sha384-fbbOQedDUMZZ5KreZpsbe1LCZPVmfTnH7ois6mU1QK+m14rQ1l2bGBq41eYeM/fS" crossorigin="anonymous"></script>
<script type="text/javascript" src="<%= typeof pathDepth != 'undefined' ? pathDepth : './..' %>/javascripts/app.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/gh/AmauriC/tarteaucitron.js@1.11.0/tarteaucitron.js"></script>
<script type="text/javascript">
  tarteaucitron.init({
    "privacyUrl": "", /* Privacy policy url */
    "bodyPosition": "bottom", /* or top to bring it as first element for accessibility */
    "hashtag": "#tarteaucitron", /* Open the panel with this hashtag */
    "cookieName": "tarteaucitron", /* Cookie name */
    "orientation": "bottom", /* Banner position (top - bottom) */
    "groupServices": false, /* Group services by category */
    "serviceDefaultState": "wait", /* Default state (true - wait - false) */
    "showAlertSmall": false, /* Show the small banner on bottom right */
    "cookieslist": false, /* Show the cookie list */
    "closePopup": false, /* Show a close X on the banner */
    "showIcon": true, /* Show cookie icon to manage cookies */
    //"iconSrc": "", /* Optionnal: URL or base64 encoded image */
    "iconPosition": "BottomRight", /* BottomRight, BottomLeft, TopRight and TopLeft */
    "adblocker": false, /* Show a Warning if an adblocker is detected */
    "DenyAllCta" : true, /* Show the deny all button */
    "AcceptAllCta" : true, /* Show the accept all button when highPrivacy on */
    "highPrivacy": true, /* HIGHLY RECOMMANDED Disable auto consent */
    "handleBrowserDNTRequest": false, /* If Do Not Track == 1, disallow all */
    "removeCredit": true, /* Remove credit link */
    "moreInfoLink": true, /* Show more info link */
    "useExternalCss": true, /* If false, the tarteaucitron.css file will be loaded */
    "useExternalJs": false, /* If false, the tarteaucitron.js file will be loaded */
    //"cookieDomain": ".my-multisite-domaine.fr", /* Shared cookie for multisite */
    "readmoreLink": "", /* Change the default readmore link */
    "mandatory": true, /* Show a message about mandatory cookies */
    "mandatoryCta": true /* Show the disabled accept button when mandatory on */
    });
</script>

<script type="text/javascript">
  tarteaucitron.user.googleFonts = ['Roboto', 'Covered By Your Grace'];
  (tarteaucitron.job = tarteaucitron.job || []).push('googlefonts');
</script>

<% if (locals.hasTracking === true) { %>
  <script type="text/javascript">
    /* Matomo opt-in / opt-out */
    tarteaucitron.user.matomoId = 146;
    tarteaucitron.user.matomoHost = "https://matomo.inclusion.beta.gouv.fr/";
    (tarteaucitron.job = tarteaucitron.job || []).push('matomo');
  </script>
<% } %>

<% if (locals.hasIframeResizer === true) { %>
<script src="//stats.inclusion.beta.gouv.fr/app/iframeResizer.js"></script>
<script>
  iFrameResize({}, '#iframeMetabase');
</script>
<% } %>

<% if (locals.hasTallyPopup || locals.hasTallyEmbed === true) { %>
  <script src="https://tally.so/widgets/embed.js"></script>
<% } %>

<% if (locals.hasTallyEmbed === true) { %>
  <script defer>
    Tally.loadEmbeds();
  </script>
<% } %>

<% if (locals.hasTallyPopup) { %>
  <script defer>
    // Any given Tally popup will not be shown more than once every `minDaysBetweenDisplays` days.
    const minDaysBetweenDisplays = 14;
    const delayBeforeShowingPopupInSeconds = 45;
    const formId = '<%= locals.hasTallyPopup %>';
    const key = 'statsTallyPopupLastShown-' + formId;
    const todaysDate = new Date();

    function supportsLocalStorage() {
      try {
        return 'localStorage' in window && window['localStorage'] !== null;
      } catch (e) {
        return false;
      }
    };

    function stopShowingPopupForAWhile() {
      localStorage.setItem(key, JSON.stringify(todaysDate));
    }

    function displayTallyPopup() {
      window.Tally.openPopup(formId, {
        emoji: {
          text: "ðŸ‘‹",
          animation: "wave"
        },
        onClose: () => {
          stopShowingPopupForAWhile();
        },
        onSubmit: () => {
          stopShowingPopupForAWhile();
        }
      });
    };

    function shouldDisplayTallyPopup() {
      if (!supportsLocalStorage()) {
        return true;
      }
      infoKey = localStorage.getItem(key);
      if (infoKey) {
        const lastShown = Date.parse(JSON.parse(localStorage.getItem(key)));
        const milliSecondsElapsed = todaysDate - lastShown;
        const daysElapsed = milliSecondsElapsed / (1000 * 3600 * 24);
        if (daysElapsed <= minDaysBetweenDisplays) {
          return false;
        };
      };
      return true;
    };

    if (shouldDisplayTallyPopup()) {
      setTimeout(displayTallyPopup, delayBeforeShowingPopupInSeconds * 1000);
    };
  </script>
<% } %>
