/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

use super::error::MyResult;
use crate::helper::{accept::Accept, RequestInfo};
use jellycommon::api::ApiHomeResponse;
use jellyui::{home::HomePage, render_page};
use rocket::{get, response::content::RawHtml, serde::json::Json, Either};

#[get("/home")]
pub fn r_home(ri: RequestInfo) -> MyResult<Either<RawHtml<String>, Json<ApiHomeResponse>>> {
    let r = jellylogic::home::home(&ri.session)?;

    Ok(if matches!(ri.accept, Accept::Json) {
        Either::Right(Json(r))
    } else {
        Either::Left(RawHtml(render_page(
            &HomePage { lang: &ri.lang, r },
            ri.render_info(),
        )))
    })
}
