وحدة:بطاقة/قالب/جغرافيا منطقة

local localdata = require("وحدة:بطاقة/بيانات")
local generic = require("وحدة:بطاقة/أدوات")
local wdm = require "Module:Wikidata.Ca"

local item = localdata.item
local parent = {}

function getInfoFromParent(prop,wd)
    local id = (type(localdata.item) == "table") and (type(localdata.item.id) == "string") and localdata.item.id
    
    if not id then return nil end
    if not parent[prop] then
        local wd0 = {} 
        wd0.item = id
        wd0.separator= "/·/"
        wd0.property = prop
        wd0.listrank = "bestrank"
        wd0.editicon  = "no" 
        wd0.formatting = "raw" 

        local parents = wdm.claim(wd0)
        
        if parents then	parents = mw.text.split(parents, '/·/')	else return nil end
        parent[prop] = parents
    end
    
	local default = nil
	
	for i, pitem in pairs(parent[prop] or {}) do
		wd.item = pitem
        wd.query = "num"
        local v,nb = wdm.claim(wd)
        if v then
			return v,nb
		end
	end
	return default    
end

return {
    description = "بطاقة لبيانات مختصرة حول جغرافيا منطقة أو بلد",
    maincolor = "#80B0E0",
    wikimod = "Wikidata.Ca",
    parts = {
        generic.title(),
        generic.logo(),
        generic.mainimage(),
        generic.locationmap(),
        {
            type = "table",
            description = "معلومات عامة",
            title = "معلومات عامة",
            rows = {
                {
                    type = "row",
                    label = "البلد",
                    value = {"بلد", "country"},
                    wikidata = {property = "P17"},
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "المنطقة",
                    value = {"منطقة", "المنطقة", "region"},
                    --wikidata = {property = "P"},
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "القارة",
                    value = {"قارة", "القارة", "continent"},
                    wikidata = {
                        property = "P30", qualifier1="P518", formatting="table", rowformat="$0$R0 $1",
                        rowsubformat1="<small>(ينطبق على $1)</small>", separator = "<br />"
                    },
                    wikidata2 = getInfoFromParent("P1269",{
                        property = "P30",qualifier1="P518", formatting="table", rowformat="$0$R0 $1",
                        rowsubformat1="<small>(ينطبق على $1)</small>", separator = "<br />"
                    }),
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "المناخ",
                    value = {"مناخ", "المناخ", "climate"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "الساحل",
                    value = {"طول الساحل", "km coastline", "miles coastline"},
                    wikidata = {
                        property = "P206",
                        separator = "<br />"
                    },
                    wikidata2 = getInfoFromParent("P1269",{
                        property = "P206",
                        separator = "<br />"
                    }),
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "الحدود",
                    value = {"حدود", "الحدود", "borders"},
                    wikidata = {
                        property = "P47",
                        separator = "<br />"
                    },
                    wikidata2 = getInfoFromParent("P1269",{
                        property = "P47",
                        separator = "<br />"
                    }) ,
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "الأراضي",
                    value = {"أراضي", "الأراضي", "terrain"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                generic.coordinates()
            }
        },
        {
            type = "table",
            --description = "",
            title = "الأرض والتضاريس",
            rows = {
                {
                    type = "row",
                    label = "ترتيب المساحة",
                    value = {"ترتيب المساحة", "area ranking"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "المساحة",
                    value = {"المساحة", "km area", "miles area"},
                    wikidata = {
                        property = "P1269",
                        qualifier = "P1269/P2046",
                        formatting = "table",
                        rowformat = "$1",
                        colformat1 = "unitcode"
                    },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "نسبة اليابسة",
                    value = {"نسبة اليابسة", "percent land"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "نسبة المياه",
                    value = {"نسبة المياه", "percent water"},
                    wikidata = {
                        property = "P1269",
                        qualifier = "P1269/P2927",
                        formatting = "table",
                        rowformat = "$1"
                    },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "أعلى نقطة",
                    value = {"أعلى نقطة", "highest point"},
                    wikidata = {
                        property = "P1269",
                        qualifier = "P1269/P610",
                        formatting = "table",
                        rowformat = "$1"
                    },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "أدنى نقطة",
                    value = {"أدنى نقطة", "lowest point"},
                    wikidata = {
                        property = "P1269",
                        qualifier = "P1269/P1589",
                        formatting = "table",
                        rowformat = "$1"
                    },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "أطول نهر",
                    value = {"أطول نهر", "longest river"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "أكبر بحيرة",
                    value = {"أكبر بحيرة", "largest lake"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                }
            }
        },
        {
            type = "table",
            --description = "",
            title = "متفرقات",
            rows = {
                {
                    type = "row",
                    label = "المصادر الطبيعية",
                    value = {"مصادر طبيعية", "المصادر الطبيعية", "natural resources"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "المخاطر الطبيعية",
                    value = {"مخاطر طبيعية", "الأخطار الطبيعية", "natural hazards"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "القضايا البيئية",
                    value = {"قضايا بيئية", "القضايا البيئية", "environmental issues"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                },
                {
                    type = "row",
                    label = "منطقة اقتصادية خالصة",
                    value = {"منطقة اقتصادية خالصة", "exclusive economic zone"},
                    --, wikidata = { property='P' },
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                }
            }
        },
        {
            type = "table",
            --description = "",
            title = "المراجع",
            rows = {
                {
                    type = "row1col",
                    value = {"مراجع", "references"},
                    metadata = {
                        description = "",
                        option = "", 
                        type = "", 
                    }
                }
            }
        }
    }
}