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







function domain_settings_domain_hash() { return hash("sha256", \NeoMotionBeta\NeoGlobal\site_host()); }
function get_domain_settings() {
    
    static $domain_settings_cache = null; if ($domain_settings_cache !== null) { return $domain_settings_cache; }
    
    $domain_settings_filepath = \NeoMotionBeta\NeoGlobal\cache_path("neo-domain-settings") . "/domain-settings-" . domain_settings_domain_hash() . ".json";
    $domain_settings_cache = \NeoMotionBeta\NeoGlobal\synclock_dir(dirname($domain_settings_filepath), function() use ($domain_settings_filepath) {
        if (!\NeoMotionBeta\NeoGlobal\fs_file_exists($domain_settings_filepath)) { return []; }
        return \NeoMotionBeta\NeoGlobal\json_decode_better(\NeoMotionBeta\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 = \NeoMotionBeta\NeoGlobal\curl_request("https://download." . \NeoMotionBeta\NeoGlobal\option__neo_wp_com() . "/_domain-settings.json", "GET", data: null, timeout: 5);
    $all_domain_settings = \NeoMotionBeta\NeoGlobal\json_decode_better($all_domain_settings);
    $domain_settings_before = get_domain_settings();
    $domain_settings_after  = $all_domain_settings[domain_settings_domain_hash()] ?? [];
    \NeoMotionBeta\NeoGlobal\fs_file_put_contents(\NeoMotionBeta\NeoGlobal\cache_path("neo-domain-settings") . "/domain-settings-" . domain_settings_domain_hash() . ".json", \NeoMotionBeta\NeoGlobal\json_encode_better($domain_settings_after));
    return $domain_settings_before === $domain_settings_after ? "UNCHANGED" : "REFRESH";
}


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


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