import React from 'react';

import type { GeneralSizeProp } from '@/mui/types';

import { getInputPropsByName } from '@/modules/@common/Form/helpers';
import { schemeSelector, videoMaxZoomSelector } from '@/modules/feeds/Editor/redux/selectors';
import { removeErrorByPropAction, setAction } from '@/modules/feeds/Editor/redux/slices';

import { useFormSettings } from '@/modules/@common/Form';
import { useAppDispatch, useAppSelector } from '@/modules/@common/store/hooks';
import { NumberField } from '@/mui/components';

type PropTypes = {
  disabled?: boolean;
};

function VideoMaxZoom({ disabled = false }: PropTypes) {
  const dispatch = useAppDispatch();
  const { size } = useFormSettings();

  const scheme = useAppSelector(schemeSelector);
  const videoMaxZoom = useAppSelector(videoMaxZoomSelector);

  return (
    <NumberField
      min={1}
      max={100}
      step={1}
      placeholder="Video Max Zoom"
      size={size as GeneralSizeProp}
      value={videoMaxZoom}
      disabled={disabled}
      onChange={(e) => {
        dispatch(setAction({ videoMaxZoom: parseInt(e.target.value, 10) || ('' as unknown as number) }));
      }}
      {...getInputPropsByName(scheme, ['videoMaxZoom'])}
      onFocus={() => dispatch(removeErrorByPropAction(['videoMaxZoom']))}
    />
  );
}

export default VideoMaxZoom;
