import { mergeProps } from 'zag-ripple';
import { trackSplit, track } from 'ripple';
import { useDrawerContext } from './use-drawer-context';
import { ark } from '../factory';
import type { HTMLProps, MaybeTracked, PolymorphicProps } from '../../types';

export interface DrawerGrabberIndicatorBaseProps extends PolymorphicProps<'div'> {}
export interface DrawerGrabberIndicatorProps extends HTMLProps<
  'div'
>, DrawerGrabberIndicatorBaseProps {}

export component DrawerGrabberIndicator(props: MaybeTracked<DrawerGrabberIndicatorProps>) {
  const [children, localProps] = trackSplit(props, ['children']);
  const drawer = useDrawerContext();

  let mergedProps = track(() => mergeProps(@drawer.getGrabberIndicatorProps(), @localProps));

  <ark.div {...@mergedProps}>
    <@children />
  </ark.div>
}
