       counterStyle: counterStyle
       dataTransferType: dataTransferType
       onDelete: onDeleteItem
-      onToggleCollapsed: (item) ->
-        return unless item.children.length > 0
-        key = "core.accountSidebarCollapsed.#{item.id}"
-        NylasEnv.config.set(key, not item.collapsed)
+      onToggleCollapsed: toggleItemCollapsed
       onDrop: (item, ids) ->
         return unless ids
         item.perspective.applyToThreads(ids)

    id += "-#{opts.name}" if opts.name
    @forPerspective(id, perspective, opts)

  @forSheet: (name, iconName, sheet, count, children = []) ->
    id = sheet?.id ? name
    return {
      id,
      name,

      count,
      sheet,
      children,
      collapsed: isItemCollapsed(id)
      onToggleCollapsed: toggleItemCollapsed
      onSelect: (item) ->
        Actions.selectRootSheet(item.sheet)
    }

  @forDrafts: ({accountId, name, children} = {}) ->
    id = 'Drafts'
    id += "-#{name}" if name
    sheet = WorkspaceStore.Sheet.Drafts
    iconName = 'drafts.png'
    count = if accountId?
      DraftCountStore.count(accountId)
    else
      DraftCountStore.totalCount()
    @forSheet(id, name ? id, iconName, sheet, count, children)


module.exports = SidebarItem
