-- vim: ft=terra
local pstr = lib.mem.ptr(int8)
local pref = lib.mem.ref(int8)

local terra cs(s: rawstring)
	return pstr { ptr = s, ct = lib.str.sz(s) }
end

local terra 
render_conf_users(co: &lib.srv.convo, path: lib.mem.ptr(pref)): pstr
	if path.ct == 2 then
		var uid, ok = lib.math.shorthand.parse(path(1).ptr,path(1).ct)
		var user = co.srv:actor_fetch_uid(uid)
		if not user then goto e404 end
		var islinkct = false
		var cinp: lib.str.acc
		var clnk: lib.str.acc clnk:compose('<hr>')

		var cinpp = cinp:finalize() defer cinpp:free()
		var clnkp: pstr
		if islinkct then clnkp = clnk:finalize() else
			clnk:free()
			clnkp = pstr { ptr='', ct=0 }
		end
		var pg = data.view.conf_user_ctl {
			name = cs(user(0).handle);
			inputcontent = cinpp;
			linkcontent = clnkp;
		}
		var ret = pg:tostr()
		if islinkct then clnkp:free() end
		return ret
	else

	end
	do return pstr.null() end
	::e404:: co:complain(404, 'not found', 'there is no user or resource by that identifier on this server')

	do return pstr.null() end
end

return render_conf_users
