Documentația acestui modul poate fi creată la Modul:InfoboxMinistry/doc

local p = {}
local wikidata = require('Modul:Wikidata')
local infobox = require('Modul:Infobox').infobox
local getArgs = require('Modul:Arguments').getArgs
local ibImage = require('Modul:InfoboxImage').InfoboxImage
local editAtWd = require('Modul:EditAtWikidata').displayMessage
local appendToString = require('Modul:StringUtils')._appendToString

local function brSeparatedEntries(array)
	if not array then return nil end
	if type(array) ~= 'table' then array = { array } end
	array.separator = tostring(mw.html.create('br'))
	return require('Modul:Separated entries')._main(array)
end

local fromArgs = function(name, interface, leadership, history)
	local ibArgs = {antet = 'default', imageclass="Stema", doc="Infocaseta Minister", wikidata="y"}
	ibArgs.title = name
	ibArgs.image = ibImage{image = interface.stema}
	local idx = 1
	ibArgs['label' .. tostring(idx)] = 'Primul deținător al funcției'
	ibArgs['data' .. tostring(idx)] = leadership.firstLeader
	ibArgs['class'.. tostring(idx)] = 'note'
	idx = idx + 1
	ibArgs['label' .. tostring(idx)] = 'Ministru actual'
	ibArgs['data' .. tostring(idx)] = leadership.currentLeader
	idx = idx + 1
	ibArgs['label' .. tostring(idx)] = 'Fondat'
	ibArgs['data' .. tostring(idx)] = history.inception
	idx = idx + 1
	ibArgs['label' .. tostring(idx)] = 'Prezență online'
	ibArgs['data' .. tostring(idx)] = interface.website
	idx = idx + 1

	return infobox(ibArgs)
end

local fromFrame = function(frame)
	local args = getArgs(frame)
	local interface = {}
	interface.stema = args['Stema'] or args['imagine'] or wikidata.findOneValue('P94')
	interface.website = args['Web'] or appendToString({brSeparatedEntries(wikidata.findOnlineLinks()), editAtWd()})
	
	local name = args['Nume'] or args['nume_articol']
	if not name then
		local offNameWdClaims = wikidata.findBestClaimsForProperty(nil, 'P1448')
		if offNameWdClaims then for _,eachOffNameClaim in ipairs(offNameWdClaims) do
			if eachOffNameClaim.type == 'statement' and eachOffNameClaim.mainsnak.snaktype == 'value' and eachOffNameClaim.mainsnak.datavalue.value.language == 'ro' then
				name = appendToString({eachOffNameClaim.mainsnak.datavalue.value.text, editAtWd('P1448')})
			end
		end end
	end
	if not name then name = wikidata.findLabel() end
	local leadership = {}
	leadership.firstLeader = args['Primul']
	leadership.currentLeader = args['Actual']
	if not leadership.currentLeader then
		local positionWdIds = wikidata.findBestClaimsForProperty(nil, 'P2388')
		if positionWdIds and positionWdIds[1] and positionWdIds[1].type == 'statement' and positionWdIds[1].mainsnak.snaktype == 'value' then
			leadership.currentLeader = appendToString({wikidata.findOneValue('P1308', positionWdIds[1].mainsnak.datavalue.value.id), editAtWd('P1308', positionWdIds[1].mainsnak.datavalue.value.id)})
		end
	end
	local history = {}
	history.inception = args['Fondat'] or appendToString({wikidata.findOneValue('P571'), editAtWd('P571')})
	
	return p.fromArgs(name, interface, leadership, history)
end

p.fromArgs = fromArgs
p.fromFrame = fromFrame
return p