ХӀокху модулах лаьцна хааман Модуль:TeamBracketParts/doc агӀо кхолла мега

local p = {} -- p stands for package

function get(args, tour, name, number)
	local res = args[tour .. '-' .. name .. number] or ''
	if res ~= '' then
		return res
	else
		return args[tour .. '-' .. name .. '0' .. number] or ''
	end
end

function p.cell (frame)
	local args = frame:getParent().args
	local tour = frame.args[1]
	local number = frame.args[2]
	
	local twin_number = nil
	if (number % 2 == 0) then
		twin_number = number - 1
	else
		twin_number = number + 1
	end
	
	local res = {}
	res.seed = get(args, tour, 'seed', number)
	if res.seed == '' and get(args, tour, 'seed', twin_number) ~= '' then
		res.seed = ' '
	end
	
	res.team = get(args, tour, 'team', number)
	if get(args, tour, 'team', twin_number) == '' then
		res.team = ''
	end
	
	res.score = get(args, tour, 'score', number)
	if res.score == '' and get(args, tour, 'score', number .. '-A') ~= '' then
		res.score = get(args, tour, 'score', number .. '-A')
	end
	if res.score == '' and get(args, tour, 'score', number .. '-agg') ~= '' then
		res.score = get(args, tour, 'score', number .. '-agg')
	end
	
	if res.score == '' and (
		get(args, tour, 'score', twin_number) ~= '' or
		get(args, tour, 'score', twin_number .. '-A') ~= '' or
		get(args, tour, 'score', twin_number .. '-agg') ~= ''
		) then
		res.score = ' '
	end
	
	for i = 1, 7 do
		res['score' .. i] = get(args, tour, 'score', number .. '-' .. i)
		if (res['score' .. i] == '') and get(args, tour, 'score', twin_number .. '-' .. i) ~= '' then
			res['score' .. i] = ' '
		end
	end
	
	return frame:expandTemplate{title='Кеп:Турнирная сетка/ячейка', args=res}
end

return p