<commit_before>React = require 'react'
crypto = require 'crypto'
classNames = require 'classnames'
{Actions} = require 'nylas-exports'
{RetinaImg} = require 'nylas-component-kit'
SidebarActions = require '../sidebar-actions'


ItemTypes = {
  "Unified"
}

class AccountSwitcher extends React.Component
  @displayName: 'AccountSwitcher'

  @propTypes:
    accounts: React.PropTypes.array.isRequired
    focusedAccounts: React.PropTypes.array.isRequired

  # Helpers

  _makeAccountItem: (account) =>
    {id, label, emailAddress, provider} = account
    email = emailAddress
    iconName = provider
    accounts = [account]
    return {id, label, email, iconName, accounts}

  _makeUnifiedItem: =>
    id = ItemTypes.Unified
    label = "All Accounts"
    email = ""
    iconName = 'unified'
    accounts = @props.accounts
    return {id, label, email, iconName, accounts}


  _selectedItem: =>
    if @props.focusedAccounts.length > 1
      @_makeUnifiedItem()
    else
      @_makeAccountItem(@props.focusedAccounts[0])

  _toggleDropdown: =>
    @setState showing: !@state.showing

  _makeMenuItem: (item, idx = 0) =>
    menuItem = {
      label: item.label,
      click: @_onSwitchAccount.bind(@, item)
      accelerator: "CmdOrCtrl+#{idx}"
    }

    if @_selectedItem().id is item.id
      menuItem.type = 'checkbox'
      menuItem.checked = true

    return menuItem

  _makeMenuTemplate: =>
    template = []
    items = @props.accounts.map(@_makeAccountItem)

    if @props.accounts.length > 1
      unifiedItem = @_makeUnifiedItem()
      template = [
        @_makeMenuItem(unifiedItem)
        {type: 'separator'}
      ]

    items.forEach (item, idx) => template.push(@_makeMenuItem(item, idx + 1))<commit_msg>fix(sidebar): Display correct keyboard shortcuts in account switcher<commit_after>React = require 'react'
crypto = require 'crypto'
classNames = require 'classnames'
{Actions} = require 'nylas-exports'
{RetinaImg} = require 'nylas-component-kit'
SidebarActions = require '../sidebar-actions'


ItemTypes = {
  "Unified"
}

class AccountSwitcher extends React.Component
  @displayName: 'AccountSwitcher'

  @propTypes:
    accounts: React.PropTypes.array.isRequired
    focusedAccounts: React.PropTypes.array.isRequired

  # Helpers

  _makeAccountItem: (account) =>
    {id, label, emailAddress, provider} = account
    email = emailAddress
    iconName = provider
    accounts = [account]
    return {id, label, email, iconName, accounts}

  _makeUnifiedItem: =>
    id = ItemTypes.Unified
    label = "All Accounts"
    email = ""
    iconName = 'unified'
    accounts = @props.accounts
    return {id, label, email, iconName, accounts}


  _selectedItem: =>
    if @props.focusedAccounts.length > 1
      @_makeUnifiedItem()
    else
      @_makeAccountItem(@props.focusedAccounts[0])

  _toggleDropdown: =>
    @setState showing: !@state.showing

  _makeMenuItem: (item, idx) =>
    menuItem = {
      label: item.label,
      click: @_onSwitchAccount.bind(@, item)
      accelerator: "CmdOrCtrl+#{idx}"
    }

    if @_selectedItem().id is item.id
      menuItem.type = 'checkbox'
      menuItem.checked = true

    return menuItem

  _makeMenuTemplate: =>
    template = []
    items = @props.accounts.map(@_makeAccountItem)

    if @props.accounts.length > 1
      unifiedItem = @_makeUnifiedItem()
      template = [
        @_makeMenuItem(unifiedItem, 1)
        {type: 'separator'}
      ]

    items.forEach (item, idx) => template.push(@_makeMenuItem(item, idx + 2))
{'fraction_non_alphanumeric': 0.11907481439177613, 'fraction_numerical': 0.0028555111364934323, 'mean_word_length': 3.3193588162762024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '4556555', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1108, 'n_words': 246}