"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const reactBinding = require("@contember/react-binding");
const reactUtils = require("@contember/react-utils");
const ui = require("@contember/ui");
const react = require("react");
const reactBindingUi = require("@contember/react-binding-ui");
const PersistButton = react.memo(
  react.forwardRef((props, ref) => {
    const isMutating = reactBinding.useMutationState();
    const isDirty = reactBinding.useDirtinessState();
    const triggerPersist = reactBindingUi.usePersistWithFeedback();
    const onClick = react.useCallback(() => {
      triggerPersist().catch(() => {
      });
    }, [triggerPersist]);
    const isDisabled = isMutating || !isDirty;
    const className = reactUtils.useClassName("persist-button", props.className);
    if (!triggerPersist) {
      return null;
    }
    return /* @__PURE__ */ jsxRuntime.jsx(
      ui.SaveButton,
      {
        ref,
        disabled: isDisabled,
        intent: isDisabled ? "default" : props.intent,
        isDirty,
        loading: isMutating,
        onClick,
        className,
        ...props
      }
    );
  })
);
PersistButton.displayName = "PersistButton";
exports.PersistButton = PersistButton;
//# sourceMappingURL=PersistButton.cjs.map
