local p = {}

local data = {
	['done'] = {
		status = {"done", "完成", "批准", "准許", "准许", "允許", "允许", "+"},
		color = '#00AF89',
		text = '完成'
	},
	['nd'] = {
		status = {"拒絕", "拒绝", "驳回", "駁回", "未完成", "不准許", "不准许", "不允許", "不允许", "-", "not done", "nd"},
		color = '#D11D13',
		text = '未完成'
	},
	['oh'] = {
		status = {"on hold", "擱置", "搁置", "等待", "等待中", "oh", "hold", "*", "?"},
		color = '#FFCC00',
		text = '等待中',
		keep = true
	},
	['wd'] = {
		status = {"撤回", "w", "wd", "withdrawn"},
		color = '#000088',
		text = '撤回'
	},
	['ad'] = {
		status = {"already done", "ad", "此前已完成", "此前已批准", "此前已准許", "此前已准许", "此前已允許", "此前已允许"},
		color = '#000000',
		text = '此前已完成'
	},
	['rd'] = {
		status = {"rd", "redundant", "重複", "重复", "重複請求", "重复请求"},
		color = '#FF9999',
		text = '重複請求'
	},

	['unknown'] = {
		status = {},
		color = '#AAAAAA',
		keep = true
	}
}

local function status (x)
	for k,v in pairs(data) do
		for _,s in pairs(v.status) do
			if x == s then return k end
		end
	end
	return 'unknown'
end

local function color (x)
	return data[status(x)].color
end

local function text (x, arg1, arg2)
	return arg2 or data[status(x)].text or arg1 or '處理中'
end

local function isKeep (x)
	return data[status(x)].keep or false
end

function p._main(args)
	local arg = args[1] and args[1]:lower() or '處理中'
    local code = args['prefix'] or '狀態:'
    local spanid = nil
    local bot_archive = ''
    if isKeep(arg) then
    	spanid = '_new_request'
    	bot_archive = mw.getCurrentFrame():expandTemplate{title='Bot-directive-archiver', args={'keep'}}
    end
    code = code ..  mw.text.tag('span', {
    		['style'] = 'background:' .. color(arg),
    		['id'] = spanid or ''
    		}, '  ')
    code = code .. ' ' .. mw.text.tag('b', {}, text(arg, args[1], args[2])) .. (args['sign'] or '')
    code = mw.text.tag('div', {}, code) .. bot_archive
    return code
end
--[=[
	local paid = {}
	if id then paid['id'] = id end
	if id then paid['id'] = id end
	if style then paid['style'] = style end
	if title then paid['title'] = title end
]=]--
function p.main(frame)
	local args = {}
	for k, v in pairs( frame:getParent().args ) do
		args[k] = v
	end
    return p._main(args)
end

return p