/// <reference types="@uiw/react-amap-types" />

import { useImperativeHandle, forwardRef } from 'react';
import { OverlayProps } from '@uiw/react-amap-map';
import { useMarker } from './useMarker';

export * from './useMarker';

export interface MarkerProps extends OverlayProps, AMap.MarkerEvents, AMap.MarkerOptions {
  /** @deprecated use {@link visible} */
  visiable?: boolean;
  /** 覆盖物是否可见 */
  visible?: boolean;
  className?: string;
  children?: JSX.Element;
}

export const Marker = forwardRef<MarkerProps & { marker?: AMap.Marker }, MarkerProps>((props, ref) => {
  const { marker, MarkerPortal } = useMarker(props);
  useImperativeHandle(ref, () => ({ ...props, marker }), [marker]);
  return <MarkerPortal>{props.children}</MarkerPortal>;
});
