import { jsx } from "react/jsx-runtime";
import { useMutationState, useDirtinessState } from "@contember/react-binding";
import { useClassName } from "@contember/react-utils";
import { SaveButton } from "@contember/ui";
import { memo, forwardRef, useCallback } from "react";
import { usePersistWithFeedback } from "@contember/react-binding-ui";
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;
    const className = useClassName("persist-button", props.className);
    if (!triggerPersist) {
      return null;
    }
    return /* @__PURE__ */ jsx(
      SaveButton,
      {
        ref,
        disabled: isDisabled,
        intent: isDisabled ? "default" : props.intent,
        isDirty,
        loading: isMutating,
        onClick,
        className,
        ...props
      }
    );
  })
);
PersistButton.displayName = "PersistButton";
export {
  PersistButton
};
//# sourceMappingURL=PersistButton.js.map
