local export = {}
local gsub = mw.ustring.gsub
local u = mw.ustring.char

local tt = {
	-- consonants
	['𑘎'] = 'ก', ['𑘏'] = 'ข', ['𑘐'] = 'ค', ['𑘑'] = 'ฆ', ['𑘒'] = 'ง',
	['𑘓'] = 'จ', ['𑘔'] = 'ฉ', ['𑘕'] = 'ช', ['𑘖'] = 'ฌ', ['𑘗'] = 'ญ',
	['𑘘'] = 'ฏ', ['𑘙'] = 'ฐ', ['𑘚'] = 'ฑ', ['𑘛'] = 'ฒ', ['𑘜'] = 'ณ',
	['𑘝'] = 'ต', ['𑘞'] = 'ถ', ['𑘟'] = 'ท', ['𑘠'] = 'ธ', ['𑘡'] = 'น',
	['𑘢'] = 'ป', ['𑘣'] = 'ผ', ['𑘤'] = 'พ', ['𑘥'] = 'ภ', ['𑘦'] = 'ม',
	['𑘧'] = 'ย', ['𑘨'] = 'ร', ['𑘩'] = 'ล', ['𑘯'] = 'ฬ', ['𑘪'] = 'ว',
	['𑘫'] = 'ศ', ['𑘬'] = 'ษ', ['𑘭'] = 'ส', ['𑘮'] = 'ห',
	-- independent vowels
	['𑘀'] = 'อ', ['𑘁'] = 'อา', ['𑘂'] = 'อิ', ['𑘃'] = 'อี', ['𑘄'] = 'อุ', ['𑘅'] = 'อู',
	['𑘆'] = 'ฤ', ['𑘇'] = 'ฤๅ', ['𑘈'] = 'ฦ', ['𑘉'] = 'ฦๅ',
	['𑘊'] = 'เอ', ['𑘋'] = 'ไอ', ['𑘌'] = 'โอ', ['𑘍'] = 'เอา',
	-- dependent vowels and diacritics (excluding front type)
	['𑘰'] = 'า', ['𑘱'] = 'ิ', ['𑘲'] = 'ี', ['𑘳'] = 'ุ', ['𑘴'] = 'ู',
	['𑘵'] = 'ฺฤ', ['𑘶'] = 'ฺฤๅ', ['𑘷'] = 'ฺฦ', ['𑘸'] = 'ฺฦๅ',
	['𑘽'] = 'ํ', ['𑘾'] = 'ห์', ['𑘿'] = 'ฺ', ['𑙀'] = '็',
	-- marks
	['𑙁'] = 'ฯ', ['𑙂'] = '๚', ['𑙃'] = '.', ['𑙄'] = '๏',
	-- numerals
	['𑙐'] = '0', ['𑙑'] = '1', ['𑙒'] = '2', ['𑙓'] = '3', ['𑙔'] = '4',
	['𑙕'] = '5', ['𑙖'] = '6', ['𑙗'] = '7', ['𑙘'] = '8', ['𑙙'] = '9',
	-- zero-width space (display it if it hides in a word)
	[u(0x200B)] = '‼',
	-- zero-width joiner (display it if it hides in a word)
	[u(0x200D)] = "₊",
}

local adjust1 = {
	-- dependent vowels (front type)
	['𑘹'] = 'เ%1', ['𑘺'] = 'ไ%1', ['𑘻'] = 'โ%1', ['𑘼'] = 'เ%1า',
}

function export.tr(text, lang, sc, debug_mode)

	if type(text) == 'table' then -- called directly from a template
		text = text.args[1]
	end

	text = gsub(text, '.', tt)

	for k, v in pairs(adjust1) do
		text = gsub(text, letter_with_mark..k, v)
	end

	text = gsub(text, '([เแไโ])อฺ', 'อฺ%1')
	text = gsub(text, 'ฯฯ', '๚')
	
	return text

end

return export