import React, { useState } from 'react'; import { IonModal, IonContent, IonList, IonItem, IonLabel } from '@ionic/react'; import { useAppSelector } from '../../redux'; import { selectSingersArray, selectControllerName, selectQueueObject } from '../../redux'; import { queueService } from '../../firebase/services'; import { useToast } from '../../hooks/useToast'; import { useActions } from '../../hooks'; import { ModalHeader } from './ModalHeader'; import { NumberDisplay } from './NumberDisplay'; import { SongInfoDisplay } from './SongItem'; import type { Song, Singer, QueueItem } from '../../types'; interface SelectSingerProps { isOpen: boolean; onClose: () => void; song: Song; } const SelectSinger: React.FC = ({ isOpen, onClose, song }) => { const singers = useAppSelector(selectSingersArray); const controllerName = useAppSelector(selectControllerName); const currentQueue = useAppSelector(selectQueueObject); const toast = useToast(); const showSuccess = toast?.showSuccess; const showError = toast?.showError; const [isLoading, setIsLoading] = useState(false); const { handleAddToQueue } = useActions(); const handleSelectSinger = async (singer: Singer) => { if (!controllerName) { if (showError) showError('Controller not found'); return; } setIsLoading(true); try { await handleAddToQueue(song, singer); if (showSuccess) showSuccess(`${song.title} added to queue for ${singer.name}`); onClose(); } catch (error) { console.error('Failed to add song to queue:', error); if (showError) showError('Failed to add song to queue'); } finally { setIsLoading(false); } }; return ( {/* Song Information */}
{/* Singers List */}
{singers.map((singer, index) => ( handleSelectSinger(singer)} disabled={isLoading} detail={false} style={{ '--padding-start': '0px', '--min-height': '60px' }} > {/* Order Number */} {/* Singer Name */}
{singer.name}
))}
{singers.length === 0 && (
No singers available
)}
); }; export default SelectSinger;