import { View } from "react-native-ui-lib";
import React from "react";
import { FlatList } from "react-native";
import { useFeedbackContext } from "@/contexts/FeedbackContext";
import Feedback from "./Feedback";

const FeedbackList = (props: { searchText: string }) => {
  const { feedbacks } = useFeedbackContext();

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

  return (
    <View marginB-70>
      <FlatList
        style={{ zIndex: -1 }}
        data={filteredBrainDumps}
        keyExtractor={(item) => item.title}
        renderItem={({ item }) => (
          <Feedback key={item.title} item={item} />
        )}
      />
    </View>
  );
};

export default FeedbackList;
