import { useState, useRef } from 'react' import { useRouter } from 'next/router' import cx from 'classnames' import { useTranslation } from 'components/hooks/useTranslation' import { DEFAULT_VERSION, useVersion } from 'components/hooks/useVersion' import { useQuery } from 'components/hooks/useQuery' import styles from './Search.module.scss' type Props = { isHeaderSearch?: true variant?: 'compact' | 'expanded' iconSize: number } export function BasicSearch({ isHeaderSearch = true, variant = 'compact', iconSize = 24 }: Props) { const router = useRouter() const { query, debug } = useQuery() const [localQuery, setLocalQuery] = useState(query) const inputRef = useRef(null) const { t } = useTranslation('search') const { currentVersion } = useVersion() function redirectSearch() { let asPath = `/${router.locale}` if (currentVersion !== DEFAULT_VERSION) { asPath += `/${currentVersion}` } asPath += '/search' const params = new URLSearchParams({ query: localQuery }) if (debug) { params.set('debug', '1') } asPath += `?${params}` router.push(asPath) } return (
{ event.preventDefault() redirectSearch() }} >
) }