<?php
namespace NeoLibraryFull\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-library-full 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(\NeoLibraryFull\NeoGlobal\get_plugin_entry_path_relative($plugin_data["plugin-slug"])) ?>"></neo-switch-neo-library-full><?php 
    } else if ($setting_slot === "tooltip") {
        ?><neo-info-tooltip-neo-library-full class="neo-manager-installer--tooltip" data-neo-manager-installer--plugin-slug="<?php echo esc_attr($plugin_data["plugin-slug"]) ?>"></neo-info-tooltip-neo-library-full><?php 
    } else if ($setting_slot === "install-options") {
        [$user_type, $interface_ok] = \NeoLibraryFull\NeoGlobal\call_interface_func_implemented('\NeoLibraryFull\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-library-full 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 \NeoLibraryFull\NeoGlobal\echo_neo_attr__("Install", "Install") ?>"></neo-dropdown-button-neo-library-full>
        <?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 
    }
}


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


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


\NeoLibraryFull\NeoGlobal\register_rest_endpoint("/wp-json/neo/neo-manager-installer--install", "POST", fn () => \NeoLibraryFull\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 = \NeoLibraryFull\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list();
        $suppressed_plugins = \NeoLibraryFull\NeoGlobal\array_diff_better($suppressed_plugins, [$plugin_slug]);
        \NeoLibraryFull\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list($suppressed_plugins);

        $is_plugin_module_available = count(\NeoLibraryFull\NeoGlobal\array_filter_better(\NeoLibraryFull\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 . "/" . \NeoLibraryFull\NeoGlobal\get_plugin_entry_path_relative($plugin_slug);
        if ($is_install_button_pressed || !\NeoLibraryFull\NeoGlobal\fs_file_exists($entry_file_path)) {
            $edition ??= "full";
            $zip_url = $version !== null ? \NeoLibraryFull\NeoGlobal\get_plugin_download_zip_file_url($plugin_slug, $edition, $version) : \NeoLibraryFull\NeoGlobal\get_plugin_download_zip_file_url_without_version($plugin_slug, $edition);
            if ($version === "Alpha") { $zip_url = "https://" . \NeoLibraryFull\NeoGlobal\option__neo_wp_com() . "/wp-json/neo/bundler-action?plugin-slug=$plugin_slug&edition=$edition&action=alpha"; }
            if ($version === "Live")  { $zip_url = "https://" . \NeoLibraryFull\NeoGlobal\option__neo_wp_com() . "/wp-json/neo/bundler-action?plugin-slug=$plugin_slug&edition=$edition&action=live"; }
            \NeoLibraryFull\NeoGlobal\install_plugin_zip($zip_url);
        }

        if (!is_plugin_active(\NeoLibraryFull\NeoGlobal\get_plugin_entry_path_relative($plugin_slug))) {
            $result = activate_plugin(\NeoLibraryFull\NeoGlobal\get_plugin_entry_path_relative($plugin_slug));
            if (is_wp_error($result)) { \NeoLibraryFull\NeoGlobal\throw_global_exception("Plugin activation failed: " . $result->get_error_message()); }
        }
    } else if ($action === "deactivate") {

        $suppressed_plugins = \NeoLibraryFull\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list();
        $suppressed_plugins[] = $plugin_slug;
        $suppressed_plugins = \NeoLibraryFull\NeoGlobal\array_unique_better($suppressed_plugins);
        \NeoLibraryFull\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list($suppressed_plugins);
    } else { \NeoLibraryFull\NeoGlobal\throw_global_exception("Invalid action: " . $action); }
    exit;
});


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

    $suppressed_plugins = \NeoLibraryFull\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list();
    $suppressed_plugins = \NeoLibraryFull\NeoGlobal\array_diff_better($suppressed_plugins, [$plugin_slug]);
    \NeoLibraryFull\NeoGlobal\option__neo_manager_installer__suppressed_plugins_list($suppressed_plugins);
});


\NeoLibraryFull\NeoGlobal\add_filter_hook("all_plugins", function ($all_plugins) {
    $suppressed_active_plugin_files = \NeoLibraryFull\NeoGlobal\array_filter_better(array_map(fn ($plugin_slug) => \NeoLibraryFull\NeoGlobal\get_plugin_entry_path_relative($plugin_slug), \NeoLibraryFull\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"] .= " - " . \NeoLibraryFull\NeoGlobal\neo__("Turned off in neoSettings", "In neoSettings ausgeschaltet");
    }
    return $all_plugins;
});
