local Filename = {}
local lib = require('Module:Feature')
 
function Filename.ability(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    return handleArgs(args, mw.text.trim(encode(formatnil('%s.%s.png', args['champion'] or args[1], args['ability'] or args[2]) or 'Umiejetnosc.png')))
end
 
function Filename.rune(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    return handleArgs(args, mw.text.trim(encode(formatnil('%s.png', args['rune'] or args[1]) or 'Rune.png')))
end
 
function Filename.mastery(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    return handleArgs(args, mw.text.trim(encode(formatnil('%s.specjalizacja.s%d.png', args['mastery'] or args[1], tonumber(args['season'] or args[2])) or 'Specjalizacja.png')))
end
 
function Filename.item(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    return handleArgs(args, mw.text.trim(encode(formatnil('%s item.png', args['item'] or args[1]) or 'Item.png')))
end
 
function Filename.spell(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    return handleArgs(args, mw.text.trim(encode(formatnil('%s.png', args['spell'] or args[1]) or 'Czar.png')))
end
 
function Filename.effect(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    return handleArgs(args, mw.text.trim(encode(formatnil('%s.png', args['effect'] or args[1]) or 'Efekt.png')))
end
 
function Filename.enchantment(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    return handleArgs(args, mw.text.trim(encode(formatnil('%s - %s Item.png', args['item'] or args[1], args['enchantment'] or args[2]) or 'Item.png')))
end
 
function Filename.character(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    return handleArgs(args, mw.text.trim(encode(formatnil('%sSquare.png', args['character'] or args[1]) or 'ChampionSquare.png')))
end
 
function Filename.skin(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
    return handleArgs(args, mw.text.trim(encode(formatnil('%s %sSkin.jpg', args['champion'] or args[1], args['skin'] or args[2] or 'Original') or 'Champion SkinSkin.jpg')))
end
 
function Filename.loading(frame)
    local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
      return handleArgs(args, mw.text.trim(encode(formatnil('%s %sLoading.jpg', args['champion'] or args[1], args['skin'] or args[2] or 'Original') or 'Champion SkinLoading.jpg')))
end
 
function Filename.encode(frame)
    return mw.text.trim(encode(frame.args[1]))
end
function handleArgs(args, filename)
    local result = filename
    if args['prefix'] then filename = args['prefix'] .. filename end
    if args['suffix'] then filename = filename .. args['suffix'] end
    if args['parse'] then filename = mw.getCurrentFrame():preprocess(filename) end
    if args['else'] then
 
    end
    return result
end
function encode(text)
    if text == nil then return nil end
    text = mw.ustring.gsub(text, ':', '')
    return text
end
function formatnil(text, ...)
    if select("#", ...) == 0 then return text end
    for i=1, select("#", ...) do
        if select(i, ...) == nil then return nil end
    end
    return mw.ustring.format(text, ...)
end
 
return Filename