
// ==================
// User Subscriptions
// ==================   

$(document).ready(function () {

    var $application = $("#APPLICATION_MNEMONIC").val(), $sessionStorage = JSON.parse(sessionStorage.getItem($application) || "{}");

    // -------------------
    // Subscriptions Table
    // -------------------

    $("#usersubscription-table tbody").on("click touch", "tr", function (e) {

        e.preventDefault();

        let subscription_status = $(this).find("td.usersubscription_status").text().trim(); // Adjust class as needed

        if (subscription_status === "EXPIRED") {

            $("#continue-dialog .modal-header")
                    .removeClass()
                    .addClass("modal-header bg-danger p-1 ps-3")
                    .html('<i class="bi bi-cone-striped text-white me-2"></i> <span class="text-white">Subscription Expired</span>');

            $("#continue-dialog .btnClose")
                    .removeClass("btn-primary")
                    .addClass("btn-danger");

            $("#continue-dialog")
                    .removeClass()
                    .addClass("modal confirm-delete-note")
                    .find(".modal-title").html("Subscription Expired").end()
                    .find(".modal-body").html("This subscription has expired. Please contact sales to renew.").end()
                    .modal("show");

            return;
        }

        $("#spinner-dialog").modal("show");

        $sessionStorage.action = "Subscriptions.goToSubscription";
        $sessionStorage.subscription_serial = $(this).data("subscription-serial");
        $sessionStorage.userSubscriptions = "Subscriptions.userSubscriptions";

        sessionStorage.setItem($application, JSON.stringify($sessionStorage));

        formSubmit($sessionStorage);

    });

});