---------------------------------------------------------------------------------------------------
-- Addon Manager
-- Popup
---------------------------------------------------------------------------------------------------
Global( 'AddonManager', {} )
local moduleName = 'Popup'
local module = { state = false }
AddonManager[ moduleName ] = module
---------------------------------------------------------------------------------------------------
module.GetWidgets = function( self )
	self.widget = W( 'Popup' )
	self.container = W( 'Container', self.widget )
end

module.AddItem = function( self, name )
	local widget
	if not self.itemDesc then
		widget = W( 'PopupItem' )
		self.itemDesc = widget:GetWidgetDesc()
	else
		widget = mainForm:CreateWidgetByDesc( self.itemDesc )
	end
	widget:SetName( name )
	local placement = widget:GetPlacementPlain()
	widget:SetVal( 'value', locales[ name ][ 'Locale' ] )
	widget:Show( true )
	self.container:PushBack( widget )
end

module.SetPlacement = function( self, widget )
	local placement = self.widget:GetPlacementPlain()
	local widgetPlacement = widget:GetPlacementPlain()
	placement.alignX = widgetPlacement.alignX
	placement.alignY = placement.alignX	
	placement.highPosX = widgetPlacement.highPosX - 5 	--ugly :'(
	placement.highPosY = widgetPlacement.highPosY
	self.widget:SetPlacementPlain( placement )
end

module.Toggle = function( self )
	self.state = not self.state
	self.widget:Show( self.state )
end

module.Init = function( self )
	self:GetWidgets()
	for locale in locales do self:AddItem( locale )	end
	self:SetPlacement( W( 'LanguagePanel' ) )
end
---------------------------------------------------------------------------------------------------