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

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 (
    <ScrollView
      style={styles.mainContainer}
      contentContainerStyle={{paddingBottom: SCREEN_HEIGHT * 0.1}}>
      <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}
      />
    </ScrollView>
  );
};

const styles = StyleSheet.create({
  mainContainer: {
    marginLeft: '3%',
    padding: 20,
  },
  container: {
    flexDirection: 'row',
  },
  title: {
    fontSize: 18,
    fontWeight: '600',
    flexGrow: 1,
    marginBottom: '5%',
  },
  clear: {
    fontSize: 18,
    fontWeight: 'bold',
    color: TAGG_LIGHT_BLUE,
  },
});

export default RecentSearches;
