import * as Ariakit from '@ariakit/react';
import { getClassNames } from '@websolutespa/bom-core';
import React, { forwardRef } from 'react';
import { Label } from '../label/label';

type LabelProps = React.ComponentProps<typeof Label>;

export type ComboboxLabelProps = Omit<Ariakit.ComboboxLabelProps, 'render'> & LabelProps;

export const ComboboxLabel = forwardRef<HTMLLabelElement, ComboboxLabelProps>(
  function ComboboxLabel({
    store,
    className,
    ...props
  }: ComboboxLabelProps, ref) {
    const context = Ariakit.useComboboxContext();
    const classNames = getClassNames('combobox__label', className);
    return (
      <Ariakit.ComboboxLabel
        ref={ref}
        className={classNames}
        store={store || context}
        {...props}
        render={
          <Label />
        }
      ></Ariakit.ComboboxLabel>
    );
  });
