Documentation for this module may be created at Module:Design/doc

local p = {}
local h = require("Module:HF")
local getArgs = require('Dev:Arguments').getArgs

function p.lua_getMainBorderColor()
    return '#B5B7CF'
end

function p.lua_getMainBackgroundColor()
    return '#EFF0FF'
end

function p.lua_green(text)
    local output = ''
    if not h.isempty(text)
        then 
            output = mw.html.create( 'span' )
                :css( 'color', 'darkgreen' )
                :css( 'font-weight', 'bold' )
                :css( 'font-style', 'italic' )
                :css( 'font-size', 'smaller' )
                :wikitext('('..text..')')
                :done()
            output = tostring(output)
    end
    return output
end


function p.lua_span(text)
    local italic = mw.html.create( 'span' ):css( 'font-style', 'italic' )
    local bold = mw.html.create( 'span' ):css( 'font-weight', 'bold' )
    local both = mw.html.create( 'span' ):css( 'font-weight', 'bold' ):css( 'font-style', 'italic' )
    local output = { italic = '', bold = '', both = '' }
    
    if not h.isempty(text)
        then
            output = {
                italic  = tostring(italic:wikitext(text):done()),
                bold    = tostring(bold:wikitext(text):done()),
                both    = tostring(both:wikitext(text):done()),
            }
    end

    return output
end


-- creates message box
function p.messagebox(frame)
    local args = getArgs (frame)
    local width = args['width'] or '95%'
    local textalign = args['text-align'] or 'center'
    local fontsize = args['font-size'] or '100%'
    local border = args['border'] or p.lua_getMainBorderColor()
    local background = args['background'] or p.lua_getMainBackgroundColor()
    local margin = args['margin'] or '1em'
    local clear = args['clear'] or 'none'
    local padding = args['padding'] or '5px'
    local extrastyle = args['extrastyle'] or ''
    local message = args[1] or args['Message'] or ''
    
    local tag = mw.html.create( 'div' )
                :attr( 'id', 'messageBox' )
                :attr( 'align', 'center' )
                :css( 'width', width )
                :css( 'text-align', textalign )
                :css( 'font-size', fontsize )
                :css( 'border', '1px solid '..border )
                :css( 'background', background )
                :css( 'border-radius', '10px' )
                :css( 'margin', margin )
                :css( 'clear', clear )
                :css( 'padding', padding )
                :wikitext( message )
                :done()
    if not h.isempty(extrastyle)
        then tag:cssText (extrastyle):done()
    end
    
    return tostring(tag)
end


-- creates a header
function p.lua_header(text, level, align)
	local output = ''
	level = level or '2'
	align = align or 'left'
	
	if not h.isempty(text)
		then output = '\n'..tostring( mw.html.create( 'h'..level ):css('text-align', align):wikitext( text ) )
	end
	
	return output
end


function p.show_hide(frame)
    local args = getArgs (frame)

    local title = args['title'] or args['header'] or ' '
    local body = args['body'] or args['text'] or ''
    local collapsed = args['collapsed']
    local clear = args['clear'] or 'both'
    local border = args['border'] or p.lua_getMainBorderColor()
    local extrastyle = args['extrastyle'] or ''
    local extrastyle2 = args['extrastyle2'] or ''
    local extrastyle3 = args['extrastyle3'] or ''
    local width = args['width'] or '100%'
    local background = args['background'] or p.lua_getMainBackgroundColor()
    local titlestyle = args['titlestyle'] or ''

    if h.isempty(collapsed) or collapsed == 'true' or collapsed == true
        then collapsed = ' mw-collapsed'
        else collapsed = ''
    end

    local tag_td = mw.html.create( 'td' )
        :css( 'margin', '0.5em' )
        :css( 'font-size', '12px' )
        :wikitext(body)
        :done()
    if not h.isempty(extrastyle3)
        then tag_td:cssText (extrastyle3):done()
    end
    tag_td = '<tr>'..tostring(tag_td)..'</tr>'

    local tag_div = mw.html.create( 'div' )
        :css( 'font-weight', 'bold' )
        :wikitext(title)
        :done()
    if not h.isempty(titlestyle)
        then tag_div:cssText (titlestyle):done()
    end
    tag_div = tostring(tag_div)
    
    local tag_th = mw.html.create( 'th' )
        :attr('colspan', '1')
        :css( 'background-color', background )
        :css( 'font-size', '12px' )
        :wikitext(tag_div)
        :done()
    if not h.isempty(extrastyle2)
        then tag_th:cssText (extrastyle2):done()
    end
    tag_th = '<tr>'..tostring(tag_th)..'</tr>'
    
    local tag_table = mw.html.create( 'table' )
        :addClass('mw-collapsible'..collapsed)
        :css( 'clear', clear )
        :css( 'border', '1px solid '..border )
        :css( 'font-size', '12px' )
        :css( 'width', width )
        :wikitext(tag_th..tag_td)
        :done()
    if not h.isempty(extrastyle)
        then tag_table:cssText (extrastyle):done()
    end
     
    
    return tostring(tag_table) 
end


function p.lua_story_contributors(contributors, title, collapsed, reprint_message, part_of_story)
    reprint_message = reprint_message or ''
    part_of_story = part_of_story or ''
    return p.show_hide({
            collapsed   = collapsed,
            extrastyle  = 'width:100%; margin:0px; border:none; border-top:2px solid '..p.lua_getMainBorderColor()..'; text-align:left; font-size: 12px;',
            title       = title,
            body        = part_of_story..reprint_message..contributors,
        })
end


