import { Metadata } from "next";
import { getServerI18n, I18nProvider } from "@/i18n";
import Typography from "@mui/material/Typography";
import { Button, Link, Stack } from "@mui/material";
import { Add } from "@mui/icons-material";
import { Suspense } from "react";
import QcCategorySearch from "@/components/QcCategorySearch";
import { preloadQcCategory } from "@/app/api/settings/qcCategory";

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

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

  preloadQcCategory();

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

export default qcCategory;
