import * as utils from '../../utils';
import { header as headerWidget, backButton } from '../shared/common';
import formWidgets from '../shared/form';
import layout from '../layout';
import i18n from '../../i18n';
import session from '../../session';
import { swapKeyValue, Challenge, Message } from '../../lichess/prefs';
import m from 'mithril';

function renderBody(ctrl) {
  return [
    m('ul.native_scroller.page.settings_list.game', [
      m('li.list_item', formWidgets.renderCheckbox(i18n('letOtherPlayersFollowYou'),
        'follow', ctrl.follow)),
      m('li.list_item', [
        m('div.label', i18n('letOtherPlayersChallengeYou')),
        m('div.select_input.no_label.settingsChoicesBlock', formWidgets.renderSelect('', 'challenge', swapKeyValue(Challenge.choices), ctrl.challenge))
      ]),
      m('li.list_item', [
        m('div.label', i18n('Let other players message you')),
        m('div.select_input.no_label.settingsChoicesBlock', formWidgets.renderSelect('', 'message', swapKeyValue(Message.choices), ctrl.message))
      ])
    ])
  ];
}

export default {
  controller: function() {
    const follow = session.lichessBackedProp('follow');
    const challenge = session.lichessBackedProp('challenge');
    const message = session.lichessBackedProp('message');

    return {
      follow,
      challenge,
      message
    };
  },

  view: function(ctrl) {
    const header = utils.partialf(headerWidget, null,
      backButton(i18n('privacy'))
    );
    return layout.free(header, renderBody.bind(undefined, ctrl));
  }
};


@@ -280,17 +280,8 @@
 enge
-, Message
  %7D f
@@ -787,253 +787,8 @@
 e))%0A
-      %5D),%0A      m('li.list_item', %5B%0A        m('div.label', i18n('Let other players message you')),%0A        m('div.select_input.no_label.settingsChoicesBlock', formWidgets.renderSelect('', 'message', swapKeyValue(Message.choices), ctrl.message))%0A
     
@@ -972,66 +972,8 @@
 e');
-%0A    const message = session.lichessBackedProp('message');
 %0A%0A  
@@ -1016,23 +1016,8 @@
 enge
-,%0A      message
 %0A   
@@ -1219,9 +1219,8 @@
 %0A  %7D%0A%7D;%0A
-%0A

Remove PM privacy setting