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

export interface TagsInputLabelBaseProps extends PolymorphicProps<'label'> {}
export interface TagsInputLabelProps extends HTMLProps<'label'>, TagsInputLabelBaseProps {}

export component TagsInputLabel(props: MaybeTracked<TagsInputLabelProps>) {
  const [children, localProps] = trackSplit(props, ['children']);
  const api = useTagsInputContext();

  let mergedProps = track(() => mergeProps(@api.getLabelProps(), @localProps));

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