(function($) {
    'use strict';

    $(document).ready(function() {
        // After successful connection, open Peligent dashboard in a new tab
        var urlParams = new URLSearchParams(window.location.search);
        if (urlParams.get('peligent_connected') === '1') {
            var siteUrl = encodeURIComponent(window.location.origin + '/');
            window.open('https://app.peligent.com/dashboard/websites?site_url=' + siteUrl, '_blank');
            // Clean up the URL parameter to prevent re-triggering on refresh
            urlParams.delete('peligent_connected');
            var cleanUrl = window.location.pathname + '?' + urlParams.toString();
            window.history.replaceState({}, '', cleanUrl);
        }
    });
})(jQuery);
