// Auto-rotating carousel over the shared list in
// /src/snippets/configs/popular-models.jsx:
//
// // docs home
// // cookbook home
//
// variant="hero" full-width banner per model — headline, blurb, tags, CTA,
// brand tile, from the entry's `hero` block.
// variant="strip" (default) one compact line per model — brand mark, name,
// tags, "Open" button. No prose; the tags carry the pitch.
//
// Rotation pauses on hover/focus and is skipped under prefers-reduced-motion.
//
// One export for both shapes: Mintlify evaluates each exported component on its
// own at hydration, so anything two components would share (rotation state, the
// timer, the control cluster) has to sit inside one — module-level helpers are
// out of scope by the time this runs.
export const PopularModels = ({
models = [],
variant = "strip",
// A hero blurb takes longer to read than one line of tags.
interval = variant === "hero" ? 9000 : 6000,
label = "Popular models",
}) => {
const [index, setIndex] = useState(0);
const [paused, setPaused] = useState(false);
const [reduceMotion, setReduceMotion] = useState(false);
useEffect(() => {
if (typeof window === "undefined" || !window.matchMedia) return;
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
const sync = () => setReduceMotion(mq.matches);
sync();
mq.addEventListener("change", sync);
return () => mq.removeEventListener("change", sync);
}, []);
const count = models.length;
const isHero = variant === "hero";
// Functional update so the timer never closes over a stale index.
useEffect(() => {
if (count < 2 || paused || reduceMotion) return;
const id = window.setInterval(
() => setIndex((i) => (i + 1) % count),
Math.max(2000, interval)
);
return () => window.clearInterval(id);
}, [count, paused, reduceMotion, interval]);
// A shortened list must not leave the track parked past its last slide.
const active = count ? Math.min(index, count - 1) : 0;
if (!count) return null;
const navButtonStyle = {
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
width: "1.15rem",
height: "1.15rem",
padding: 0,
border: "1px solid rgba(255, 255, 255, 0.28)",
borderRadius: "999px",
background: "rgba(255, 255, 255, 0.1)",
color: "rgba(255, 255, 255, 0.92)",
fontSize: "0.8rem",
lineHeight: 1,
cursor: "pointer",
};
const controls =
count > 1 ? (
{models.map((m, i) => (
) : null;
// Only the active slide is opaque: mid-slide, a visible neighbour reads as two
// half-drawn cards rather than as motion.
const slideStyle = (i) => ({
flex: "0 0 100%",
minWidth: 0,
opacity: i === active ? 1 : 0,
pointerEvents: i === active ? "auto" : "none",
transition: reduceMotion ? "none" : "opacity 0.3s ease",
});
const tagChip = (t, big) => (
{t}
);
const heroSlide = (m, i) => {
const hero = m.hero || {};
const cta = hero.cta || `Open the ${m.name} cookbook`;
return (
{hero.headline || m.name}
{hero.blurb ? (
// A div, not a p: MDX rewrites `p` to its own inline element, so a
// paragraph here would depend on how that element is styled.