{{ if (and (not .Params.hide_feedback) (.Site.Params.ui.feedback.enable)) -}}
{{ with .Site.Params.ui.feedback -}}
<style>
  .feedback--answer {
    display: inline-block;
  }
  .feedback--answer-no {
    margin-left: 1em;
  }
  .feedback--response {
    display: none;
    margin-top: 1em;
  }
  .feedback--response__visible {
    display: block;
  }
</style>
<div class="d-print-none">
<h2 class="feedback--title">{{- i18n "feedback_title" -}}</h2>
<p class="feedback--question">{{- i18n "feedback_question" -}}</p>
<button class="btn btn-primary mb-4 feedback--answer feedback--answer-yes">{{- i18n "feedback_positive" -}}</button>
<button class="btn btn-primary mb-4 feedback--answer feedback--answer-no">{{- i18n "feedback_negative" -}}</button>
<p class="feedback--response feedback--response-yes">
  {{ .yes | safeHTML }}
</p>
<p class="feedback--response feedback--response-no">
  {{ .no | safeHTML }}
</p>
</div>
<script>
  const yesButton = document.querySelector('.feedback--answer-yes');
  const noButton = document.querySelector('.feedback--answer-no');
  const yesResponse = document.querySelector('.feedback--response-yes');
  const noResponse = document.querySelector('.feedback--response-no');
  const disableButtons = () => {
    yesButton.disabled = true;
    noButton.disabled = true;
  };
  const sendFeedback = (value) => {
    if (typeof gtag !== 'function') return;
    gtag('event', 'page_helpful', {
      'event_category': 'Helpful',
      'event_label': window.location.pathname,
      'value': value
    });
  };
  yesButton.addEventListener('click', () => {
    yesResponse.classList.add('feedback--response__visible');
    disableButtons();
    {{ $maxValue := .max_value | default 100 -}}
    sendFeedback({{ $maxValue }});
  });
  noButton.addEventListener('click', () => {
    noResponse.classList.add('feedback--response__visible');
    disableButtons();
    sendFeedback(0);
  });
</script>
{{ end -}}
<br />
{{ end -}}
