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";

const DumpList = (props: { searchText: string }) => {
  const { brainDumps } = useBrainDumpContext();

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

  return (
    <View>
      <FlatList
        data={filteredBrainDumps}
        keyExtractor={(item) => item.title}
        renderItem={({ item }) => (
          <BrainDumpItem key={item.title} item={item} />
        )}
      />
    </View>
  );
};

export default DumpList;
