import React, { useContext } from 'react';
import { Pressable, ScrollView, View, useWindowDimensions } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import {
Avatar,
Divider,
Icon,
Text,
createStyleSheet,
useHeaderStyle,
useUIKitTheme,
} from '@gathertown/uikit-react-native-foundation';
import { conditionChaining } from '@gathertown/uikit-utils';
import { useLocalization, useSendbirdChat } from '../../../hooks/useContext';
import useKeyboardStatus from '../../../hooks/useKeyboardStatus';
import useMentionSuggestion from '../../../hooks/useMentionSuggestion';
import { GroupChannelContexts } from '../module/moduleContext';
import type { GroupChannelProps } from '../types';
const GroupChannelSuggestedMentionList = ({
text,
selection,
inputHeight,
bottomInset,
onPressToMention,
mentionedUsers,
}: GroupChannelProps['SuggestedMentionList']) => {
const { width: screenWidth, height: screenHeight } = useWindowDimensions();
const { channel } = useContext(GroupChannelContexts.Fragment);
const { sdk, mentionManager } = useSendbirdChat();
const { STRINGS } = useLocalization();
const { colors } = useUIKitTheme();
const { topInset } = useHeaderStyle();
const { left, right } = useSafeAreaInsets();
const keyboard = useKeyboardStatus();
const { members, reset, searchStringRange, searchLimited } = useMentionSuggestion({
sdk,
text,
selection,
channel,
mentionedUsers,
});
const isLandscape = screenWidth > screenHeight;
const isShortened = isLandscape && keyboard.visible;
const canRenderMembers = members.length > 0;
const maxHeight = isShortened ? screenHeight - (topInset + inputHeight + keyboard.height) : styles.suggestion.height;
const renderLimitGuide = () => {
return (
{STRINGS.GROUP_CHANNEL.MENTION_LIMITED(mentionManager.config.mentionLimit)}
);
};
const renderMembers = () => {
return (
{members.map((member) => {
return (
{
onPressToMention(member, searchStringRange);
reset();
}}
key={member.userId}
style={styles.userContainer}
>
{member.nickname || STRINGS.LABELS.USER_NO_NAME}
{member.userId}
);
})}
);
};
return (
{conditionChaining([searchLimited, canRenderMembers], [renderLimitGuide(), renderMembers(), null])}
);
};
const styles = createStyleSheet({
suggestion: {
height: 196,
},
container: {
position: 'absolute',
top: 0,
right: 0,
left: 0,
},
scrollView: {
position: 'absolute',
left: 0,
right: 0,
},
userContainer: {
paddingLeft: 16,
flexDirection: 'row',
height: 44,
alignItems: 'center',
justifyContent: 'center',
},
userAvatar: {
marginRight: 16,
},
userInfo: {
flexDirection: 'row',
flex: 1,
},
userNickname: {
flexShrink: 1,
lineHeight: 44,
textAlignVertical: 'center',
marginRight: 6,
},
userId: {
lineHeight: 44,
textAlignVertical: 'center',
minWidth: 32,
flexShrink: 1,
marginRight: 16,
},
searchLimited: {
borderTopWidth: 1,
paddingHorizontal: 16,
height: 44,
flexDirection: 'row',
alignItems: 'center',
},
});
export default GroupChannelSuggestedMentionList;