// import { preloadProjects } from "@/app/api/projects";
// import ProjectSearch from "@/components/ProjectSearch";
// import { getServerI18n } from "@/i18n";

import {I18nProvider} from "@/i18n";
import { preloadProjects } from "../../../app/api/projects";
import ProjectSearch from "../../../components/ProjectSearch";
import { getServerI18n } from "../../../i18n";

import Add from "@mui/icons-material/Add";
import Button from "@mui/material/Button";
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import { Metadata } from "next";
import Link from "next/link";
import { Suspense } from "react";

export const metadata: Metadata = {
  title: "Projects",
};

const Projects: React.FC = async () => {
  const { t } = await getServerI18n("project");
  preloadProjects();

  return (
    <>
      <Stack
        direction="row"
        justifyContent="space-between"
        flexWrap="wrap"
        rowGap={2}
      >
        <Typography variant="h4" marginInlineEnd={2}>
          {t("Projects")}
        </Typography>
        <Button
          variant="contained"
          startIcon={<Add />}
          LinkComponent={Link}
          href="/projects/create"
        >
          {t("Create Project")}
        </Button>
      </Stack>
      <I18nProvider namespaces={["project","navigation","common"]}>
      <Suspense fallback={<ProjectSearch.Loading />}>
        <ProjectSearch />
      </Suspense>
      </I18nProvider>
    </>
  );
};

export default Projects;
