FontLoader = require '../../controller/font-loader'

class FontItem
	template: require '../../views/font/font-item'

	constructor: (@font, @fontData) ->
		@render()
		@source = @fontData.source
		@el.on 'change', 'input[type="radio"]', @loadFont

	render: =>
		@el = $ @template @

	loadFont: =>
		FontLoader
			.load({families: [@font], text: @font, @source}, @el.get(0).ownerDocument.defaultView)
			.then => @el.addClass 'loaded'

	show: =>
		do @loadFont

module.exports = FontItem
