|
| 1 | +import clsx from "clsx"; |
| 2 | +import { BRANCH_META, BRANCH_ORDER } from "./branch-meta"; |
| 3 | +import { FAMILIES } from "@/lib/career-guides"; |
| 4 | +import type { Branch, Family, Rank, SortKey } from "./types"; |
| 5 | + |
| 6 | +interface Props { |
| 7 | + branchCounts: Record<Branch, number>; |
| 8 | + branch: "all" | Branch; |
| 9 | + onBranch: (v: "all" | Branch) => void; |
| 10 | + rank: "all" | Rank; |
| 11 | + onRank: (v: "all" | Rank) => void; |
| 12 | + family: "all" | Family; |
| 13 | + onFamily: (v: "all" | Family) => void; |
| 14 | + sort: SortKey; |
| 15 | + onSort: (v: SortKey) => void; |
| 16 | + showing: number; |
| 17 | + total: number; |
| 18 | +} |
| 19 | + |
| 20 | +const RANK_OPTS: Array<{ key: "all" | Rank; label: string }> = [ |
| 21 | + { key: "all", label: "All" }, |
| 22 | + { key: "Enlisted", label: "Enlisted" }, |
| 23 | + { key: "Warrant", label: "Warrant" }, |
| 24 | + { key: "Officer", label: "Officer" }, |
| 25 | +]; |
| 26 | + |
| 27 | +const SORT_OPTS: Array<{ key: SortKey; label: string }> = [ |
| 28 | + { key: "code", label: "Code (A→Z)" }, |
| 29 | + { key: "title", label: "Title (A→Z)" }, |
| 30 | + { key: "salaryHigh", label: "Salary (High→Low)" }, |
| 31 | + { key: "salaryLow", label: "Salary (Low→High)" }, |
| 32 | + { key: "demand", label: "Demand" }, |
| 33 | +]; |
| 34 | + |
| 35 | +const RAINBOW = |
| 36 | + "linear-gradient(90deg, #6b8050 0%, #6b8050 20%, #5b87c4 20%, #5b87c4 40%, #8eb4d8 40%, #8eb4d8 60%, #d9514a 60%, #d9514a 80%, #e89149 80%, #e89149 100%)"; |
| 37 | + |
| 38 | +const Filters = ({ |
| 39 | + branchCounts, |
| 40 | + branch, |
| 41 | + onBranch, |
| 42 | + rank, |
| 43 | + onRank, |
| 44 | + family, |
| 45 | + onFamily, |
| 46 | + sort, |
| 47 | + onSort, |
| 48 | + showing, |
| 49 | + total, |
| 50 | +}: Props) => { |
| 51 | + const allCount = BRANCH_ORDER.reduce((sum, b) => sum + branchCounts[b], 0); |
| 52 | + |
| 53 | + return ( |
| 54 | + <div className="tw-flex tw-flex-col tw-gap-6"> |
| 55 | + {/* Branch chips */} |
| 56 | + <div className="tw-flex tw-flex-wrap tw-gap-2"> |
| 57 | + <button |
| 58 | + type="button" |
| 59 | + onClick={() => onBranch("all")} |
| 60 | + className={clsx( |
| 61 | + "tw-flex tw-items-center tw-gap-2.5 tw-border tw-px-3.5 tw-py-2 tw-font-mono tw-text-[11.5px] tw-uppercase tw-tracking-[0.08em] tw-transition-colors", |
| 62 | + branch === "all" |
| 63 | + ? "tw-border-accent tw-bg-accent tw-text-secondary" |
| 64 | + : "tw-border-cream/[0.18] tw-bg-secondary tw-text-[#c4cad6] hover:tw-border-[#8590a6] hover:tw-text-cream", |
| 65 | + )} |
| 66 | + > |
| 67 | + <span |
| 68 | + aria-hidden |
| 69 | + className="tw-h-2 tw-w-2" |
| 70 | + style={{ backgroundImage: RAINBOW }} |
| 71 | + /> |
| 72 | + All |
| 73 | + <span |
| 74 | + className={clsx( |
| 75 | + "tw-tabular-nums", |
| 76 | + branch === "all" ? "tw-text-secondary/60" : "tw-text-[#8590a6]", |
| 77 | + )} |
| 78 | + > |
| 79 | + {allCount.toLocaleString()} |
| 80 | + </span> |
| 81 | + </button> |
| 82 | + {BRANCH_ORDER.map((b) => { |
| 83 | + const active = branch === b; |
| 84 | + return ( |
| 85 | + <button |
| 86 | + type="button" |
| 87 | + key={b} |
| 88 | + onClick={() => onBranch(b)} |
| 89 | + className={clsx( |
| 90 | + "tw-flex tw-items-center tw-gap-2.5 tw-border tw-px-3.5 tw-py-2 tw-font-mono tw-text-[11.5px] tw-uppercase tw-tracking-[0.08em] tw-transition-colors", |
| 91 | + active |
| 92 | + ? "tw-border-accent tw-bg-accent tw-text-secondary" |
| 93 | + : "tw-border-cream/[0.18] tw-bg-secondary tw-text-[#c4cad6] hover:tw-border-[#8590a6] hover:tw-text-cream", |
| 94 | + )} |
| 95 | + > |
| 96 | + <span |
| 97 | + aria-hidden |
| 98 | + className="tw-h-2 tw-w-2" |
| 99 | + style={{ backgroundColor: BRANCH_META[b].color }} |
| 100 | + /> |
| 101 | + {BRANCH_META[b].short} |
| 102 | + <span |
| 103 | + className={clsx( |
| 104 | + "tw-tabular-nums", |
| 105 | + active ? "tw-text-secondary/60" : "tw-text-[#8590a6]", |
| 106 | + )} |
| 107 | + > |
| 108 | + {branchCounts[b].toLocaleString()} |
| 109 | + </span> |
| 110 | + </button> |
| 111 | + ); |
| 112 | + })} |
| 113 | + </div> |
| 114 | + |
| 115 | + {/* Facet bar */} |
| 116 | + <div className="tw-flex tw-flex-col tw-gap-6 tw-border-t tw-border-cream/10 tw-border-b tw-py-5 lg:tw-flex-row lg:tw-flex-wrap lg:tw-items-center"> |
| 117 | + {/* Rank segmented */} |
| 118 | + <div className="tw-flex tw-items-center tw-gap-3"> |
| 119 | + <span className="tw-font-mono tw-text-[10.5px] tw-uppercase tw-tracking-[0.14em] tw-text-[#8590a6]"> |
| 120 | + Rank |
| 121 | + </span> |
| 122 | + <div className="tw-flex tw-border tw-border-cream/[0.18]"> |
| 123 | + {RANK_OPTS.map((r) => ( |
| 124 | + <button |
| 125 | + key={r.key} |
| 126 | + type="button" |
| 127 | + onClick={() => onRank(r.key)} |
| 128 | + className={clsx( |
| 129 | + "tw-px-3 tw-py-1.5 tw-font-mono tw-text-[11px] tw-uppercase tw-tracking-[0.1em] tw-transition-colors", |
| 130 | + rank === r.key |
| 131 | + ? "tw-bg-accent tw-text-secondary" |
| 132 | + : "tw-bg-secondary tw-text-[#c4cad6] hover:tw-text-cream", |
| 133 | + )} |
| 134 | + > |
| 135 | + {r.label} |
| 136 | + </button> |
| 137 | + ))} |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + |
| 141 | + {/* Family */} |
| 142 | + <label className="tw-flex tw-items-center tw-gap-3"> |
| 143 | + <span className="tw-font-mono tw-text-[10.5px] tw-uppercase tw-tracking-[0.14em] tw-text-[#8590a6]"> |
| 144 | + Family |
| 145 | + </span> |
| 146 | + <select |
| 147 | + value={family} |
| 148 | + onChange={(e) => onFamily(e.target.value as Family | "all")} |
| 149 | + className="tw-border tw-border-cream/[0.18] tw-bg-secondary tw-px-3 tw-py-1.5 tw-font-mono tw-text-[11px] tw-uppercase tw-tracking-[0.1em] tw-text-cream tw-outline-none focus:tw-border-accent" |
| 150 | + > |
| 151 | + <option value="all">All families</option> |
| 152 | + {FAMILIES.map((f) => ( |
| 153 | + <option key={f} value={f}> |
| 154 | + {f} |
| 155 | + </option> |
| 156 | + ))} |
| 157 | + </select> |
| 158 | + </label> |
| 159 | + |
| 160 | + {/* Sort */} |
| 161 | + <label className="tw-flex tw-items-center tw-gap-3"> |
| 162 | + <span className="tw-font-mono tw-text-[10.5px] tw-uppercase tw-tracking-[0.14em] tw-text-[#8590a6]"> |
| 163 | + Sort |
| 164 | + </span> |
| 165 | + <select |
| 166 | + value={sort} |
| 167 | + onChange={(e) => onSort(e.target.value as SortKey)} |
| 168 | + className="tw-border tw-border-cream/[0.18] tw-bg-secondary tw-px-3 tw-py-1.5 tw-font-mono tw-text-[11px] tw-uppercase tw-tracking-[0.1em] tw-text-cream tw-outline-none focus:tw-border-accent" |
| 169 | + > |
| 170 | + {SORT_OPTS.map((s) => ( |
| 171 | + <option key={s.key} value={s.key}> |
| 172 | + {s.label} |
| 173 | + </option> |
| 174 | + ))} |
| 175 | + </select> |
| 176 | + </label> |
| 177 | + |
| 178 | + <span className="tw-ml-auto tw-font-mono tw-text-[10.5px] tw-uppercase tw-tracking-[0.12em] tw-text-[#8590a6]"> |
| 179 | + Showing{" "} |
| 180 | + <span className="tw-font-bold tw-text-cream tw-tabular-nums"> |
| 181 | + {showing.toLocaleString()} |
| 182 | + </span>{" "} |
| 183 | + of{" "} |
| 184 | + <span className="tw-font-bold tw-text-cream tw-tabular-nums"> |
| 185 | + {total.toLocaleString()} |
| 186 | + </span>{" "} |
| 187 | + Guides |
| 188 | + </span> |
| 189 | + </div> |
| 190 | + </div> |
| 191 | + ); |
| 192 | +}; |
| 193 | + |
| 194 | +export default Filters; |
0 commit comments