import clsx from 'clsx'; import React from 'react'; import { Insets } from '@/types/misc'; import { PageInfo, TimeInfo } from '@/types/book'; import { useEnv } from '@/context/EnvContext'; import { useReaderStore } from '@/store/readerStore'; import { useTranslation } from '@/hooks/useTranslation'; import { formatReadingProgress } from '@/utils/progress'; interface PageInfoProps { bookKey: string; bookFormat: string; section?: PageInfo; pageinfo?: PageInfo; timeinfo?: TimeInfo; horizontalGap: number; contentInsets: Insets; gridInsets: Insets; } const ProgressInfoView: React.FC = ({ bookKey, bookFormat, section, pageinfo, timeinfo, horizontalGap, contentInsets, gridInsets, }) => { const _ = useTranslation(); const { appService } = useEnv(); const { getView, getViewSettings } = useReaderStore(); const view = getView(bookKey); const viewSettings = getViewSettings(bookKey)!; const showDoubleBorder = viewSettings.vertical && viewSettings.doubleBorder; const isScrolled = viewSettings.scrolled; const isVertical = viewSettings.vertical; const { progressStyle: readingProgressStyle } = viewSettings; const formatTemplate = readingProgressStyle === 'fraction' ? isVertical ? '{current} ยท {total}' : '{current} / {total}' : '{percent}%'; const progressInfo = ['PDF', 'CBZ'].includes(bookFormat) ? formatReadingProgress(section?.current, section?.total, formatTemplate) : formatReadingProgress(pageinfo?.current, pageinfo?.total, formatTemplate); const timeLeft = timeinfo ? _('{{time}} min left in chapter', { time: Math.round(timeinfo.section) }) : ''; const { page = 0, pages = 0 } = view?.renderer || {}; const pageLeft = pages - 1 > page ? _('{{count}} pages left in chapter', { count: pages - 1 - page }) : ''; return (
{viewSettings.showRemainingTime ? ( {timeLeft} ) : viewSettings.showRemainingPages ? ( {pageLeft} ) : null} {viewSettings.showProgressInfo && {progressInfo}}
); }; export default ProgressInfoView;