import { View } from "react-native-ui-lib";
import React from "react";
import { useBrainDumpContext } from "@/contexts/DumpContext";
import { FlatList } from "react-native";
import BrainDumpItem from "./DumpItem";
import { StyleSheet } from "react-native";
const DumpList = (props: { searchText: string }) => {
  const { brainDumps } = useBrainDumpContext();

  const sortedDumps =
    props.searchText.trim() === ""
      ? brainDumps
      : brainDumps.filter(
          (item) =>
            item.title.toLowerCase().includes(props.searchText.toLowerCase()) ||
            item.description
              .toLowerCase()
              .includes(props.searchText.toLowerCase())
        );

        return (
          <View marginB-70>
            {brainDumps?.length ? <FlatList
              style={{ zIndex: -1 }}
              data={sortedDumps}
              keyExtractor={(item) => item.title}
              renderItem={({ item }) => (
                <BrainDumpItem key={item.title} item={item} />
              )}
            /> : <Text marginT-20 center style={styles.alert}>You have no notes</Text>}
          </View>
        );
      };
      
      const styles = StyleSheet.create({
        alert: {fontFamily: "PlusJakartaSans_300Light", fontSize: 20}
      })
export default DumpList;
