import React from "react";
import { motion, AnimatePresence } from "framer-motion";
import { CONFIG } from "./grid/gridConfig";
// 1. THE PHYSICS
// High stiffness, moderate damping = "Snappy but smooth" (Apple feel)
const islandTransition = {
type: "spring",
stiffness: 500,
damping: 30,
mass: 1,
};
export function UnifiedControlBar({
currentCollection,
onSwitch,
setZoomTrigger,
isZoomedIn,
hasActiveSelection,
nikeFilter,
onFilterChange,
}) {
const collections = [
"Nike",
"New Balance",
"Under $150",
];
const nikeFilters = [
{ id: "all", label: "All" },
{ id: "jordan", label: "Jordan" },
{ id: "dunk", label: "Dunk" },
];
return (
{/*
THE ISLAND CONTAINER
- layout: Animates width/height changes
- borderRadius: 32px is standard for pill shapes
*/}
{/*
mode="popLayout" is CRITICAL.
It lets the outgoing component "pop" out of the layout flow
so the container can instantly shrink/grow to the new content's size.
*/}
{hasActiveSelection ? (
/* ---------------- STATE 1: BUY NOW (Active Selection) ---------------- */
{
// Handle buy now action
}}
style={{
background: "#000",
color: "#fff",
border: "none",
borderRadius: "24px",
padding: "0 24px",
height: "44px",
fontSize: "14px",
fontWeight: "600",
cursor: "pointer",
display: "flex",
alignItems: "center",
whiteSpace: "nowrap",
}}
whileTap={{ scale: 0.95 }}
>
Buy Now
) : isZoomedIn ? (
/* ---------------- STATE 2: COMPACT (Zoomed In) ---------------- */
setZoomTrigger("OUT")}
label="Zoom Out"
/>
) : (
/* ---------------- STATE 2: EXPANDED (Zoomed Out) ---------------- */
setZoomTrigger(CONFIG.zoomIn)
}
label="Zoom In"
/>
{/* Vertical Divider */}
{/* Collection Tabs Group */}
{collections.map((name, index) => {
const isActive =
currentCollection === index;
return (
onSwitch(index)}
>
{name}
);
})}
{/* Nike Filters - only show when Nike collection is active (desktop only) */}
{currentCollection === 0 && (
{/* Vertical Divider */}
{/* Filter Chips */}
{nikeFilters.map((filter) => (
onFilterChange(filter.id)}
layoutGroup="desktop"
>
{filter.label}
))}
)}
)}
{/* Mobile Nike Filters - appears above main bar */}
{currentCollection === 0 && !isZoomedIn && !hasActiveSelection && (
{nikeFilters.map((filter) => (
onFilterChange(filter.id)}
layoutGroup="mobile"
>
{filter.label}
))}
)}
{/* Responsive scaling for shorter viewports (tablets) and mobile */}
);
}
// --- Sub-components for cleaner code & isolated animations ---
function ControlButton({ onClick, icon, label }) {
return (
{/* Simple SVG Icons instead of text for a sharper look */}
{icon === "add" ? (
) : (
)}
);
}
function TabButton({ children, isActive, onClick }) {
return (
{children}
{isActive && (
)}
);
}
function FilterChip({ children, isActive, onClick, layoutGroup = "default" }) {
return (
{/* Animated background pill */}
{isActive && (
)}
{!isActive && (
)}
{children}
);
}