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 DrawerTitleBaseProps extends PolymorphicProps<'h2'> {}
export interface DrawerTitleProps extends HTMLProps<'h2'>, DrawerTitleBaseProps {}

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

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

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