import React from 'react';
import {ProfilePreviewType, PreviewType, ScreenType} from '../../types';
import ProfilePreview from '../profile/ProfilePreview';
import {StyleSheet, View} from 'react-native';
interface SearchResultsProps {
  results: Array<ProfilePreviewType>;
  previewType: PreviewType;
  screenType: ScreenType;
}
const SearchResults: React.FC<SearchResultsProps> = ({
  results,
  previewType,
  screenType,
}) => {
  /**
   * Added the following swicth case to make Results on Search and Recents screen a list
   * Flex is love
   */
  var containerStyle;
  switch (previewType) {
    case 'Search':
      containerStyle = styles.containerSearch;
      break;
    case 'Recent':
      containerStyle = styles.containerSearch;
      break;
    default:
      containerStyle = styles.container;
  }
  return (
    <View style={containerStyle}>
      {results &&
        results.map((profilePreview) => (
          <ProfilePreview
            style={styles.result}
            key={profilePreview.id}
            {...{profilePreview}}
            previewType={previewType}
            screenType={screenType}
          />
        ))}
    </View>
  );
};

const styles = StyleSheet.create({
  containerSearch: {flexDirection: 'column', flexWrap: 'wrap'},
  container: {flexDirection: 'row', flexWrap: 'wrap'},
  result: {
    marginVertical: 10,
  },
});

export default SearchResults;
