"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const client = require("@contember/client");
const ui = require("@contember/ui");
const react = require("react");
const removeMember = require("../../mutations/membership/removeMember.cjs");
const useRemoveMemberIntent = (project, onRemove) => {
  const [removeMemberInner] = removeMember.useRemoveProjectMembership();
  const addToast = ui.useShowToast();
  return react.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) => client.getTenantErrorMessage(it.code)).join(", ")}`,
          type: "error",
          dismiss: true
        });
      }
      onRemove && await onRemove();
    },
    [addToast, project, onRemove, removeMemberInner]
  );
};
exports.useRemoveMemberIntent = useRemoveMemberIntent;
//# sourceMappingURL=useRemoveMemberIntent.cjs.map
