"use client";
import DenyAccess from "@/components/DenyAccess";
import CreateMedicalPackageForm from "@/components/forms/medical-packages/new/CreateMedicalPackageForm";
import Loader from "@/components/Loader";
import {useGetLanguages} from "@/hooks/languages";
import {useCreateMedicalPackage, useGetAllMedicalPackagesParent} from "@/hooks/medical-package";
import {useQueryClient} from "@tanstack/react-query";
import React, {Suspense} from "react";

export default function Page() {
  const {data} = useGetLanguages();
  const {mutateAsync, isPending} = useCreateMedicalPackage();
  const {data:parents}=useGetAllMedicalPackagesParent("fa")
  const queryClient = useQueryClient();
  return (
    <div>
      <Suspense fallback={<Loader />}>
        {data?.data?.length > 0   ?  (
          <CreateMedicalPackageForm
            languages={data?.data}
            createFn={mutateAsync}
            createPending={isPending}
            queryClient={queryClient}
            parents={parents?.data}
          />
        ) : <DenyAccess label="زبان" link="/languages"/> }
      </Suspense>
    </div>
  );
}
