import React from 'react';
import {
  View,
  Text,
  TouchableOpacity,
  StyleSheet,
  TouchableOpacityProps,
} from 'react-native';
import {PreviewType, ProfilePreviewType, ScreenType} from 'src/types';
import {TAGG_TEXT_LIGHT_BLUE} from '../../constants';
import SearchResults from './SearchResults';

interface RecentSearchesProps extends TouchableOpacityProps {
  sectionTitle: PreviewType;
  sectionButtonTitle: string;
  recents: Array<ProfilePreviewType>;
  screenType: ScreenType;
}
/**
 * An image component that returns the <Image> of the icon for a specific social media platform.
 */
const RecentSearches: React.FC<RecentSearchesProps> = (props) => {
  return (
    <>
      <View style={styles.container}>
        <Text style={styles.title}>{props.sectionTitle}</Text>
        {props.sectionButtonTitle && (
          <TouchableOpacity {...props}>
            <Text style={styles.clear}>Clear all</Text>
          </TouchableOpacity>
        )}
      </View>
      <SearchResults
        results={props.recents}
        previewType={props.sectionTitle}
        screenType={props.screenType}
      />
    </>
  );
};

const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
  },
  title: {
    fontSize: 17,
    fontWeight: 'bold',
    flexGrow: 1,
  },
  clear: {
    fontSize: 17,
    fontWeight: 'bold',
    color: TAGG_TEXT_LIGHT_BLUE,
  },
});

export default RecentSearches;
