Audio = require '../audio'
$body = $ 'body'

class DetailsAudio extends Audio
	className: 'control control-url control-audio-details'
	template:  'core/views/audio-details'
	silent: true

	elements:
		'.audio-title': 'title'
		'.audio-title, .icon': 'toggleTarget'

	events:
		'click .audio-title, .icon': 'toggle'

	onInvalidURL: => 
		@$removeClass 'invalid'
		@title.text 'File missing.'

	update: ->
		super
		(title = @item.path.split('/').pop().split('.')).pop()
		@title.text (unescape title.join '.').trim() or 'No Title'

	toggle: =>
		super
		@delay => $body.one 'click', @_forcePause

	_forcePause: (e) =>
		return if @toggleTarget.is e.target
		@sound.pause()

module.exports = DetailsAudio