import { getTenantErrorMessage } from "@contember/client";
import { useShowToast } from "@contember/ui";
import { useCallback } from "react";
import { useRemoveProjectMembership } from "../../mutations/membership/removeMember.js";
const useRemoveMemberIntent = (project, onRemove) => {
  const [removeMemberInner] = useRemoveProjectMembership();
  const addToast = useShowToast();
  return useCallback(async (id) => {
    const confirmed = confirm("Do you want to remove member from project?");
    if (!confirmed) {
      return;
    }
    const result = await removeMemberInner(project, id);
    if (result.removeProjectMember.ok) {
      addToast({
        message: `Member removed`,
        type: "success",
        dismiss: true
      });
    } else {
      addToast({
        message: `Error removing member: ${result.removeProjectMember.errors.map((it) => getTenantErrorMessage(it.code)).join(", ")}`,
        type: "error",
        dismiss: true
      });
    }
    onRemove && await onRemove();
  }, [addToast, project, onRemove, removeMemberInner]);
};
export { useRemoveMemberIntent };
//# sourceMappingURL=useRemoveMemberIntent.js.map
