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

class Attributes extends Controller
	className : 'item-details-attributes'
	@include Container

	constructor: ->
		super

		@length = 0
		for attribute, options of @options when @isEditable options
			Control = window.require(options.control)
			# load the details controller for first attribute of type image,video or audio
			k = Control = window.require @det options.control if !k?

			control =  new Control
				options: $.extend true, {}, options.options or {}
				attribute: attribute
				item: @item
				isDetailInput: true
				conditions: options.if

			@append control

			@el.toggleClass 'no-attributes', ++@length < 2

	update:=>
		@delay =>
			for child in @children()
				child.setItem @item
	det: (str) ->
		if (/audio|video|image/.test str) then str.replace('core/controls/', 'core/controls/details/') else str

	deactivate: =>
		@children (child) -> child.deactivate?()

	isEditable: (opts) ->
		opts.options.editable isnt false

	onDrop: ->
		@children (child) -> child.onDrop?()


module.exports = Attributes
