"use client" /** * "Home layout" block for the profile menu — switches between `/home/` * links (`use-home-variant`). * * Lives in the profile menu rather than on the page itself for the same reason * theme does: it is a standing preference about a surface, not an action on the * content in front of you, and putting a layout control in the page's own * header would spend the most valuable row on the page on a setting most people * set once. * * Choosing a layout navigates to that layout's URL and remembers it so bare * `/home` (post-login, All products) still lands on the last one you used. * * Campus carries a second preference — greeting-only vs full cover banner — * in a nested submenu (`use-campus-banner-mode`). Spotlight carries v1 vs v2 * in a nested submenu (`SPOTLIGHT_VARIANTS`). * * Rendered in both profile menus — the utility bar's avatar (the one that is * actually visible on `/home`, since the shell strips the sidebar there) and * the sidebar's `NavUser`, so someone who changes their mind from inside a * product does not have to go back to home to find the control. */ import type { ReactNode } from "react" import { useLocation, useNavigate } from "react-router" import { DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, } from "@/components/ui/dropdown-menu" import { CAMPUS_BANNER_MODES, setCampusBannerMode, useCampusBannerMode, type CampusBannerMode, } from "@/hooks/use-campus-banner-mode" import { CAMPUS_VARIANTS, HOME_VARIANTS, SPOTLIGHT_VARIANTS, STOREFRONT_VARIANTS, homeVariantFromPathname, homeVariantPath, setHomeVariant, useHomeVariant, type HomeVariant, } from "@/hooks/use-home-variant" const FLAT_VARIANTS = HOME_VARIANTS.filter( option => option.id !== "campus" && option.id !== "spotlight" && option.id !== "storefront", ) const CAMPUS_VARIANT = HOME_VARIANTS.find(option => option.id === "campus")! const SPOTLIGHT_VARIANT = HOME_VARIANTS.find(option => option.id === "spotlight")! const STOREFRONT_VARIANT = HOME_VARIANTS.find(option => option.id === "storefront")! function isCampusVariant(variant: HomeVariant): variant is "campus" | "campus-v3" { return variant === "campus" || variant === "campus-v3" } function isSpotlightVariant( variant: HomeVariant, ): variant is "spotlight" | "spotlight-v2" | "spotlight-v3" | "spotlight-v4" { return ( variant === "spotlight" || variant === "spotlight-v2" || variant === "spotlight-v3" || variant === "spotlight-v4" ) } function isStorefrontVariant( variant: HomeVariant, ): variant is "storefront" | "storefront-v2" { return variant === "storefront" || variant === "storefront-v2" } type VariantOption = { id: string; label: string; description: string } function VariantRadioItems({ options }: { options: readonly VariantOption[] }) { return ( <> {options.map(option => ( {option.label} {option.description} ))} ) } function findLabel(options: readonly VariantOption[], id: string): string | undefined { return options.find(option => option.id === id)?.label } function resolveTrailingLabel(variant: HomeVariant, bannerMode: CampusBannerMode): string | undefined { const campusLayout = isCampusVariant(variant) ? findLabel(CAMPUS_VARIANTS, variant) : undefined const banner = findLabel(CAMPUS_BANNER_MODES, bannerMode) if (campusLayout && banner) return `${campusLayout} · ${banner}` const familyLabel = (isSpotlightVariant(variant) && findLabel(SPOTLIGHT_VARIANTS, variant)) || (isStorefrontVariant(variant) && findLabel(STOREFRONT_VARIANTS, variant)) || undefined return familyLabel || findLabel(HOME_VARIANTS, variant) } function isGroupedVariant(variant: HomeVariant): boolean { return isCampusVariant(variant) || isSpotlightVariant(variant) || isStorefrontVariant(variant) } type LayoutFamilySubProps = { root: VariantOption groupLabel: string options: readonly VariantOption[] isActive: boolean current: HomeVariant fallback: HomeVariant onSelect: (next: HomeVariant) => void children?: ReactNode } function LayoutFamilySub({ root, groupLabel, options, isActive, current, fallback, onSelect, children, }: LayoutFamilySubProps) { const selected = isActive ? current : fallback return ( onSelect(selected)} > {root.label} {root.description} {isActive ? (