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







function domain_settings_domain_hash() { return hash("sha256", \NeoAnimateBeta\NeoGlobal\site_host()); }
function get_domain_settings() {
    
    static $domain_settings_cache = null; if ($domain_settings_cache !== null) { return $domain_settings_cache; }
    
    $domain_settings_filepath = \NeoAnimateBeta\NeoGlobal\cache_path("neo-domain-settings") . "/domain-settings-" . domain_settings_domain_hash() . ".json";
    $domain_settings_cache = \NeoAnimateBeta\NeoGlobal\synclock_dir(dirname($domain_settings_filepath), function() use ($domain_settings_filepath) {
        if (!\NeoAnimateBeta\NeoGlobal\fs_file_exists($domain_settings_filepath)) { return []; }
        return \NeoAnimateBeta\NeoGlobal\json_decode_better(\NeoAnimateBeta\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()); }


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


\NeoAnimateBeta\NeoGlobal\register_rest_endpoint("/wp-json/neo/domain-settings", "POST", fn () => \NeoAnimateBeta\NeoGlobal\current_user_can__neo_domain_settings__update(), function () {
    return refresh_domain_settings_cache();
});


\NeoAnimateBeta\NeoGlobal\add_action_hook("neo_init", function () {
    $enqueue_domain_settings_update_js = function () { \NeoAnimateBeta\NeoGlobal\enqueue_js("neo-domain-settings.js"); };
    \NeoAnimateBeta\NeoGlobal\call_interface_func_implemented('\NeoAnimateBeta\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 (\NeoAnimateBeta\NeoGlobal\plugin_slug() === "neo-media")                          { $user_type = "pro";  }
    else                                                                        { $user_type = "user"; }
    return $user_type;
}
