class NotificationController
	className: 'message notification'
	template: (message) =>
		"<div class='text'>#{message}</div><div class='close' data-icon='x'></div>"

	constructor: ->
		@el = $ "<div class=\"#{@className}\">"
		@message = ''
		@el.on 'click', '.close', @close
		@el.on 'click', @_onClick

	render: (@message = @message)=>
		@el.html @template @message

	close: (ev) =>
		ev?.stopPropagation()
		clearTimeout @interval
		@el.transition top: -60, queue: false
		@el.trigger 'editor:notification', show: false

	notify: (message, options = {}) =>
		@el.trigger 'editor:notification', show: true
		@render message

		clearTimeout @interval
		@clickAction = options.onClick
		@el.show().stop(true,false).transition top: 0, =>
			@interval = setTimeout @close, options.interval || 3000

	_onClick: (ev) =>
		ev.preventDefault()
		@clickAction?()
		@close(ev)

module.exports = NotificationController
