import { memo, forwardRef, useCallback, createElement } from "react";
import { useMutationState, useDirtinessState } from "@contember/binding";
import { SaveButton } from "@contember/ui";
import { usePersistWithFeedback } from "../../ui/usePersistWithFeedback.js";
const PersistButton = memo(forwardRef((props, ref) => {
  const isMutating = useMutationState();
  const isDirty = useDirtinessState();
  const triggerPersist = usePersistWithFeedback();
  const onClick = useCallback(() => {
    triggerPersist().catch(() => {
    });
  }, [triggerPersist]);
  const isDisabled = isMutating || !isDirty;
  if (!triggerPersist) {
    return null;
  }
  return /* @__PURE__ */ createElement(SaveButton, {
    ref,
    disabled: isDisabled,
    intent: isDisabled ? "default" : props.intent,
    isDirty,
    loading: isMutating,
    onClick,
    size: "large",
    ...props
  });
}));
PersistButton.displayName = "PersistButton";
export { PersistButton };
//# sourceMappingURL=PersistButton.js.map
