local Azurah		= _G['Azurah'] -- grab addon table from global
local LAM			= LibStub('LibAddonMenu-2.0')
local LMP			= LibStub('LibMediaProvider-1.0')
local L				= Azurah:GetLocale()

-- UPVALUES --
local WM					= GetWindowManager()
local CM					= CALLBACK_MANAGER
local tinsert 				= table.insert
local tsort					= table.sort
local strformat				= string.format

-- DROPDOWN CHOICES --
local dropOverlay			= {L.DropOverlay1, L.DropOverlay2, L.DropOverlay3, L.DropOverlay4, L.DropOverlay5, L.DropOverlay6}
local dropOverlayRef		= {[L.DropOverlay1] = 1, [L.DropOverlay2] = 2, [L.DropOverlay3] = 3, [L.DropOverlay4] = 4, [L.DropOverlay5] = 5, [L.DropOverlay6] = 6}
local dropColourBy			= {L.DropColourBy1, L.DropColourBy2, L.DropColourBy3}
local dropColourByRef		= {[L.DropColourBy1] = 1, [L.DropColourBy2] = 2, [L.DropColourBy3] = 3}
local dropExpBarStyle		= {L.DropExpBarStyle1, L.DropExpBarStyle2, L.DropExpBarStyle3}
local dropExpBarStyleRef	= {[L.DropExpBarStyle1] = 1, [L.DropExpBarStyle2] = 2, [L.DropExpBarStyle3] = 3}

local dropFontStyle			= {'none', 'outline', 'thin-outline', 'thick-outline', 'shadow', 'soft-shadow-thin', 'soft-shadow-thick'}

local tabButtons			= {}
local tabPanels				= {}
local lastAddedControl		= {}
local settingsGlobalStr		= strformat('%s_%s', Azurah.name, 'Settings')
local settingsGlobalStrBtns	= strformat('%s_%s', settingsGlobalStr, 'TabButtons')
local availableProfiles		= {}	-- profiles avilable to player to copy (either from other characters or built-in choices)
local profileToCopy			= false -- profile to copy (if chosen)
local controlPanel, controlPanelWidth, tabButtonsPanel, tabPanelData


-- ------------------------
-- PROFILE FUNCTIONS
-- ------------------------
local function CopyTable(src, dest)
	if (type(dest) ~= 'table') then
		dest = {}
	end

	if (type(src) == 'table') then
		for k, v in pairs(src) do
			if (type(v) == 'table') then
				CopyTable(v, dest[k])
			end

			dest[k] = v
		end
	end
end

local function CopyProfileSettings(source)
	local sourceData, destData
	local dest = GetUnitName('player')

	for account, accountData in pairs(AzurahDB.Default) do
		for character, data in pairs(accountData) do
			if (character == source and data.version == 2) then -- source character data (and is of the right version)
				sourceData = data
			end

			if (character == dest) then -- dest character data (current character)
				destData = data
			end
		end
	end

	if (not sourceData or not destData) then -- something went wrong, abort
		CHAT_SYSTEM:AddMessage(string.format('%s: %s', L.Azurah, L.Profile_CopyCannotCopy))
	else
		CopyTable(sourceData, destData) -- do the copy
		ReloadUI()
	end
end

local function GetAvailableProfiles()
	local currentPlayer = GetUnitName('player')

    for account, accountData in pairs(AzurahDB.Default) do
        for player, data in pairs (accountData) do
            if (data.version == 2 and player ~= currentPlayer) then -- only copy 2.X settings, ignore 1.X and current character
                tinsert(availableProfiles, player)
            end
        end
    end

	-- eventually add suggested default profiles to this list as well kt

    tsort(availableProfiles)
end


-- ------------------------
-- PANEL CONSTRUCTION
-- ------------------------
local function CreateWidgets(panelID, panelData)
	local panel = tabPanels[panelID]

	for entry, widgetData in ipairs(panelData) do
		local widgetType = widgetData.type
		local widget = LAMCreateControl[widgetType](panel, widgetData)

		if (widget.data.isFontColour) then -- special case for font colour widgets
			widget.thumb:ClearAnchors()
			widget.thumb:SetAnchor(RIGHT, widget.color, RIGHT, 0, 0)

			widget:SetAnchor(TOPLEFT, lastAddedControl[panelID], TOPLEFT, 0, 0) -- overlay widget with previous
			widget:SetWidth(controlPanelWidth - (controlPanelWidth / 3) - 15) -- shrink widget to give appearance of sharing a row
		else
			widget:SetAnchor(TOPLEFT, lastAddedControl[panelID], BOTTOMLEFT, 0, 15)
			lastAddedControl[panelID] = widget
		end
	end
