local PANEL = class.create("SkinSelect", "Panel")

PANEL:ACCESSOR("Skin", "m_strSkin", "Default")

local overlay = require("overlay")

function PANEL:SkinSelect()
	self:super() -- Initialize our baseclass

	self:DockPadding(1, 1, 1, 1)
	self:SetSize(80, 24)
	self:SetPos(512-80, 0)
	self:SetBorderColor(color_clear)
	self:SetBackgroundColor(color(0, 0, 0, 200))

	local LABEL = self:Add("Label")
	LABEL:SetText("Themes")
	LABEL:SetTextAlignmentX("center")
	LABEL:SizeToText()
	LABEL:Dock(DOCK_TOP)
	LABEL:SetTextColor(color_white)
	LABEL:SetShadowDistance(1)
	LABEL:SetShadowColor(color_black)
	LABEL:SetFont("fonts/melee-bold.otf", 12)
	self.LABEL = LABEL

	self.SKIN_BUTTONS = {}
end

function PANEL:UpdateSkins()
	local numskins = 0
	for id, skin in ipairs(overlay.getSkins()) do
		local SKIN = self:Add("RadioBox")
		SKIN:SetText(skin)
		SKIN:DockMargin(1, 1, 1, 1)
		SKIN:Dock(DOCK_TOP)
		SKIN:SetToggled(false)

		SKIN.OnClick = function()
			self:ChangeSkin(skin)
		end

		self.SKIN_BUTTONS[skin] = SKIN
		numskins = numskins + 1
	end

	self:SetSize(80, self.LABEL:GetHeight() + 26*numskins + 6)
	self:CenterVertical()
end

function PANEL:ChangeSkin(skin)
	skin = self.SKIN_BUTTONS[skin] and skin or "Default"
	if self.SKIN_BUTTONS[skin] then
		for name, pnl in pairs(self.SKIN_BUTTONS) do
			pnl:SetToggled(false)
		end
		self.SKIN_BUTTONS[skin]:SetToggled(true)
		self:SetSkin(skin)
	end
end
