console = window.require 'spine/utils/console'

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) =>
		console.group 'SkinEditorPanel:skinLoad ' + @tabTitle
		console.debug item, @tabTitle
		unless @skin?
			for attribute, config of @meta
				Control     = window.require config.control
				isAccesible = @accessLevel >= (config.access || 0)
				options     = config.options
				if !isAccesible then options.readonly = true
				@append new Control {item, attribute, options, @composition, isAccesible}

		@children (child) -> child.setItem item
		@skin = item
		@scroll().update()
		console.groupEnd 'SkinEditorPanel:skinLoad ' + @tabTitle

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

module.exports = SkinEditorPanel
