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

export interface TreeViewTreeBaseProps extends PolymorphicProps<'div'> {}
export interface TreeViewTreeProps extends HTMLProps<'div'>, TreeViewTreeBaseProps {}

export component TreeViewTree(props: MaybeTracked<TreeViewTreeProps>) {
  const [children, localProps] = trackSplit(props, ['children']);
  const treeView = useTreeViewContext();

  let mergedProps = track(() => mergeProps(@treeView.getTreeProps(), @localProps));

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