/* eslint-disable no-mixed-spaces-and-tabs */
import { View, Image, Pressable, useColorScheme, ViewStyle } from 'react-native';
import { Divider, Text, ScrollView, Row, useMediaQuery, useTheme } from 'native-base';
import { useAssets } from 'expo-asset';
import { useQuery } from '../../Queries';
import API from '../../API';
import ButtonBase from './ButtonBase';
import { Icon } from 'iconsax-react-native';
import { LoadingView } from '../Loading';
import { Translate, translate } from '../../i18n/i18n';
import { useNavigation } from '../../Navigation';
import Spacer from './Spacer';
import LogoutButtonCC from './LogoutButtonCC';
import { BottomTabBarProps } from '@react-navigation/bottom-tabs';
import { ReactElement } from 'react';
import { NavigationState } from '@react-navigation/native';
// 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 ? (
) : (
musics.map((song) => (
navigation.navigate('Play', { songId: song!.id })}
>
{song!.name}
))
)}
);
};
const NavigationButton = ({
isSmallScreen,
label,
icon,
isFocused,
navigation,
route,
}: {
isSmallScreen: boolean;
label: string;
icon?: Icon;
isFocused: boolean;
navigation: BottomTabBarProps['navigation'];
route: NavigationState['routes'][0];
}) => {
return (
{
const event = navigation.emit({
type: 'tabPress',
target: route.key,
canPreventDefault: true,
});
if (!isFocused && !event.defaultPrevented) {
navigation.navigate(route.name, route.params);
}
}}
onLongPress={() => {
navigation.emit({
type: 'tabLongPress',
target: route.key,
});
}}
/>
);
};
const ScaffoldDesktopCC = ({
state,
descriptors,
navigation,
children,
style,
}: Omit & { children: ReactElement; style?: ViewStyle }) => {
const user = useQuery(API.getUserInfo);
const [isSmallScreen] = useMediaQuery({ maxWidth: 1100 });
const { colors } = useTheme();
const colorScheme = useColorScheme();
const [logo] = useAssets(
colorScheme == 'light'
? require('../../assets/icon_light.png')
: require('../../assets/icon_dark.png')
);
return (
{!isSmallScreen && (
ChromaCase
)}
{state.routes.map((route, index) => {
const { options } = descriptors[route.key]!;
if ((options as any).subMenu) return null;
return (
);
})}
{!isSmallScreen && (
{translate('menuRecentlyPlayed')}
)}
{state.routes.map((route, index) => {
const { options } = descriptors[route.key]!;
if (!(options as any).subMenu) return null;
return (
);
})}
{children}
);
};
export default ScaffoldDesktopCC;