include("WBInclusions")

global ThisFile = "Filler.html"
include("WB_Transforms")
global MDN = "MACRODICT"

# EMP("global MACRODICT = " * RRead("MACRODICT", "asis"))

# I make mountains out of molehills: 
#     global DICT = EMP(EMP("global " * MDN * " = RRead(\"" * MDN * "\", \"asis\")"))

global dict = EMP(RRead(MDN, "asis"))
global DICT = dict[2]

global KWHO = Dict{String,Int32}()

for itm in Transforms
    temp = string(itm.first)
    KWHO[temp] = get!(DICT, temp, 0)          # This adds elements to MACRODICT, too!
end

a1 = replace(string(KWHO), "}}\\\"i\"" => "}}")    # God nows what mess for key that ends with '}}"i' 

a = replace(replace(replace(replace(string(a1), r"(, |Int32}\()" => "\n"), r"(r\\|\\\")" => ""),
         "\\ =" => " ="),r" (\d+)\)" => s" \1")

b = replace(replace(replace(replace(replace(a, "\\\\|" => "    | "), r"({{|}})" => s"  "), "=>" => ""),
         r"\| [^ ]+" => ""), r"  ([^ ]+) +(\d+)" => s"  \2   \1")

b = replace(b, r"  (\d)   "    => s"    \1   ")
b = replace(b, r"  (\d{2})   " => s"   \1   ")
b = replace(b, r"  (\d{3})   " => s"  \1   ")
b = replace(b, r"  (\d{4})   " => s" \1   ")
b = replace(b, r"  (\d{5})   " => s"\1   ")

c = split(b, "\n")

x = []

for i = 1 : length(c)    
    push!(x, (findfirst("BIDEN", c[i]) == nothing ? "a" : " ") * c[i])  # BIDEN is worthless
end

y = sort(x, rev=true)
println("")
global firstbreak = true
global HILITE_COLOR = HI_YELLOW
global pct = (dict[1][3] / dict[1][2]) * 100

# WB counters added +2023.11.08

global ver = "             v023 (" * string(length(KWHO) - 1) * ")  " * hilite(HI_YELLOW, MDN) * "  " *
                           string(dict[1][1]) * "  " * string(dict[1][2]) * " " * string(dict[1][3]) *
                           " (" * formatDecimal(pct,2) * "%)"
for i = 2 : length(y)
    yi = replace(y[i], r"^a" => " ")
    breaker = ""
    if findfirst(" 0 ", yi) != nothing
        if firstbreak
            breaker = "\n"
            global HILITE_COLOR = ""
            global firstbreak = false
        end
    end    
    
    biden = findfirst("BIDEN", yi) != nothing    
    println(breaker * "  " * hilite(biden ? LO_GRAY : HILITE_COLOR, yi), ver)
    global ver = ""
end