use dioxus::prelude::*;

const FAVICON: Asset = asset!("/assets/favicon.jpg");
const THEME_CSS: Asset = asset!("/assets/styling/theme.css");
const BASE_CSS: Asset = asset!("/assets/styling/base.css");
const CARDS_CSS: Asset = asset!("/assets/styling/cards.css");
const BROWSE_CSS: Asset = asset!("/assets/styling/browse.css");
const POLYMODEL_CSS: Asset = asset!("/assets/styling/polymodel.css");

fn main() {
    #[cfg(all(target_family = "wasm", target_os = "unknown"))]
    {
        console_error_panic_hook::set_once();
        tracing_wasm::set_as_global_default();
    }

    dioxus::launch(App);
}

#[component]
fn App() -> Element {
    rsx! {
        document::Meta { name: "viewport", content: "width=device-width, initial-scale=1" }
        document::Title { "Polymodel" }
        document::Link { rel: "icon", href: FAVICON }
        document::Link { rel: "preconnect", href: "https://fonts.googleapis.com" }
        document::Link { rel: "preconnect", href: "https://fonts.gstatic.com", crossorigin: "anonymous" }
        document::Link { rel: "stylesheet", href: "https://fonts.googleapis.com/css2?family=Capriola&family=DM+Sans:opsz,wght@9..40,300..800&display=swap" }
        Stylesheet { href: THEME_CSS }
        Stylesheet { href: BASE_CSS }
        Stylesheet { href: CARDS_CSS }
        Stylesheet { href: BROWSE_CSS }
        Stylesheet { href: POLYMODEL_CSS }

        main { class: "browse-page",
            header { class: "browse-header",
                h1 { "Polymodel" }
                div { class: "demo-context",
                    strong { "Thingiverse on atproto. " }
                    "Project/profile/like lexicons, social feeds, and a browser STL viewer. "
                    strong { "Workflow: " }
                    "Jira + Confluence + jj + Polytoken."
                }
            }
            section { class: "browse-grid",
                for card in roadmap_cards() {
                    RoadmapCard { card }
                }
            }
        }
    }
}

#[derive(Clone, Copy, PartialEq)]
struct RoadmapCardData {
    token: &'static str,
    title: &'static str,
    body: &'static str,
}

fn roadmap_cards() -> [RoadmapCardData; 6] {
    [
        RoadmapCardData {
            token: "NSID",
            title: "Project lexicon",
            body: "Define the model/project record: title, description, files, preview assets, tags, license, and attribution.",
        },
        RoadmapCardData {
            token: "DID",
            title: "Profile publishing",
            body: "Use ATProto identity and profile-oriented feeds so makers can publish and browse from their own repos.",
        },
        RoadmapCardData {
            token: "★",
            title: "Likes and saves",
            body: "Start with lightweight feedback records that can drive hot/recent discovery without inventing a heavyweight backend.",
        },
        RoadmapCardData {
            token: "STL",
            title: "Model viewer",
            body: "Spike three-d and kiss3d as WASM viewer candidates; choose based on STL loading, orbit controls, rendering quality, and Dioxus integration friction.",
        },
        RoadmapCardData {
            token: "PM",
            title: "Jira and Confluence",
            body: "Use Jira and Confluence as both planning/demo narrative and agent-readable workflow state.",
        },
        RoadmapCardData {
            token: "pt",
            title: "Polytoken workflow",
            body: "Use facets, skills, hooks, project vars, jj workspaces, and review gates to make the demo workflow real.",
        },
    ]
}

#[component]
fn RoadmapCard(card: RoadmapCardData) -> Element {
    rsx! {
        article { class: "video-card card-surface demo-card",
            div { class: "video-card-thumbnail",
                span { class: "demo-card-token", "{card.token}" }
            }
            div { class: "video-card-body demo-card-body",
                h2 { class: "card-title", "{card.title}" }
                p { "{card.body}" }
            }
        }
    }
}

#[cfg(test)]
mod tests {
    use super::roadmap_cards;

    #[test]
    fn roadmap_includes_stl_viewer() {
        assert!(roadmap_cards().iter().any(|card| card.token == "STL"));
    }
}
