URL = require './url'
$body = $ 'body'
###
	Initialize with {item:{skin instance},attribute:'attribute',options:{options from meta}}
###
class Image extends URL
	className: 'control control-image'
	template : 'core/views/image'
	type     : 'photo'

	elements: 
		'input'     : 'input'
		'.url-thumb': 'thumb'

	update: (item='',t,options={}) =>
		@lastURL =(if ( typeof item == 'string' or item instanceof String) then item else (item[@attribute] or ''))
		@input.val @lastURL
		@onURL true, silent: true

	onInput: (e) ->
		@thumb.css backgroundImage: 'none'
		super

	onValidURL: =>
		super
		@thumb.attr
			'data-tooltip-image': @lastURL
			'data-tooltip-position': 'center top'

		@thumb.toggle(@lastURL.length > 0).css 
			backgroundImage: "url(#{@attachedBackground = @lastURL})"

	onInvalidURL: =>
		super
		@attachedBackground = null

module.exports = Image