#include "ui_carStatus.lua"
#include "../../../script/helpers/uifr.lua"

UI_CARTITLE = {
    tiers = {
        ["B"] = "MOD/ui/pc/garage_and_store/tier_b.png",
        ["A"] = "MOD/ui/pc/garage_and_store/tier_a.png",
        ["S"] = "MOD/ui/pc/garage_and_store/tier_s.png",
    },
    cardTiers = {
        ["B"] = "MOD/ui/pc/garage_and_store/car_tier_b.png",
        ["A"] = "MOD/ui/pc/garage_and_store/car_tier_a.png",
        ["S"] = "MOD/ui/pc/garage_and_store/car_tier_s.png",
    },
}

function UI_CARTITLE:draw(carIndex, carInfo, baseModId, modId)
    local tier = carInfo.mods and carInfo.mods[modId].tier or "B"

    -- Hardcode to show A tier on every industrial vehicles
    if VEHICLES_REGISTRY[carIndex] and vehiclesRegistry:GetVehicleClass(carIndex) == CAR_INFO.class.Industrial then
        tier = "A"
    end
    local baseOptions = carInfo.mods[baseModId]
    local carOptions = carInfo.mods[modId]
    UiPush()
        w,h = UI_CARTITLE:drawTier(tier)
        UiTranslate(w + 12, 12)
        UI_CARTITLE:drawName(carInfo.name)
        UiTranslate(0, h - 3)
        UI_CARTITLE:drawSubName(carInfo.classLoc)
        UiTranslate(-w - 12, 22)
        UI_CARSTATUS:draw(240, 200, baseOptions, carOptions)
    UiPop()
end

function UI_CARTITLE:drawTier(tier, isVehCard)
    local arr = isVehCard and "cardTiers" or "tiers"
    local imgPath = self[arr][tier] and self[arr][tier] or ""
    local w, h = UiGetImageSize(imgPath)

    UiPush()
        UiWindow(w, h)
        UiAlign("left top")
        UiImage(imgPath)
    UiPop()
    return w,h
end

function UI_CARTITLE:drawName(name)
    UiPush()
        UiFont("bold.ttf", 54)
        UiDrawTextShadow(name, 0, 3, 0, 0, 0, 0.5)
        UiText(name)
    UiPop()
end

function UI_CARTITLE:drawSubName(class)
    UiPush()
        UiAlign("left bottom")
        UiFont("medium.ttf", 28)
        UiDrawTextShadow(class, 0, 3, 0, 0, 0, 0.5)
        UiText(class)
    UiPop()
end
