import { preloadClaims } from "@/app/api/claims";
import ClaimSearch from "@/components/ClaimSearch";
import { I18nProvider, 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: "Claims",
};

const StaffReimbursement: React.FC = async () => {
  const { t } = await getServerI18n("claim");
  preloadClaims();

  return (
    <>
      <Stack
        direction="row"
        justifyContent="space-between"
        flexWrap="wrap"
        rowGap={2}
      >
        <Typography variant="h4" marginInlineEnd={2}>
          {t("Staff Reimbursement")}
        </Typography>
        <Button
          variant="contained"
          startIcon={<Add />}
          LinkComponent={Link}
          href="/staffReimbursement/create"
        >
          {t("Create Claim")}
        </Button>
      </Stack>
      <I18nProvider namespaces={["claim", "common"]}>
        <Suspense fallback={<ClaimSearch.Loading />}>
          <ClaimSearch />
        </Suspense>
      </I18nProvider>
    </>
  );
};

export default StaffReimbursement;
