local _, addonTable = ...

local COLUMN_WIDTHS = {
    presence = 14,
    name = 150,
    armor = 80,
    key = 160,
    tp = 60,
    rating = 80,
    hide = 80,
    roles = 100,
    accountType = 150,
    meetingStone = 110,
}

local CARPOOL_COLUMN_WIDTHS = {
    presence = 14,
    name = 150,
    armor = 80,
    key = 160,
    tp = 60,
    rating = 80,
    hide = 80,
    roles = 100,
    accountType = 150,
    meetingStone = 110,
}

local COLUMN_ORDER = {
    "presence",
    "name",
    "armor",
    "key",
    "rating",
    "roles",
    "tp",
    "accountType",
    "meetingStone",
}

addonTable.GROUP_LIST_COLUMN_WIDTHS = COLUMN_WIDTHS
addonTable.CARPOOL_LIST_COLUMN_WIDTHS = CARPOOL_COLUMN_WIDTHS
addonTable.GROUP_SORT_DEFAULT = {
    key = "presence",
    direction = "desc",
}

addonTable.CARPOOL_SORT_DEFAULT = {
    key = "meetingStone",
    direction = "asc",
}

addonTable.GROUP_SORT_INITIAL_DIRECTION = {
    presence = "desc",
    name = "asc",
    armor = "asc",
    key = "asc",
    rating = "desc",
    roles = "asc",
}

addonTable.CARPOOL_SORT_INITIAL_DIRECTION = {
    meetingStone = "asc",
    name = "asc",
    armor = "asc",
    key = "desc",
    rating = "desc",
    roles = "asc",
}

function addonTable.GetGroupColumnWidths(widths)
    widths = widths or COLUMN_WIDTHS

    return {
        presence = widths.presence or COLUMN_WIDTHS.presence,
        name = widths.name or COLUMN_WIDTHS.name,
        armor = widths.armor or COLUMN_WIDTHS.armor,
        key = widths.key or COLUMN_WIDTHS.key,
        rating = widths.rating or COLUMN_WIDTHS.rating,
        roles = widths.roles or COLUMN_WIDTHS.roles,
        tp = widths.tp or COLUMN_WIDTHS.tp,
        accountType = widths.accountType or COLUMN_WIDTHS.accountType,
        meetingStone = widths.meetingStone or COLUMN_WIDTHS.meetingStone,
    }
end

function addonTable.GetGroupColumnLayout(widths)
    local resolvedWidths = addonTable.GetGroupColumnWidths(widths)
    local layout = {
        widths = resolvedWidths,
    }
    local offset = 0

    for _, key in ipairs(COLUMN_ORDER) do
        local width = resolvedWidths[key] or 0
        layout[key] = {
            x = offset,
            width = width,
        }
        offset = offset + width
    end

    layout.totalWidth = offset
    return layout
end
