A complex if function

What I want to do is a widget that displays wifi speed, with some additional flavour.
I have made that work as shown here:

$if(nc(wspeed) >= 100,
                1, "[c=#5d1b56]0[/c]"
                )
        
$if(nc(wspeed) >= 100,
                nc(wspeed)-100, 0
                )

$if(nc(wspeed) = 0,
                0, ""
                )
$

Now, I want this to show up only, when I'm not connected to wifi, if which case, it should show network type. Tryed many variation of parentheses, $ signs, etc. but I coulnd't make it work.
One of my last tries is this:

$if
(nc(wifi) = connected,
        (       
                if(nc(wspeed) >= 100,
                        1, "[c=#5d1b56]0[/c]"
                        )
                
                if(nc(wspeed) >= 100,
                        nc(wspeed)-100, 0
                        )
                
                if(nc(wspeed) = 0,
                        0, ""
                        )
        ),
        0
)
$

I'm sure it's my fault, but for the life of me I can't find the problem.