import { useMemo, useState } from 'react'
import { Bookmark, Trash2 } from '../../lib/icons'
import { useSavedSearches, type SavedSearchFilters } from '../../stores/saved-searches-store'
export function WatchedPills({
value,
onChange,
}: {
value: 'any' | 'played' | 'unplayed'
onChange: (v: 'any' | 'played' | 'unplayed') => void
}) {
const opts: Array<{ key: 'any' | 'played' | 'unplayed'; label: string }> = [
{ key: 'any', label: 'All' },
{ key: 'unplayed', label: 'Unwatched' },
{ key: 'played', label: 'Watched' },
]
return (
{opts.map(o => {
const on = value === o.key
return (
)
})}
)
}
export function SavedSearchMenu({
scope,
onApply,
onSave,
}: {
scope: 'movies' | 'shows'
onApply: (filters: SavedSearchFilters) => void
onSave: () => void
}) {
// Select the whole array; filter in render. Returning a fresh array from
// the selector breaks Zustand's snapshot identity check and sends
// useSyncExternalStore into an update loop.
const allSearches = useSavedSearches(s => s.searches)
const searches = useMemo(
() => allSearches.filter(x => x.scope === scope),
[allSearches, scope],
)
const remove = useSavedSearches(s => s.remove)
const [open, setOpen] = useState(false)
return (
{open && (
<>
setOpen(false)} />
{searches.length === 0 ? (
No saved searches yet.
) : (
searches.map(s => (
))
)}
>
)}
)
}