import { useEntity, useMutationState, EntityAccessor } from "@contember/binding";
import { Button, toThemeClass, Icon } from "@contember/ui";
import cn from "classnames";
import { memo, useCallback } from "react";
import { jsxDEV } from "react/jsx-dev-runtime";
import { usePersistWithFeedback } from "../../../ui/usePersistWithFeedback.js";
var _jsxFileName = "/__w/interface/interface/packages/admin/src/components/bindingFacade/collections/helpers/DeleteEntityButton.tsx";
const DeleteEntityButton = memo((props) => {
  const {
    children,
    immediatePersist,
    className,
    ...rest
  } = props;
  const parentEntity = useEntity();
  const triggerPersist = usePersistWithFeedback();
  const isMutating = useMutationState();
  const onClick = useCallback(() => {
    if (props.immediatePersist && !confirm("Really?")) {
      return;
    }
    parentEntity.deleteEntity();
    if (props.immediatePersist && triggerPersist) {
      triggerPersist().catch(() => {
      });
    }
  }, [triggerPersist, props.immediatePersist, parentEntity]);
  if (!(parentEntity instanceof EntityAccessor)) {
    return null;
  }
  let defaultProps = {
    size: "small",
    flow: "circular",
    distinction: "seamless",
    bland: true
  };
  return /* @__PURE__ */ jsxDEV(Button, {
    distinction: "primary",
    ...defaultProps,
    ...rest,
    className: cn(className, toThemeClass(null, "danger", ":hover")),
    disabled: isMutating || rest.disabled,
    onClick,
    children: children || /* @__PURE__ */ jsxDEV(Icon, {
      blueprintIcon: "trash"
    }, void 0, false, {
      fileName: _jsxFileName,
      lineNumber: 51,
      columnNumber: 17
    }, void 0)
  }, void 0, false, {
    fileName: _jsxFileName,
    lineNumber: 40,
    columnNumber: 3
  }, void 0);
});
DeleteEntityButton.displayName = "DeleteEntityButton";
export {
  DeleteEntityButton
};
//# sourceMappingURL=DeleteEntityButton.js.map
