import React, { useEffect, useRef } from 'react';
import { Animated, Easing, Switch, Text, TouchableWithoutFeedback, View } from 'react-native';
import Touch from '../../containers/Touch';
import { CustomIcon, TIconsName } from '../../containers/CustomIcon';
import Check from '../../containers/Check';
import I18n from '../../i18n';
import { SWITCH_TRACK_COLOR } from '../../lib/constants';
import styles from './styles';
import { useTheme } from '../../theme';
const ANIMATION_DURATION = 200;
const ANIMATION_PROPS = {
duration: ANIMATION_DURATION,
easing: Easing.inOut(Easing.quad),
useNativeDriver: true
};
interface IDirectoryOptionsProps {
type: string;
globalUsers: boolean;
isFederationEnabled: boolean;
close: Function;
changeType: Function;
toggleWorkspace(): void;
}
const DirectoryOptions = ({
type: propType,
globalUsers,
isFederationEnabled,
close: onClose,
changeType,
toggleWorkspace
}: IDirectoryOptionsProps) => {
const animatedValue = useRef(new Animated.Value(0)).current;
const { colors } = useTheme();
useEffect(() => {
Animated.timing(animatedValue, {
toValue: 1,
...ANIMATION_PROPS
}).start();
}, [animatedValue]);
const close = () => {
Animated.timing(animatedValue, {
toValue: 0,
...ANIMATION_PROPS
}).start(() => onClose());
};
const renderItem = (itemType: string) => {
let text = 'Users';
let icon: TIconsName = 'user';
if (itemType === 'channels') {
text = 'Channels';
icon = 'channel-public';
}
if (itemType === 'teams') {
text = 'Teams';
icon = 'teams';
}
return (
changeType(itemType)} style={styles.dropdownItemButton} accessibilityLabel={I18n.t(text)}>
{I18n.t(text)}
{propType === itemType ? : null}
);
};
const translateY = animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [-326, 0]
});
const backdropOpacity = animatedValue.interpolate({
inputRange: [0, 1],
outputRange: [0, colors.backdropOpacity]
});
return (
<>
{I18n.t('Search_by')}
{renderItem('channels')}
{renderItem('users')}
{renderItem('teams')}
{isFederationEnabled ? (
<>
{I18n.t('Search_global_users')}
{I18n.t('Search_global_users_description')}
>
) : null}
>
);
};
export default DirectoryOptions;