وحدة:Wikidata2/P39/ملعب

  1. ^ "Representative Don Sundquist (1936 - 2023). In Congress 1983 - 1995" (بالإنجليزية). United States Congress. Retrieved 2023-09-04.
  2. ^ Biographical Directory of the United States Congress (بالإنجليزية), United States Government Publishing Office, 1903, QID:Q1150348
---@diagnostic disable: undefined-global
local p = {}

local table_maker = require("Module:ص.م")

local function valid_value(x)
	if x and x ~= "" and x ~= "لا" then return x end
	return nil
end

local function valid_values(xs)
	for _, x in pairs(xs) do
		if valid_value(x) then
			return x
		end
	end
	return nil
end

local function notvalid_value(x)
	if not x or x == "" or x == nil then return true end
	return false
end

local function render_infobox(args)
	local co = valid_value(args.co) or 2

	local output = "</tr>"

	local series_line = ""

	if valid_value(args.series) then
		-- remove &nbsp; form it
		args.series = args.series:gsub("&nbsp;", "")
		series_line = "(" .. args.series .. ")"
	end

	-- ص.م/عنوان فرعي
	local head_title = args.office_img .. (args.office or "") .. " " .. series_line
	local head_row = table_maker.SubTitle({
		[1] = head_title,
		[2] = head_title,
		[3] = "E1E1E1",
		[4] = "000000",
		[5] = co,
	})

	output = output .. head_row

	-- ص.م/سطر
	local term_content = ""
	if valid_value(args.termstart) then
		if valid_value(args.termend) then
			term_content = args.termstart .. " – " .. args.termend
		else
			term_content = "'''منذ''' " .. args.termstart
		end
	else
		if valid_value(args.termend) then
			term_content = "'''حتى''' " .. args.termend
		end
	end

	local date_line = table_maker.Line({
		[1] = term_content,
		[2] = term_content,
		[3] = "center",
		[4] = "f9f9f9",
		[5] = "000000",
		[6] = co,
	})

	output = output .. date_line

	-- أسطر مختلطة شرطية
	local mixed_rows = {
		{ label = "الانتخابات", param = args.electedin },
		{ label = "الرئيس", param = args.president },
		{ label = "رئيس الوزراء", param = args.premier },
		{ label = "مجلس الوزراء", param = args.P5054 },
		{ label = "الدائرة الإنتخابية", param = args.constituency },
		{ label = "فترة برلمانية", param = args.P2937 },
		{ label = "الاختصاص", param = args.jurisdiction },
		{ label = "في", param = valid_values({ args.of, args.employer }) }
	}

	for _, row in ipairs(mixed_rows) do
		if valid_value(row.param) then
			local mixed_row = table_maker.MixedLine({
				[1] = row.label,
				[2] = row.param,
				[3] = row.param,
				[5] = co,
				[6] = "f9f9f9"
			})
			output = output .. mixed_row
		end
	end

	local before_after_row = table_maker.PrevNextLine1({
		[1] = args.predecessor,
		[2] = args.successor,
		["خلفية"] = "f9f9f9",
		["colspan"] = co,
		["سهم يمين"] = "Fleche-defaut-droite-gris-32.png",
		["سهم يسار"] = "Fleche-defaut-gauche-gris-32.png",
		[5] = 8
	})

	output = output .. before_after_row
	output = output .. "<tr>"

	return output
end

local function result_table(s, office_img, personqid, entity_id, options, qualifiers)
	local args = {
		office = s,
		office_img = office_img,
		entityId = personqid,
		q = entity_id,
		co = options.co,
		termstart = qualifiers.start,
		termend = qualifiers.finish,
		constituency = qualifiers.constituency,
		predecessor = qualifiers.before,
		successor = qualifiers.after,
		president = qualifiers.president,
		premier = qualifiers.premier,
		series = qualifiers.series,
		electedin = qualifiers.electedin,
		jurisdiction = qualifiers.P1001,
		employer = qualifiers.P108,
		of = qualifiers.P642,
		P2937 = qualifiers.P2937,
		P5054 = qualifiers.p5054
	}
	local result1 = render_infobox(args)
	if result1 then
		return result1
	end
	local result = mw.getCurrentFrame():expandTemplate {
		title = "صندوق معلومات صاحب منصب/منصب ويكي بيانات/نواة/ملعب",
		args = args
	}
	return result
