import { h } from 'preact'; import { useState, useEffect } from 'preact/hooks'; import htm from 'htm'; import { api } from '../api.js'; const html = htm.bind(h); // Flat SVG icons using stroke/fill="currentColor" so they automatically // follow the button's text colour in light mode, dark mode, and in the // accent-inverted active state — no CSS filter needed. function IconVolume({ muted = false, size = 20 }) { if (muted) { return html``; } return html``; } function IconShuffle() { return html``; } function IconRepeat({ one = false }) { return html``; } export function Controls({ deviceId, status }) { const np = status?.nowPlaying; const isPlaying = np?.PlayStatus === 'PLAY_STATE'; const actualVolume = status?.volume?.ActualVolume ?? 0; const isMuted = status?.volume?.MuteEnabled ?? false; const shuffle = np?.ShuffleSetting ?? 'SHUFFLE_OFF'; const repeat = np?.RepeatSetting ?? 'REPEAT_OFF'; const actualBass = status?.bass?.TargetBass ?? 0; const hasBass = status?.bass != null; const [localVolume, setLocalVolume] = useState(actualVolume); const [localBass, setLocalBass] = useState(actualBass); useEffect(() => { setLocalVolume(actualVolume); }, [actualVolume]); useEffect(() => { setLocalBass(actualBass); }, [actualBass]); const send = (key) => api.key(deviceId, key); function onVolumeChange(e) { const val = parseInt(e.target.value, 10); setLocalVolume(val); api.volume(deviceId, val); } function onBassChange(e) { const val = parseInt(e.target.value, 10); setLocalBass(val); api.bass(deviceId, val); } function toggleShuffle() { send(shuffle === 'SHUFFLE_ON' ? 'SHUFFLE_OFF' : 'SHUFFLE_ON'); } function cycleRepeat() { if (repeat === 'REPEAT_OFF') send('REPEAT_ALL'); else if (repeat === 'REPEAT_ALL') send('REPEAT_ONE'); else send('REPEAT_OFF'); } return html`