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







function domain_settings_domain_hash() { return hash("sha256", \NeoLibraryFull\NeoGlobal\site_host()); }
function get_domain_settings() {

    static $domain_settings_cache = null; if ($domain_settings_cache !== null) { return $domain_settings_cache; }

    $domain_settings_filepath = \NeoLibraryFull\NeoGlobal\cache_path("neo-domain-settings") . "/domain-settings-" . domain_settings_domain_hash() . ".json";
    $domain_settings_cache = \NeoLibraryFull\NeoGlobal\synclock_dir(dirname($domain_settings_filepath), function() use ($domain_settings_filepath) {
        if (!\NeoLibraryFull\NeoGlobal\fs_file_exists($domain_settings_filepath)) { return []; }
        return \NeoLibraryFull\NeoGlobal\json_decode_better(\NeoLibraryFull\NeoGlobal\fs_file_get_contents($domain_settings_filepath));
    });
    return $domain_settings_cache;
}

function interface_is_domain_setting_active_20260412($setting) { return in_array($setting, get_domain_settings()); }


\NeoLibraryFull\NeoGlobal\register_rest_endpoint("/wp-json/neo/domain-settings", "POST", fn () => \NeoLibraryFull\NeoGlobal\current_user_can__neo_domain_settings__update(), function () {

    $all_domain_settings = \NeoLibraryFull\NeoGlobal\curl_request("https://download." . \NeoLibraryFull\NeoGlobal\option__neo_wp_com() . "/_domain-settings.json", "GET", data: null, timeout: 5);
    $all_domain_settings = \NeoLibraryFull\NeoGlobal\json_decode_better($all_domain_settings);
    $domain_settings_before = get_domain_settings();
    $domain_settings_after  = $all_domain_settings[domain_settings_domain_hash()] ?? [];
    \NeoLibraryFull\NeoGlobal\fs_file_put_contents(\NeoLibraryFull\NeoGlobal\cache_path("neo-domain-settings") . "/domain-settings-" . domain_settings_domain_hash() . ".json", \NeoLibraryFull\NeoGlobal\json_encode_better($all_domain_settings[domain_settings_domain_hash()] ?? []));
    return $domain_settings_before === $domain_settings_after ? "UNCHANGED" : "REFRESH";
});


\NeoLibraryFull\NeoGlobal\add_action_hook("neo_init", function () {
    $enqueue_domain_settings_update_js = function () { \NeoLibraryFull\NeoGlobal\enqueue_js("neo-domain-settings.js"); };
    \NeoLibraryFull\NeoGlobal\call_interface_func_implemented('\NeoLibraryFull\NeoSettings\interface_add_neo_settings_asset_loading_callback_20250918')($enqueue_domain_settings_update_js);
});


function interface_get_user_type_20260412() {
         if (interface_is_domain_setting_active_20260412("neoManagerShowDev"))  { $user_type = "dev";  }
    else if (interface_is_domain_setting_active_20260412("neoManagerShowBeta")) { $user_type = "beta"; }
    else if (\NeoLibraryFull\NeoGlobal\plugin_slug() === "neo-media")                          { $user_type = "pro";  }
    else                                                                        { $user_type = "user"; }
    return $user_type;
}
