

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

Skin 		= window.require 'core/models/skin'
Scrollable  = require '../../../core/controller/scrollable'

class SkinEditorPanel extends Controller
	className: 'controls'
	@include Container
	@include Activateable
	@include Scrollable

	constructor: ->
		super
		@bind 'activate', => @skinLoad(@skin) if @skin

	skinLoad: (item) =>
		unless @skin?
			for attribute, config of @meta
				Control     = window.require config.control
				isAccesible = @accessLevel >= (config.access || 0)
				options     = config.options
				conditions      = config.if
				if !isAccesible then options.readonly = true
				@append new Control {item, attribute, options, @composition, isAccesible, conditions}

		@children (child) -> child.setItem item
		@skin = item
		@scroll().update()

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

module.exports = SkinEditorPanel
