local Arguments = require('Module:Arguments')

local data = {
    city = {
        lines = {
            ["1"] = {
                ["background_color"] = "#ed2225",
                ["type"] = "rapid",
                ["color"] = "white"
            },
            ["2"] = {
                ["background_color"] = "#4b0082",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["3"] = {
                ["background_color"] = "#1c990c",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["4"] = {
                ["background_color"] = "#3b3f9a",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["5"] = {
                ["background_color"] = "#ffdf00",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["6"] = {
                ["background_color"] = "#50c878",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["7"] = {
                ["background_color"] = "#0d264f",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["8"] = {
                ["background_color"] = "#ff4500",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["9"] = {
                ["background_color"] = "#256862",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["10"] = {
                ["background_color"] = "#40a83b",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["11"] = {
                ["background_color"] = "#56bf89",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["12"] = {
                ["background_color"] = "#2498aa",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["13"] = {
                ["background_color"] = "#55bfe9",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["14"] = {
                ["background_color"] = "#4052a4",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["15"] = {
                ["background_color"] = "#5b7552",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["16"] = {
                ["background_color"] = "#b09fca",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["17"] = {
                ["background_color"] = "#6cbd45",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["18"] = {
                ["background_color"] = "#F38761",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["19"] = {
                ["background_color"] = "#E4BE5F",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["20"] = {
                ["background_color"] = "#ff469a",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["21"] = {
                ["background_color"] = "#1E5369",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["22"] = {
                ["background_color"] = "#a739da",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["23"] = {
                ["background_color"] = "#EA4924",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["24"] = {
                ["background_color"] = "#ff5b2b",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["25"] = {
                ["background_color"] = "#827B60",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["26"] = {
                ["background_color"] = "#976FAE",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["27"] = {
                ["background_color"] = "#0F51A3",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["28"] = {
                ["background_color"] = "#F7B039",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["29"] = {
                ["background_color"] = "#40B0BB",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["30"] = {
                ["background_color"] = "#b30000",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["31"] = {
                ["background_color"] = "#E85293",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["32"] = {
                ["background_color"] = "#223A29",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["33"] = {
                ["background_color"] = "#AB4390",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["34"] = {
                ["background_color"] = "#F9CF47",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["35"] = {
                ["background_color"] = "#bd144c",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["36"] = {
                ["background_color"] = "#40a83b",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["37"] = {
                ["background_color"] = "#49B3E7",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["38"] = {
                ["background_color"] = "#6D268C",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["39"] = {
                ["background_color"] = "#f58020",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["40"] = {
                ["background_color"] = "#DC7070",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["41"] = {
                ["background_color"] = "#34c367",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["42"] = {
                ["background_color"] = "#E3833F",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["43"] = {
                ["background_color"] = "#A5DACE",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["44"] = {
                ["background_color"] = "#89C35C",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["45"] = {
                ["background_color"] = "#224237",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["46"] = {
                ["background_color"] = "#02c40b",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["47"] = {
                ["background_color"] = "#105F32",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["48"] = {
                ["background_color"] = "#00d3c2",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["49"] = {
                ["background_color"] = "#9116d9",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["50"] = {
                ["background_color"] = "#ff469a",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["51"] = {
                ["background_color"] = "#8A3B3E",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["52"] = {
                ["background_color"] = "#a52a2a",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["53"] = {
                ["background_color"] = "#36454F",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["54"] = {
                ["background_color"] = "#3A5F0B",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["55"] = {
                ["background_color"] = "#000000",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["56"] = {
                ["background_color"] = "#ddffdd",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["57"] = {
                ["background_color"] = "#3954A5",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["58"] = {
                ["background_color"] = "#CD7F32",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["59"] = {
                ["background_color"] = "#1ab4a2",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["60"] = {
                ["background_color"] = "#EB5456",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["61"] = {
                ["background_color"] = "#008080",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["62"] = {
                ["background_color"] = "#7AC044",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["63"] = {
                ["background_color"] = "#8C6E2D",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["64"] = {
                ["background_color"] = "#fccf03",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["65"] = {
                ["background_color"] = "#189BCC",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["66"] = {
                ["background_color"] = "#105F32",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["PNR 1"] = {
                ["background_color"] = "#AA6C39",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["PNR 2"] = {
                ["background_color"] = "#000080",
                ["type"] = "bus",
                ["color"] = "white"
            }
        },
        image = {},
        article = "List of bus routes in Metro Manila"
    },
    bgc = {
        lines = {
            ["EX"] = {
                ["background_color"] = "#fe0000",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["N"] = {
                ["background_color"] = "#fd7d00",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["C"] = {
                ["background_color"] = "#884a9d",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["AS"] = {
                ["background_color"] = "#6d6d6d",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["W"] = {
                ["background_color"] = "#ffff00",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["WR"] = {
                ["background_color"] = "#000000",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["NR"] = {
                ["background_color"] = "#00ffff",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["L"] = {
                ["background_color"] = "#ff0080",
                ["type"] = "bus",
                ["color"] = "white"
            }
        },
        image = {"BGC Bus Logo.svg", "30px"},
        article = "BGC Bus"
    },
    lovebus = {
        lines = {
            ["1"] = {
                ["background_color"] = "#0083e8",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["2"] = {
                ["background_color"] = "#0083e8",
                ["type"] = "bus",
                ["color"] = "white"
            }
        },
        image = {"Red Heart.svg", "15px"},
        article = "List of bus routes in Metro Manila#Love Bus"
    },
    qc = {
        lines = {
            ["1"] = {
                ["background_color"] = "#fe0000",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["2"] = {
                ["background_color"] = "#ff469a",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["3"] = {
                ["background_color"] = "#ffdf00",
                ["type"] = "bus",
                ["color"] = "black"
            },
            ["4"] = {
                ["background_color"] = "#a739da",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["5"] = {
                ["background_color"] = "#ff5b2b",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["6"] = {
                ["background_color"] = "#02c40b",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["7"] = {
                ["background_color"] = "#0034bb",
                ["type"] = "bus",
                ["color"] = "white"
            },
            ["8"] = {
                ["background_color"] = "#00d3c2",
                ["type"] = "bus",
                ["color"] = "white"
            }
        },
        image = {"QuezonCityBusService.png", "20px"},
        article = "Quezon City Bus Service"
    }
}

local p = {}

-- Note: This function returns the hex color code without the '#'
function p.getColor(frame)
    local args = Arguments.getArgs(frame)
    local service_type = args[1] and tostring(args[1]):lower()
    local route_number = args[2] and tostring(args[2])

    if not service_type or not route_number then
        return ""
    end

    local service_data = data[service_type]
    if not service_data then
        return ""
    end

    local line_data = service_data.lines[route_number]
    if not line_data then
        return ""
    end

    return (string.gsub(line_data.background_color, "#", ""))
end

return {
    data = data,
    getColor = p.getColor
}