let _state: any = {
  role: null,
  cid: null,
  roomId: null,
  userInfo: {},
  runners: [],
  catcher: {}
}

const listenners = []

class Store {
  static getState() {
    return _state
  }

  static onMessage(message) {
    const { payload, room_id } = message
    switch (message.type) {
      case 'game_ready': {
        const runners = payload.filter(runner => runner.role !== 'ghost')
        _state = {
          ..._state,
          roomId: room_id,
          runners, 
        } 
        break;
      }
      case 'setUserInfo':
        _state = {
          ..._state,
          userInfo: payload
        }
        break;
      case 'updateCid':
        _state = {
          ..._state,
          cid: payload.cid
        }
        
        break;
      default:
        break;
    }
    return _state
  }  

  static subscribe(fn) {
    
  }
  static getMyInfo() {
    return _state.userInfo
  }

  static getMyPosition

  static isCatcher() {
    console.log('isCatcher_____', _state.runners, _state.cid)
    return !_state.runners.some(runner => runner.t_cid === _state.cid)
  }
}

window.Store = Store