import { jsx } from 'react/jsx-runtime';
import { useContext, forwardRef } from 'react';
import { B as Button } from './Button-BNzCI47m.js';
import { D as DialogContext } from './DialogContext-DBgtApl9.js';
import { useTrackingId } from './useTrackingId.js';

function useDialogContext() {
  const context = useContext(DialogContext);
  if (!context) {
    throw new Error(
      "useDialogContext must be used within a DialogContextProvider"
    );
  }
  return context;
}

const DialogCancelButton = forwardRef((props, ref) => {
  const { onClick, ...rest } = props;
  const { close } = useDialogContext();
  const data = {
    title: props.title,
    appearance: props.appearance,
    size: props.size,
    type: props.type
  };
  const trackingId = useTrackingId({
    name: "DialogCancelButton",
    data,
    hasOverride: !!props["data-tracking-id"]
  });
  const onClickHandler = (e) => {
    onClick?.(e);
    close();
  };
  return /* @__PURE__ */ jsx(
    Button,
    {
      "aria-label": "Close dialog",
      "data-anv": "dialog-cancel-button",
      "data-tracking-id": trackingId,
      onClick: onClickHandler,
      ref,
      ...rest
    }
  );
});
DialogCancelButton.displayName = "DialogCancelButton";

export { DialogCancelButton as D, useDialogContext as u };
//# sourceMappingURL=DialogCancelButton-DmSUPuCR.js.map
