import clsx from 'clsx'; import React, { useCallback } from 'react'; import { IoChevronBack, IoChevronForward } from 'react-icons/io5'; import { useReaderStore } from '@/store/readerStore'; import { useTranslation } from '@/hooks/useTranslation'; import { viewPagination } from '../hooks/usePagination'; import { useBookDataStore } from '@/store/bookDataStore'; interface PageNavigationButtonsProps { bookKey: string; isDropdownOpen: boolean; } const PageNavigationButtons: React.FC = ({ bookKey, isDropdownOpen, }) => { const _ = useTranslation(); const { getBookData } = useBookDataStore(); const { getView, getProgress, getViewSettings, hoveredBookKey } = useReaderStore(); const bookData = getBookData(bookKey); const view = getView(bookKey); const viewSettings = getViewSettings(bookKey); const progress = getProgress(bookKey); const { section, pageinfo } = progress || {}; const pageInfo = bookData?.isFixedLayout ? section : pageinfo; const currentPage = pageInfo?.current; const isPageNavigationButtonsVisible = (hoveredBookKey === bookKey || isDropdownOpen) && viewSettings?.showPaginationButtons; const handleGoLeftPage = useCallback(() => { viewPagination(view, viewSettings, 'left', 'page'); }, [view, viewSettings]); const handleGoRightPage = useCallback(() => { viewPagination(view, viewSettings, 'right', 'page'); }, [view, viewSettings]); const getLeftPageLabel = () => { const baseLabel = viewSettings?.rtl ? _('Next Page') : _('Previous Page'); if (currentPage !== undefined) { return `${baseLabel}, ${_('Page {{number}}', { number: currentPage + 1 })}`; } return baseLabel; }; const getRightPageLabel = () => { const baseLabel = viewSettings?.rtl ? _('Previous Page') : _('Next Page'); if (currentPage !== undefined) { return `${baseLabel}, ${_('Page {{number}}', { number: currentPage + 1 })}`; } return baseLabel; }; return ( <> {currentPage !== undefined && (
{_('Page {{number}}', { number: currentPage + 1 })}
)} ); }; export default PageNavigationButtons;