'use strict';
export default function changeUpTo3Cards(duelController) {
  let duelCtrl = duelController;
  let start = () => {
    console.log('Start state 2');
    let gameData = duelCtrl.getGameData();
    console.log('gameData :>> ', gameData);
    duelCtrl.storeData(gameData);
  };

  // Should receive in paylod : {color, faction}
  let update = (payload = null) => {
    let gameData = duelCtrl.getGameData();
    if (payload) {
      console.log('payload :>> ', payload);

      /**  TODO : process player response */
      gameData.game['waitingFor/' + payload.color] = false;
      duelCtrl.storeData(gameData);
    }

    if (
      gameData.game['waitingFor/blue'] === false &&
      gameData.game['waitingFor/red'] === false
    ) {
      duelCtrl.endCurrentState();
    }
  };

  let end = () => {
    console.log('Go to next game state : 3...');

    // duelCtrl.setCurrentState('3...');
    // duelCtrl.startCurrentState();
  };
  return {
    start,
    update,
    end
  };
}