import { useHotkeys } from '@mantine/hooks';
import { motion, Variants } from 'motion/react';
import { CSSProperties, useLayoutEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router';
import styles from './full-screen-player.module.css';
import { TableConfigDropdown } from '/@/renderer/components/virtual-table';
import { FullScreenPlayerImage } from '/@/renderer/features/player/components/full-screen-player-image';
import { FullScreenPlayerQueue } from '/@/renderer/features/player/components/full-screen-player-queue';
import { useFastAverageColor } from '/@/renderer/hooks';
import {
useCurrentSong,
useFullScreenPlayerStore,
useFullScreenPlayerStoreActions,
useLyricsSettings,
useSettingsStore,
useSettingsStoreActions,
useWindowSettings,
} from '/@/renderer/store';
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
import { Divider } from '/@/shared/components/divider/divider';
import { Group } from '/@/shared/components/group/group';
import { NumberInput } from '/@/shared/components/number-input/number-input';
import { Option } from '/@/shared/components/option/option';
import { Popover } from '/@/shared/components/popover/popover';
import { Select } from '/@/shared/components/select/select';
import { Slider } from '/@/shared/components/slider/slider';
import { Switch } from '/@/shared/components/switch/switch';
import { Platform } from '/@/shared/types/types';
const mainBackground = 'var(--theme-colors-background)';
const Controls = () => {
const { t } = useTranslation();
const {
dynamicBackground,
dynamicImageBlur,
dynamicIsImage,
expanded,
opacity,
useImageAspectRatio,
} = useFullScreenPlayerStore();
const { setStore } = useFullScreenPlayerStoreActions();
const { setSettings } = useSettingsStoreActions();
const lyricConfig = useLyricsSettings();
const handleToggleFullScreenPlayer = () => {
setStore({ expanded: !expanded });
};
const handleLyricsSettings = (property: string, value: any) => {
setSettings({
lyrics: {
...useSettingsStore.getState().lyrics,
[property]: value,
},
});
};
useHotkeys([['Escape', handleToggleFullScreenPlayer]]);
return (
{t('page.fullscreenPlayer.config.dynamicBackground', {
postProcess: 'sentenceCase',
})}
setStore({
dynamicBackground: e.target.checked,
})
}
/>
{dynamicBackground && (
{t('page.fullscreenPlayer.config.dynamicIsImage', {
postProcess: 'sentenceCase',
})}
setStore({
dynamicIsImage: e.target.checked,
})
}
/>
)}
{dynamicBackground && dynamicIsImage && (
{t('page.fullscreenPlayer.config.dynamicImageBlur', {
postProcess: 'sentenceCase',
})}
`${e} rem`}
max={6}
min={0}
onChangeEnd={(e) => setStore({ dynamicImageBlur: Number(e) })}
step={0.5}
w="100%"
/>
)}
{dynamicBackground && (
{t('page.fullscreenPlayer.config.opacity', {
postProcess: 'sentenceCase',
})}
`${e} %`}
max={100}
min={0}
onChangeEnd={(e) => setStore({ opacity: Number(e) })}
w="100%"
/>
)}
{t('page.fullscreenPlayer.config.useImageAspectRatio', {
postProcess: 'sentenceCase',
})}
setStore({
useImageAspectRatio: e.target.checked,
})
}
/>
{t('page.fullscreenPlayer.config.followCurrentLyric', {
postProcess: 'sentenceCase',
})}
handleLyricsSettings('follow', e.currentTarget.checked)
}
/>
{t('page.fullscreenPlayer.config.showLyricProvider', {
postProcess: 'sentenceCase',
})}
handleLyricsSettings('showProvider', e.currentTarget.checked)
}
/>
{t('page.fullscreenPlayer.config.showLyricMatch', {
postProcess: 'sentenceCase',
})}
handleLyricsSettings('showMatch', e.currentTarget.checked)
}
/>
{t('page.fullscreenPlayer.config.lyricSize', {
postProcess: 'sentenceCase',
})}
`${t('page.fullscreenPlayer.config.synchronized', {
postProcess: 'titleCase',
})}: ${e}px`
}
max={72}
min={8}
onChangeEnd={(e) => handleLyricsSettings('fontSize', Number(e))}
w="100%"
/>
`${t('page.fullscreenPlayer.config.unsynchronized', {
postProcess: 'sentenceCase',
})}: ${e}px`
}
max={72}
min={8}
onChangeEnd={(e) =>
handleLyricsSettings('fontSizeUnsync', Number(e))
}
w="100%"
/>
{t('page.fullscreenPlayer.config.lyricGap', {
postProcess: 'sentenceCase',
})}
`Synchronized: ${e}px`}
max={50}
min={0}
onChangeEnd={(e) => handleLyricsSettings('gap', Number(e))}
w="100%"
/>
`Unsynchronized: ${e}px`}
max={50}
min={0}
onChangeEnd={(e) =>
handleLyricsSettings('gapUnsync', Number(e))
}
w="100%"
/>
{t('page.fullscreenPlayer.config.lyricAlignment', {
postProcess: 'sentenceCase',
})}
{t('page.fullscreenPlayer.config.lyricOffset', {
postProcess: 'sentenceCase',
})}
handleLyricsSettings('delayMs', Number(e.currentTarget.value))
}
step={10}
/>
);
};
const containerVariants: Variants = {
closed: (custom) => {
const { windowBarStyle } = custom;
return {
height:
windowBarStyle === Platform.WINDOWS || windowBarStyle === Platform.MACOS
? 'calc(100vh - 120px)'
: 'calc(100vh - 90px)',
position: 'absolute',
top: '100vh',
transition: {
duration: 0.5,
ease: 'easeInOut',
},
width: '100vw',
y: -100,
};
},
open: (custom) => {
const { background, backgroundImage, dynamicBackground, windowBarStyle } = custom;
return {
background: dynamicBackground ? backgroundImage : mainBackground,
backgroundColor: dynamicBackground ? background : mainBackground,
backgroundPosition: 'center',
backgroundRepeat: 'no-repeat',
backgroundSize: 'cover',
height:
windowBarStyle === Platform.WINDOWS || windowBarStyle === Platform.MACOS
? 'calc(100vh - 120px)'
: 'calc(100vh - 90px)',
left: 0,
position: 'absolute',
top: 0,
transition: {
background: {
duration: 0.5,
ease: 'easeInOut',
},
delay: 0.1,
duration: 0.5,
ease: 'easeInOut',
},
width: '100vw',
y: 0,
};
},
};
export const FullScreenPlayer = () => {
const { dynamicBackground, dynamicImageBlur, dynamicIsImage } = useFullScreenPlayerStore();
const { setStore } = useFullScreenPlayerStoreActions();
const { windowBarStyle } = useWindowSettings();
const location = useLocation();
const isOpenedRef = useRef(null);
useLayoutEffect(() => {
if (isOpenedRef.current !== null) {
setStore({ expanded: false });
}
isOpenedRef.current = true;
}, [location, setStore]);
const currentSong = useCurrentSong();
const { background } = useFastAverageColor({
algorithm: 'dominant',
src: currentSong?.imageUrl,
srcLoaded: true,
});
const imageUrl = currentSong?.imageUrl && currentSong.imageUrl.replace(/size=\d+/g, 'size=500');
const backgroundImage =
imageUrl && dynamicIsImage
? `url("${imageUrl.replace(currentSong.id, currentSong.albumId)}"), url("${imageUrl}")`
: mainBackground;
return (
{dynamicBackground && (
)}
);
};