import { faChevronDown } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' import { useAttributes } from '@reservoir0x/reservoir-kit-ui' import { Box, Flex, Switch, Text } from 'components/primitives' import { useRouter } from 'next/router' import { CSSProperties, FC, useMemo, useState } from 'react' import { addParam, hasParam, removeParam } from 'utils/router' import { FixedSizeList as List } from 'react-window' type Props = { attribute: NonNullable['data']>[0] scrollToTop: () => void } export const AttributeSelector: FC = ({ attribute, scrollToTop }) => { const router = useRouter() const [open, setOpen] = useState(false) const sortedAttributes = useMemo(() => { return attribute?.values?.sort((a, b) => { if (!a.count || !b.count) { return 0 } else { return b.count - a.count } }) }, [attribute]) const AttributeRow: FC<{ index: number; style: CSSProperties }> = ({ index, style, }) => { const currentAttribute = attribute?.values?.[index] return ( { if ( hasParam( router, `attributes[${attribute.key}]`, currentAttribute?.value ) ) { removeParam( router, `attributes[${attribute.key}]`, currentAttribute?.value ) } else { addParam( router, `attributes[${attribute.key}]`, currentAttribute?.value || '' ) } }} > {currentAttribute?.value} {currentAttribute?.count} { if (checked) { addParam( router, `attributes[${attribute.key}]`, currentAttribute?.value || '' ) } else { removeParam( router, `attributes[${attribute.key}]`, currentAttribute?.value ) } scrollToTop() }} /> ) } return ( setOpen(!open)} > {attribute.key} = 7 ? 300 : (sortedAttributes?.length ?? 1) * 36 : 0 } itemCount={sortedAttributes?.length ?? 1} itemSize={36} width={'100%'} style={{ overflow: 'auto', transition: 'max-height .3s ease-in-out', }} > {AttributeRow} ) }