import React from 'react'; import { IonCard, IonCardContent, IonChip, IonIcon } from '@ionic/react'; import { play, pause, stop } from 'ionicons/icons'; import { useAppSelector } from '../../redux'; import { selectIsAdmin, selectPlayerState, selectQueueLength, selectControllerName } from '../../redux'; import { playerService } from '../../firebase/services'; import { PlayerState } from '../../types'; import ActionButton from './ActionButton'; import { useToast } from '../../hooks/useToast'; import { debugLog } from '../../utils/logger'; interface PlayerControlsProps { className?: string; } const PlayerControls: React.FC = ({ className = '' }) => { const isAdmin = useAppSelector(selectIsAdmin); const playerState = useAppSelector(selectPlayerState); const queueLength = useAppSelector(selectQueueLength); const controllerName = useAppSelector(selectControllerName); const { showSuccess, showError } = useToast(); // Debug logging debugLog('PlayerControls - playerState:', playerState); debugLog('PlayerControls - isAdmin:', isAdmin); debugLog('PlayerControls - queue length:', queueLength); const handlePlay = async () => { if (!controllerName) return; try { await playerService.updatePlayerStateValue(controllerName, PlayerState.playing); showSuccess('Playback started'); } catch (error) { console.error('Failed to start playback:', error); showError('Failed to start playback'); } }; const handlePause = async () => { if (!controllerName) return; try { await playerService.updatePlayerStateValue(controllerName, PlayerState.paused); showSuccess('Playback paused'); } catch (error) { console.error('Failed to pause playback:', error); showError('Failed to pause playback'); } }; const handleStop = async () => { if (!controllerName) return; try { await playerService.updatePlayerStateValue(controllerName, PlayerState.stopped); showSuccess('Playback stopped'); } catch (error) { console.error('Failed to stop playback:', error); showError('Failed to stop playback'); } }; // Only show controls for admin users if (!isAdmin) { return null; } const currentState = playerState?.state || PlayerState.stopped; const hasSongsInQueue = queueLength > 0; debugLog('PlayerControls - currentState:', currentState); debugLog('PlayerControls - hasSongsInQueue:', hasSongsInQueue); const getStateColor = () => { switch (currentState) { case PlayerState.playing: return 'success'; case PlayerState.paused: return 'warning'; default: return 'medium'; } }; return (

Player Controls

{currentState}
{currentState === PlayerState.playing ? ( ) : ( )} {currentState !== PlayerState.stopped && ( )}
Admin controls - Only visible to admin users {!hasSongsInQueue && (
Add songs to queue to enable playback controls
)}
); }; export default PlayerControls;