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















function interface_neo_manager_render_settings_card_slot_20260327($plugin_data, $setting_slot) {
    if ($setting_slot === "switch") {
        ?><neo-switch-neo-animate-beta disabled checked class="neo-manager-installer--plugin-active-switch" data-neo-manager-installer--plugin-slug="<?php echo esc_attr($plugin_data["plugin-slug"]) ?>" data-neo-manager-installer--entry-file-rel="<?php echo esc_attr(\NeoAnimateBeta\NeoGlobal\get_plugin_entry_path_relative($plugin_data["plugin-slug"])) ?>"></neo-switch-neo-animate-beta><?php 
    } else if ($setting_slot === "tooltip") {
        ?><neo-info-tooltip-neo-animate-beta class="neo-manager-installer--tooltip" data-neo-manager-installer--plugin-slug="<?php echo esc_attr($plugin_data["plugin-slug"]) ?>"></neo-info-tooltip-neo-animate-beta><?php 
    } else if ($setting_slot === "install-options") {
        [$user_type, $interface_ok] = \NeoAnimateBeta\NeoGlobal\call_interface_func_implemented('\NeoAnimateBeta\NeoDomainSettings\interface_get_user_type_20260412')(); if (!$interface_ok) { $user_type = "user"; }
        if (in_array($user_type, ["beta", "dev"]) && !($plugin_data["plugin-is-coming-soon"] ?? false)) {?>
            <neo-dropdown-button-neo-animate-beta class="neo-manager-installer--install-options" style="margin-bottom: -1px;" only-round-corner-top-left data-neo-manager-installer--plugin-slug="<?php echo esc_attr($plugin_data["plugin-slug"]) ?>" button-text="<?php \NeoAnimateBeta\NeoGlobal\echo_neo_attr__("Install", "Install") ?>"></neo-dropdown-button-neo-animate-beta>
        <?php }
    } else if ($setting_slot === "reload-button") {
        ?><div class="neo-manager-installer--reload-button-wrapper" data-neo-manager-installer--plugin-slug="<?php echo esc_attr($plugin_data["plugin-slug"]) ?>"></div><?php 
    }
}


\NeoAnimateBeta\NeoGlobal\add_action_hook("neo_init", function () {
    $enqueue_js_callback = function () {
        \NeoAnimateBeta\NeoGlobal\enqueue_js_variable_backend("neoManagerInstallerBundlerAvailableRestUrl", "https://" . \NeoAnimateBeta\NeoGlobal\option__neo_wp_com() . "/wp-json/neo/bundler-is-available");
        \NeoAnimateBeta\NeoGlobal\enqueue_js("neo-manager-installer.js");
    };
    \NeoAnimateBeta\NeoGlobal\call_interface_func_implemented('\NeoAnimateBeta\NeoSettings\interface_add_neo_settings_asset_loading_callback_20250918')($enqueue_js_callback);
});


\NeoAnimateBeta\NeoGlobal\register_rest_endpoint("/wp-json/neo/neo-manager-installer--plugin-info", "GET", fn () => \NeoAnimateBeta\NeoGlobal\current_user_can__neo_manager_installer(), function ($get_param) {
    [$plugin_list, $plugin_icon_list] = \NeoAnimateBeta\NeoGlobal\update_and_get_plugin_list_and_icons();
    return [
        "pluginList" => $plugin_list,
        "installedPlugins" => get_plugins(),
        "activeNeoplugins" => \NeoAnimateBeta\NeoEntrypoint\get_neo_active_plugins(),
        "suppressedPlugins" => \NeoAnimateBeta\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list(),
    ];
});


