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







function get_domain_settings() {

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

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


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

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


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