export default withPhone(connect((_, {
  phone: {
    locale,
    oAuth,
    environment,
    connectivityMonitor,
    rateLimiter,
  }
}) => ({
  currentLocale: locale.currentLocale,
  server: environment.server,
  enabled: environment.enabled,
  offline: (
    !connectivityMonitor.connectivity ||
    oAuth.proxyRetryCount > 0 ||
    rateLimiter.throttling
  ),
  redirectUri: oAuth.redirectUri
}), (_, {
  phone: {
    environment,
    connectivityMonitor,
    rateLimiter,
  },
}) => ({
  onSetData: (options) => {
    environment.setData(options);
  },
  showOfflineAlert: () => {
    rateLimiter.showAlert();
    connectivityMonitor.showAlert();
  },
}))(AppView));
export default withPhone(connect((state, {
  phone: {
    locale,
    auth,
    webphone,
    audioSettings,
    environment,
    connectivityMonitor,
    rateLimiter,
    callingSettings,
  },
}) => ({
  currentLocale: locale.currentLocale,
  server: environment.server,
  enabled: environment.enabled,
  offline: (
    !connectivityMonitor.connectivity ||
    auth.proxyRetryCount > 0 ||
    rateLimiter.throttling
  ),
  webphoneUnavailable: (
    auth.ready &&
    audioSettings.ready &&
    webphone.ready &&
    auth.loggedIn && (
      callingSettings.callingMode === callingModes.webphone &&
      (
        !audioSettings.userMedia ||
        !!webphone.errorCode
      )
    )
  ),
}), (dispatch, {
  phone: {
    webphone,
    environment,
    audioSettings,
    connectivityMonitor,
    rateLimiter,
    callingSettings,
  },
}) => ({
  onSetData(options) {
    environment.setData(options);
  },
  showOfflineAlert() {
    rateLimiter.showAlert();
    connectivityMonitor.showAlert();
  },
  onWebphoneBadgeClicked() {
    // Only works for webphone mode
    if (callingSettings.callingMode !== callingModes.webphone) {
      return;
    }
    if (audioSettings && audioSettings.ready) {
      audioSettings.showAlert();
      audioSettings.getUserMedia();
    }
    if (webphone && webphone.ready) {
      // Trigger reconnect
      // webphone.connect();
      webphone.showAlert();
    }
  },
}))(AppView));