'use client'; /** * The per-card basket toggle. * * The links around it are server-rendered, so the section works with JS off; * this adds the basket interaction on top rather than being what makes the * section function. */ import { useComparisonContext } from '@/context/ComparisonContext'; import type { School, NearbySchool } from '@/lib/types'; import styles from './NearbySchools.module.css'; export function AddToCompareButton({ school }: { school: NearbySchool }) { const { addSchool, removeSchool, selectedSchools } = useComparisonContext(); const selected = selectedSchools.some((s) => s.urn === school.urn); const toggle = () => { if (selected) { removeSchool(school.urn); return; } // The basket only needs identity and display fields; the compare page // fetches everything it renders by URN. addSchool({ urn: school.urn, school_name: school.school_name, school_type: school.school_type, age_range: school.age_range, } as School); }; return ( ); }