import { useRouter } from 'next/router' import { Form, Select, DatePicker } from './form' import { ITEM_SORTS, SUB_SORTS, USER_SORTS, WHENS } from '@/lib/constants' import { whenToFrom } from '@/lib/time' export default function TopHeader ({ sub, cat }) { const router = useRouter() const top = async values => { const { what, when, ...query } = values if (what === 'cowboys') { await router.push({ pathname: `/top/${what}` }) return } const prefix = sub ? `/~${sub}` : '' if (typeof query.by !== 'undefined') { if (query.by === '' || (what === 'stackers' && (query.by === 'value' || !USER_SORTS.includes(query.by))) || (what === 'territories' && (query.by === 'stacking' || !SUB_SORTS.includes(query.by))) || (['posts', 'comments'].includes(what) && (query.by === 'zaprank' || !ITEM_SORTS.includes(query.by)))) { delete query.by } } if (when !== 'custom') { delete query.from; delete query.to } if (query.from && !query.to) return await router.push({ pathname: `${prefix}/top/${what}/${when || 'day'}`, query }) } const what = cat const by = router.query.by || (what === 'stackers' ? 'value' : what === 'territories' ? 'stacking' : 'zaprank') const when = router.query.when || '' return (
top({ ...formik?.values, by: e.target.value })} name='by' size='sm' overrideValue={by} items={sortItemsForCategory(cat)} /> for