<commit_before>/** @jsx m */
import utils from '../../utils';
import userPerfs from '../../lichess/perfs';
import widgets from '../widget/common';
import perf from '../widget/perf';
import layout from '../layout';
import i18n from '../../i18n';
import countries from './countries';
import helper from '../helper';
import session from '../../session';
const moment = window.moment;

export default function view(ctrl) {
  const user = ctrl.user();
  const header = utils.partialf(widgets.header, null,
    widgets.backButton(user.username)
  );

  function profile() {
    return (
      <div className="native_scroller">
        {renderProfile(user)}
        {renderStats(user)}
        {renderRatings(user)}
        {renderActions(ctrl)}
      </div>
    );
  }

  return layout.free(header, profile, widgets.empty, widgets.empty);
};

function renderProfile(user) {
  if (user.profile) {
    const fullname = (user.profile.firstName || user.profile.lastName) ?
      user.profile.firstName + ' ' + user.profile.lastName :
      null;
    const country = countries[user.profile.country];
    const location = user.profile.location;
    var locationString = '';
    if (location) locationString += location;
    if (country) locationString += (location ? ', ' : '') + country;
    const memberSince = i18n('memberSince') + ' ' + moment(user.createdAt).format('LL');
    const seenAt = user.seenAt ? i18n('lastLogin') + ' ' + moment(user.seenAt).calendar() : null;
    return (
      <div className="profile">
        {fullname ?
        <h3 className="fullname">{fullname}</h3> : null
        }
        {user.profile.bio ?
        <p className="profileBio">{user.profile.bio}</p> : null
        }
        <div className="userInfos">
          <p className="location">
            {location}
            {country ?
            <span className="country">
              , <img className="flag" src={'images/flags/' + user.profile.country + '.png'} />
              {country}
            </span> : null
            }
          </p>
          <p className="memberSince">{memberSince}</p>
          {seenAt ?
          <p className="lastSeen">{seenAt}</p> : null
          }
        </div>
      </div>
    );
  } else
    return null;
}

function renderStats(user) {
  const totalPlayTime = user.playTime ? 'Time spent playing: ' + moment.duration(user.playTime.total, 'seconds').humanize() : null;
  const tvTime = user.playTime && user.playTime.tv > 0 ? 'Time on TV: ' + moment.duration(user.playTime.tv, 'seconds').humanize() : null;

  return (
    <div className="userStats">
      {totalPlayTime ?
      <p className="playTime">{totalPlayTime}</p> : null
      }
      {tvTime ?
      <p className="onTv">{tvTime}</p> : null
      }
    </div>
  );
}

function renderRatings(user) {
  return (
    <section className="ratings">
      {userPerfs(user).map(p => perf(p.key, p.name, p.perf))}
    </section>
  );
}

function renderActions(ctrl) {<commit_msg>Don't show perf variants with no games<commit_after>/** @jsx m */
import utils from '../../utils';
import userPerfs from '../../lichess/perfs';
import widgets from '../widget/common';
import perf from '../widget/perf';
import layout from '../layout';
import i18n from '../../i18n';
import countries from './countries';
import helper from '../helper';
import session from '../../session';
const moment = window.moment;

export default function view(ctrl) {
  const user = ctrl.user();
  const header = utils.partialf(widgets.header, null,
    widgets.backButton(user.username)
  );

  function profile() {
    return (
      <div className="native_scroller">
        {renderProfile(user)}
        {renderStats(user)}
        {renderRatings(user)}
        {renderActions(ctrl)}
      </div>
    );
  }

  return layout.free(header, profile, widgets.empty, widgets.empty);
};

function renderProfile(user) {
  if (user.profile) {
    const fullname = (user.profile.firstName || user.profile.lastName) ?
      user.profile.firstName + ' ' + user.profile.lastName :
      null;
    const country = countries[user.profile.country];
    const location = user.profile.location;
    var locationString = '';
    if (location) locationString += location;
    if (country) locationString += (location ? ', ' : '') + country;
    const memberSince = i18n('memberSince') + ' ' + moment(user.createdAt).format('LL');
    const seenAt = user.seenAt ? i18n('lastLogin') + ' ' + moment(user.seenAt).calendar() : null;
    return (
      <div className="profile">
        {fullname ?
        <h3 className="fullname">{fullname}</h3> : null
        }
        {user.profile.bio ?
        <p className="profileBio">{user.profile.bio}</p> : null
        }
        <div className="userInfos">
          <p className="location">
            {location}
            {country ?
            <span className="country">
              , <img className="flag" src={'images/flags/' + user.profile.country + '.png'} />
              {country}
            </span> : null
            }
          </p>
          <p className="memberSince">{memberSince}</p>
          {seenAt ?
          <p className="lastSeen">{seenAt}</p> : null
          }
        </div>
      </div>
    );
  } else
    return null;
}

function renderStats(user) {
  const totalPlayTime = user.playTime ? 'Time spent playing: ' + moment.duration(user.playTime.total, 'seconds').humanize() : null;
  const tvTime = user.playTime && user.playTime.tv > 0 ? 'Time on TV: ' + moment.duration(user.playTime.tv, 'seconds').humanize() : null;

  return (
    <div className="userStats">
      {totalPlayTime ?
      <p className="playTime">{totalPlayTime}</p> : null
      }
      {tvTime ?
      <p className="onTv">{tvTime}</p> : null
      }
    </div>
  );
}

function renderRatings(user) {
  function isShowing(p) {
    return [
      'blitz', 'bullet', 'classical', 'correspondence'
    ].indexOf(p.key) !== -1 || p.perf.games > 0;
  }

  return (
    <section className="ratings">
      {userPerfs(user).filter(isShowing).map(p => perf(p.key, p.name, p.perf))}
    </section>
  );
}

function renderActions(ctrl) {
{'fraction_non_alphanumeric': 0.16467311158446665, 'fraction_numerical': 0.0039324922169424875, 'mean_word_length': 2.60117994100295, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '954130', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1856, 'n_words': 401}