-kd = require 'kd'
 _ = require 'lodash'
 $ = require 'jquery'
+kd = require 'kd'
 React = require 'app/react'
-TimeAgo = require 'app/components/common/timeago'
-UnreadCount = require 'app/components/sidebarmachineslistitem/unreadcount'
-getBoundingClientReact = require 'app/util/getBoundingClientReact'
-StackUpdatedWidget = require 'app/sidebar/components/stackupdatedwidget'
+
 isAdmin = require 'app/util/isAdmin'
 whoami = require 'app/util/whoami'
 isDefaultTeamStack = require 'app/util/isdefaultteamstack'
+getBoundingClientReact = require 'app/util/getBoundingClientReact'
+
+TimeAgo = require 'app/components/common/timeago'
+UnreadCount = require 'app/components/sidebarmachineslistitem/unreadcount'
+StackUpdatedWidget = require 'app/sidebar/components/stackupdatedwidget'
+
 
 module.exports = class StackTemplateItem extends React.Component
 

  handleUnreadCountClick: ->

    @setCoordinates()
    @setState { showWidget: yes }


  onWidgetClose: ->

    @setState { showWidget: no }


  renderStackUpdatedWidget: ->

    { coordinates, showWidget } = @state

    return null  unless showWidget
    return null  unless @props.stack?.getUnreadCount()
    return null  if not coordinates.left and coordinates.top



    super

    @state =
      widgetVisible: no
      coordinates: { left: 0, top: 0 }


  componentWillReceiveProps: (nextProps) ->

    if @props.stack?.getUnreadCount() < nextProps.stack?.getUnreadCount()
      @setState { widgetVisible: yes }

    @setCoordinates()