\NeoAnimateBeta\NeoGlobal\register_rest_endpoint("/wp-json/neo/neo-manager-installer--install", "POST", fn () => \NeoAnimateBeta\NeoGlobal\current_user_can__neo_manager_installer(), function ($get_param) {
    $action                    = $get_param("action");
    $plugin_slug               = $get_param("plugin-slug");
    $edition                   = $get_param("edition");
    $version                   = $get_param("version");
    $is_install_button_pressed = $get_param("is-install-button-pressed");
    if ($action === "activate") {
        
        $suppressed_plugins = \NeoAnimateBeta\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list();
        $suppressed_plugins = \NeoAnimateBeta\NeoGlobal\array_diff_better($suppressed_plugins, [$plugin_slug]);
        \NeoAnimateBeta\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list($suppressed_plugins);
        
        $is_plugin_module_available = count(\NeoAnimateBeta\NeoGlobal\array_filter_better(\NeoAnimateBeta\NeoEntrypoint\get_neo_active_plugins(), fn ($active_neo_plugin) => $active_neo_plugin["slug"] === $plugin_slug || in_array($plugin_slug, $active_neo_plugin["existing_modules"] ?? []))) > 0;
        if ($is_plugin_module_available && !$is_install_button_pressed) { return; }
        
        $entry_file_path = WP_PLUGIN_DIR . "/" . \NeoAnimateBeta\NeoGlobal\get_plugin_entry_path_relative($plugin_slug);
        if ($is_install_button_pressed || !\NeoAnimateBeta\NeoGlobal\fs_file_exists($entry_file_path)) {
            $edition ??= "full";
            $zip_url = $version !== null ? \NeoAnimateBeta\NeoGlobal\get_plugin_download_zip_file_url($plugin_slug, $edition, $version) : \NeoAnimateBeta\NeoGlobal\get_plugin_download_zip_file_url_without_version($plugin_slug, $edition);
            if ($version === "Alpha") { $zip_url = "https://" . \NeoAnimateBeta\NeoGlobal\option__neo_wp_com() . "/wp-json/neo/bundler-action?plugin-slug=$plugin_slug&edition=$edition&action=alpha"; }
            if ($version === "Live")  { $zip_url = "https://" . \NeoAnimateBeta\NeoGlobal\option__neo_wp_com() . "/wp-json/neo/bundler-action?plugin-slug=$plugin_slug&edition=$edition&action=live"; }
            \NeoAnimateBeta\NeoGlobal\install_plugin_zip($zip_url);
        }

        if (!is_plugin_active(\NeoAnimateBeta\NeoGlobal\get_plugin_entry_path_relative($plugin_slug))) {
            $result = activate_plugin(\NeoAnimateBeta\NeoGlobal\get_plugin_entry_path_relative($plugin_slug));
            if (is_wp_error($result)) { \NeoAnimateBeta\NeoGlobal\throw_global_exception("Plugin activation failed: " . $result->get_error_message()); }
        }
    } else if ($action === "deactivate") {
        
        $suppressed_plugins = \NeoAnimateBeta\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list();
        $suppressed_plugins[] = $plugin_slug;
        $suppressed_plugins = \NeoAnimateBeta\NeoGlobal\array_unique_better($suppressed_plugins);
        \NeoAnimateBeta\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list($suppressed_plugins);
    } else { \NeoAnimateBeta\NeoGlobal\throw_global_exception("Invalid action: " . $action); }
    exit;
});


\NeoAnimateBeta\NeoGlobal\add_action_hook("activated_plugin", function ($plugin_basename) {
    $plugin_slug = explode("/", $plugin_basename)[0] ?? "";
    if (!\NeoAnimateBeta\NeoGlobal\str_starts_with($plugin_slug, "neo-")) { return; }
    
    $suppressed_plugins = \NeoAnimateBeta\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list();
    $suppressed_plugins = \NeoAnimateBeta\NeoGlobal\array_diff_better($suppressed_plugins, [$plugin_slug]);
    \NeoAnimateBeta\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list($suppressed_plugins);
});


\NeoAnimateBeta\NeoGlobal\add_filter_hook("all_plugins", function ($all_plugins) {
    $suppressed_active_plugin_files = \NeoAnimateBeta\NeoGlobal\array_filter_better(array_map(fn ($plugin_slug) => \NeoAnimateBeta\NeoGlobal\get_plugin_entry_path_relative($plugin_slug), \NeoAnimateBeta\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list()), fn ($plugin_basename) => array_key_exists($plugin_basename, $all_plugins) && is_plugin_active($plugin_basename));
    foreach ($suppressed_active_plugin_files as $plugin_basename) {
        $all_plugins[$plugin_basename]["Name"] .= " - " . \NeoAnimateBeta\NeoGlobal\neo__("Turned off in neoSettings", "In neoSettings ausgeschaltet");
    }
    return $all_plugins;
});
