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







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


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


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