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

export interface PasswordInputInputBaseProps extends PolymorphicProps<'input'> {}
export interface PasswordInputInputProps extends HTMLProps<'input'>, PasswordInputInputBaseProps {}

export component PasswordInputInput(props: MaybeTracked<PasswordInputInputProps>) {
  const [localProps] = trackSplit(props, []);
  const passwordInput = usePasswordInputContext();
  const field = useFieldContext();

  let mergedProps = track(() => mergeProps(@passwordInput.getInputProps(), @localProps));

  <ark.input aria-describedby={@field?.ariaDescribedby} {...@mergedProps} />
}
