Panel = require './panel'
Activateable = window.require 'spine/controller/activateable'

class ReferencePanel extends Panel
	@include Activateable

	events:
		'click .options span': '_onClick'

	elements:
		'.options': 'options'

	_onClick: (e) =>
		target = $ e.target
		@reference = y: (c = target.attr('class').split ' ')[0], x: c[1]
		@change()

	selectCurrent: =>
		@options.find("span[class='#{@reference.y} #{@reference.x}']")
			.addClass('active').siblings().removeClass 'active'

	update : (item, type, options={}) =>
		super
		@selectCurrent() unless !item.reference? or options.from is @

module.exports = ReferencePanel
