extends vibenews.admin.layout

block title
	- title = "All users";
	
block vibenews.navigation
	ul
		li
			a(href="../") Admin panel
		li
			a(href="./")= title

block vibenews.body
	- import std.algorithm;
	- import std.array : join;
	- import vibe.data.bson;
	
	p
		a(href="../") Back to overview
	
	- void pageLinks()
		- if( info.pageCount > 1 )
			p.pages Pages: 
				- bool last = true;
				- foreach( i; 0 .. info.pageCount )
					- if( i > 9 && i+10 < info.pageCount && (i+10 < info.page || i > info.page+10) )
						- last = false;
						- continue;
					- if( !last )
						| â€¦
						- last = true;
					- if( info.page == i )
						|= i+1
					- else
						a(href="#{req.rootDir}users/?page=#{i+1}")= i+1

	- pageLinks();

	table
		tr
			th Email
			th Display name
			th # of Messages (# removed)
			th Auth tags
			th Ban

		- foreach( usr; info.users )
			tr(class='#{usr.banned ? "inactive" : "active"}')
				td
					a(href="#{req.rootDir}users/#{usr.id}/")= usr.email
				td= usr.fullName
				td #{usr.messageCount} (#{usr.deletedMessageCount})
				td= join(usr.groupStrings, ", ")
				td
					form(method="POST", action="/users/#{usr.id}/update")
						- if (usr.active)
							input(type="hidden", name="active", value=true)
						- if (!usr.banned)
							input(type="hidden", name="banned", value=true)
						button(type="submit")= usr.banned ? "Unban" : "Ban"

	- pageLinks();

	p
		form(method="POST", action="deleteOrphaned")
			button(type="sumbit") Delete orphaned user accounts

		| Orphaned user accounts that are accounts that have no active articles
		| (e.g. none at all or only spam/deactivated articles) and are older
		| than two months.
