import React from 'react';

import { FILE_SELECTION_OPTIONS } from '@/modules/feeds/Editor/constants';

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

import { filterOptionsByType } from '@/modules/feeds/Editor/helpers';
import { fileSelectionSelector, typeSelector } from '@/modules/feeds/Editor/redux/selectors';
import { setAction } from '@/modules/feeds/Editor/redux/slices';

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

type PropTypes = {
  disabled?: boolean;
};

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

  const fileSelection = useAppSelector(fileSelectionSelector);
  const type = useAppSelector(typeSelector);

  if (!type) return null;
  return (
    <Select
      // placeholder="Select File Selection"
      size={size as GeneralSizeProp}
      value={fileSelection}
      disabled={disabled}
      onChange={(e) => dispatch(setAction({ fileSelection: e.target.value as typeof fileSelection }))}
    >
      {filterOptionsByType(FILE_SELECTION_OPTIONS, type).map((option) => (
        <MenuItem key={option.value} value={option.value}>
          {option.label}
        </MenuItem>
      ))}
    </Select>
  );
}

export default FileSelection;
