/* eslint-disable no-mixed-spaces-and-tabs */
import { View, Image, Pressable } from 'react-native';
import { Divider, Text, ScrollView, Row, useMediaQuery, useTheme } from 'native-base';
import { useQuery } from '../../Queries';
import API from '../../API';
import ButtonBase from './ButtonBase';
import { Icon } from 'iconsax-react-native';
import { LoadingView } from '../Loading';
import { TranslationKey, translate } from '../../i18n/i18n';
import { useNavigation } from '../../Navigation';
import Spacer from './Spacer';
import User from '../../models/User';
import LogoutButtonCC from './LogoutButtonCC';
import GlassmorphismCC from './Glassmorphism';
type ScaffoldDesktopCCProps = {
widthPadding: boolean;
children?: React.ReactNode;
user: User;
logo: string;
routeName: string;
menu: readonly {
type: 'main' | 'sub';
title: TranslationKey;
icon: Icon;
link: string;
}[];
};
// TODO a tester avec un historique de plus de 3 musics différente mdr !!
const SongHistory = (props: { quantity: number }) => {
const history = useQuery(API.getUserPlayHistory);
const navigation = useNavigation();
if (!history.data || history.isLoading) {
return ;
}
const musics = history.data
.reduce(
(acc, curr) => {
if (acc.length === 0) {
return [curr];
}
if (acc.find((h) => h.song!.id === curr.song!.id)) {
return acc;
}
return [...acc, curr];
},
[] as typeof history.data
)
.map((h) => h.song)
?.slice(0, props.quantity);
return (
{musics.length === 0 ? (
{translate('menuNoSongsPlayedYet')}
) : (
musics.map((song) => (
navigation.navigate('Play', { songId: song!.id })}
>
{song!.name}
))
)}
);
};
const ScaffoldDesktopCC = (props: ScaffoldDesktopCCProps) => {
const navigation = useNavigation();
const userQuery = useQuery(API.getUserInfo);
const [isSmallScreen] = useMediaQuery({ maxWidth: 1100 });
const { colors } = useTheme();
if (!userQuery.data || userQuery.isLoading) {
return ;
}
return (
{!isSmallScreen && (
Chromacase
)}
{props.menu.map(
(value) =>
value.type === 'main' && (
navigation.navigate(value.link as never)
}
/>
)
)}
{!isSmallScreen && (
{translate('menuRecentlyPlayed')}
)}
{props.menu.map(
(value) =>
value.type === 'sub' && (
navigation.navigate(value.link as never)}
/>
)
)}
{props.children}
);
};
export default ScaffoldDesktopCC;