"use client"; import { useEffect, useRef } from "react"; import { AnimatePresence, motion } from "motion/react"; import { VersandSections } from "../versand/components/VersandSections"; import type { ShippingSettings } from "../lib/payload"; /** * Quick-reference version of /versand, opened from the cart's order * summary "Versand" info link — a full page navigation would pull you out * of checkout, which is exactly what the link is there to avoid. Reuses * VersandSections so the two never carry different numbers/copy. * `shipping` is threaded down from CartContent/CheckoutContent's own page * (a Server Component), not fetched here — this is a Client Component. */ export function VersandModal({ open, onClose, shipping, }: { open: boolean; onClose: () => void; shipping: ShippingSettings; }) { const dialogRef = useRef(null); const closeButtonRef = useRef(null); useEffect(() => { if (!open) return; const prevOverflow = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.body.style.overflow = prevOverflow; }; }, [open]); useEffect(() => { if (!open) return; closeButtonRef.current?.focus({ preventScroll: true }); const onKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { e.preventDefault(); onClose(); return; } if (e.key !== "Tab") return; const focusables = dialogRef.current?.querySelectorAll( 'a[href], button:not([disabled])' ); if (!focusables || focusables.length === 0) return; const first = focusables[0]; const last = focusables[focusables.length - 1]; if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus({ preventScroll: true }); } else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus({ preventScroll: true }); } }; document.addEventListener("keydown", onKeyDown); return () => document.removeEventListener("keydown", onKeyDown); }, [open, onClose]); return ( {open && ( { if (e.target === e.currentTarget) onClose(); }} >

Versand

)}
); }