local M = {}

local match = mw.ustring.match
local sub = mw.ustring.sub

function M.syn(frame, kind)
	local args = frame:getParent().args
	local title = mw.title.getCurrentTitle().text
	local word = args[1] or title
	local content = mw.title.new("อรรถาภิธาน:" .. word):getContent()
	local temp = kind or "คำพ้องความ"
	local template = match(content, "=+ *".. temp .." *=+\n{{ws beginlist}}(.+){{ws endlist}}")
	if template and template ~= "" then
		local set = {}
		for item in mw.text.gsplit(template, "\n") do
			--table.insert(set, sub(item,6,-3) ~= title and sub(item,6,-3) or nil)
			table.insert(set, match(item,'{{ws|(.+)}}') ~= title and match(item,'{{ws|(.+)}}') or nil)
		end
		--set["name"] = ((args["name"] or kind) == "ant") and "คำตรงข้ามของ" or "คำพ้องความของ"
		set["title"] = args["title"] or nil
		--if args["fold"] or #set > 10 then set["fold"] = 1 end
		return --"''ดูที่ [[อรรถาภิธาน:" .. title .. "]]''" .. 
		'<div style="float: right; clear: right; font-size:60%"><span class="plainlinks">[[อรรถาภิธาน:' .. title .. '|อรรถาภิธาน]]</span> <span class="plainlinks">[' ..
		tostring(mw.uri.fullUrl("อรรถาภิธาน:" .. word, { ["action"] = "edit" })) ..
		' แก้ไข]</span></div>' .. frame:expandTemplate{ title = "template:th-saurus-list", args = set }
	else
		return ""
	end
end

return M