Skip to content
1        10        20        30        40        50        60        70        80        90        100       110       1201use crate::models::Pokemon;2use maud::{Markup, html};34const TYPES_LIST: &[&str] = &[5    "grass", "fire", "water", "electric", "poison", "bug", "normal", "ground", "flying",6    "fighting", "psychic", "rock", "ghost", "ice", "dragon",7];89pub fn pokedex_tab_view(10    pokemon_list: &[Pokemon],11    query: &str,12    total: usize,13    has_more: bool,14    next_offset: usize,15) -> Markup {16    html! {17        div class="w-full" {18            div class="cottage-search-container" {19                div class="search-field-wrapper" {20                    span class="search-icon-left" { "🔍" }21                    input22                        type="search"23                        name="q"24                        value=(query)25                        class="cottage-search-input"26                        placeholder="Search by name, #ID, or type (e.g. Bulbasaur, 25, grass)..."27                        hx-get="/pokedex/search"28                        hx-trigger="input changed delay:250ms, search"29                        hx-target="#pokemon-grid"30                        hx-indicator="#search-spinner"31                        autocomplete="off";32                    span id="search-spinner" class="search-spinner" { "🌿" }33                }3435                div class="type-pills-row" {36                    button37                        type="button"38                        class={"type-pill " (if query.is_empty() { "active" } else { "" })}39                        hx-get="/pokedex/search?q="40                        hx-target="#pokemon-grid" {41                        "All (" (total) ")"42                    }43                    @for t in TYPES_LIST {44                        button45                            type="button"46                            class={"type-pill type-" (t) " " (if query.eq_ignore_ascii_case(t) { "active" } else { "" })}47                            hx-get={"/pokedex/search?q=" (t)}48                            hx-target="#pokemon-grid" {49                            (t)50                        }51                    }52                }53            }5455            div id="pokemon-grid" class="botanical-grid" {56                (pokemon_grid_items(pokemon_list, query, has_more, next_offset))57            }58        }59    }60}6162pub fn pokemon_grid_items(63    pokemon_list: &[Pokemon],64    query: &str,65    has_more: bool,66    next_offset: usize,67) -> Markup {68    if pokemon_list.is_empty() {69        return html! {70            div class="col-span-full empty-notice" {71                div class="empty-notice-icon" { "🍂" }72                h3 class="text-lg font-bold text-stone-700" { "No specimens found" }73                p class="text-sm text-stone-500 mt-1" {74                    "No Pokémon matches your search query “" (query) "”. Try another name, number, or element."75                }76            }77        };78    }7980    html! {81        @for p in pokemon_list {82            (pokemon_card(p))83        }8485        @if has_more {86            div87                class="col-span-full py-6 text-center text-xs font-bold text-stone-500 tracking-wider uppercase"88                hx-get={"/pokedex/page?offset=" (next_offset) "&q=" (query)}89                hx-trigger="revealed"90                hx-swap="outerHTML" {91                "🌿 Loading more Kanto specimens..."92            }93        }94    }95}9697pub fn pokemon_card(p: &Pokemon) -> Markup {98    html! {99        a100            href={"/pokemon/" (p.id)}101            class="specimen-card"102            hx-get={"/pokemon/" (p.id)}103            hx-target="#main-content"104            hx-push-url={"/pokemon/" (p.id)} {105            div class="specimen-id" { (p.formatted_id()) }106            div class="specimen-img-frame" {107                img108                    src=(p.artwork_url)109                    alt=(p.display_name)110                    class="specimen-img"111                    loading="lazy";112            }113            h3 class="specimen-name" { (p.display_name) }114            div class="types-badge-list" {115                @for t in &p.types {116                    span class={"type-tag type-" (t)} { (t) }117                }118            }119        }120    }121}122123#[allow(clippy::too_many_lines)]124pub fn pokemon_detail_page(p: &Pokemon) -> Markup {125    let level_moves = p.level_up_moves();126    let other_moves = p.machine_tutor_moves();127128    html! {129        div class="specimen-detail-container" {130            div class="specimen-nav-bar" {131                a132                    href="/"133                    class="specimen-back-btn"134                    hx-get="/pokedex"135                    hx-target="#main-content"136                    hx-push-url="/" {137                    "← Back to Pokédex"138                }139140                div class="flex items-center gap-2" {141                    @if p.id > 1 {142                        a143                            href={"/pokemon/" (p.id - 1)}144                            class="specimen-nav-arrow"145                            hx-get={"/pokemon/" (p.id - 1)}146                            hx-target="#main-content"147                            hx-push-url={"/pokemon/" (p.id - 1)} {148                            "← #" (format!("{:03}", p.id - 1))149                        }150                    }151                    @if p.id < 151 {152                        a153                            href={"/pokemon/" (p.id + 1)}154                            class="specimen-nav-arrow"155                            hx-get={"/pokemon/" (p.id + 1)}156                            hx-target="#main-content"157                            hx-push-url={"/pokemon/" (p.id + 1)} {158                            "#" (format!("{:03}", p.id + 1)) " →"159                        }160                    }161                }162            }163164            div class="specimen-page-card" {165                div class="specimen-header" {166                    img167                        src=(p.artwork_url)168                        alt=(p.display_name)169                        class="specimen-header-art";170171                    div class="specimen-intro" {172                        p class="specimen-field-number" {173                            "Specimen " (p.formatted_id()) " • " (p.genus)174                        }175                        h2 class="specimen-modal-title" { (p.display_name) }176                        div class="types-badge-list justify-start mb-3" {177                            @for t in &p.types {178                                span class={"type-tag type-" (t)} { (t) }179                            }180                        }181                        div class="flex flex-wrap gap-4 text-xs text-stone-600 font-mono" {182                            span { "Height: " strong { (p.height_meters()) } }183                            span { "Weight: " strong { (p.weight_kg()) } }184                            span { "Base Total: " strong { (p.total_stats()) } }185                        }186                    }187                }188189                @if !p.description.is_empty() {190                    div class="specimen-quote-box" {191                        "“" (p.description) "”"192                        p class="text-xs text-stone-500 mt-1 not-italic font-sans text-right" {193                            "— Pokémon FireRed Field Notes"194                        }195                    }196                }197198                h3 class="text-md font-bold text-stone-800 mb-2" { "Combat Characteristics" }199                div class="stat-bar-group" {200                    (stat_row("HP", p.hp, 255))201                    (stat_row("Attack", p.attack, 190))202                    (stat_row("Defense", p.defense, 230))203                    (stat_row("Sp. Attack", p.sp_attack, 194))204                    (stat_row("Sp. Defense", p.sp_defense, 230))205                    (stat_row("Speed", p.speed, 180))206                }207208                h3 class="text-md font-bold text-stone-800 mb-2 mt-6" {209                    "FireRed & LeafGreen Learnset (" (level_moves.len() + other_moves.len()) " Moves)"210                }211212                div class="mb-4" {213                    h4 class="text-xs uppercase font-bold text-stone-500 mb-1" { "Level-Up Moves" }214                    table class="moves-journal-table" {215                        thead {216                            tr {217                                th class="w-24" { "Requirement" }218                                th { "Move Name" }219                                th class="w-28" { "Method" }220                            }221                        }222                        tbody {223                            @for m in level_moves {224                                tr {225                                    td class="font-mono text-xs font-bold" {226                                        (m.formatted_method())227                                    }228                                    td class="font-semibold text-stone-800 capitalize" {229                                        (m.formatted_name())230                                    }231                                    td class="text-xs text-stone-500" { "Level" }232                                }233                            }234                        }235                    }236                }237238                @if !other_moves.is_empty() {239                    details class="mt-4" {240                        summary class="text-xs uppercase font-bold text-stone-600 cursor-pointer py-1" {241                            "View TM, HM & Move Tutor Techniques (" (other_moves.len()) ")"242                        }243                        table class="moves-journal-table mt-2" {244                            thead {245                                tr {246                                    th { "Move Name" }247                                    th class="w-32" { "Method" }248                                }249                            }250                            tbody {251                                @for m in other_moves {252                                    tr {253                                        td class="font-semibold text-stone-800 capitalize" {254                                            (m.formatted_name())255                                        }256                                        td class="text-xs text-stone-500" {257                                            (m.formatted_method())258                                        }259                                    }260                                }261                            }262                        }263                    }264                }265266                div class="specimen-detail-footer-nav" {267                    a268                        href="/"269                        class="specimen-back-btn"270                        hx-get="/pokedex"271                        hx-target="#main-content"272                        hx-push-url="/" {273                        "← Back to Pokédex"274                    }275276                    div class="flex items-center gap-2" {277                        @if p.id > 1 {278                            a279                                href={"/pokemon/" (p.id - 1)}280                                class="specimen-nav-arrow"281                                hx-get={"/pokemon/" (p.id - 1)}282                                hx-target="#main-content"283                                hx-push-url={"/pokemon/" (p.id - 1)} {284                                "← #" (format!("{:03}", p.id - 1))285                            }286                        }287                        @if p.id < 151 {288                            a289                                href={"/pokemon/" (p.id + 1)}290                                class="specimen-nav-arrow"291                                hx-get={"/pokemon/" (p.id + 1)}292                                hx-target="#main-content"293                                hx-push-url={"/pokemon/" (p.id + 1)} {294                                "#" (format!("{:03}", p.id + 1)) " →"295                            }296                        }297                    }298                }299            }300        }301    }302}303304fn stat_row(label: &str, val: i32, max: i32) -> Markup {305    #[allow(clippy::cast_precision_loss)]306    let pct = ((f64::from(val) / f64::from(max)) * 100.0).clamp(5.0, 100.0);307    html! {308        div class="stat-bar-row" {309            span class="stat-label" { (label) }310            span class="stat-num" { (val) }311            div class="stat-progress-track" {312                div class="stat-progress-fill" style={"width: " (pct) "%;"} {}313            }314        }315    }316}