import { NativeSelect, type NativeSelectProps, Tooltip } from '@mantine/core';
import { Controller } from 'react-hook-form';

import type { FormerControllersProps, SpecialIDProps } from '../FormerControllers.types';

const NativeSelectCtrl = (props: FormerControllersProps & NativeSelectProps & SpecialIDProps) => {
  const { control, name, sid, tooltip, ...innerProps } = props;
  return (
    <Controller
      control={control}
      name={name}
      render={({ field, formState }) => (
        <Tooltip label={tooltip ?? ''} withArrow>
          <NativeSelect
            {...innerProps}
            {...field}
            disabled={formState.disabled}
            id={`field_${name}_${sid ?? ''}`}
            key={`field_${name}_${sid ?? ''}`}
          >
            {props.children}
          </NativeSelect>
        </Tooltip>
      )}
    />
  );
};

export { NativeSelectCtrl };
export default NativeSelectCtrl;
