<% if user %>
    <% if subscriptions.includes? ucid %>
            <form action="/subscription_ajax?action_remove_subscriptions=1&c=<%= ucid %>&referer=<%= env.get("current_page") %>" method="post">
                <input type="hidden" name="csrf_token" value="<%= HTML.escape(env.get?("csrf_token").try &.as(String) || "") %>">
                <button data-type="unsubscribe" id="subscribe" class="pure-button pure-button-primary">
                    <b><input style="all:unset" type="submit" value="<%= translate(locale, "Unsubscribe") %> | <%= sub_count_text %>"></b>
                </button>
            </form>
    <% else %>
            <form action="/subscription_ajax?action_create_subscription_to_channel=1&c=<%= ucid %>&referer=<%= env.get("current_page") %>" method="post">
                <input type="hidden" name="csrf_token" value="<%= HTML.escape(env.get?("csrf_token").try &.as(String) || "") %>">
                <button data-type="subscribe" id="subscribe" class="pure-button pure-button-primary">
                    <b><input style="all:unset" type="submit" value="<%= translate(locale, "Subscribe") %> | <%= sub_count_text %>"></b>
                </button>
            </form>
    <% end %>

    <script id="subscribe_data" type="application/json">
    <%=
    {
        "ucid" => ucid,
        "author" => HTML.escape(author),
        "sub_count_text" => HTML.escape(sub_count_text),
        "csrf_token" => URI.encode_www_form(env.get?("csrf_token").try &.as(String) || ""),
        "subscribe_text" => HTML.escape(translate(locale, "Subscribe")),
        "unsubscribe_text" => HTML.escape(translate(locale, "Unsubscribe"))
    }.to_pretty_json
    %>
    </script>
    <script src="/js/subscribe_widget.js?v=<%= ASSET_COMMIT %>"></script>
<% else %>
        <a id="subscribe" class="pure-button pure-button-primary"
            href="/login?referer=<%= env.get("current_page") %>">
            <b><%= translate(locale, "Subscribe") %> | <%= sub_count_text %></b>
        </a>
<% end %>
