use rocket_dyn_templates::{context, Template};
use sqlx::Acquire;

use crate::{
	auth::session::Admin,
	db::{admin, schema::DollTagsDb},
	pages::CommonTemplateState,
};

use super::error_handlers::PageResult;

#[get("/")]
pub async fn index(meta: CommonTemplateState, mut db: DollTagsDb, user: Admin) -> PageResult {
	let mut trx = db.begin().await?;
	let service_status = admin::get_service_status(&mut trx).await?;
	trx.commit().await?;

	Ok(Template::render(
		"admin/index",
		context! {
			meta: meta.for_user(&user.0),
			service_status,
		},
	)
	.into())
}
