(function ($) {
    'use strict';

    function openTaskPanel() {
        var params = new URLSearchParams(window.location.search);
        if (!params.get('ccpr_task')) { return; }
        var tab = document.querySelector('a[href="#ccpr_product_data"]');
        if (!tab) { return; }

        if ($) { $(tab).trigger('click'); }
        else { tab.click(); }

        window.setTimeout(function () {
            var panel = document.getElementById('ccpr_product_data');
            if (panel) { panel.scrollIntoView({ block: 'center' }); }
        }, 120);
    }

    function scheduleTaskPanel() {
        [100, 500, 1200].forEach(function (delay) {
            window.setTimeout(openTaskPanel, delay);
        });
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', scheduleTaskPanel, { once: true });
    } else {
        scheduleTaskPanel();
    }
}(window.jQuery));
