Documentation icon دستاویز [تخلیق]
require('strict')
local p = {}
local sandbox-- = '/sandbox'
local cfg = mw.loadData('Module:WikiProject banner/config' .. (sandbox or ''))
local yesno = require('Module:Yesno')
local lang = mw.getLanguage(cfg.language)

p.b_checklist = function(args, raw_args, class, demo, assessment_link)
---------------------------
-- B-class checklist ------
---------------------------
if raw_args.HOOK_ASSESS then return nil end -- temporary transition code to prevent two checklists appearing
local show_checklist, parameters_used = false, nil
parameters_used = args.b1 or args.b2 or args.b3 or args.b4 or args.b5 or args.b6
if class=='B' or class=='C' then -- always displayed on C or B
	show_checklist = true
elseif class=='Start' and yesno(args.B_DISPLAY_ON_START) then -- show on Start if option selected
	show_checklist = true
elseif (class=='Start' or class=='Stub') and parameters_used then -- show on Start or Stub if any parameters used
	show_checklist = true
end
if show_checklist then
	local scale = args.QUALITY_CRITERIA=='custom' and assessment_link and assessment_link..'#'..lang:ucfirst(cfg.quality.name)
		or cfg.b_checklist.default_scale
	local text = string.format(
		cfg.b_checklist.text,
		parameters_used and cfg.b_checklist.checked or cfg.b_checklist.not_checked,
		scale
	)
	local syntax = {}
	local criteria = mw.html.create('ol')
	for i = 1, 6 do
		local b = raw_args['b'..i]
		if b and b~='unused' then -- crtierion in use
			b = cfg.b_checklist.mask[string.lower(b)] or cfg.b_checklist.mask.default
			local image = '[[File:' .. cfg.b_checklist.icon[b] .. '.svg|16x16px|link=|alt=]]'
			local failed_cat = args['B'..i..'_CAT']
			local category = ''
			if b~='y' and b~='x' and failed_cat and not demo then -- criterion failed
				category = '[[Category:' .. failed_cat .. ']]'
			end
			if (b=='u' or b=='i') and args.B_MAIN_CAT and not demo then -- unevaluated or invalid parameter
				category = category .. '[[Category:' .. args.B_MAIN_CAT .. ']]'
			end
			criteria:tag('li')
				:wikitext(image .. ' ' .. cfg.b_checklist.criteria[i] .. ': ')
				:tag('span')
					:css('font-style', 'italic')
					:wikitext(cfg.b_checklist.status[b])
					:wikitext(category)
			:allDone()
			local new_syntax = mw.html.create('li')
				:addClass('nowrap')
				:wikitext(string.format(
					cfg.b_checklist.syntax.prompt,
					tostring(i),
					cfg.b_checklist.criteria[i] .. string.rep(' ', cfg.b_checklist.syntax.max_width-#cfg.b_checklist.criteria[i])
			))
			:done()
			table.insert(syntax, tostring(new_syntax))
		end
	end
	local prompt
	if not parameters_used then
		prompt = mw.html.create('span')
			:wikitext(string.format(
				cfg.b_checklist.syntax.text,
				tostring(mw.title.getCurrentTitle():fullUrl({action = 'edit'}))
			))
			:tag('ul')
				:css('font-size', '88%'):css('margin', '0px'):css('font-family', 'monospace, sans-serif'):css('padding', '1em'):css('border', '1px dashed #2f6fab')
				:css('background-color', '#f9f9f9'):css('line-height', '1.1em'):css('list-style', 'none')
				:node(table.concat(syntax))
			:done()
			:wikitext(cfg.b_checklist.syntax.assess)
		:done()
	end
	local checklist = mw.html.create('tr')
		:tag('td')
			:addClass('assess-b')
			:css('background', cfg.b_checklist.background):css('padding-bottom', '5px')
			:wikitext(cfg.b_checklist.image)
		:done()
		:tag('td')
			:addClass('wpb-collapsed-notes')
			:tag('table')
				:addClass('plainlinks mw-collapsible mw-collapsed')
				:tag('tr')
					:tag('th')
						:addClass('wpb-collapsed-head mbox-text')
						:attr('colspan', '3')
						:css('font-weight', 'normal')
						:wikitext(text)
					:done()
					:tag('td'):css('min-width', '3em'):done() -- empty cell for show/hide toggle
				:done()
				:tag('tr')
					:tag('td')
						:css('font-size', '90%')
						:node(criteria)
					:done()
					:tag('td')
						:css('font-size', '88%')
						:node(prompt)
					:done()
					:tag('td'):addClass('empty-cell'):done()
				:done()
			:done()
		:done()
	:done()
	return checklist
end

end
return p