// Search results screen — match-degree sorted grid + filter sidebar const SearchResults = ({ tags = [], setTags, onOpenRecipe, onBack, mobile = false }) => { const [sort, setSort] = React.useState('match'); const [active, setActive] = React.useState({ time: null, diff: null, diet: null, cat: null }); const [showFilter, setShowFilter] = React.useState(false); const results = React.useMemo(() => { const list = window.RECIPES.map(r => { const have = tags.filter(t => r.have && r.have.includes(t)).length; const need = (r.have || []).length; const m = need === 0 ? r.match : Math.round(have / Math.max(tags.length, 1) * 100); return { ...r, _m: tags.length === 0 ? r.match : Math.max(m, 60) }; }); list.sort((a, b) => { if (sort === 'match') return b._m - a._m; if (sort === 'time') return a.time - b.time; if (sort === 'cal') return a.cal - b.cal; if (sort === 'rating') return b.rating - a.rating; return 0; }); return list; }, [tags, sort]); const W = mobile ? 'm' : 'd'; return (
首頁 / 食材搜索 / {tags.join(' + ') || '所有食譜'}
搜索結果

找到 {results.length} 道用
{tags.map(t => ( {t} ))} 能做的料理

排序 {[['match','匹配度'],['time','烹飪時間'],['cal','卡路里'],['rating','評分']].map(([k,l]) => ( ))}
{mobile && ( )}
{!mobile && ( )}
{results.map(r => onOpenRecipe && onOpenRecipe(r)}/>)}
); }; const FilterGroup = ({ label, opts, active, set }) => (

{label}

{opts.map(o => ( ))}
); window.SearchResults = SearchResults;