import { ActionIcon, Box, Button, Divider, Group, NativeSelect, Stack, Text, Title } from '@mantine/core'; import { SpotifyLogoIcon, DevicesIcon, SignOutIcon, ArrowsClockwiseIcon } from '@phosphor-icons/react'; import { Trans, useLingui } from '@lingui/react/macro'; import { useSpotify } from '@/lib/spotify/hooks'; import { useAuth } from '@/contexts/auth-context'; import Sheet from '@/components/sheet/sheet'; interface SpotifySheetProps { opened: boolean; onClose: () => void; } const SpotifySheet: React.FC = ({ opened, onClose }) => { const { roles } = useAuth(); const isAdmin = roles?.includes('Admin') || false; const spotify = useSpotify(); const { t } = useLingui(); if (!isAdmin || !spotify) return null; const { isAuthenticated, login, logout, devices, activeDevice, currentTrack, getDevices, setActiveDevice, isLoading, error, } = spotify; if (!isAdmin) return null; const handleDeviceChange = (deviceId: string) => { if (deviceId && deviceId !== activeDevice?.id) { setActiveDevice(deviceId); } }; const refreshDevices = () => { getDevices(); }; const handleChange = (opened: boolean) => { if (!opened) onClose(); }; return ( {!isAuthenticated ? ( <> Connect your Spotify account ) : ( <> {/* Current track display */} {currentTrack && ( <> <Trans>Now Playing</Trans> {currentTrack.album.images[2] && ( {currentTrack.album.name} )} {currentTrack.name} {currentTrack.artists.map(a => a.name).join(', ')} {currentTrack.album.name} )} <Group gap="xs"> <DevicesIcon size={20} /> <Trans>Select Device</Trans> </Group> {devices.length > 0 ? ( handleDeviceChange(event.currentTarget.value)} data={[ { value: '', label: t`Select a device...` }, ...devices.map(device => ({ value: device.id, label: `${device.name} ${device.is_active ? t`(Active)` : ''} - ${device.type}`, })), ]} disabled={isLoading} /> ) : ( No devices found. )} {activeDevice && ( Active device: {activeDevice.name} {activeDevice.volume_percent !== null && t` (Volume: ${activeDevice.volume_percent}%)` } )} {error && ( <> {error} )} )} ); }; export default SpotifySheet;