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


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


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


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

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

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

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


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

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


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