--ui/categories.lua, declarative option sections for the panel (frontend).
--the BuildMenuOptions method returns the menuOptions array consumed by DF:BuildMenu; every entry is a
--plain literal table (Plater style): a {type="group"} entry draws the background box for a block, and
--each widget below sets group="<name>" to sit inside that box. no descriptor is produced by a helper --
--the tables are written out in full so the panel reads top-to-bottom as data.

local _ = nil
local addonName, private = ...

local detailsFramework = DetailsFramework

private.UI = private.UI or {}

---@class FPSPP_Categories
local Categories = {}
private.UI.Categories = Categories

--constants
--the toggles flipped together by the "toggle all" master checkbox: the Interface hides plus every
--context-gated graphics reduction (the graphics.* toggles and the graphics_cvars.* CVar toggles).
--the CVar sliders (Far Clip, Terrain LOD) set a value rather than on/off, so they are not included.
local TEST_TOGGLE_PATHS = {
	"ui.disable_minimap",
	"ui.disable_buffs",
	"ui.disable_raid_frames",
	"ui.disable_action_bars",
	"graphics.reduce_shadows",
	"graphics.reduce_particle_density",
	"graphics_cvars.liquid_detail",
	"graphics_cvars.shadow_quality",
	"graphics_cvars.depth_effects",
	"graphics_cvars.outline_mode",
	"graphics_cvars.spell_density",
	"graphics_cvars.environment_detail",
	"graphics_cvars.ground_clutter",
	"graphics_cvars.view_distance",
	"graphics_cvars.anti_aliasing",
}

--true only when every test toggle is on (so the master checkbox shows as checked).
---@return boolean
local areAllTestTogglesOn = function()
	for index, path in ipairs(TEST_TOGGLE_PATHS) do
		if not private.Core.Profile:GetBool(path) then
			return false
		end
	end

	return true
end

--sets every test toggle to value, applies the changes, and refreshes the panel so the
--individual checkboxes update to match.
---@param value boolean
local setAllTestToggles = function(value)
	for index, path in ipairs(TEST_TOGGLE_PATHS) do
		private.Core.Profile:SetBool(path, value)
	end

	--the optimizer re-applies everything (graphics, CVars, and the frame hides) via the context gate.
	private.Core.Optimizer:ApplyProfile()
	private.UI.Options:RefreshIfOpen()
end

--maps the Far Clip slider's value (1500..10000) to the graphicsViewDistance quality scale (0..9),
--linearly, so the one slider drives both the far clip plane and the view-distance quality together.
--(1500 -> 0, 10000 -> 9; rounded to the nearest step and clamped to the 0-9 range.)
---@param farclip number
---@return number
local farclipToViewDistance = function(farclip)
	local scaled = math.floor((farclip - 1500) / (10000 - 1500) * 9 + 0.5)
	return math.max(0, math.min(9, scaled))
end

--visual grouping style shared by every {type="group"} entry below. a plain dark fill is nearly
--invisible against the dark panel, so the group uses a bordered backdrop (BuildMenu reads the backdrop
--keys UseBackdrop, BackgroundColor and BackdropBorderColor). one place to restyle every block.
local GROUP_BACKDROP = {
	bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
	edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
	tileSize = 16,
	tile = true,
	tileEdge = true,
	edgeSize = 16,
	insets = {left = 3, right = 3, top = 3, bottom = 3},
}
local GROUP_BG_COLOR = {0, 0, 0, 0.2}               --subtle darkening behind each block
local GROUP_BORDER_COLOR = {1, 1, 1, 0.4}           --soft light border around each block
local GROUP_PADDING = 8                              --pixels between a block's widgets and its group border
local GROUP_WIDTH = 200                              --fixed width (px) for every group box, so all blocks align

