'use client'; import { useState } from 'react'; type Product = { id: string; name: string }; // Checking a product auto-switches scope to "Specific items" — picking an // item to discount only makes sense if the promotion is actually scoped to // specific items, so we don't make the admin flip the radio manually too. export default function PromotionScopePicker({ products, defaultScope = 'ALL', defaultSelectedIds = [], }: { products: Product[]; defaultScope?: 'ALL' | 'SPECIFIC'; defaultSelectedIds?: string[]; }) { const [scope, setScope] = useState<'ALL' | 'SPECIFIC'>(defaultScope); const [selected, setSelected] = useState>(new Set(defaultSelectedIds)); const toggleProduct = (id: string, checked: boolean) => { setSelected((prev) => { const next = new Set(prev); if (checked) next.add(id); else next.delete(id); return next; }); if (checked) setScope('SPECIFIC'); }; return (
Applies to
{products.map((p) => ( ))}

Only used when "Specific items" is selected above.

); }