import React from "react";
import Search from "../ui/inputs/Search";
import { CartIcon } from "../icons/ExportModuleIcons";

interface DashboardNavBarProps {
  page: React.ReactNode;
  handleProjectsSearch?: (inputValue: string) => Promise<void>;
  handleTrashSearch?: (inputValue: string) => Promise<void>;
  handleRecentProjectSearch?: (inputValue: string) => Promise<void>;
}

const DashboardNavBar: React.FC<DashboardNavBarProps> = ({
  page,
  handleProjectsSearch,
  handleTrashSearch,
  handleRecentProjectSearch,
}) => {
  const handleSearch = async (inputValue: string) => {
    try {
      if (handleProjectsSearch) {
        await handleProjectsSearch(inputValue);
      } else if (handleTrashSearch) {
        await handleTrashSearch(inputValue);
      } else if (handleRecentProjectSearch) {
        await handleRecentProjectSearch(inputValue);
      }
    } catch (error) {
      console.error("Search failed:", error);
    }
  };

  return (
    <div className="dashboard-navbar-container">
      <div className="title">{page}</div>
      <div className="market-place-button">
        <CartIcon isActive /> Market Place
      </div>
      <Search onChange={handleSearch} />
    </div>
  );
};

export default DashboardNavBar;