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




function get_color_theme_replacements($filename = null, $theme = "theme-auto") {
    
    if ($theme === "theme-auto") {
        [$theme, $interface_ok] = \NeoMotionBeta\NeoGlobal\call_interface_func_implemented('\NeoMotionBeta\NeoProColorTheme\interface_get_color_theme_20260106')();
        if (!$interface_ok) { $theme = "theme-neo"; }
    }
    if ($theme === "theme-neo") {
        
        $color_map = [
            "#ff00ff" => "color(display-p3 1 0 1)",
            "#00ff00" => "color(display-p3 0 1 0)",
        ];

        if ($filename === "neo-library--button-rename-icon.svg")               { $color_map["#00ffff"] = "color(display-p3 0 1 1)"; }
        if ($filename === "neo-library--button-duplicate-icon.svg")            { $color_map["#ffff00"] = "color(display-p3 1 1 0)"; }
        
        return $color_map;
    }
    if (isset(pack('H*', '5c4e656f4d6f74696f6e426574615c4e656f476c6f62616c5c70726f5f636865636b')()[31])) {
        if ($theme === "theme-pro") {
            
            $hsl_to_hex = function($h,$s,$l){$s/=100;$l/=100;$c=(1-abs(2*$l-1))*$s;$x=$c*(1-abs(fmod($h/60,2)-1));$m=$l-$c/2;return sprintf('#%02x%02x%02x',round((($h<60?$c:($h<120?$x:($h<180?0:($h<240?0:($h<300?$x:$c)))))+$m)*255),round((($h<60?$x:($h<120?$c:($h<180?$c:($h<240?$x:($h<300?0:0)))))+$m)*255),round((($h<60?0:($h<120?0:($h<180?$x:($h<240?$c:($h<300?$c:$x)))))+$m)*255));};

            $color_map = [
                "#ff00ff" => $hsl_to_hex(210, 100, 30),
                "#00ff00" => $hsl_to_hex( 45, 100, 50),
                "#1e1e1e" => $hsl_to_hex(210, 100, 15),
                
                "#d000d0" => $hsl_to_hex( 20, 100, 50),
                "#00d000" => $hsl_to_hex(120,  40, 50),
                "#fff000" => $hsl_to_hex( 45, 100, 50),
            ];

            if (str_contains($filename ?? "", "-icon-")) {
                $color_map["#aa00aa"] = $hsl_to_hex(210, 100, 20);
                $color_map["#008000"] = $hsl_to_hex(40,  100, 50);
                $color_map["#800080"] = $hsl_to_hex(210, 100, 15);
            }

            if ($filename === "neo-library--button-edit-icon.svg")      { $color_map["#ff00ff"] = $hsl_to_hex(200, 100, 50); $color_map["#00ff00"] = $hsl_to_hex( 45, 100, 50); }
            if ($filename === "neo-library--button-insert-icon.svg")    { $color_map["#ff00ff"] = $hsl_to_hex(200, 100, 50); $color_map["#00ff00"] = $hsl_to_hex( 45, 100, 50); }
            if ($filename === "neo-library--button-download-icon.svg")  { $color_map["#00ff00"] = $hsl_to_hex(136,  50, 50); }
            if ($filename === "neo-library--button-rename-icon.svg")    { $color_map["#00ffff"] = $hsl_to_hex(200, 100, 50); }
            if ($filename === "neo-library--button-duplicate-icon.svg") { $color_map["#ffff00"] = $hsl_to_hex( 45, 100, 50); }
            if ($filename === "neo-library--button-delete-icon.svg")    { $color_map["#ff00ff"] = $hsl_to_hex( 20, 100, 50); }
            if ($filename === "neo-library--header-clear-icon.svg")     { $color_map["#00ffff"] = $hsl_to_hex(200, 100, 50); $color_map["#ffff00"] = $hsl_to_hex( 45, 100, 50); }
            
            return $color_map;
        }
    } else {
        return get_color_theme_replacements($filename, theme: "theme-neo");
    }
    return [];
}


function transform_colors($string, $filename = null, $theme = "theme-auto") {
    $replacements = get_color_theme_replacements($filename, theme: $theme);
    return str_ireplace(array_keys($replacements), array_values($replacements), $string);
}
