{{ define "subscription" }}
{{ template "header" .}}
<section>
    <h2>Unsubscribe</h2>
    <p>Do you wish to unsubscribe from this mailing list?</p>
    <form method="post">
        <div>
            {{ if .Data.AllowBlocklist }}
                <p>
                    <input id="privacy-blocklist" type="checkbox" name="blocklist" value="true" /> <label for="privacy-blocklist">Also unsubscribe from all future e-mails.</label>
                </p>
            {{ end }}

            <p>
                <button type="submit" class="button" id="btn-unsub">Unsubscribe</button>
            </p>
        </div>
    </form>
</section>

{{ if or .Data.AllowExport .Data.AllowWipe }}
<form id="data-form" method="post" action="" onsubmit="return handleData()">
    <section>
        <h2>Privacy and data</h2>
        {{ if .Data.AllowExport }}
        <div class="row">
            <div class="one columns">
                <input id="privacy-export" type="radio" name="data-action" value="export" required />
            </div>
            <div class="ten columns">
                <label for="privacy-export"><strong>Export your data</strong></label>
                <br />
                A copy of your data will be e-mailed to you.
            </div>
        </div>
        {{ end }}

        {{ if .Data.AllowWipe }}
        <div class="row">
            <div class="one columns">
                <input id="privacy-wipe" type="radio" name="data-action" value="wipe" required />
            </div>
            <div class="ten columns">
                <label for="privacy-wipe"><strong>Wipe your data</strong></label>
                <br />
                Delete all your subscriptions and related data from our database permanently.
            </div>
        </div>
        {{ end }}
        <p>
            <input type="submit" value="Continue" class="button button-outline" />
        </p>
    </section>
</form>
<script>
    function handleData() {
        var a = document.querySelector('input[name="data-action"]:checked').value,
            f = document.querySelector("#data-form");
        if (a == "export") {
            f.action = "/subscription/export/{{ .Data.SubUUID }}";
            return true;
        } else if (confirm("Are you sure you want to delete all your subscription data permanently?")) {
            f.action = "/subscription/wipe/{{ .Data.SubUUID }}";
            return true;
        }
        return false;
    }
</script>
{{ end }}

{{ template "footer" .}}
{{ end }}