وحدة:بطاقة/قالب/مجرى مائي

local generic = require( 'وحدة:بطاقة/أدوات' )

local function ifExist(localdata,item,params)

   if type(params.required) == 'string' then return localdata[params.required] end
   if type(params.required) == 'table' then
      for _,v in ipairs(params.required) do
          if localdata[v] then
             return localdata[v] 
           end
      end
   end
   if type(params.lookfor) == 'table' then
      local d = nil
      for _,v in ipairs(params.lookfor) do
          d = localdata[v] or d
      end
      if d then return ' ' end
   end

   return nil
end


local function tableMerge(t1, t2)

	if type(t1) == 'string' then t1={t1} end
	if type(t2) == 'string' then t2={t2} end
	if type(t2) ~= 'table' then return t1 end

	for _, v in ipairs(t2) do
		table.insert( t1, v ) 
	end
	return t1
end

local function showInfoPoint(label,required ,datas)
  local lookfor={}
  local rows={}

  for k,v in pairs(datas) do
     lookfor = tableMerge(lookfor, v)
  end

  table.insert( rows, {type = 'row' 
		, label = label
		, value = ifExist
        , required = required
        , lookfor = lookfor
	} )

  for k,v in pairs(datas) do
      table.insert( rows, {type = 'row' , style={['font-size']='small', ['font-weight']= 'normal'}
		, label = '←  '..k
		, value = v
	  } )
  end

  return { type = 'multi' ,rows = rows }
end

--[[
local function showInfoPoint0(label,required ,location,coordinates,elevation,length)
  local lookfor
  lookfor = tableMerge(location, coordinates)
  lookfor = tableMerge(lookfor, elevation)
  lookfor = tableMerge(lookfor, length)

  return { type = 'multi' ,rows = {
	{type = 'row' 
		, label = label
		, value = ifExist
        , required = required
        , lookfor = lookfor
	},
	{type = 'row' , style={['font-size']='small', ['font-weight']= 'normal'}
		, label = ['المكان'] =['الطول'] =['الارتفاع'] =['الاحداثيات'] =
		, value = location
	},
	{type = 'row' , style={['font-size']='small', ['font-weight']= 'normal'}
		, label = 
		, value = length
	},
	{type = 'row' , style={['font-size']='small', ['font-weight']= 'normal'}
		, label = 
		, value = elevation
	},
	{type = 'row' , style={['font-size']='small', ['font-weight']= 'normal'}
		, label = 
		, value = coordinates
	},
  }}
end
]]

