import { newCourseFields } from 'src/pages/dashboard/Learning/Courses/New/forms';
import { type Selected } from 'src/pages/dashboard/Learning/Courses/types';
import { useLokaliseTranslation } from 'src/utils/i18n';
import { validateMinRule } from 'src/utils/validation';

import FormTextField from 'src/components/FormInputs/FormTextField';

export type QuestionScoreProps = {
  disabled?: boolean;
  selected: Selected;
  index: number;
};

export const QuestionScore = ({
  disabled = false,
  selected,
  index,
}: QuestionScoreProps) => {
  const { t } = useLokaliseTranslation('learning');

  return (
    <FormTextField
      name={newCourseFields.content.modules.tasks.form.questions.points(
        selected.module,
        selected.task,
        index,
      )}
      label={t('general:score')}
      placeholder={t('general:score')}
      disabled={disabled}
      allowJustNumbers
      required
      rules={{ validate: { positive: validateMinRule(0) } }}
      InputProps={{ inputProps: { min: 0 } }}
      sx={{ width: 'auto' }}
    />
  );
};

export default QuestionScore;
