//necesito  expandir la funcionalidad de esta funcion, y indicar especificamente, indicar cuales script no deben cargar si el usuario no esta logeado (entorno wordpress)
//Script principal
function scriptsOrdenados()
{
    $dev_mode = true;
    $error_log = [];

    $script_handles = [
        'ajaxPage' => '5.0.11',
        'autorows' => '1.0.1',
        'fan' => '1.0.36',
        'stripeAccion' => '1.0.6',
        'reproductor' => '2.1.2',
        'stripepro' => '1.0.8',
        'progreso' => '1.0.23',
        'modal' => '1.0.22',
        'alert' => '1.0.4',
        'submenu' => '1.2.15',
        'descargas' => '2.0.1',
        'pestanas' => '1.1.10',
        'tagify' => '2.0.1',
        'wavesDos' => '1.0.1',
        'configPerfil' => '1.0.14',
        'diferido-post' => '4.0.0',
        'registro' => '1.0.12',
        'colab' => '1.0.2',
        'grained' => '1.0.3',
        'subida' => '1.1.21',
        'RS' => '1.0.1',
        'tagsPosts' => '1.0.1',
        'hashs' => '1.0.1',
        'background' => '1.0.1',
        //'formSubida' => '4.1.56',
        'ajax-submit' => '2.1.38',
        'formscript' => '1.1.11',
        'genericAjax' => '2.1.13',
        'wavejs' => ['2.0.12', ['jquery', 'wavesurfer']],
        'inversores' => '1.0.4',
        'likes' => '2.0.1',
        'galleV2' => '2.0.1',
    ];

    foreach ($script_handles as $handle => $data) {
        $version = is_array($data) ? $data[0] : $data;
        $deps = is_array($data) && isset($data[1]) ? $data[1] : [];
        $version = $dev_mode ? $version . '.' . mt_rand() : $version;

        $script_url = get_template_directory_uri() . "/js/{$handle}.js";
        if (!file_exists(get_template_directory() . "/js/{$handle}.js")) {
            $error_log[] = "Error: El archivo {$handle}.js no existe.";
            continue;
        }

        wp_enqueue_script(
            $handle,
            $script_url,
            $deps,
            $version,
            true
        );
    }

    $nonce = wp_create_nonce('wp_rest');
    wp_localize_script('galleV2', 'galleV2', array(
        'nonce' => $nonce,
        'apiUrl' => esc_url_raw(rest_url('galle/v2/guardarMensaje/')),
        'emisor' => get_current_user_id()
    ));

    // Scripts externos
    wp_enqueue_script('chart-js', 'https://cdn.jsdelivr.net/npm/chart.js', [], null, true);
    wp_enqueue_script('chartjs-adapter-date-fns', 'https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns', ['chart-js'], null, true);
    wp_enqueue_script('wavesurfer', 'https://unpkg.com/wavesurfer.js', [], '7.7.6', true);
    wp_enqueue_script('jquery');

    // Localización de scripts
    $ajax_url = admin_url('admin-ajax.php');
    wp_localize_script('subida', 'my_ajax_object', ['ajax_url' => $ajax_url]);
    wp_localize_script('social-post-script', 'my_ajax_object', [
        'ajax_url' => $ajax_url,
        'social_post_nonce' => wp_create_nonce('social-post-nonce'),
    ]);
    wp_localize_script('my-ajax-script', 'ajax_params', array(
        'ajax_url' => admin_url('admin-ajax.php')
    ));

    wp_localize_script('wavejs', 'ajax_params', ['ajaxurl' => $ajax_url]);
    wp_localize_script('form-script', 'wpData', ['isAdmin' => current_user_can('administrator')]);

    // Registrar errores si los hay
    if (!empty($error_log)) {
        error_log("Errores en scriptsOrdenados: " . print_r($error_log, true));
    }
}

add_action('wp_enqueue_scripts', 'scriptsOrdenados');