import { useEffect, useState } from "react"; import { getOutfit } from "../api"; import type { Outfit, OutfitComplement, PaletteSwatch, Product } from "../types"; const PLACEHOLDER = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Crect fill='%23262626' width='100' height='100'/%3E%3Ctext x='50' y='55' text-anchor='middle' fill='%23737373' font-size='12'%3ENo Image%3C/text%3E%3C/svg%3E"; const BUCKET_LABEL: Record = { top: "Top", bottom: "Bottom", dress: "Dress", outerwear: "Outerwear", shoes: "Shoes", bag: "Bag", accessory: "Accessory", intimates: "Intimates", swimwear: "Swimwear", }; function bucketLabel(b: string) { return BUCKET_LABEL[b] ?? b; } interface Props { anchorUrl: string; onClose: () => void; } function OutfitTile({ p, label, isAnchor = false, rationale, }: { p: Product; label: string; isAnchor?: boolean; rationale?: string; }) { return (
{label}
{p.name} { (e.target as HTMLImageElement).src = PLACEHOLDER; }} />
{p.brand || p.store}
{p.name}
{p.price_text || `${Math.round(p.price_nok)} kr`}
{rationale &&
{rationale}
}
); } function PaletteStrip({ palette }: { palette: PaletteSwatch[] }) { if (!palette || palette.length === 0) return null; return (
{palette.map((s, i) => ( ))}
); } function StyleSummary({ outfit }: { outfit: Outfit }) { const axes = outfit.axes_covered; const contrasted = outfit.axes_contrasted; const isScandi = outfit.scandi_score >= 0.65; if (axes.length === 0 && !isScandi) return null; return (
{isScandi && Scandi-fit} {axes.length > 0 && ( {axes.length} axis{axes.length === 1 ? "" : "es"} of style {contrasted.length > 0 ? `, ${contrasted.length} contrasted` : ""} )} {Math.round(outfit.scandi_score * 100)}% Scandi
); } export function OutfitModal({ anchorUrl, onClose }: Props) { const [outfit, setOutfit] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { setLoading(true); setError(null); getOutfit(anchorUrl) .then(setOutfit) .catch((e) => setError(String(e))) .finally(() => setLoading(false)); }, [anchorUrl]); useEffect(() => { function onKey(e: KeyboardEvent) { if (e.key === "Escape") onClose(); } window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [onClose]); return (
e.stopPropagation()}>

Shop the look

{outfit && (

Built around this {bucketLabel(outfit.anchor_bucket).toLowerCase()}

)}
{loading &&
Building the look…
} {error &&
Couldn't build outfit: {error}
} {outfit && ( <>
{outfit.complements.map((c: OutfitComplement) => ( ))}
{outfit.complements.length === 0 ? (
No complements found for this {bucketLabel(outfit.anchor_bucket).toLowerCase()} — try one with more catalog coverage.
) : (
Total look {Math.round(outfit.total_nok).toLocaleString()} kr
)} )}
); }