import { Metadata } from "next";
import { getServerI18n, I18nProvider } from "@/i18n";
import Typography from "@mui/material/Typography";
import { Suspense } from "react";
import { Stack } from "@mui/material";
import { Button } from "@mui/material";
import Link from "next/link";
import UserSearch from "@/components/UserSearch";
import Add from "@mui/icons-material/Add";

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

const User: React.FC = async () => {
  const { t } = await getServerI18n("user");
  return (
    <>
      <Stack
        direction="row"
        justifyContent="space-between"
        flexWrap="wrap"
        rowGap={2}
      >
        <Typography variant="h4" marginInlineEnd={2}>
          {t("User")}
        </Typography>
        <Button
          variant="contained"
          startIcon={<Add />}
          LinkComponent={Link}
          href="/settings/user/create"
        >
          {t("Create User")}
        </Button>
      </Stack>
      <I18nProvider namespaces={["user", "common"]}>
        <Suspense fallback={<UserSearch.Loading />}>
          <UserSearch />
        </Suspense>
      </I18nProvider>
    </>
  );
};
export default User;
