{% block install_button %}
    {% include 'django_spire/auth/button/android_install_button.html' with button_type='btn-app-primary' %}
{% endblock %}

<script type="application/javascript">
    let android_install_prompt = null;
    let android_install_button = document.querySelector("#android-install-button");

    window.addEventListener("beforeinstallprompt", (event) => {
        event.preventDefault();
        android_install_prompt = event;
        android_install_button.removeAttribute("hidden");
    });

    android_install_button.addEventListener("click", async () => {
        if (!android_install_prompt) {
            return;
        }
        const result = await android_install_prompt.prompt();
        disableInAppInstallPrompt();
    });

    window.addEventListener("appinstalled", () => {
        disableInAppInstallPrompt();
    });

    function disableInAppInstallPrompt() {
        android_install_prompt = null;
        android_install_button.setAttribute("hidden", "");
    }
</script>
