import React, { useEffect, useState, useCallback } from 'react'; import PropTypes from 'prop-types'; import debounce from 'lodash.debounce'; import Icon from '../Icon'; import Tooltip from '../Tooltip'; import InputRange from '../InputRange'; import './CinePlayer.css'; export type CinePlayerProps = { className: string; isPlaying: boolean; minFrameRate?: number; maxFrameRate?: number; stepFrameRate?: number; frameRate?: number; onFrameRateChange: (value: number) => void; onPlayPauseChange: (value: boolean) => void; onClose: () => void; updateDynamicInfo?: () => void; dynamicInfo?: { timePointIndex: number; numTimePoints: number; label?: string; }; }; const fpsButtonClassNames = 'cursor-pointer text-primary-active active:text-primary-light hover:bg-customblue-300 w-4 flex items-center justify-center'; const CinePlayer: React.FC = ({ className, isPlaying = false, minFrameRate = 1, maxFrameRate = 90, stepFrameRate = 1, frameRate: defaultFrameRate = 24, onFrameRateChange = () => {}, onPlayPauseChange = () => {}, onClose = () => {}, dynamicInfo = {}, updateDynamicInfo, }) => { const isDynamic = !!dynamicInfo?.numTimePoints; const [frameRate, setFrameRate] = useState(defaultFrameRate); const debouncedSetFrameRate = useCallback(debounce(onFrameRateChange, 100), [onFrameRateChange]); const getPlayPauseIconName = () => (isPlaying ? 'icon-pause' : 'icon-play'); const handleSetFrameRate = (frameRate: number) => { if (frameRate < minFrameRate || frameRate > maxFrameRate) { return; } setFrameRate(frameRate); debouncedSetFrameRate(frameRate); }; useEffect(() => { setFrameRate(defaultFrameRate); }, [defaultFrameRate]); const handleTimePointChange = useCallback( (newIndex: number) => { if (isDynamic && dynamicInfo) { // Here, you would update the component's state or context that controls the current time point index // For demonstration, assuming a hypothetical function that updates the time point index updateDynamicInfo({ ...dynamicInfo, timePointIndex: newIndex, }); } }, [isDynamic, dynamicInfo] ); return (
{isDynamic && dynamicInfo && ( )}
onPlayPauseChange(!isPlaying)} data-cy={'cine-player-play-pause'} /> {isDynamic && dynamicInfo && (
{/* Add Tailwind classes for monospace font and center alignment */}
{dynamicInfo.timePointIndex}{' '} {`/${dynamicInfo.numTimePoints}`}
{dynamicInfo.label}
)}
handleSetFrameRate(frameRate - 1)} data-cy={'cine-player-left-arrow'} >
} >
{`${frameRate} `} {' FPS'}
handleSetFrameRate(frameRate + 1)} data-cy={'cine-player-right-arrow'} >
); }; CinePlayer.propTypes = { /** Minimum value for range slider */ minFrameRate: PropTypes.number, /** Maximum value for range slider */ maxFrameRate: PropTypes.number, /** Increment range slider can "step" in either direction */ stepFrameRate: PropTypes.number, frameRate: PropTypes.number, /** 'true' if playing, 'false' if paused */ isPlaying: PropTypes.bool.isRequired, onPlayPauseChange: PropTypes.func, onFrameRateChange: PropTypes.func, onClose: PropTypes.func, isDynamic: PropTypes.bool, dynamicInfo: PropTypes.shape({ timePointIndex: PropTypes.number, numTimePoints: PropTypes.number, label: PropTypes.string, }), }; export default CinePlayer;