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


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


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


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

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

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

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


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

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


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