Documentation for this module may be created at မော်ဂျူး:hi-headword/doc

local export = {}
local pos_functions = {}
local m_links = require('Module:links')
local m_labels = require('Module:labels')
local m_scripts = require("Module:scripts")

local lang = require('Module:languages').getByCode('hi')
local ur_lang = require('Module:languages').getByCode('ur')
local ur_sc = require('Module:scripts').getByCode('ur-Arab')
local PAGENAME = mw.title.getCurrentTitle().text

local sub = mw.ustring.sub

local genders = {
	['m'] = 'ပုလ္လိင်', ['f'] = 'ဣတ္ထိလိင်'
}

function export.show(frame)
	local args = frame:getParent().args
	PAGENAME = mw.title.getCurrentTitle().text
	
	local head = args["head"]; if head == "" then head = nil end
	local tr = args["tr"]; if tr == "" then tr = nil end
	
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	
	local data = {lang = lang, sc = current_script,
		pos_category = poscat,
		categories = {},
		heads = {args['head']},
		translits = {args['tr']},
		genders = {},
		inflections = {}
	}

	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end
	
	return require("Module:headword").full_headword(data)
end

pos_functions.adjectives = function(args, data)
	local params = {
		['comparative'] = {},
		['superlative'] = {},
		[1] = {},
		[2] = {},
		['head'] = {},
		['tr'] = {},
		['ur'] = {},
		['ur2'] = {},
		['g']= {},
		['f'] = {}, -- to prevent errors
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = {args["head"]}
	data.translits = {args["tr"]}
	
	args['comparative'] = args[1] or args['comparative']
	args['superlative'] = args[2] or args['superlative']
	if args['comparative'] then
		table.insert(data.inflections, {label = 'နှိုင်းယှဉ်နိုင်သော', args['comparative']})
	end
	if args['superlative'] then
		table.insert(data.inflections, {label = 'အသာလွန်ဆုံး', args['superlative']})
	end
	
	if args['ur'] and args['ur2'] then
		table.insert(data.inflections, {label = 'အူရဒူ စာလုံးပေါင်း',
			{term = args['ur'], lang = ur_lang, sc = ur_sc},
			{term = args['ur2'], lang = ur_lang, sc = ur_sc}
		})
	elseif args['ur'] then
		table.insert(data.inflections, {label = 'အူရဒူ စာလုံးပေါင်း', {term = args['ur'], lang = ur_lang, sc = ur_sc}})
	end
end

pos_functions.nouns = function(args, data)
	params = {
		['g'] = {default = '?'},
		['f'] = {},
		['m'] = {},
		["head"] = {},
		["tr"] = {},
		['ur'] = {},
		['ur2'] = {},
		['sg'] = {}, -- to prevent errors
		['pl'] = {}, -- to prevent errors
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = {args["head"]}
	data.translits = {args["tr"]}
		
	local g = args['g']
	if g == 'm' or g == 'f' or g == 'm-p' or g == 'f-p' then
		table.insert(data.genders, g)
		table.insert(data.categories, 'ဟင်ဒီ ' .. genders[sub(g, 1, 1)] .. ' နာမ်များ')
	elseif g == 'mf' or g == 'fm' then
		table.insert(data.genders, sub(g, 1, 1))
		table.insert(data.genders, sub(g, 2, 2))
		table.insert(data.categories, 'ဟင်ဒီ ပုလ္လိင်နှင့် ဣတ္ထိလိင် နာမ်များ')
	elseif g == 'mfp' or g == 'fmp' or g == 'mf-p' or g == 'fm-p' then
		table.insert(data.genders, sub(g, 1, 1) .. '-p')
		table.insert(data.genders, sub(g, 2, 2) .. '-p')
		table.insert(data.categories, 'ဟင်ဒီ ပုလ္လိင်နှင့် ဣတ္ထိလိင် နာမ်များ')
	else
		table.insert(data.genders, '?')
	end
		
	if args['m'] then
		table.insert(data.inflections, {label = genders['m'], args['m']})
	end
	if args['f'] then
		table.insert(data.inflections, {label = genders['f'], args['f']})
	end
	
	if args['ur'] and args['ur2'] then
		table.insert(data.inflections, {label = 'အူရဒူ အသံထွက်',
			{term = args['ur'], lang = ur_lang, sc = ur_sc},
			{term = args['ur2'], lang = ur_lang, sc = ur_sc}
		})
	elseif args['ur'] then
		table.insert(data.inflections, {label = 'အူရဒူ အသံထွက်', {term = args['ur'], lang = ur_lang, sc = ur_sc}})
	end
end

pos_functions.adverbs = function(args, data)
	local params = {
		['head'] = {},
		['tr'] = {},
		['ur'] = {},
		['ur2'] = {},
		['sg'] = {}, -- to prevent errors
	}
	local args = require("Module:parameters").process(args, params)
	data.heads = {args["head"]}
	data.translits = {args["tr"]}
	
	if args['ur'] and args['ur2'] then
		table.insert(data.inflections, {label = 'Urdu spelling',
			{term = args['ur'], lang = ur_lang, sc = ur_sc},
			{term = args['ur2'], lang = ur_lang, sc = ur_sc}
		})
	elseif args['ur'] then
		table.insert(data.inflections, {label = 'အူရဒူ အသံထွက်', {term = args['ur'], lang = ur_lang, sc = ur_sc}})
	end
end

return export