{# Paddle.js — include only on pages with checkout flows via {% block paddle %}. #}
<script defer src="https://cdn.paddle.com/paddle/v2/paddle.js"></script>
<script>
  document.addEventListener('DOMContentLoaded', function() {
    {% if config.PADDLE_ENVIRONMENT == "sandbox" %}
    Paddle.Environment.set("sandbox");
    {% endif %}
    {% if config.PADDLE_CLIENT_TOKEN %}
    Paddle.Initialize({
      token: "{{ config.PADDLE_CLIENT_TOKEN }}",
      eventCallback: function(ev) {
        if (ev.name === "checkout.error") console.error("Paddle checkout error:", ev.data);
      },
      checkout: {
        settings: {
          displayMode: "overlay",
          theme: "light",
          locale: "en",
        }
      }
    });
    {% else %}
    console.warn("Paddle: PADDLE_CLIENT_TOKEN not configured");
    {% endif %}
  });
</script>
