local addonName, addon = ...

local FALLBACK_FONT = "Fonts\\FRIZQT__.TTF"

local function GetFont()
    if addon.fontPath and addon.fontPath ~= "" then
        return addon.fontPath
    end

    if CompactUtilityPanelDB
        and CompactUtilityPanelDB.fontPath
        and CompactUtilityPanelDB.fontPath ~= "" then

        addon.fontPath =
            CompactUtilityPanelDB.fontPath

        return addon.fontPath
    end

    return FALLBACK_FONT
end

local function GetFontSize()
    local size =
        tonumber(addon.fontSize)

    if not size
        and CompactUtilityPanelDB then

        size =
            tonumber(
                CompactUtilityPanelDB.fontSize
            )
    end

    if not size or size <= 0 then
        return 14
    end

    return size
end

local function GetFontColor()
    local db =
        CompactUtilityPanelDB

    if not db
        or type(db.fontColor) ~= "table" then

        return 1, 1, 1, 1
    end

    return
        tonumber(db.fontColor.r) or 1,
        tonumber(db.fontColor.g) or 1,
        tonumber(db.fontColor.b) or 1,
        1
end

function addon:CreateReadyCheckButton(parent)
    local button =
        self:CreateButton(
            parent,
            105,
            24,
            false
        )

    local text =
        button:CreateFontString(
            nil,
            "OVERLAY"
        )

    local fontPath =
        GetFont()

    local fontSize =
        GetFontSize()

    local r, g, b, a =
        GetFontColor()

    if not fontPath
        or fontPath == "" then

        fontPath =
            FALLBACK_FONT
    end

    text:SetFont(
        fontPath,
        fontSize,
        ""
    )

    text:SetTextColor(
        r,
        g,
        b,
        a
    )

    text:SetPoint("CENTER")
    text:SetText("READY")

    button.text = text

    button:SetScript(
        "OnClick",
        function()
            DoReadyCheck()
        end
    )

    return button
end