import { useCallback, forwardRef } from 'react';
import { prependContext } from "../../../../utils/tracking/index.js";
import DefaultCloseButton from '../DefaultCloseButton';
const CloseButton = forwardRef((props, ref) => {
  const {
    drawer,
    tracking,
    name,
    CustomCloseButton
  } = props;
  const Button = CustomCloseButton || DefaultCloseButton;
  const trackingContext = prependContext({
    prefix: tracking?.context,
    context: 'DefaultCloseButton'
  });
  const toggleAndTrack = useCallback(() => {
    drawer.toggle({
      context: trackingContext
    });
  }, [drawer, trackingContext]);
  return <Button onClick={toggleAndTrack} ref={ref} title={name} />;
});
export default CloseButton;