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

export interface FileUploadLabelBaseProps extends PolymorphicProps<'label'> {}
export interface FileUploadLabelProps extends HTMLProps<'label'>, FileUploadLabelBaseProps {}

export component FileUploadLabel(props: MaybeTracked<FileUploadLabelProps>) {
  const [children, localProps] = trackSplit(props, ['children']);
  const fileUpload = useFileUploadContext();

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

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