import { Box } from "@mui/material";
import React, { useEffect, useState } from "react";
import { SearchInput } from "../../SearchInput";
import { SearchProps } from "./type";

const Search = ({
  onChange,
  placeholder,
  searchTextValue = "",
  entity
}: SearchProps) => {
  const [searchText, setSearchText] = useState(searchTextValue);

  useEffect(() => {
    setSearchText('');
    onChange?.('');
  }, [entity]);

  return (
    <Box>
      <SearchInput
        searchText={searchText}
        onSearchText={(text: string) => {
          setSearchText(text);
          onChange?.(text);
        }}
        placeholder={placeholder}
      />
    </Box>
  );
};

export default Search;
