import type { ComponentChildren } from 'preact' import { useMemo } from 'preact/hooks' import { useLocale } from '../../contexts/index.js' import { useLocalStorage, useSearchParam } from '../../hooks/index.js' import type { VersionMeta } from '../../services/index.js' import { Checkbox, TextInput } from '../index.js' import { VersionEntry } from './VersionEntry.js' const INCLUDE_SNAPSHOTS = 'misode_include_snapshots' const SEARCH_KEY = 'search' interface Props { versions?: VersionMeta[], link?: (id: string) => string, navigation?: ComponentChildren, } export function VersionList({ versions, link, navigation }: Props) { const { locale } = useLocale() const [snapshots, setSnapshots] = useLocalStorage(INCLUDE_SNAPSHOTS, true, v => v === 'true', b => `${b}`) const [search, setSearch] = useSearchParam(SEARCH_KEY) const filteredVersions = useMemo(() => versions?.filter(v => { if (v.type === 'snapshot' && !snapshots) return false return v.id.includes(search ?? '') }), [versions, snapshots, search]) return <>