local function LSX(class, props, children)
    do
        local s = "<" .. class
        if props then
            s = s .. " "
            for k,v in pairs(props) do
                s = s .. k .. "='" .. tostring(v) .. "'"
            end
        end
        s = s .. ">"

        if children then
            for _, v in ipairs(children) do
                if type(v) == "table" then
                    print(v)
                    for _, v in ipairs(v) do
                        s = s .. tostring(v)
                    end
                else
                    s = s .. tostring(v)
                end
            end
        end

        s = s .. "</" .. class .. ">"

        return s
    end

    return {
        class = class,
        props = props,
        children = children,
    }
end

function math.suffixes(num, suffix)
    return tostring(num) .. suffix
end

local function async(func)
    tasks.enabled = true
    local t = tasks.CreateTask()
    t.OnStart = function(_, ...) return func(...) end
    return t
end

local function CSS(tbl)
    local s = ""
    for k,v in pairs(tbl) do
        s = s .. k .. ":" .. tostring(v) .. ";"
    end
    return s
end

---- ^ above should maybe be moved to a runtime

local function Result({html_url, stargazers_count, description, full_name})
    return <div style={CSS{
        padding = 10px,
        margin = 10px,
        background = 'white',
        ["box-shadow"] = "0 1px 5px rgba(0,0,0,0.5)"
    }}>
        <div>
            <a href={html_url} target="_blank">
                {full_name}
            </a>
            🌟
            <strong>{stargazers_count}</strong>
        </div>
        <p>{description}</p>
    </div>
end

local async function run()
    local path = resource.Download("http://api.github.com/search/repositories?q=preact")
    local items = vfs.Read(path).items

    local html = <div>
        <h1 style="text-align:center;">Example</h1>
        <div class="list">
            { list.map(results, do v Result(v)) }
        </div>
    </div>

    vfs.Write("index.html", html)
end