$(document).ready(() => {
    checkCertificateValidity();
});

function checkCertificateValidity() {
    $.get("/establishments/check-certificate-validity", function (response) {
        window.is_cer_active = response.is_cer_active;
        const is_admin = response.is_admin;

        if (!response.is_cer_active) {
            Swal.fire({
                icon: "warning",

                html: `
                    <h2>${translateAndReplace('common_responses_and_messages.expired_csd_title')}</h2>

                    <p class="mt-4" style="font-size: 1.1rem; font-weight: 500;">
                        ${translateAndReplace(`common_responses_and_messages.${is_admin ? 'expired_csd' : 'expired_csd_common'}`)}
                    </p>

                    <p style="margin-top: 12px; font-size: 0.95rem;">
                        <strong>${translateAndReplace('neutral_words.validity')}:</strong> ${response.valid_from} → ${response.valid_to}
                    </p>

                    <p style="margin-top: 18px;">
                        ${translateAndReplace(`common_responses_and_messages.${is_admin ? 'expired_csd_instructions' : 'expired_csd_common_instructions'}`)}
                    </p>

                    <p style="margin-top: 16px; font-size: 0.9rem; color: #777;">
                        ${is_admin ? translateAndReplace('common_responses_and_messages.expired_csd_alternative') : ""}
                    </p>
                `,

                confirmButtonText: translateAndReplace("common_responses_and_messages.ok"),
            });

        }
    });
}
