import { modals } from "@mantine/modals";
import { useCallback } from "react";

export default function useModal<T>(
    Component: React.ComponentType<T>, 
    defaulTitle: string
  ) {
      const openModal = useCallback((params: T, title?: string) => {
          modals.open({
              title: title ?? defaulTitle,
              children: <Component afterSubmit={() => modals.closeAll()} {...params} />,
          });
      }, [Component, defaulTitle ]);
  
      return openModal;
}