import { ProbabilityInput } from '@/ui/data/field/meta-types/input/components/internal/ProbabilityInput';

import { usePersistField } from '../../../hooks/usePersistField';
import { useProbabilityField } from '../../hooks/useProbabilityField';

import { FieldInputEvent } from './DateFieldInput';

export type ProbabilityFieldInputProps = {
  onSubmit?: FieldInputEvent;
};

export const ProbabilityFieldInput = ({
  onSubmit,
}: ProbabilityFieldInputProps) => {
  const { probabilityIndex } = useProbabilityField();

  const persistField = usePersistField();

  const handleChange = (newValue: number) => {
    onSubmit?.(() => persistField(newValue));
  };

  return (
    <ProbabilityInput
      probabilityIndex={probabilityIndex}
      onChange={handleChange}
    />
  );
};