end

local function CreateTabPanel(panelID)
	local panel = WM:CreateControl(nil, controlPanel.scroll, CT_CONTROL)
	panel.panel = controlPanel
	panel:SetWidth(controlPanelWidth)
	panel:SetAnchor(TOPLEFT, tabButtonsPanel, BOTTOMLEFT, 0, 6)
	panel:SetResizeToFitDescendents(true)

	tabPanels[panelID] = panel

	local ctrl = LAMCreateControl.header(panel, {
		type = 'header',
		name = L['TabHeader' .. panelID],
	})
	ctrl:SetAnchor(TOPLEFT)

	lastAddedControl[panelID] = ctrl

	CreateWidgets(panelID, tabPanelData[panelID]) -- create the actual setting elements
end


-- ------------------------
-- TAB BUTTON HANDLER
-- ------------------------
local function TabButtonOnClick(self)
	if (not tabPanels[self.panelID]) then
		CreateTabPanel(self.panelID) -- call to create appropriate panel if not created yet
	end

	for x = 1, 6 do
		tabButtons[x].button:SetState(0) -- unset selected state for all buttons
	end

	tabButtons[self.buttonID].button:SetState(1, true) -- set selected state for current button

	for id, panel in pairs(tabPanels) do
		panel:SetHidden(not (id == self.panelID)) -- hide all other tab panels but intended
	end
end


-- -----------------------
-- INITIALIZATION
-- -----------------------
local function CompleteInitialization(panel)
	if (panel ~= controlPanel) then return end -- only proceed if this is our settings panel

	tabButtonsPanel		= _G[settingsGlobalStrBtns] -- setup reference to tab buttons (custom) panel
	controlPanelWidth	= controlPanel:GetWidth() - 60 -- used several times

	local btn

	for x = 1, 6 do
		btn = LAMCreateControl.button(tabButtonsPanel, { -- create our tab buttons
			type = 'button',
			name = L['TabButton' .. x],
			func = TabButtonOnClick,
		})
		btn.button.buttonID	= x -- reference lookup to refer to buttons
		btn.button.panelID	= x -- reference lookup to refer to panels

		btn:SetWidth((controlPanelWidth / 3) - 2)
		btn.button:SetWidth((controlPanelWidth / 3) - 2)
		btn:SetAnchor(TOPLEFT, tabButtonsPanel, TOPLEFT, (controlPanelWidth / 3) * ((x - 1) % 3), (x <= 3) and 0 or 34)

		tabButtons[x] = btn
	end

	tabButtons[1].button:SetState(1, true) -- set selected state for first (General) panel

	CreateTabPanel(1) -- create first (General) panel on settings first load

	GetAvailableProfiles() -- populate available profiles
end

function Azurah:InitializeSettings()
	local panelData = {
		type = 'panel',
		name = self.name,
		displayName = L.Azurah,
		author = 'Kith, Garkin, Phinix, Sounomi',
		version = self.version,
		registerForRefresh = true,
		registerForDefaults = false,
	}

	controlPanel = LAM:RegisterAddonPanel(settingsGlobalStr, panelData)

	local optionsData = {
		[1] = {
			type = 'custom',
			reference = settingsGlobalStrBtns,
		}
	}

	LAM:RegisterOptionControls(settingsGlobalStr, optionsData)

	CM:RegisterCallback('LAM-PanelControlsCreated', CompleteInitialization)
end


