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







\NeoLibraryBeta\NeoGlobal\val("neo_reset__actions", []);
function interface_register_neo_reset_action_20260410($id, $button_text, $confirm_title, $confirm_text, $action_callback) {
    \NeoLibraryBeta\NeoGlobal\val("neo_reset__actions", array_merge(\NeoLibraryBeta\NeoGlobal\val("neo_reset__actions"), [[
        "id" => $id,
        "button_text" => $button_text,
        "confirm_title" => $confirm_title,
        "confirm_text" => $confirm_text,
        "action_callback" => $action_callback,
    ]]));
}


\NeoLibraryBeta\NeoGlobal\add_action_hook("neo_init", function () {
    
    interface_register_neo_reset_action_20260410(
        id: "neo-reset--delete-localstorage-and-cookies", button_text: \NeoLibraryBeta\NeoGlobal\neo__("Clear cookies and localStorage", "Cookies und localStorage löschen"), confirm_title: \NeoLibraryBeta\NeoGlobal\neo__("Delete all neoCookies and localStorage?", "Alle neoCookies und localStorage löschen?"), confirm_text: \NeoLibraryBeta\NeoGlobal\neo__("Are you sure you want to delete all cookies and localStorage data? For example notice dialogs appear again.", "Möchtest du wirklich alle Cookies und gespeicherten lokalen Daten löschen? Dadurch werden z.B. Hinweisdialoge wieder angezeigt."),
        action_callback: function () {}
    );
    interface_register_neo_reset_action_20260410(
        id: "neo-reset--clear-cache", button_text: \NeoLibraryBeta\NeoGlobal\neo__("Clear cache", "Cache leeren"), confirm_title: \NeoLibraryBeta\NeoGlobal\neo__("Clear all caches?", "Alle Caches leeren?"), confirm_text: \NeoLibraryBeta\NeoGlobal\neo__("Are you sure you want to clear all cache folders and third-party caches?", "Möchtest du wirklich alle Cache-Ordner und Drittanbieter-Caches löschen?"),
        action_callback: function () { \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoGlobal\interface_all_bundles_clear_cache_20260202', throw_if_interface_not_ok: true)(force: true); }
    );
    interface_register_neo_reset_action_20260410(
        id: "neo-reset--delete-settings", button_text: \NeoLibraryBeta\NeoGlobal\neo__("Reset settings", "Einstellungen zurücksetzen"), confirm_title: \NeoLibraryBeta\NeoGlobal\neo__("Reset all plugin settings?", "Alle Plugin-Einstellungen zurücksetzen?"), confirm_text: \NeoLibraryBeta\NeoGlobal\neo__("Are you sure you want to delete all plugin settings?", "Möchtest du wirklich alle Plugin-Einstellungen löschen?"),
        action_callback: function () { \NeoLibraryBeta\NeoGlobal\delete_all_neo_options(); }
    );
    interface_register_neo_reset_action_20260410(
        id: "neo-reset--delete-license-cache", button_text: \NeoLibraryBeta\NeoGlobal\neo__("Delete license cache", "Lizenz-Cache löschen"), confirm_title: \NeoLibraryBeta\NeoGlobal\neo__("Delete license cache?", "Lizenz-Cache löschen?"), confirm_text: \NeoLibraryBeta\NeoGlobal\neo__("Are you sure you want to delete the license check cache? The license itself will remain intact.", "Möchtest du wirklich den Lizenzprüfungs-Cache löschen? Die Lizenz selbst bleibt unberührt."),
        action_callback: function () { \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoGlobal\interface_all_bundles_clear_license_cache_20260131', throw_if_interface_not_ok: true)(); }
    );

    usort(\NeoLibraryBeta\NeoGlobal\val("neo_reset__actions"), function ($a, $b) {
             if ( str_starts_with($a["id"], "neo-reset--") && !str_starts_with($b["id"], "neo-reset--")) { return -1; }
        else if (!str_starts_with($a["id"], "neo-reset--") &&  str_starts_with($b["id"], "neo-reset--")) { return  1; }
        else { return 0; }
    });

    $settings_render_callback = function () {
        ?><neo-setting-neo-library-beta>
            <div slot="left">
                <h3><?php \NeoLibraryBeta\NeoGlobal\echo_neo__("Clear Cache & Reset Settings", "Cache leeren & Einstellungen zurücksetzen") ?></h3>
                <p><?php \NeoLibraryBeta\NeoGlobal\echo_neo__("Here we go again. Reset the plugin to its original state, as if freshly installed.", "Setze das Plugin in den Ursprungszustand zurück, als wäre es frisch installiert.") ?></p>
            </div>
            <div slot="right">
                <neo-dropdown-button-neo-library-beta class="neo-reset--dropdown" button-text="<?php \NeoLibraryBeta\NeoGlobal\echo_neo_attr__("OK", "OK") ?>">
                    <option value="" selected disabled><?php \NeoLibraryBeta\NeoGlobal\echo_neo__("Select action", "Aktion auswählen") ?></option>
                    <?php foreach (\NeoLibraryBeta\NeoGlobal\val("neo_reset__actions") as $action) {
                        ?><option value="<?php echo esc_attr($action["id"]) ?>" data-neo-reset--confirm-title="<?php echo esc_attr($action["confirm_title"]) ?>" data-neo-reset--confirm-text="<?php echo esc_attr($action["confirm_text"]) ?>"><?php echo esc_html($action["button_text"]) ?></option><?php 
                    } ?>
                </neo-dropdown-button-neo-library-beta>
            </div>
            <style>.neo-reset--dropdown { max-width: min(320px, calc(100vw - 140px)); }</style>
        </neo-setting-neo-library-beta>
    <?php };
    \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoSettings\interface_add_neo_setting_20260326')("neo-reset", $settings_render_callback);
    
    $enqueue_assets_callback = function () { \NeoLibraryBeta\NeoGlobal\enqueue_js_variable_backend("neoResetPluginPageUrl", admin_url("plugins.php")); \NeoLibraryBeta\NeoGlobal\enqueue_js("neo-reset.js"); };
    \NeoLibraryBeta\NeoGlobal\call_interface_func_implemented('\NeoLibraryBeta\NeoSettings\interface_add_neo_settings_asset_loading_callback_20250918')($enqueue_assets_callback);
});


\NeoLibraryBeta\NeoGlobal\register_rest_endpoint("/wp-json/neo/neo-reset", "POST", fn () => \NeoLibraryBeta\NeoGlobal\current_user_can__neo_reset(), function ($get_param) {
    $reset_action = $get_param("reset-action");
    \NeoLibraryBeta\NeoGlobal\global_log_with_module_name("neo-reset", "Reset action: " . $reset_action);
    foreach (\NeoLibraryBeta\NeoGlobal\val("neo_reset__actions") as $action) {
        if (!($action["id"] === $reset_action)) { continue; }
        $action["action_callback"]();
        return "OKAY";
    }
    \NeoLibraryBeta\NeoGlobal\throw_global_exception("Invalid reset action: " . $reset_action);
});
