 
 
 class SkuSelectorRenderer
-	constructor: (context) ->
+	constructor: (context, selectors) ->
 		@context = context
+		@select = {}
+		for key, value of selectors
+			@select[key] = -> $(value, @context)
+		console.log @select
 
 	generateItemDimensionClass: (dimensionName) =>
 		"item-dimension-#{sanitize(dimensionName)}"


$.skuSelector.getAddUrlForSku = (sku, seller = 1, qty = 1, redirect = true) ->
	window.location.protocol + '//' + window.location.host + "/checkout/cart/add?qty=#{qty}&seller=#{seller}&sku=#{sku}&redirect=#{redirect}"


#
# PRIVATE FUNCTIONS
#
selectDimension = (dimArray) ->
	# Tenta selecionar apenas dos disponíveis
	available = dimArray.filter('input:not(.item_unavaliable)')
	# Caso não haja indisponível, seleciona primeiro não-desabilitado (sku existente)
	el = (if available.length > 0 then available else dimArray).filter('input:enabled')[0]
	$(el).attr('checked', 'checked').change() if dimArray.length > 0

updatePrice = (sku, options, context) ->
	if sku and sku.available
		updatePriceAvailable(sku, options, context)
	else
		updatePriceUnavailable(options, context)

updatePriceAvailable = (sku, options, context) ->
	listPrice = formatCurrency sku.listPrice
	bestPrice = formatCurrency sku.bestPrice
	installments = sku.installments
	installmentValue = formatCurrency sku.installmentsValue

	# Modifica href do botão comprar
	options.selectors.buyButton(context).attr('href', $.skuSelector.getAddUrlForSku(sku.sku)).show()
	options.selectors.price(context).show()
	options.selectors.listPriceValue(context).text("R$ #{listPrice}")
	options.selectors.bestPriceValue(context).text("R$ #{bestPrice}")
	if installments > 1
		options.selectors.installment(context).text("ou até #{installments}x de R$ #{installmentValue}")

updatePriceUnavailable = (options, context) ->
	# Modifica href do botão comprar
	options.selectors.buyButton(context).attr('href', 'javascript:void(0);').hide()
	options.selectors.price(context).hide()
	# $('.notifyme-skuid').val()


#
# UTILITY FUNCTIONS

	warnUnavailable: false
	selectOnOpening: false
	selectors:
		listPriceValue: '.skuselector-list-price .value'
		bestPriceValue: '.skuselector-best-price .value'
		installment: '.skuselector-installment'
		buyButton: '.skuselector-buy-btn'
		price: '.skuselector-price'
		warning: '.skuselector-warning'
		warnUnavailable: '.skuselector-warn-unavailable'

	# Called when we failed to receive variations.
	skuVariationsFailHandler: ($el, options, reason) ->
