# Module:Flag

local margs = require('Module:Arguments')  

local function _main(, name, mode)  
local categories = {  
['Flag icon'] = '',  
['Flag decoration'] = '',  
}  

local yesno = require('Module:Yesno')  

--Get input arguments  
local args = margs.getArgs(, {  
frameOnly = ((.args.frameonly or *) ~= *), valueFunc =  
function(key,value)  
if value then  
value = mw.text.trim(value)  
--Change empty string to nil for all args except 'image' and ''  
if key=="image" or key=="" or value~="" then  
return value  
end  
end  
return nil  
end  
} )  

local preftext, sufftext = "", ""  

if name == 'Flag+link' then  
args.pref = args[1]  
elseif name == 'Flag athlete' then  
args.preftext = args[1]  
args[2] = args.code or args[2] or ""  
args.variant = args.variant or args[3]  
elseif name == 'Flag medalist' then  
preftext = (args[1] or "") .. "  
"  
args[2] = args.code or args[2] or ""  
args.variant = args.variant or args[3]  
elseif name == 'Flag link' then  
args.suff = args[2]  
args[2] = args[1] or ""  
args.variant = args.variant or args[3]  
else  
sports = {fb = 'fb', ['fb-rt'] = 'fb', fbicon = 'fb', ru = 'ru'}  
if sports[name] then  
args.avar = sports[name]  
if name == 'fb' and yesno(args.align) == true then  
args.  
end  
elseif name == "Flag team" and (args.code or args[1]) then  
sufftext = '&nbsp;<span>('..(args.code or args[1])..')</span>'  
end  
args.variant = args.variant or args[2]  
args[2] = args[1] or ""  
end  

args[1] = mode .. (args.opts or '')  
args.missingcategory = categories[name]  
args.noredlink = args.noredlink or 'notext'  

if args.placeholder and yesno(args.placeholder) ~= true then  
args[1] = args[1] .. 'o'  
end  

if mw.title.getCurrentTitle.namespace == 0 then  
local unknown = ''  
else  
local unknown = ''  
end  

check = ''  

if name == 'Flag icon' then  
local opts = {  
unknown=unknown,  
preview='Page using Template:' .. name .. ' with unknown parameter "_VALUE_"',  
ignoreblank='y',  
'1','2','variant','image','size','sz','','align','al','width',  
'w','alt','ilink','noredlink','missingcategory','name','clink','link',  
'pref','suff','plink','the','section','altvar','avar','age','nalign',  
'nal','text','nodata','opts','placeholder','getParent','frameonly'  
}  
check = require('Module:Check for unknown parameters')._check(opts,args)  
end  

return preftext .. require('Module:Flagg').luaMain(,args) .. sufftext .. check  
end  

local p = {  
[''] = function return _main(, 'Flag', 'unc' ) end,  
decoration = function return _main(, 'Flag decoration', 'uxx' ) end,  
icon = function return _main(, 'Flag icon', 'cxxl' ) end,  
link = function return _main(, 'Flag link', 'unpe' ) end,  
['+link'] = function return _main(, 'Flag+link', 'unpefo') end,  
country = function return _main(, 'Flag country', 'unce' ) end,  
team = function return _main(, 'Flag team', 'unce' ) end,  
athlete = function return _main(, 'Flag athlete', 'unape' ) end,  
medalist = function return _main(, 'Flag medalist', 'unce' ) end,  
fb = function return _main(, 'fb', 'unpe' ) end,  
['fb-rt'] = function return _main(, 'fb-rt', 'unpre' ) end,  
fbicon = function return _main(, 'fbicon', 'pxxl' ) end,  
ru = function return _main(, 'ru', 'unpe' ) end,  
IOC = function return require('Module:Country_alias').flagIOC(:newChild{ title = 'Template:Flag IOC' }) end,  
IOC2 = function return require('Module:Country_alias').flagXYZ(:newChild{ title = 'Template:Flag IOC 2', args = {name = margs.getArgs.name or '', type = 'name'} }) end,  
IOCathlete = function return require('Module:Country_alias').flagXYZ(:newChild{ title = 'Template:Flag IOC athlete', args = {type = 'athlete-O'} }) end,  
}  

p['deco'] = p.decoration  
p['IOC 2'] = p.IOC2  
p['IOC athlete'] = p.IOCathlete  

return p