local _, ns = ...
local L = ns.L or {}

local UI = ns.UI or {}
ns.UI = UI

local UISettingsPanel = ns.UISettingsPanel or {}

function UI:GetDisplayVersionLabel()
    local version = tostring(ns.VERSION or "")
    version = version:gsub("^Vaultloom_v", "")
    if version == "" then
        version = "?"
    end
    return string.format("%s %s", L.SETTINGS_VERSION or "Version", version)
end

function UI:ApplyDisplaySettings()
    if not self.frame then
        return
    end

    local scalePercent = ns:GetScalePercent()
    local opacityPercent = ns:GetOpacityPercent()

    self.frame:SetScale(scalePercent / 100)
    self.frame:SetAlpha(opacityPercent / 100)

    if self.frame.settingsScaleValue then
        self.frame.settingsScaleValue:SetText(string.format("%d%%", scalePercent))
    end
    if self.frame.settingsOpacityValue then
        self.frame.settingsOpacityValue:SetText(string.format("%d%%", opacityPercent))
    end
    if self.frame.settingsMinimapToggle and self.frame.settingsMinimapToggle.label then
        self.frame.settingsMinimapToggle.label:SetText(ns:IsMinimapHidden() and (L.SETTINGS_MINIMAP_SHOW or "Show") or (L.SETTINGS_MINIMAP_HIDE or "Hide"))
    end
    if self.frame.settingsAltScoreToggle and self.frame.settingsAltScoreToggle.label then
        self.frame.settingsAltScoreToggle.label:SetText(ns:IsAltScoreHidden() and (L.SETTINGS_ALT_SCORE_SHOW or "Show") or (L.SETTINGS_ALT_SCORE_HIDE or "Hide"))
    end
    if self.frame.settingsVersion then
        self.frame.settingsVersion:SetText(self:GetDisplayVersionLabel())
    end
    local settingsOpen = self.frame.settingsPanel and self.frame.settingsPanel:IsShown()
    if settingsOpen and self.frame.settingsChangelogBody then
        self.frame.settingsChangelogBody:SetText((ns.GetNewsBodyText and ns:GetNewsBodyText()) or "")
        if self.frame.LayoutSettingsChangelog then
            self.frame.LayoutSettingsChangelog()
        end
    end
    if UISettingsPanel.RefreshMainTabControls then
        UISettingsPanel.RefreshMainTabControls(self, self.frame)
    end
    self:RefreshFeaturesButton()
end
