import * as CONST from './Accordion.actionConstants';
/*
index - accordion item index
[true|false,true|false] 
*/

export default function reducer() {
  let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  let {
    type,
    data
  } = arguments.length > 1 ? arguments[1] : undefined;

  switch (type) {
    case CONST.OPEN:
      {
        let newState = state.slice();
        newState[data.index] = true;
        return newState;
      }

    case CONST.CLOSE:
      {
        let newState = state.slice();
        newState[data.index] = false;
        return newState;
      }

    case CONST.TOGGLE:
      {
        let newState = state.slice();
        newState[data.index] = !newState[data.index];
        return newState;
      }
  }

  return state;
}