-- -----------------------
-- OPTIONS DATA TABLES
-- -----------------------
tabPanelData = {
	-- -----------------------
	-- GENERAL PANEL
	-- -----------------------
	[1] = {
		{
			type = "description",
			text = L.GeneralAnchorDesc,
		},
		{
			type = "button",
			name = L.GeneralAnchorUnlock,
			func = function()
				Azurah.SlashCommand('unlock')

			end,
		},
		-- -----------------------
		-- COMPASS PINS
		-- -----------------------
		{
			type = "header",
			name = L.GeneralCompassPins,
		},
		{
			type = "slider",
			name = L.GeneralPinScale,
			tooltip = L.GeneralPinScaleTip,
			min = 60,
			max = 110,
			getFunc = function()
				return Azurah.db.compassPinScale * 100
			end,
			setFunc = function(arg)
				Azurah.db.compassPinScale = arg / 100
				Azurah:ConfigureCompass()
			end,
		},
		{
			type = "checkbox",
			name = L.GeneralPinLabel,
			tooltip = L.GeneralPinLabelTip,
			getFunc = function()
				return Azurah.db.compassHidePinLabel
			end,
			setFunc = function(arg)
				Azurah.db.compassHidePinLabel = arg
				Azurah:ConfigureCompass()
			end,
		},
	},
	-- -----------------------
	-- ATTRIBUTES PANEL
	-- -----------------------
	[2] = {
		{
			type = "slider",
			name = L.AttributesFadeMin,
			tooltip = L.AttributesFadeMinTip,
			min = 0,
			max = 100,
			step = 5,
			getFunc = function() return Azurah.db.attributes.fadeMinAlpha * 100 end,
			setFunc = function(arg)
					Azurah.db.attributes.fadeMinAlpha = arg / 100
					Azurah:ConfigureAttributeFade()
				end,
		},
		{
			type = "slider",
			name = L.AttributesFadeMax,
			tooltip = L.AttributesFadeMaxTip,
			min = 0,
			max = 100,
			step = 5,
			getFunc = function() return Azurah.db.attributes.fadeMaxAlpha * 100 end,
			setFunc = function(arg)
					Azurah.db.attributes.fadeMaxAlpha = arg / 100
					Azurah:ConfigureAttributeFade()
				end,
		},
		{
			type = "checkbox",
			name = L.AttributesCombatBars,
			tooltip = L.AttributesCombatBarsTip,
			getFunc = function() return Azurah.db.attributes.combatBars end,
			setFunc = function(arg)
				Azurah.db.attributes.combatBars = arg
				Azurah:ConfigureAttributeFade()
			end,
		},
		{
			type = "checkbox",
			name = L.AttributesLockSize,
			tooltip = L.AttributesLockSizeTip,
			getFunc = function() return Azurah.db.attributes.lockSize end,
			setFunc = function(arg)
					Azurah.db.attributes.lockSize = arg
					Azurah:ConfigureAttributeSizeLock()
				end,
			warning = L.AttributesLockSizeWarn,
		},
		-- -----------------------
		-- OVERLAY: HEALTH
		-- -----------------------
		{
			type = "header",
			name = L.AttributesOverlayHealth,
		},
		{
			type = "dropdown",
			name = L.SettingOverlayFormat,
			tooltip = L.AttributesOverlayFormatTip,
			choices = dropOverlay,
			getFunc = function() return dropOverlay[Azurah.db.attributes.healthOverlay] end,
			setFunc = function(arg)
					Azurah.db.attributes.healthOverlay = dropOverlayRef[arg]
					Azurah:ConfigureAttributeOverlays()
				end,
		},
		{
			type = "checkbox",
			name = L.SettingOverlayFancy,
			tooltip = L.SettingOverlayFancyTip,
			getFunc = function() return Azurah.db.attributes.healthOverlayFancy end,
			setFunc = function(arg)
					Azurah.db.attributes.healthOverlayFancy = arg
					Azurah:ConfigureAttributeOverlays()
				end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayFont,
			choices = LMP:List('font'),
			getFunc = function()
				return Azurah.db.attributes.healthFontFace
			end,
			setFunc = function(v)
				Azurah.db.attributes.healthFontFace = v
				Azurah:ConfigureAttributeOverlays()
			end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayStyle,
			choices = dropFontStyle,
			getFunc = function()
				return Azurah.db.attributes.healthFontOutline
			end,
			setFunc = function(v)
				Azurah.db.attributes.healthFontOutline = v
				Azurah:ConfigureAttributeOverlays()
			end,
		},
		{
			type = 'colorpicker',
			getFunc = function()
				return Azurah.db.attributes.healthFontColour.r, Azurah.db.attributes.healthFontColour.g, Azurah.db.attributes.healthFontColour.b, Azurah.db.attributes.healthFontColour.a
			end,
			setFunc = function(r, g, b, a)
				Azurah.db.attributes.healthFontColour.r = r
				Azurah.db.attributes.healthFontColour.g = g
				Azurah.db.attributes.healthFontColour.b = b
				Azurah.db.attributes.healthFontColour.a = a
				Azurah:ConfigureAttributeOverlays()
			end,
			isFontColour = true,
		},
		{
			type = 'slider',
			name = L.SettingOverlaySize,
			min = 8,
			max = 32,
			getFunc = function()
				return Azurah.db.attributes.healthFontSize
			end,
			setFunc = function(v)
				Azurah.db.attributes.healthFontSize = v
				Azurah:ConfigureAttributeOverlays()
			end,
		},
		-- -----------------------
		-- OVERLAY: MAGICKA
		-- -----------------------
		{
			type = "header",
			name = L.AttributesOverlayMagicka,
		},
		{
			type = "dropdown",
			name = L.SettingOverlayFormat,
			tooltip = L.AttributesOverlayFormatTip,
			choices = dropOverlay,
			getFunc = function() return dropOverlay[Azurah.db.attributes.magickaOverlay] end,
			setFunc = function(arg)
					Azurah.db.attributes.magickaOverlay = dropOverlayRef[arg]
					Azurah:ConfigureAttributeOverlays()
				end,
		},
		{
			type = "checkbox",
			name = L.SettingOverlayFancy,
			tooltip = L.SettingOverlayFancyTip,
			getFunc = function() return Azurah.db.attributes.magickaOverlayFancy end,
			setFunc = function(arg)
					Azurah.db.attributes.magickaOverlayFancy = arg
					Azurah:ConfigureAttributeOverlays()
				end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayFont,
			choices = LMP:List('font'),
			getFunc = function()
				return Azurah.db.attributes.magickaFontFace
			end,
			setFunc = function(v)
				Azurah.db.attributes.magickaFontFace = v
				Azurah:ConfigureAttributeOverlays()
			end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayStyle,
			choices = dropFontStyle,
			getFunc = function()
				return Azurah.db.attributes.magickaFontOutline
			end,
			setFunc = function(v)
				Azurah.db.attributes.magickaFontOutline = v
				Azurah:ConfigureAttributeOverlays()
			end,
		},
		{
			type = 'colorpicker',
			getFunc = function()
				return Azurah.db.attributes.magickaFontColour.r, Azurah.db.attributes.magickaFontColour.g, Azurah.db.attributes.magickaFontColour.b, Azurah.db.attributes.magickaFontColour.a
			end,
			setFunc = function(r, g, b, a)
				Azurah.db.attributes.magickaFontColour.r = r
				Azurah.db.attributes.magickaFontColour.g = g
				Azurah.db.attributes.magickaFontColour.b = b
				Azurah.db.attributes.magickaFontColour.a = a
				Azurah:ConfigureAttributeOverlays()
			end,
			isFontColour = true,
		},
		{
			type = 'slider',
			name = L.SettingOverlaySize,
			min = 8,
			max = 32,
			getFunc = function()
				return Azurah.db.attributes.magickaFontSize
			end,
			setFunc = function(v)
				Azurah.db.attributes.magickaFontSize = v
				Azurah:ConfigureAttributeOverlays()
			end,
		},
		-- -----------------------
		-- OVERLAY: STAMINA
		-- -----------------------
		{
			type = "header",
			name = L.AttributesOverlayStamina,
		},
		{
			type = "dropdown",
			name = L.SettingOverlayFormat,
			tooltip = L.AttributesOverlayFormatTip,
			choices = dropOverlay,
			getFunc = function() return dropOverlay[Azurah.db.attributes.staminaOverlay] end,
			setFunc = function(arg)
					Azurah.db.attributes.staminaOverlay = dropOverlayRef[arg]
					Azurah:ConfigureAttributeOverlays()
				end,
		},
		{
			type = "checkbox",
			name = L.SettingOverlayFancy,
			tooltip = L.SettingOverlayFancyTip,
			getFunc = function() return Azurah.db.attributes.staminaOverlayFancy end,
			setFunc = function(arg)
					Azurah.db.attributes.staminaOverlayFancy = arg
					Azurah:ConfigureAttributeOverlays()
				end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayFont,
			choices = LMP:List('font'),
			getFunc = function()
				return Azurah.db.attributes.staminaFontFace
			end,
			setFunc = function(v)
				Azurah.db.attributes.staminaFontFace = v
				Azurah:ConfigureAttributeOverlays()
			end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayStyle,
			choices = dropFontStyle,
			getFunc = function()
				return Azurah.db.attributes.staminaFontOutline
			end,
			setFunc = function(v)
				Azurah.db.attributes.staminaFontOutline = v
				Azurah:ConfigureAttributeOverlays()
			end,
		},
		{
			type = 'colorpicker',
			getFunc = function()
				return Azurah.db.attributes.staminaFontColour.r, Azurah.db.attributes.staminaFontColour.g, Azurah.db.attributes.staminaFontColour.b, Azurah.db.attributes.staminaFontColour.a
			end,
			setFunc = function(r, g, b, a)
				Azurah.db.attributes.staminaFontColour.r = r
				Azurah.db.attributes.staminaFontColour.g = g
				Azurah.db.attributes.staminaFontColour.b = b
				Azurah.db.attributes.staminaFontColour.a = a
				Azurah:ConfigureAttributeOverlays()
			end,
			isFontColour = true,
		},
		{
			type = 'slider',
			name = L.SettingOverlaySize,
			min = 8,
			max = 32,
			getFunc = function()
				return Azurah.db.attributes.staminaFontSize
			end,
			setFunc = function(v)
				Azurah.db.attributes.staminaFontSize = v
				Azurah:ConfigureAttributeOverlays()
			end,
		},
	},
	-- -----------------------
	-- TARGET PANEL
	-- -----------------------
	[3] = {
		{
			type = "checkbox",
			name = L.TargetLockSize,
			tooltip = L.TargetLockSizeTip,
			getFunc = function() return Azurah.db.target.lockSize end,
			setFunc = function(arg)
					Azurah.db.target.lockSize = arg
					Azurah:ConfigureTargetSizeLock()
				end
		},
		{
			type = "dropdown",
			name = L.TargetColourByBar,
			tooltip = L.TargetColourByBarTip,
			choices = dropColourBy,
			getFunc = function() return dropColourBy[Azurah.db.target.colourByBar] end,
			setFunc = function(arg)
					Azurah.db.target.colourByBar = dropColourByRef[arg]
					Azurah:ConfigureTargetColouring()
				end,
		},
		{
			type = "dropdown",
			name = L.TargetColourByName,
			tooltip = L.TargetColourByNameTip,
			choices = dropColourBy,
			getFunc = function() return dropColourBy[Azurah.db.target.colourByName] end,
			setFunc = function(arg)
					Azurah.db.target.colourByName = dropColourByRef[arg]
					Azurah:ConfigureTargetColouring()
				end,
		},
		{
			type = "checkbox",
			name = L.TargetColourByLevel,
			tooltip = L.TargetColourByLevelTip,
			getFunc = function() return Azurah.db.target.colourByLevel end,
			setFunc = function(arg)
					Azurah.db.target.colourByLevel = arg
					Azurah:ConfigureTargetColouring()
				end,
		},
		{
			type = "checkbox",
			name = L.TargetIconClassShow,
			tooltip = L.TargetIconClassShowTip,
			getFunc = function() return Azurah.db.target.classShow end,
			setFunc = function(arg)
					Azurah.db.target.classShow = arg
					Azurah:ConfigureTargetIcons()
				end,
		},
		{
			type = "checkbox",
			name = L.TargetIconClassByName,
			tooltip = L.TargetIconClassByNameTip,
			getFunc = function() return Azurah.db.target.classByName end,
			setFunc = function(arg)
					Azurah.db.target.classByName = arg
					Azurah:ConfigureTargetIcons()
				end,
		},
		{
			type = "checkbox",
			name = L.TargetIconAllianceShow,
			tooltip = L.TargetIconAllianceShowTip,
			getFunc = function() return Azurah.db.target.allianceShow end,
			setFunc = function(arg)
					Azurah.db.target.allianceShow = arg
					Azurah:ConfigureTargetIcons()
				end,
		},
		{
			type = "checkbox",
			name = L.TargetIconAllianceByName,
			tooltip = L.TargetIconAllianceByNameTip,
			getFunc = function() return Azurah.db.target.allianceByName end,
			setFunc = function(arg)
					Azurah.db.target.allianceByName = arg
					Azurah:ConfigureTargetIcons()
				end,
		},
		{
			type = "dropdown",
			name = L.SettingOverlayFormat,
			tooltip = L.TargetOverlayFormatTip,
			choices = dropOverlay,
			getFunc = function() return dropOverlay[Azurah.db.target.overlay] end,
			setFunc = function(arg)
					Azurah.db.target.overlay = dropOverlayRef[arg]
					Azurah:ConfigureTargetOverlay()
				end,
		},
		{
			type = "checkbox",
			name = L.SettingOverlayFancy,
			tooltip = L.SettingOverlayFancyTip,
			getFunc = function() return Azurah.db.target.overlayFancy end,
			setFunc = function(arg)
					Azurah.db.target.overlayFancy = arg
					Azurah:ConfigureTargetOverlay()
				end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayFont,
			choices = LMP:List('font'),
			getFunc = function()
				return Azurah.db.target.fontFace
			end,
			setFunc = function(v)
				Azurah.db.target.fontFace = v
				Azurah:ConfigureTargetOverlay()
			end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayStyle,
			choices = dropFontStyle,
			getFunc = function()
				return Azurah.db.target.fontOutline
			end,
			setFunc = function(v)
				Azurah.db.target.fontOutline = v
				Azurah:ConfigureTargetOverlay()
			end,
		},
		{
			type = 'colorpicker',
			getFunc = function()
				return Azurah.db.target.fontColour.r, Azurah.db.target.fontColour.g, Azurah.db.target.fontColour.b, Azurah.db.target.fontColour.a
			end,
			setFunc = function(r, g, b, a)
				Azurah.db.target.fontColour.r = r
				Azurah.db.target.fontColour.g = g
				Azurah.db.target.fontColour.b = b
				Azurah.db.target.fontColour.a = a
				Azurah:ConfigureTargetOverlay()
			end,
			isFontColour = true,
		},
		{
			type = 'slider',
			name = L.SettingOverlaySize,
			min = 8,
			max = 32,
			getFunc = function()
				return Azurah.db.target.fontSize
			end,
			setFunc = function(v)
				Azurah.db.target.fontSize = v
				Azurah:ConfigureTargetOverlay()
			end,
		},
		-- -----------------------
		-- BOSSBAR SETTINGS
		-- -----------------------
		{
			type = "header",
			name = L.BossbarHeader,
		},
		{
			type = "dropdown",
			name = L.SettingOverlayFormat,
			tooltip = L.BossbarOverlayFormatTip,
			choices = dropOverlay,
			getFunc = function() return dropOverlay[Azurah.db.bossbar.overlay] end,
			setFunc = function(arg)
					Azurah.db.bossbar.overlay = dropOverlayRef[arg]
					Azurah:ConfigureBossbarOverlay()
				end,
		},
		{
			type = "checkbox",
			name = L.SettingOverlayFancy,
			tooltip = L.SettingOverlayFancyTip,
			getFunc = function() return Azurah.db.bossbar.overlayFancy end,
			setFunc = function(arg)
					Azurah.db.bossbar.overlayFancy = arg
					Azurah:ConfigureBossbarOverlay()
				end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayFont,
			choices = LMP:List('font'),
			getFunc = function()
				return Azurah.db.bossbar.fontFace
			end,
			setFunc = function(v)
				Azurah.db.bossbar.fontFace = v
				Azurah:ConfigureBossbarOverlay()
			end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayStyle,
			choices = dropFontStyle,
			getFunc = function()
				return Azurah.db.bossbar.fontOutline
			end,
			setFunc = function(v)
				Azurah.db.bossbar.fontOutline = v
				Azurah:ConfigureBossbarOverlay()
			end,
		},
		{
			type = 'colorpicker',
			getFunc = function()
				return Azurah.db.bossbar.fontColour.r, Azurah.db.bossbar.fontColour.g, Azurah.db.bossbar.fontColour.b, Azurah.db.bossbar.fontColour.a
			end,
			setFunc = function(r, g, b, a)
				Azurah.db.bossbar.fontColour.r = r
				Azurah.db.bossbar.fontColour.g = g
				Azurah.db.bossbar.fontColour.b = b
				Azurah.db.bossbar.fontColour.a = a
				Azurah:ConfigureBossbarOverlay()
			end,
			isFontColour = true,
		},
		{
			type = 'slider',
			name = L.SettingOverlaySize,
			min = 8,
			max = 32,
			getFunc = function()
				return Azurah.db.bossbar.fontSize
			end,
			setFunc = function(v)
				Azurah.db.bossbar.fontSize = v
				Azurah:ConfigureBossbarOverlay()
			end,
		},
	},
	-- -----------------------
	-- ACTION BAR PANEL
	-- -----------------------
	[4] = {
		{
			type = "checkbox",
			name = L.ActionBarHideBindBG,
			tooltip = L.ActionBarHideBindBGTip,
			getFunc = function() return Azurah.db.actionBar.hideBindBG end,
			setFunc = function(arg)
					Azurah.db.actionBar.hideBindBG = arg
					Azurah:ConfigureActionBarElements()
				end,
		},
		{
			type = "checkbox",
			name = L.ActionBarHideBindText,
			tooltip = L.ActionBarHideBindTextTip,
			getFunc = function() return Azurah.db.actionBar.hideBindText end,
			setFunc = function(arg)
					Azurah.db.actionBar.hideBindText = arg
					Azurah:ConfigureActionBarElements()
				end,
		},
		{
			type = "checkbox",
			name = L.ActionBarHideWeaponSwap,
			tooltip = L.ActionBarHideWeaponSwapTip,
			getFunc = function() return Azurah.db.actionBar.hideWeaponSwap end,
			setFunc = function(arg)
					Azurah.db.actionBar.hideWeaponSwap = arg
					Azurah:ConfigureActionBarElements()
				end,
		},
		-- ----------------------------
		-- OVERLAY: ULTIMATE (VALUE)
		-- ----------------------------
		{
			type = "header",
			name = L.ActionBarOverlayUltValue,
		},
		{
			type = "checkbox",
			name = L.ActionBarOverlayShow,
			tooltip = L.ActionBarOverlayUltValueShowTip,
			getFunc = function() return Azurah.db.actionBar.ultValueShow end,
			setFunc = function(arg)
					Azurah.db.actionBar.ultValueShow = arg
					Azurah:ConfigureUltimateOverlays()
				end,
		},
		{
			type = "checkbox",
			name = L.ActionBarOverlayUltValueShowCost,
			tooltip = L.ActionBarOverlayUltValueShowCostTip,
			getFunc = function() return Azurah.db.actionBar.ultValueShowCost end,
			setFunc = function(arg)
					Azurah.db.actionBar.ultValueShowCost = arg
					Azurah:ConfigureUltimateOverlays()
				end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayFont,
			choices = LMP:List('font'),
			getFunc = function()
				return Azurah.db.actionBar.ultValueFontFace
			end,
			setFunc = function(v)
				Azurah.db.actionBar.ultValueFontFace = v
				Azurah:ConfigureUltimateOverlays()
			end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayStyle,
			choices = dropFontStyle,
			getFunc = function()
				return Azurah.db.actionBar.ultValueFontOutline
			end,
			setFunc = function(v)
				Azurah.db.actionBar.ultValueFontOutline = v
				Azurah:ConfigureUltimateOverlays()
			end,
		},
		{
			type = 'colorpicker',
			getFunc = function()
				return Azurah.db.actionBar.ultValueFontColour.r, Azurah.db.actionBar.ultValueFontColour.g, Azurah.db.actionBar.ultValueFontColour.b, Azurah.db.actionBar.ultValueFontColour.a
			end,
			setFunc = function(r, g, b, a)
				Azurah.db.actionBar.ultValueFontColour.r = r
				Azurah.db.actionBar.ultValueFontColour.g = g
				Azurah.db.actionBar.ultValueFontColour.b = b
				Azurah.db.actionBar.ultValueFontColour.a = a
				Azurah:ConfigureUltimateOverlays()
			end,
			isFontColour = true,
		},
		{
			type = 'slider',
			name = L.SettingOverlaySize,
			min = 8,
			max = 32,
			getFunc = function()
				return Azurah.db.actionBar.ultValueFontSize
			end,
			setFunc = function(v)
				Azurah.db.actionBar.ultValueFontSize = v
				Azurah:ConfigureUltimateOverlays()
			end,
		},
		-- ----------------------------
		-- OVERLAY: ULTIMATE (PERCENT)
		-- ----------------------------
		{
			type = "header",
			name = L.ActionBarOverlayUltPercent,
		},
		{
			type = "checkbox",
			name = L.ActionBarOverlayShow,
			tooltip = L.ActionBarOverlayUltPercentShowTip,
			getFunc = function() return Azurah.db.actionBar.ultPercentShow end,
			setFunc = function(arg)
					Azurah.db.actionBar.ultPercentShow = arg
					Azurah:ConfigureUltimateOverlays()
				end,
		},
		{
			type = "checkbox",
			name = L.ActionBarOverlayUltPercentRelative,
			tooltip = L.ActionBarOverlayUltPercentRelativeTip,
			getFunc = function() return Azurah.db.actionBar.ultPercentRelative end,
			setFunc = function(arg)
					Azurah.db.actionBar.ultPercentRelative = arg
					Azurah:ConfigureUltimateOverlays()
				end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayFont,
			choices = LMP:List('font'),
			getFunc = function()
				return Azurah.db.actionBar.ultPercentFontFace
			end,
			setFunc = function(v)
				Azurah.db.actionBar.ultPercentFontFace = v
				Azurah:ConfigureUltimateOverlays()
			end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayStyle,
			choices = dropFontStyle,
			getFunc = function()
				return Azurah.db.actionBar.ultPercentFontOutline
			end,
			setFunc = function(v)
				Azurah.db.actionBar.ultPercentFontOutline = v
				Azurah:ConfigureUltimateOverlays()
			end,
		},
		{
			type = 'colorpicker',
			getFunc = function()
				return Azurah.db.actionBar.ultPercentFontColour.r, Azurah.db.actionBar.ultPercentFontColour.g, Azurah.db.actionBar.ultPercentFontColour.b, Azurah.db.actionBar.ultPercentFontColour.a
			end,
			setFunc = function(r, g, b, a)
				Azurah.db.actionBar.ultPercentFontColour.r = r
				Azurah.db.actionBar.ultPercentFontColour.g = g
				Azurah.db.actionBar.ultPercentFontColour.b = b
				Azurah.db.actionBar.ultPercentFontColour.a = a
				Azurah:ConfigureUltimateOverlays()
			end,
			isFontColour = true,
		},
		{
			type = 'slider',
			name = L.SettingOverlaySize,
			min = 8,
			max = 32,
			getFunc = function()
				return Azurah.db.actionBar.ultPercentFontSize
			end,
			setFunc = function(v)
				Azurah.db.actionBar.ultPercentFontSize = v
				Azurah:ConfigureUltimateOverlays()
			end,
		},
	},
	-- ----------------------------
	-- EXPERIENCE BAR PANEL
	-- ----------------------------
	[5] = {
		{
			type = "dropdown",
			name = L.ExperienceDisplayStyle,
			tooltip = L.ExperienceDisplayStyleTip,
			choices = dropExpBarStyle,
			getFunc = function() return dropExpBarStyle[Azurah.db.experienceBar.displayStyle] end,
			setFunc = function(arg)
					Azurah.db.experienceBar.displayStyle = dropExpBarStyleRef[arg]
					Azurah:ConfigureExperienceBarDisplay()
				end,
		},
		{
			type = "dropdown",
			name = L.SettingOverlayFormat,
			tooltip = L.ExperienceOverlayFormatTip,
			choices = dropOverlay,
			getFunc = function() return dropOverlay[Azurah.db.experienceBar.overlay] end,
			setFunc = function(arg)
					Azurah.db.experienceBar.overlay = dropOverlayRef[arg]
					Azurah:ConfigureExperienceBarOverlay()
				end,
		},
		{
			type = "checkbox",
			name = L.SettingOverlayFancy,
			tooltip = L.SettingOverlayFancyTip,
			getFunc = function() return Azurah.db.experienceBar.overlayFancy end,
			setFunc = function(arg)
					Azurah.db.experienceBar.overlayFancy = arg
					Azurah:ConfigureExperienceBarOverlay()
				end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayFont,
			choices = LMP:List('font'),
			getFunc = function()
				return Azurah.db.experienceBar.fontFace
			end,
			setFunc = function(v)
				Azurah.db.experienceBar.fontFace = v
				Azurah:ConfigureExperienceBarOverlay()
			end,
		},
		{
			type = 'dropdown',
			name = L.SettingOverlayStyle,
			choices = dropFontStyle,
			getFunc = function()
				return Azurah.db.experienceBar.fontOutline
			end,
			setFunc = function(v)
				Azurah.db.experienceBar.fontOutline = v
				Azurah:ConfigureExperienceBarOverlay()
			end,
		},
		{
			type = 'colorpicker',
			getFunc = function()
				return Azurah.db.experienceBar.fontColour.r, Azurah.db.experienceBar.fontColour.g, Azurah.db.experienceBar.fontColour.b, Azurah.db.experienceBar.fontColour.a
			end,
			setFunc = function(r, g, b, a)
				Azurah.db.experienceBar.fontColour.r = r
				Azurah.db.experienceBar.fontColour.g = g
				Azurah.db.experienceBar.fontColour.b = b
				Azurah.db.experienceBar.fontColour.a = a
				Azurah:ConfigureExperienceBarOverlay()
			end,
			isFontColour = true,
		},
		{
			type = 'slider',
			name = L.SettingOverlaySize,
			min = 8,
			max = 32,
			getFunc = function()
				return Azurah.db.experienceBar.fontSize
			end,
			setFunc = function(v)
				Azurah.db.experienceBar.fontSize = v
				Azurah:ConfigureExperienceBarOverlay()
			end,
		},
	},
	-- ----------------------------
	-- PROFILES PANEL
	-- ----------------------------
	[6] = {
		{
			type = "dropdown",
			name = L.ProfileCharacterList,
			tooltip = L.ProfileCharacterListTip,
			choices = availableProfiles,
			getFunc = function()
					if (#availableProfiles >= 1) then -- if there are entries, set the first as default
						if (not profileToCopy) then -- profile hasn't been set yet
							profileToCopy = availableProfiles[1]
						end

						return availableProfiles[1]
					end
				end,
			setFunc = function(arg)
				profileToCopy = arg
			end,
		},
		{
			type = "button",
			name = L.ProfileCopyFrom,
			tooltip = L.ProfileCopyFromTip,
			warning = L.ProfileCopyFromWarn,
			func = function(btn)
				CopyProfileSettings(profileToCopy)
			end,
		},
	},
}