function p.infobox_line(frame)
    local args = getArgs (frame)
    local left = args['left'] or ''
    local right = args['right'] or ''
    local text = args['text'] or ''
    local width_l = args['width_l'] or '40%' --'100px'
    local width_r = args['width_r'] or '60%' --'190px'

    local tag_l = mw.html.create( 'div' )
        :css( 'width', width_l )
        :css( 'text-align', 'left' )
        :css( 'float', 'left' )
        :wikitext(left)
        :done()        
    local tag_r = mw.html.create( 'div' )
        :css( 'width', width_r )
        :css( 'text-align', 'right' )
        :css( 'float', 'left' )
        :wikitext(right)
        :done() 
        
    tag_l = tostring(tag_l)
    tag_r = tostring(tag_r)

    local tag = mw.html.create( 'div' )
        :css( 'border-top', '1px solid '..p.lua_getMainBorderColor() )
        :css( 'text-align', 'center' )
        :css( 'clear', 'left' )
        :css( 'font-size', '12px' )
        :wikitext(text..tag_l..tag_r)
        :done()
      
    return tostring(tag)
end


function p.infobox_line_horizontal(frame)
    local args = getArgs (frame)
    local centralheader = args['central_header'] or ''
    local leftheader = args['left_header'] or ''
    local lefttext = args['left_text'] or ''
    local rightheader = args['right_header'] or ''
    local righttext = args['right_text'] or ''
    local totalwidth = args['total_width']
    local fontsize_text = args['font_size_text'] or '10px'
    local tag_centralheader
    local tag_leftheader
    local tag_rightheader
    local tag_lefttext
    local tag_righttext
    local output = ''

    if not h.isempty(righttext)
        then 
            if not h.isempty(totalwidth)
                then totalwidth = tostring(tonumber(totalwidth)/2)..'px' 
                else totalwidth = '50%'
            end
        else totalwidth = '100%'
    end

    if not h.isempty(centralheader)
        then
            tag_centralheader = mw.html.create( 'div' )
                :css( 'width', '100%' )
                :css( 'float', 'left' )
                :css( 'font-size', '12px' )
                :wikitext(centralheader)
                :done()
            output = output..tostring(tag_centralheader)
        else
            tag_leftheader = mw.html.create( 'div' )
                :css( 'width', totalwidth )
                :css( 'float', 'left' )
                :css( 'font-size', '12px' )
                :wikitext(leftheader)
                :done()
            output = output..tostring(tag_leftheader)
    end

    if not h.isempty(righttext) and h.isempty(centralheader)
        then
            tag_rightheader = mw.html.create( 'div' )
                    :css( 'width', totalwidth )
                    :css( 'float', 'left' )
                    :css( 'clear', 'right' )
                    :css( 'font-size', '12px' )
                    :wikitext(rightheader)
                    :done()
            output = output..tostring(tag_rightheader)
    end

    tag_lefttext = mw.html.create( 'div' )
        :css( 'width', totalwidth )
        :css( 'float', 'left' )
        :css( 'clear', 'left' )
        :css( 'font-size', fontsize_text )
        :wikitext(lefttext)
        :done()
    output = output..tostring(tag_lefttext)
    

    if not h.isempty(righttext)
        then
            tag_righttext = mw.html.create( 'div' )
                    :css( 'width', totalwidth )
                    :css( 'float', 'left' )
                    :css( 'font-size', fontsize_text )
                    :css( 'text-align', 'center' )
                    :wikitext(righttext)
                    :done()
            output = output..tostring(tag_righttext)
    end

    return tostring( mw.html.create( 'div' )
        :css( 'border-top', '1px solid '..p.lua_getMainBorderColor() )
        :css( 'text-align', 'center' )
        --:css( 'clear', 'left' )
        :wikitext(output)
        :done() )
end  


--transform the list of contributors into infobox line with or without categorization
function p.lua_infobox_line_staff(list, occupation, released, canceled, reprint)
    local SC = require("Module:StaffCorrection")
    local staff_info = mw.loadData("Module:Comics/Staff")
    local i
    local name = ''
    local s = ':Category:Marvel Staff/'
    local field_name = ''
    local names = {}
    local categories = {}
    local output = ''

    list = list or {}
    occupation = occupation or 1
    released = released or true
    canceled = canceled or false

    if not h.isempty(list)
        then 
            field_name = h.Link(s..staff_info[occupation].link, staff_info[occupation].text)

            for i = 1, #list do
                table.insert(names, list[i].link)
                table.insert(categories, list[i].category)
            end
            
            if not h.isempty(names)
                then
                    output = mw.text.listToText(names, '<br />', '<br />')
                    output = p.infobox_line( { left = field_name, right = output }) 
            end
        elseif not reprint and not canceled and released and staff_info[occupation].needed.category 
            then table.insert(categories, staff_info[occupation].category..' Credit Needed')
    end
    
    return output, categories
end

function p.lua_create_infobox(text, width)
    width = width or '300px'
    
    return tostring( mw.html.create( 'div' )
        :attr('class', 'infobox')
        :css( 'width', width )
        :css( 'float', 'right' )
        :css( 'clear', 'none' )
        :css( 'margin', '0px 0px 1em 1em' )
        :css( 'border', '1px solid '..p.lua_getMainBorderColor() )
        :css( 'background', p.lua_getMainBackgroundColor() )
        :css( 'border-radius', '10px' )
        :css( 'padding', '10px' )
        :wikitext(text)
        :done() )
end


-- used to add sections like "Notes", "Trivia", etc.
function p.lua_add_section(section, header)
    local output = ''
 
    if not h.isempty(section)
        then output = p.lua_header(header, 2)..'\n'..section
    end
 
    return output
end

return p
Community content is available under CC-BY-SA unless otherwise noted.