/**
* External dependencies
*/
import { Button, Text } from '@automattic/jetpack-components';
import { Icon, chevronLeft, chevronRight } from '@wordpress/icons';
import classnames from 'classnames';
/**
* Internal dependencies
*/
import useVideos, { useLocalVideos } from '../../hooks/use-videos';
import styles from './style.module.scss';
import { PaginationProps } from './types';
import type React from 'react';
const range = ( start, count ) => {
return [ ...Array( count ) ].map( ( _, index ) => index + start );
};
const Ellipsis = () => (
);
/**
* Pagination component
*
* @param {PaginationProps} props - Component props.
* @returns {React.ReactNode} - Pagination react component.
*/
const Pagination: React.FC< PaginationProps > = ( {
className,
currentPage = 1,
perPage,
total,
minColumns = 7,
disabled,
onChangePage,
} ) => {
if ( ! total || ! perPage ) {
return null;
}
const numPages = Math.ceil( total / perPage );
if ( currentPage > numPages ) {
onChangePage( numPages );
return null;
}
if ( currentPage < 1 ) {
onChangePage( 1 );
return null;
}
const PageButton = ( { page }: { page: number } ) => {
const isCurrent = page === currentPage;
return (
);
};
// Smallest odd integer from minColumns, inclusive, with a minimum of 7 columns
let numColumns = Math.max( minColumns, 7 );
numColumns = numColumns % 2 === 0 ? numColumns + 1 : numColumns;
let content;
if ( numPages <= numColumns ) {
content = range( 1, numPages ).map( i =>