--builds the full menuOptions descriptor table for DF:BuildMenu.
---@return table
function Categories:BuildMenuOptions()
	local L = private.locale
	local orangeFont = detailsFramework:GetTemplate("font", "ORANGE_FONT_TEMPLATE")

	return {
		fixed_width = 200,
		--general
		{type = "group", name = "general", UseBackdrop = GROUP_BACKDROP, BackgroundColor = GROUP_BG_COLOR, BackdropBorderColor = GROUP_BORDER_COLOR, width = GROUP_WIDTH, padding = GROUP_PADDING},
		{type = "label", get = function() return L["SECTION_GENERAL"] end, text_template = orangeFont, group = "general"},
		{
			type = "toggle",
			name = L["ENABLE_ADDON"],
			desc = L["ENABLE_ADDON_DESC"],
			boxfirst = true,
			group = "general",
			get = function() return private.Core.Profile:GetBool("enabled") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("enabled", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},

		--apply reductions when: the context gate. reductions turn on while any checked condition is
		--true (and off otherwise); "always" overrides the rest. the master "toggle all" is here too.
		{type = "blank"},
		{type = "blank"},
		{type = "group", name = "context", UseBackdrop = GROUP_BACKDROP, BackgroundColor = GROUP_BG_COLOR, BackdropBorderColor = GROUP_BORDER_COLOR, width = GROUP_WIDTH, padding = GROUP_PADDING},
		{type = "label", get = function() return L["SECTION_CONTEXT"] end, text_template = orangeFont, group = "context"},
		{
			type = "toggle",
			name = L["CONTEXT_DUNGEON"],
			desc = L["CONTEXT_DUNGEON_DESC"],
			boxfirst = true,
			group = "context",
			get = function() return private.Core.Profile:GetBool("context.in_dungeon") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("context.in_dungeon", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CONTEXT_DUNGEON_ENCOUNTER"],
			desc = L["CONTEXT_DUNGEON_ENCOUNTER_DESC"],
			boxfirst = true,
			group = "context",
			get = function() return private.Core.Profile:GetBool("context.in_dungeon_encounter") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("context.in_dungeon_encounter", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CONTEXT_RAID"],
			desc = L["CONTEXT_RAID_DESC"],
			boxfirst = true,
			group = "context",
			get = function() return private.Core.Profile:GetBool("context.in_raid") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("context.in_raid", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CONTEXT_RAID_ENCOUNTER"],
			desc = L["CONTEXT_RAID_ENCOUNTER_DESC"],
			boxfirst = true,
			group = "context",
			get = function() return private.Core.Profile:GetBool("context.in_raid_encounter") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("context.in_raid_encounter", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CONTEXT_ALWAYS"],
			desc = L["CONTEXT_ALWAYS_DESC"],
			boxfirst = true,
			group = "context",
			get = function() return private.Core.Profile:GetBool("context.always") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("context.always", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["TOGGLE_ALL"],
			desc = L["TOGGLE_ALL_DESC"],
			boxfirst = true,
			group = "context",
			get = function() return areAllTestTogglesOn() end,
			set = function(_, _, value) setAllTestToggles(value) end,
		},

		--blizzard addons: hide parts of the Blizzard UI while a chosen context is active.
		{type = "blank"},
		{type = "blank"},
		{type = "group", name = "blizzard", UseBackdrop = GROUP_BACKDROP, BackgroundColor = GROUP_BG_COLOR, BackdropBorderColor = GROUP_BORDER_COLOR, width = GROUP_WIDTH, padding = GROUP_PADDING},
		{type = "label", get = function() return L["SECTION_INTERFACE"] end, text_template = orangeFont, group = "blizzard"},
		{
			type = "toggle",
			name = L["UI_MINIMAP"],
			desc = L["UI_MINIMAP_DESC"],
			boxfirst = true,
			group = "blizzard",
			get = function() return private.Core.Profile:GetBool("ui.disable_minimap") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("ui.disable_minimap", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["UI_BUFFS"],
			desc = L["UI_BUFFS_DESC"],
			boxfirst = true,
			group = "blizzard",
			get = function() return private.Core.Profile:GetBool("ui.disable_buffs") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("ui.disable_buffs", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["UI_RAID_FRAMES"],
			desc = L["UI_RAID_FRAMES_DESC"],
			boxfirst = true,
			group = "blizzard",
			get = function() return private.Core.Profile:GetBool("ui.disable_raid_frames") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("ui.disable_raid_frames", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["UI_ACTION_BARS"],
			desc = L["UI_ACTION_BARS_DESC"],
			boxfirst = true,
			group = "blizzard",
			get = function() return private.Core.Profile:GetBool("ui.disable_action_bars") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("ui.disable_action_bars", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			--"Hide Blizzard Damage Meter": disables Blizzard's built-in meter (damageMeterEnabled CVar)
			--while the context gate is active, like the frame hides above. writes the profile and re-applies;
			--the optimizer drops/restores the CVar reversibly (see core/optimizer.lua).
			type = "toggle",
			name = L["UI_DAMAGE_METER"],
			desc = L["UI_DAMAGE_METER_DESC"],
			boxfirst = true,
			group = "blizzard",
			get = function() return private.Core.Profile:GetBool("ui.disable_damage_meter") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("ui.disable_damage_meter", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},

		--addon solutions: the addon's own lightweight replacements for Blizzard UI.
		{type = "blank"},
		{type = "blank"},
		{type = "group", name = "addons", UseBackdrop = GROUP_BACKDROP, BackgroundColor = GROUP_BG_COLOR, BackdropBorderColor = GROUP_BORDER_COLOR, width = GROUP_WIDTH, padding = GROUP_PADDING},
		{type = "label", get = function() return L["SECTION_ADDON_SOLUTIONS"] end, text_template = orangeFont, group = "addons"},
		{
			--"Use Cheap Raid Frame": the addon's lightweight raid frames in place of Blizzard's.
			--pair it with "Hide Raid Frames" in the Blizzard AddOns section above.
			type = "toggle",
			name = L["UI_CHEAP_RAID"],
			desc = L["UI_CHEAP_RAID_DESC"],
			boxfirst = true,
			group = "addons",
			get = function() return private.Core.Profile:GetBool("unit_frames.enabled") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("unit_frames.enabled", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},

		--graphics: the breakline (after the AddOn Solutions block above) forces a new column so this
		--section doesn't keep stacking down the first column.
		{type = "breakline"},
		{type = "group", name = "graphics", UseBackdrop = GROUP_BACKDROP, BackgroundColor = GROUP_BG_COLOR, BackdropBorderColor = GROUP_BORDER_COLOR, width = GROUP_WIDTH, padding = GROUP_PADDING},
		{type = "label", get = function() return L["SECTION_GRAPHICS"] end, text_template = orangeFont, group = "graphics"},
		{
			type = "toggle",
			name = L["GFX_PARTICLES"],
			desc = L["GFX_PARTICLES_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics.reduce_particle_density") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics.reduce_particle_density", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["GFX_SHADOWS"],
			desc = L["GFX_SHADOWS_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics.reduce_shadows") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics.reduce_shadows", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		--graphics CVar reductions: context-gated (writing profile.graphics_cvars.*, applied while a
		--chosen context is active). the Live FPS Test window mirrors these as immediate live-preview
		--toggles; kept in the SAME order as that window's list so the two panels match.
		{
			type = "toggle",
			name = L["CVAR_LIQUID_DETAIL"],
			desc = L["CVAR_LIQUID_DETAIL_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics_cvars.liquid_detail") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics_cvars.liquid_detail", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CVAR_SHADOW_QUALITY"],
			desc = L["CVAR_SHADOW_QUALITY_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics_cvars.shadow_quality") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics_cvars.shadow_quality", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CVAR_DEPTH_EFFECTS"],
			desc = L["CVAR_DEPTH_EFFECTS_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics_cvars.depth_effects") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics_cvars.depth_effects", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CVAR_OUTLINE_MODE"],
			desc = L["CVAR_OUTLINE_MODE_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics_cvars.outline_mode") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics_cvars.outline_mode", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CVAR_SPELL_DENSITY"],
			desc = L["CVAR_SPELL_DENSITY_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics_cvars.spell_density") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics_cvars.spell_density", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CVAR_ENVIRONMENT_DETAIL"],
			desc = L["CVAR_ENVIRONMENT_DETAIL_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics_cvars.environment_detail") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics_cvars.environment_detail", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CVAR_GROUND_CLUTTER"],
			desc = L["CVAR_GROUND_CLUTTER_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics_cvars.ground_clutter") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics_cvars.ground_clutter", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CVAR_VIEW_DISTANCE"],
			desc = L["CVAR_VIEW_DISTANCE_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics_cvars.view_distance") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics_cvars.view_distance", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			type = "toggle",
			name = L["CVAR_ANTI_ALIASING"],
			desc = L["CVAR_ANTI_ALIASING_DESC"],
			boxfirst = true,
			group = "graphics",
			get = function() return private.Core.Profile:GetBool("graphics_cvars.anti_aliasing") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("graphics_cvars.anti_aliasing", value)
				private.Core.Optimizer:ApplyProfile()
			end,
		},
		{
			--terrain LOD slider: HIDDEN (hidden=true, takes no space). kept so the wiring stays -- its
			--console variable is driven by the "View Distance" toggle above (terrainLodDist 200).
			type = "range",
			name = L["CVAR_TERRAIN_LOD"],
			desc = L["CVAR_TERRAIN_LOD_DESC"],
			min = 200,
			max = 5000,
			step = 50,
			hidden = true,
			group = "graphics",
			get = function() return tonumber(GetCVar("terrainLodDist")) or 200 end,
			set = function(_, _, value)
				private.Core.CVars:Set("terrainLodDist", value)
			end,
		},
		{
			--far clip slider: HIDDEN. also drives graphicsViewDistance from the same value (farclip 1500,
			--graphicsViewDistance 0 via farclipToViewDistance). driven by the "View Distance" toggle.
			type = "range",
			name = L["CVAR_FARCLIP"],
			desc = L["CVAR_FARCLIP_DESC"],
			min = 1500,
			max = 10000,
			step = 100,
			hidden = true,
			group = "graphics",
			get = function() return tonumber(GetCVar("farclip")) or 1500 end,
			set = function(_, _, value)
				private.Core.CVars:Set("farclip", value)
				private.Core.CVars:Set("graphicsViewDistance", farclipToViewDistance(value))
			end,
		},

		--diagnostics: a breakline at the end of the graphics block moves this and everything after
		--(safety, profiles, the action buttons) into a third column.
		{type = "breakline"},
		{type = "group", name = "diagnostics", UseBackdrop = GROUP_BACKDROP, BackgroundColor = GROUP_BG_COLOR, BackdropBorderColor = GROUP_BORDER_COLOR, width = GROUP_WIDTH, padding = GROUP_PADDING},
		{type = "label", get = function() return L["SECTION_DIAGNOSTICS"] end, text_template = orangeFont, group = "diagnostics"},
		{
			type = "toggle",
			name = L["EVENTS_ENABLE"],
			desc = L["EVENTS_ENABLE_DESC"],
			boxfirst = true,
			group = "diagnostics",
			get = function() return private.Core.Profile:GetBool("event_counter.enabled") end,
			set = function(_, _, value)
				private.Core.Profile:SetBool("event_counter.enabled", value)
				--show/hide the attached side panel to match the checkbox right away.
				private.UI.EventPanel:UpdateVisibility()
			end,
		},

		--profiles
		{type = "blank"},
		{type = "blank"},
		{type = "group", name = "profiles", UseBackdrop = GROUP_BACKDROP, BackgroundColor = GROUP_BG_COLOR, BackdropBorderColor = GROUP_BORDER_COLOR, width = GROUP_WIDTH, padding = GROUP_PADDING},
		{type = "label", get = function() return L["SECTION_PROFILES"] end, text_template = orangeFont, group = "profiles"},
		{
			type = "toggle",
			name = L["PROFILE_AUTO_ROLE"],
			desc = L["PROFILE_AUTO_ROLE_DESC"],
			boxfirst = true,
			group = "profiles",
			get = function() return private.Core.Profile:IsAutoSwitchByRole() end,
			set = function(_, _, value)
				private.Core.Profile:SetAutoSwitchByRole(value)
				--turning it on should move this character onto its role profile right away.
				if value then
					private.Core.Profile:ApplyRoleProfile()
				end
				--refresh so the profile dropdown's disableif re-evaluates (enabled only when auto is off).
				private.UI.Options:RefreshIfOpen()
			end,
		},
		{
			--profile picker: disabled while auto-switch-by-role is on (the spec role decides then). the
			--disableif is re-checked on every options refresh, so toggling auto-switch enables it live.
			type = "select",
			name = L["PROFILE_SELECT"],
			desc = L["PROFILE_SELECT_DESC"],
			group = "profiles",
			get = function() return private.Core.Profile:GetCurrentName() end,
			values = function()
				local options = {}
				for index, profileName in ipairs(private.Core.Profile:GetNames()) do
					--onclick receives (dropdown, fixedParam, value); value is the option's value.
					options[#options + 1] = {
						value = profileName,
						label = profileName,
						onclick = function(_, _, selectedProfile) private.Core.Profile:Switch(selectedProfile) end,
					}
				end

				return options
			end,
			disableif = function() return private.Core.Profile:IsAutoSwitchByRole() end,
		},

		--actions: free-standing buttons, deliberately not inside a group box.
		{type = "blank"},
		{type = "blank"},
		{
			type = "execute",
			name = L["LIVE_TEST"],
			desc = L["LIVE_TEST_DESC"],
			func = function() private.UI.Options:OpenLiveTestPanel() end,
		},
		{
			type = "execute",
			name = L["RESTORE_ALL"],
			desc = L["RESTORE_ALL_DESC"],
			func = function()
				private.Core.Optimizer:RestoreAll()
				private.Print(L["MSG_RESTORED"])
			end,
		},
		{
			type = "execute",
			name = L["MANAGE_PROFILES"],
			desc = L["MANAGE_PROFILES_DESC"],
			func = function() private.UI.Options:OpenProfilePanel() end,
		},
	}
end

--builds the menuOptions descriptor for the standalone "Live FPS Test" window: every live-hide and
--live-graphics toggle applies immediately (bypassing the context gate) so a single setting's FPS
--impact can be measured on the spot. open the FPS Monitor alongside to read the delta.
---@return table
function Categories:BuildLiveTestOptions()
	local locale = private.locale
	local widgets = private.UI.Widgets

	return {
		widgets.SectionHeader(locale["LIVE_TEST_HINT"]),

		--live hide: hide/show Blizzard UI groups right now.
		widgets.Blank(),
		widgets.SectionHeader(locale["SECTION_MANUAL_HIDE"]),
		widgets.LiveHideToggle("minimap", locale["MANUAL_MINIMAP"], locale["MANUAL_MINIMAP_DESC"]),
		widgets.LiveHideToggle("buffs", locale["MANUAL_BUFFS"], locale["MANUAL_BUFFS_DESC"]),
		widgets.LiveHideToggle("raid_frames", locale["MANUAL_RAID_FRAMES"], locale["MANUAL_RAID_FRAMES_DESC"]),
		widgets.LiveHideToggle("action_bars", locale["MANUAL_ACTION_BARS"], locale["MANUAL_ACTION_BARS_DESC"]),

		--live graphics: drop/restore each managed graphics CVar right now.
		widgets.Blank(),
		widgets.SectionHeader(locale["SECTION_LIVE_GRAPHICS"]),
		widgets.LiveCVarToggle("liquid_detail", locale["CVAR_LIQUID_DETAIL"], locale["CVAR_LIQUID_DETAIL_DESC"]),
		widgets.LiveCVarToggle("shadow_quality", locale["CVAR_SHADOW_QUALITY"], locale["CVAR_SHADOW_QUALITY_DESC"]),
		widgets.LiveCVarToggle("depth_effects", locale["CVAR_DEPTH_EFFECTS"], locale["CVAR_DEPTH_EFFECTS_DESC"]),
		widgets.LiveCVarToggle("outline_mode", locale["CVAR_OUTLINE_MODE"], locale["CVAR_OUTLINE_MODE_DESC"]),
		widgets.LiveCVarToggle("spell_density", locale["CVAR_SPELL_DENSITY"], locale["CVAR_SPELL_DENSITY_DESC"]),
		widgets.LiveCVarToggle("environment_detail", locale["CVAR_ENVIRONMENT_DETAIL"], locale["CVAR_ENVIRONMENT_DETAIL_DESC"]),
		widgets.LiveCVarToggle("ground_clutter", locale["CVAR_GROUND_CLUTTER"], locale["CVAR_GROUND_CLUTTER_DESC"]),
		widgets.LiveCVarToggle("view_distance", locale["CVAR_VIEW_DISTANCE"], locale["CVAR_VIEW_DISTANCE_DESC"]),
		widgets.LiveCVarToggle("anti_aliasing", locale["CVAR_ANTI_ALIASING"], locale["CVAR_ANTI_ALIASING_DESC"]),
		widgets.CVarSlider("terrainLodDist", locale["CVAR_TERRAIN_LOD"], locale["CVAR_TERRAIN_LOD_DESC"], 200, 5000, 50),
		widgets.CVarSlider("farclip", locale["CVAR_FARCLIP"], locale["CVAR_FARCLIP_DESC"], 1500, 10000, 100, "graphicsViewDistance", farclipToViewDistance),

		--restore just the live-test overrides (leaves your configured profile untouched).
		widgets.Blank(),
		widgets.Button(locale["LIVE_TEST_RESTORE"], locale["LIVE_TEST_RESTORE_DESC"], function()
			private.UI.Options:RestoreLiveTest()
		end),
	}
end