return 	{
    maincolor = '#CEDEFF' -- اللون المستعمل لعنوان البطاقة
    ,wikimod = 'Wikidata.Ca'
    ,parts = { -- محتويات البطاقة
	generic.title({icon="map"});
	generic.logo(),
	generic.mainimage(),
    generic.locationmap(),
    generic.geoloc(),
	
	{type = 'table' , title ='معلومات عامة' ,rows = {
	{type = 'row' 
		, label = 'Etymology'
		, value = {'etymology','name_etymology'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = 'Nickname(s)'
		, value = {'nickname'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = 'Native name'
		, value = {'native name checker','native_name','name_native'}
		--, wikidata = {property='P'}
	},
   }},
   {type = 'table' , title ='المنطقة' ,rows = {
	{type = 'row' 
		, label = {'subdivision_type1','country_type'}, defaultlabel='البلد'
		, value = {'البلد','الدولة','subdivision_name1','country'}
		, wikidata = {property='P17'}
	},
	{type = 'row' 
		, label = {'subdivision_type2','state_type'}, defaultlabel='الولاية'
		, value = {'subdivision_name2','state','الولاية'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = {'subdivision_type3','region_type'}, defaultlabel='المقاطعة'
		, value = {'subdivision_name3','region','المقاطعة'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = {'subdivision_type4','district_type'}, defaultlabel='الناحية'
		, value = {'subdivision_name4','district','الناحية'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = {'subdivision_type5','municipality_type'}, defaultlabel='البلدية'
		, value = {'subdivision_name5','municipality','البلدية'}
		--, wikidata = {property='P'}
	},
   }},
   {type = 'table' , title ='الخصائص' ,rows = {
	showInfoPoint(
		  'المنبع الرئيسي'
		, {'المنبع الرئيسي'}
		, {['المكان'] ={'مكان المنبع الرئيسي','source1_location'}
		, ['الطول'] ={'طول المنبع الرئيسي','source1_length'}
		, ['الارتفاع'] ={'ارتفاع المنبع الرئيسي','source1_elevation'}
		, ['الاحداثيات'] ={'إحداثيات المنبع الرئيسي','source1_coordinates'}}
	),
	showInfoPoint(
		  'المنبع الثانوي'
		, {'المنبع الثانوي'}
		, {['المكان'] ={'مكان المنبع الثانوي','source2_location'}
		, ['الطول'] ={'طول المنبع الثانوي','source2_length'}
		, ['الارتفاع'] ={'ارتفاع المنبع الثانوي','source2_elevation'}
		, ['الاحداثيات'] ={'إحداثيات المنبع الثانوي','source2_coordinates'}}
		),

	showInfoPoint(
		  '3rd Source'
		, nil
		, {['المكان'] ={'source3_location'}
		, ['الطول'] ={'source3_length'}
		, ['الارتفاع'] ={'source3_elevation'}
		, ['الاحداثيات'] ={'source3_coordinates'}}
		),

	showInfoPoint(
		  '4th Source'
		, nil
		, {['المكان'] ={'source4_location'}
		, ['الطول'] ={'source4_length'}
		, ['الارتفاع'] ={'source4_elevation'}
		, ['الاحداثيات'] ={'source4_coordinates'}}
		),

	showInfoPoint(
		  '5th Source'
		, nil
		, {['المكان'] ={'source5_location'}
		, ['الطول'] ={'source5_length'}
		, ['الارتفاع'] ={'source5_elevation'}
		, ['الاحداثيات'] ={'source5_coordinates'}}
		),

	showInfoPoint(
		  'التقاء المنابع'
		, {'التقاء المنابع','source_confluence'}
		, {['المكان'] ={'موقع التقاء المنابع','source_confluence_location'}
		, ['الارتفاع'] ={'ارتفاع موقع التقاء','source_confluence_elevation'}
		, ['الاحداثيات'] ={'إحداثيات موقع التقاء','source_confluence_coordinates'}}
		),

	showInfoPoint(
		  '[[مصب النهر|المصب]]'
		, {'المصب','mouth'}
		, {['المكان'] ={'مكان المصب','mouth_location'}
		, ['الارتفاع'] ={'ارتفاع المصب','mouth_elevation'}
		, ['الاحداثيات'] ={'إحداثيات المصب','mouth_coordinates'}}
		),

	{type = 'row' 
		, label = 'الطول'
		, value = {'الطول','length'}
		, wikidata = {property='P2043' , formatting='unit'}
	},
	{type = 'row' 
		, label = 'مساحة الحوض'
		, value = {'مسطح مائي','basin_size'}
		, wikidata = {property='P2053', formatting='unit'}
	},
	{type = 'row' 
		, label = 'العرض'
		, value = ifExist
        , required = {'العرض','width'}
        , lookfor = {'width_min','width_min_metric','width_min_imperial', 'width_avg','width_avg_metric','width_avg_imperial', 'width_max','width_min_metric','width_min_imperial'}
		, wikidata = {property='P', formatting='unit'}
	},
	{type = 'row' , style='font-weight:normal'
		, label = '← الأدنى'
		, value = {'width_min'}
		--, wikidata = {property='P'}
	},
	{type = 'row' , style='font-weight:normal'
		, label = '← المتوسط'
		, value = {'width_avg'}
		--, wikidata = {property='P'}
	},
	{type = 'row' , style='font-weight:normal'
		, label = '← الأقصى'
		, value = {'width_max'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = 'العمق'
		, value = ifExist
        , required = {'العمق','depth'}
        , lookfor = {'depth_min','depth_avg','depth_max'}
		--, wikidata = {property='P', formatting='unit'}
	},
	{type = 'row' , style='font-weight:normal'
		, label = '← الأدنى'
		, value = {'depth_min'}
		--, wikidata = {property='P'}
	},
	{type = 'row' , style='font-weight:normal'
		, label = '← المتوسط'
		, value = {'depth_avg'}
		--, wikidata = {property='P'}
	},
	{type = 'row' , style='font-weight:normal'
		, label = '← الأقصى'
		, value = {'depth_max'}
		--, wikidata = {property='P'}
	},

   }},
   {type = 'table' , title ='مميزات الحوض' ,rows = {
	{type = 'row' 
		, label = 'Progression'
		, value = {'progression'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = '[[Drainage basin|River system]]'
		, value = {'river_system','parent'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = 'Landmarks'
		, value = {'basin_landmarks','landmark'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = 'المدن'
		, value = {'cities','city','المدن','مدن'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = 'السكان'
		, value = {'basin_population','السكان'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = 'الروافد'
		, value = ifExist
        , required = {'الروافد','tributaries'}
        , lookfor = {'tributaries_left','tributaries_right'}
		, wikidata = {property='P974'}
	},
	{type = 'row' , style='font-weight:normal'
		, label = '← على اليسار'
		, value = {'tributaries_left'}
		--, wikidata = {property='P'}
	},
	{type = 'row' , style='font-weight:normal'
		, label = '← على اليمين'
		, value = {'tributaries_right'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = 'المسطحات المائية'
		, value = {'waterbodies','المسطحات المائية','بحيرات على النهر'}
		, wikidata = {property='P469'}
	},
	{type = 'row' 
		, label = 'الشلالات'
		, value = {'waterfalls','الشلالات'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = 'الجسور'
		, value = {'bridges','الجسور'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = '[[ميناء داخلي]]'
		, value = {'ports','موانئ'}
		--, wikidata = {property='P'}
	},
	{type = 'row' 
		, label = {'custom_label'}
		, value = {'custom_data'}
		--, wikidata = {property='P'}
	},
	}},

   {type = 'table' , title ='متفرقات' ,rows = {
	{type = 'row1col' 
		, value = {'extra','متفرقات'}
	},
	}},
    
 }
}