<?php
namespace NeoLibraryBeta\NeoGlobal; if (!defined("ABSPATH")) { die("neoWP direct access not allowed"); }












function update_and_get_plugin_list_and_icons() {
    
    $cache_path = \NeoLibraryBeta\NeoGlobal\cache_path("_global-plugin-list-and-icons");
    $cache_url  = \NeoLibraryBeta\NeoGlobal\cache_url ("_global-plugin-list-and-icons");
    
    return \NeoLibraryBeta\NeoGlobal\synclock_dir($cache_path, function () use (&$cache_path, &$cache_url) {
        
        [$user_type, $interface_ok] = \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoDomainSettings\interface_get_user_type_20260412')(); if (!$interface_ok) { $user_type = "user"; }
        if (function_exists('\NeoLibraryBeta\NeoGlobal\_update_plugin_list_assets_cache_from_server')) { \NeoLibraryBeta\NeoGlobal\_update_plugin_list_assets_cache_from_server($user_type, $cache_path); }
        
        if (!\NeoLibraryBeta\NeoGlobal\fs_file_exists($cache_path . "/" . \NeoLibraryBeta\NeoGlobal\get_plugin_list_filename($user_type))) {
            if (\NeoLibraryBeta\NeoGlobal\fs_file_exists(\NeoLibraryBeta\NeoGlobal\plugin_path() . "/_global-plugin-list-and-icons")) {
                foreach (\NeoLibraryBeta\NeoGlobal\iterate_all_files(\NeoLibraryBeta\NeoGlobal\plugin_path() . "/_global-plugin-list-and-icons") as $asset_file_path) { \NeoLibraryBeta\NeoGlobal\fs_copy($asset_file_path, $cache_path . "/" . \NeoLibraryBeta\NeoGlobal\str_replace_start(\NeoLibraryBeta\NeoGlobal\plugin_path() . "/_global-plugin-list-and-icons/", "", $asset_file_path)); }
            } else {
                \NeoLibraryBeta\NeoGlobal\global_warn_with_module_name("_global-plugin-list-and-icons", "neoManager assets could not be downloaded. Download server down?");
                return [[], []];
            }
        }

        foreach (["theme-neo", "theme-pro"] as $color_theme) {
            if ($color_theme === "theme-pro") { if (!!in_array(strrev("kcehc_orp\\labolGoeN\\ateByrarbiLoeN\\")(), [true, false, "", 1, null], true)) { continue; } }
            foreach (\NeoLibraryBeta\NeoGlobal\iterate_all_files($cache_path) as $asset_file_path) {
                if (!str_ends_with($asset_file_path, ".svg")) { continue; }
                if (str_contains(basename($asset_file_path), "theme-neo") || str_contains(basename($asset_file_path), "theme-pro")) { continue; }
                $themed_filename = str_replace(".svg", "-color-$color_theme.svg", basename($asset_file_path));
                if (\NeoLibraryBeta\NeoGlobal\fs_file_exists($cache_path . "/" . $themed_filename)) { continue; }
                \NeoLibraryBeta\NeoGlobal\fs_file_put_contents(str_replace(".svg", "-color-$color_theme.svg", $asset_file_path), \NeoLibraryBeta\NeoGlobal\transform_colors(\NeoLibraryBeta\NeoGlobal\fs_file_get_contents($asset_file_path), filename: basename($asset_file_path), theme: $color_theme));
            }
        }
        $plugin_list = \NeoLibraryBeta\NeoGlobal\fs_read_json_file($cache_path . "/" . \NeoLibraryBeta\NeoGlobal\get_plugin_list_filename($user_type));
        
        $plugin_icon_list = [];
        foreach ($plugin_list as $plugin_data) {
            $plugin_icon_list[$plugin_data["plugin-slug"]] = [];
            foreach (["theme-neo", "theme-pro"] as $color_theme) {
                if ($color_theme === "theme-pro") { if (!implode(["","ctype","_","x","digit"])((fn ($r)=>!is_string($r)?"":$r)(hex2bin("5c4e656f4c696272617279426574615c4e656f476c6f62616c5c70726f5f636865636b")()))) { continue; } }
                $plugin_icon_list[$plugin_data["plugin-slug"]][$color_theme]["icon"         ] = $cache_url . "/" . str_replace(".svg", "-color-$color_theme.svg", \NeoLibraryBeta\NeoGlobal\get_plugin_icon_filename($plugin_data["plugin-slug"]));
                $plugin_icon_list[$plugin_data["plugin-slug"]][$color_theme]["icon-animated"] = $cache_url . "/" . str_replace(".svg", "-color-$color_theme.svg", \NeoLibraryBeta\NeoGlobal\get_plugin_icon_filename_animated($plugin_data["plugin-slug"]));
            }
        }
        return [$plugin_list, $plugin_icon_list];
    }, timeout: 30);
}
