import { preloadClaims } from "@/app/api/claims";
import { fetchUserAbilities } from "@/app/utils/fetchUtil";
// import { preloadSkill, preloadTeamLeads } from "@/app/api/staff";
import SkillSearch from "@/components/SkillSearch";
import { I18nProvider, getServerI18n } from "@/i18n";
import { MAINTAIN_SKILL } from "@/middleware";
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: "Skill",
};

const Skill: React.FC = async () => {
  const { t } = await getServerI18n("skill");
//   preloadTeamLeads();
//   preloadSkill();

  const abilities = await fetchUserAbilities()
  const maintainSkill = abilities.includes(MAINTAIN_SKILL)
  
  return (
    <>
      <Stack
        direction="row"
        justifyContent="space-between"
        flexWrap="wrap"
        rowGap={2}
      >
        <Typography variant="h4" marginInlineEnd={2}>
          {t("Skill")}
        </Typography>
        {maintainSkill && <Button
          variant="contained"
          startIcon={<Add />}
          LinkComponent={Link}
          href="/settings/skill/create"
        >
          {t("Create Skill")}
        </Button>}
      </Stack>
      <I18nProvider namespaces={["skill", "common"]}>
        <Suspense fallback={<SkillSearch.Loading />}>
          <SkillSearch />
        </Suspense>
      </I18nProvider>
    </>
  );
};

export default Skill;
