#![allow(unused)]
#![warn(unused_must_use)]

use indoc::indoc;
use leptos::prelude::*;
use leptos_router::components::A;

#[component]
pub fn Projects() -> impl IntoView {
    view! {
        <h1>"Personal projects"</h1>
        <section class="projects-list">
            <ProjectSummary image="/parva_1.png".into()>
                <ProjectSummaryTitle slot>"LittleBigPlanet Computer"</ProjectSummaryTitle>
                <ProjectSummaryMain slot>
                    <p>
                        "A 120Hz 24-bit computer built using logic gates inside the game "
                        <A href="https://en.wikipedia.org/wiki/LittleBigPlanet_3">
                            "LittleBigPlanet 3"
                        </A>" that I call \"Parva\"."
                    </p>
                    <p>
                        "There's been several iterations of it. Currently I'm trying to expand the memory from ~2kiB to 24kiB using "
                        <A href="https://www.youtube.com/watch?v=jzAx65my6N0">"this"</A>
                        " technique but I'm running into problems with non-determinism in how the game simulates the logic."
                    </p>
                    <p>
                        "In the process of building it, some other members of the LittleBigPlanet logic community and I did a lot of research into the game's mechanics. Some of the findings are documented "
                        <A href="https://github.com/Nomkid/littlebiglogic/blob/master/wiki/README.md">
                            "here"
                        </A>"."
                    </p>
                    <p>
                        "I will write up a blogpost about Parva and the other computers people have built in the game along with instructions on how to use them at some point."
                    </p>
                </ProjectSummaryMain>
                <ProjectSummaryLinks slot>
                    <a href="https://wiki.littlebigcomputer.com">"Wiki"</a>
                    <a href="https://littlebigcomputer.com">"Assembler"</a>
                    <a href="https://git.mascully.com/mascully/littlebigcomputer/src/branch/master/programs/parva_0.1">
                        "Example assembly programs"
                    </a>
                </ProjectSummaryLinks>
            </ProjectSummary>
            <ProjectSummary image="/carplexity_1.png".into()>
                <ProjectSummaryTitle slot>"Carplexity"</ProjectSummaryTitle>
                <ProjectSummaryMain slot>
                    <p>
                        "Very early in development. A physics car game built using Bevy meant to be similar to Rocket League."
                    </p>
                    <p>
                        "360 ticks per second instead of 120, so less input lag, which is basically the only thing that matters."
                    </p>
                </ProjectSummaryMain>
                <ProjectSummaryLinks slot>
                    <A href="https://carplexity.com">"Website"</A>
                </ProjectSummaryLinks>
            </ProjectSummary>
            <ProjectSummary image="/endolingual_1.png".into()>
                <ProjectSummaryTitle slot>"Endolingual"</ProjectSummaryTitle>
                <ProjectSummaryMain slot>
                    <p>"Compile-time string localization for Rust."</p>
                // <pre>
                // {
                // indoc! {
                // r#"
                // let current_language = get_current_language();
                // let my_string = translate!("Enter your password: ");
                // println!("{}", my_string[current_language]);
                // "#
                // }
                // }
                // </pre>
                // <p>
                // "You can try this out by clicking the translate button at the top right of this website. All of the translation"
                // </p>
                </ProjectSummaryMain>
                <ProjectSummaryLinks slot>
                    <A href="https://github.com/mascully/endolingual">"Repo"</A>
                </ProjectSummaryLinks>
            </ProjectSummary>
        </section>
    }
}

#[component]
pub fn ProjectSummary(
    project_summary_title: ProjectSummaryTitle,
    project_summary_main: ProjectSummaryMain,
    project_summary_links: ProjectSummaryLinks,
    image: String,
) -> impl IntoView {
    view! {
        <div class="project-grid">
            <h2 class="project-title">{(project_summary_title.children)()}</h2>
            <picture class="project-image">
                <img
                    src=image
                    // srcset={image.concat(" x1")}
                    loading="lazy"
                />
            </picture>
            <div class="project-text">{(project_summary_main.children)()}</div>
            <div class="project-links">{(project_summary_links.children)()}</div>
        </div>
    }
}

#[slot]
pub struct ProjectSummaryTitle {
    children: ChildrenFn,
}

#[slot]
pub struct ProjectSummaryLinks {
    children: ChildrenFn,
}

#[slot]
pub struct ProjectSummaryMain {
    children: ChildrenFn,
}
