/*
    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>
*/
#![feature(phantom_variance_markers)]
pub mod components;
pub(crate) mod format;
mod scaffold;

use std::borrow::Cow;

pub use jellyui_client_scripts::*;
pub use jellyui_client_style::*;
pub use jellyui_locale::tr;

use jellycommon::jellyobject::Object;
use markup::DynRender;
pub use scaffold::Scaffold;
use serde::{Deserialize, Serialize};

#[rustfmt::skip]
#[derive(Debug, Deserialize, Serialize, Default)]
pub struct Config {
    pub brand: String,
    pub slogan: String,
    pub logo: bool,
}

pub trait Page {
    fn title(&self) -> Cow<'static, str>;
    fn ri(&self) -> &RenderInfo<'_>;
    fn render(&self) -> DynRender<'_>;
}

pub struct RenderInfo<'a> {
    pub user: Option<&'a Object>,
    pub message: Option<(&'a str, &'a str)>,
    pub lang: &'a str,
    pub status_message: Option<&'a str>,
    pub config: &'a Config,
}

#[macro_export]
macro_rules! page {
    ($t:ty, $title:stmt) => {
        impl $crate::Page for $t {
            fn title(&self) -> std::borrow::Cow<'static, str> {
                let x: fn(&$t) -> std::borrow::Cow<'static, str> = {$title};
                x(self)
            }
            fn ri(&self) -> &$crate::RenderInfo<'_> {
                self.ri
            }
            fn render(&self) -> markup::DynRender<'_> {
                markup::new!(@self)
            }
        }
    };
}