end

local function get_office_img(qid)
	local ca1 = formatStatements({
		property = "P154",
		otherproperty = "P41",
		entityId = qid,
		noref = "true",
		rank = "all",
		size = "25",
		image = "image",
		firstvalue = "true",
		separator = "",
		conjunction = ""
	})
	return ca1
end

local function get_female_label(office_id, personqid)
	local gender = formatStatements({
		property = 'P21',
		entityId = personqid,
		noref = 't',
		rank = 'all',
		firstvalue = 't',
		formatting = 'raw'
	})

	if gender and (gender == 'Q6581072' or gender == 'Q1052281') then
		local fem_label = formatStatements({
			property = 'P2521',
			entityId = office_id,
			noref = 'true',
			langpref = 'ar',
			formatting = 'text',
			rank = "all"
		})
		return fem_label
	end
	return ""
end

local function get_qua(property, enbarten, modifytime, statement)
	local ca = formatStatements({ property = property, illwd2 = "t", firstvalue = enbarten, modifytime = modifytime },
		statement.qualifiers) or ""
	if ca ~= "" then
		return ca .. addTrackingCategory({ property = property, noicon = "t" })
	end
	return ca
end

local function process_qualifiers(statement)
	return {
		img = formatStatements({
			property = "P94",
			otherproperty = "P41",
			noref = "true",
			rank = "all",
			size = "25",
			image = "image",
			firstvalue = "true",
			separator = "",
			conjunction = ""
		}, statement.qualifiers),
		P108 = get_qua("P108", "", "", statement),
		P108_raw = formatStatements({
			property = "P108",
			noref = "true",
			rank = "all",
			firstvalue = "true",
			formatting = 'raw'
		}, statement.qualifiers),
		start = get_qua("P580", "true", "longdate", statement),
		finish = get_qua("P582", "true", "longdate", statement),
		before = get_qua("P1365", "true", "", statement),
		after = get_qua("P1366", "true", "", statement),
		constituency = get_qua("P768", "", "", statement),
		series = get_qua("P1545", "true", "", statement),
		electedin = get_qua("P2715", "", "", statement),
		P1001 = get_qua("P1001", "", "", statement),
		P642 = get_qua("P642", "", "", statement),
		president = get_qua("P325", "", "", statement),
		premier = get_qua("P6", "", "", statement),
		p5054 = get_qua("P5054", "", "", statement),
		P2937 = get_qua("P2937", "", "", statement)
	}
end

local function office_is_okay(qualifiers, statement)
	if notvalid_value(statement.qualifiers.P108) and notvalid_value(statement.qualifiers.P642) then
		return true
	end
	if statement.qualifiers.P108 and valid_value(qualifiers.P108) then
		return true
	end
	if statement.qualifiers.P642 and valid_value(qualifiers.P642) then
		return true
	end
	return false
end

function p.office3(statement, options)
	local s_tab = formatSnak(statement.mainsnak, options)
	local s = s_tab.value
	local sqid = s_tab.item

	if notvalid_value(s) then
		return ""
	end

	local qualifiers = {}
	if statement.qualifiers then
		qualifiers = process_qualifiers(statement)
	end
	if not valid_values({ qualifiers.start, qualifiers.finish, qualifiers.constituency, qualifiers.before, qualifiers.after, qualifiers.electedin, qualifiers.P1001, qualifiers.president, qualifiers.P5054 }) then
		return ""
	end
	if not office_is_okay(qualifiers, statement) then
		return ""
	end

	local entity_id = statement.mainsnak.datavalue.value.id

	local personqid = options.entityId or options.qid

	local female_label = get_female_label(sqid, personqid)

	local office_label = formatEntityId(entity_id, options).value

	if female_label and female_label ~= "" then
		office_label = formatEntityId(entity_id, { female_label = female_label }).value
	end

	mw.log("s: ", s, "office_label: ", office_label)

	if office_label and office_label ~= "" then
		s = office_label
	end

	if statement.references and options.reff and options.reff ~= "" then
		s = s .. formatReferences(statement, options)
	end

	local office_img

	if qualifiers.img and qualifiers.img ~= "" then
		office_img = qualifiers.img
	else
		office_img = get_office_img(entity_id)
	end

	local result = result_table(s, office_img, personqid, entity_id, options, qualifiers)
	return result
end

return p