Controller 	= require './index'
Container 	= window.require 'spine/controller/container'

class Toggle extends Controller
	@include Container
	template  : 'core/views/toggle'
	className : 'control-toggle'

	elements  :
		'.input-toggle-true' : 'true'
		'.input-toggle-false': 'false'
		'.input-toggle':'input'

	events:
		'click .input-toggle':'toggle'

	update:(item)=>
		value = if item[@attribute]? then item[@attribute] else @options.default
		@input.attr 'data-value', String value
	
	toggle: (e) =>
		e?.stopPropagation()
		@item.updateAttribute @attribute, !(@input.attr('data-value') is 'true'), { @attribute, from:@}

	render: =>
		@labels = @options.values_labels or []
		super

module.exports = Toggle