import { createReducer }     from '../../../utils';
import * as AceEditorConstants from 'constants/AceEditorConstants.js';
import {VLCommonConstants} from 'constants/VLCommon';
let constants = AceEditorConstants.default;

const aceEditorInfo = {
  editor : null,
  aceEditorTheme : "monokai",
  programmingLanguage : "python",
  code : "",
  output : "",
  fontSize : "",
  isLoading : false
}

export default function aceEditorInfoReducers (state = aceEditorInfo, action) {
  switch (action.type) {
    case constants.SET_ACE_EDITOR:
      return Object.assign({}, state, {
        editor : action.editor
      })
    case constants.CHANGE_ACE_EDITOR_ACEEDITORTHEME:
      return Object.assign({}, state,
      {
        aceEditorTheme : action.aceEditorTheme,
      });
    case constants.CHANGE_ACE_EDITOR_PROGRAMMINGLANGUAGE:
      return Object.assign({}, state,
      {
        programmingLanguage : action.programmingLanguage,
      });
    case constants.CHANGE_ACE_EDITOR_CODE:
      return Object.assign({}, state,
      {
        code : action.code,
      });
    case constants.CHANGE_ACE_EDITOR_OUTPUT:
      return Object.assign({}, state,
      {
        output : action.output,
        isLoading : action.isLoading
      });
    case constants.CHANGE_ACE_EDITOR_FONTSIZE:
      return Object.assign({}, state,
      {
        fontSize : action.fontSize,
      });
    case constants.CHANGE_ACE_EDITOR_ISLOADING:
      return Object.assign({}, state,
      {
        isLoading : action.isLoading,
      });
    case VLCommonConstants.SET_HINTS:
      return Object.assign({}, state,
      {
        ...aceEditorInfo,
        code : action.metaData,
        fontSize: state.fontSize,
        programmingLanguage : state.programmingLanguage
      });
    default:
      return state;
  }
}


