 #
 class vtexTotalizers
 	constructor: (@element, options) ->
-		@options = $.extend {}, defaults, options
-
-		@_defaults = defaults
-		@_name = pluginName
+		@options = $.extend {}, $.fn.vtexTotalizers.defaults, options
 
 		@init()
 
-	init: ->
-		self = this
-
-		self.options.$template = $ """
+	init: =>
+		@options.$template = $ """
 		<div class="amount-items-in-cart amount-items-in-cart-loading">
 			<div class="cartInfoWrapper">
 				<span class="title"><span id="MostraTextoXml1">Resumo do Carrinho</span></span>

			num = value / 100
		parseFloat(num).toFixed(2).replace('.', ',').toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1.')

	getCartData: ->
		self = this

		$(self.options.$template).addClass 'amount-items-in-cart-loading'

		promise = $.ajax {
			url: '/api/checkout/pub/orderForm/'
			data: JSON.stringify {"expectedOrderFormSections": ["items", "paymentData", "totalizers"]}
			dataType: 'json'
			contentType: 'application/json; charset=utf-8'
			type: 'POST'
		}

		promise.done (data) ->
			$(self.options.$template).removeClass 'amount-items-in-cart-loading'

		promise.success (data) ->
			self.setCartData data

		promise.fail (jqXHR, textStatus, errorThrown) ->
			# console.log 'Error Message: ' + textStatus;
			# console.log 'HTTP Error: ' + errorThrown;

		promise

	setCartData: (data) ->
		self = this

		amountProducts = data.items.length
		amountItems = 0;
		amountItems += item.quantity for item in data.items

		</div>
		"""

		$(@element).after @options.$template

		@selectors = {
			amountProducts: $('.amount-products-em', @options.$template)
			amountItems: $('.amount-items-em', @options.$template)
			totalCart: $('.total-cart-em', @options.$template)
		}

		@getCartData()

		$(window).on 'cartUpdated', (event, cartData) =>
			if (cartData)
				@setCartData(cartData)
			else
				@getCartData()

		$('.amount-items-in-cart, .show-minicart-on-hover').on 'mouseover', ->
			$(window).trigger 'miniCartMouseOver'

		$('.amount-items-in-cart, .show-minicart-on-hover').on 'mouseout', ->
			$(window).trigger 'miniCartMouseOut'

	formatCurrency: (value) ->
