import { LeftOutlined, RightOutlined } from '@ant-design/icons'; import { Button, Select } from 'antd'; import { Pagination } from 'hooks/queryPagination'; import { memo, useMemo } from 'react'; import { defaultSelectStyle, ITEMS_PER_PAGE_OPTIONS } from './config'; import { Container } from './styles'; function Controls({ offset = 0, isLoading, totalCount, countPerPage, handleNavigatePrevious, handleNavigateNext, handleCountItemsPerPageChange, }: ControlsProps): JSX.Element | null { const isNextAndPreviousDisabled = useMemo( () => isLoading || countPerPage < 0 || totalCount === 0, [isLoading, countPerPage, totalCount], ); const isPreviousDisabled = useMemo(() => offset <= 0, [offset]); const isNextDisabled = useMemo(() => totalCount < countPerPage, [ countPerPage, totalCount, ]); return ( style={defaultSelectStyle} loading={isLoading} value={countPerPage} onChange={handleCountItemsPerPageChange} > {ITEMS_PER_PAGE_OPTIONS.map((count) => ( {`${count} / page`} ))} ); } Controls.defaultProps = { offset: 0, }; export interface ControlsProps { offset?: Pagination['offset']; totalCount: number; countPerPage: Pagination['limit']; isLoading: boolean; handleNavigatePrevious: () => void; handleNavigateNext: () => void; handleCountItemsPerPageChange: (value: Pagination['limit']) => void; } export default memo(Controls);