Controller = window.require 'spine/controller'
Popup	= require '../popup'
Skin    = window.require 'core/models/skin'

popup = (skin)->
	confirmBtnClass: 'green-button button--uc popup-button red-button'
	cancelBtnClass: 'dim-button button--uc popup-button dark-purple-button'
	title: "Delete Skin \"#{skin.name}\"?"
	confirmBtn: 'Delete'
	cancelBtn: 'Cancel'

class DeleteSkinController extends Controller
	constructor:->
		super
		@popup = new Popup className: 'popup skin-delete-popup'

	deleteItem: (item) =>
		@model = (@item = item).item
		@popup.render(popup(@model)).pop @place, @deleteit
		@listenToOnce Skin, 'selected', @_closePopup

	deleteit:(e)=>
		@stopListening Skin, 'selected', @_closePopup
		if @item.isActive()
			el= @item.el
			el.next().add(el.prev()).first().controller().active()
		@item.release()
		@model.destroy()

	_closePopup: =>
		@popup.close()

module.exports = DeleteSkinController
