<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">(function ($, $sl, $baseUrl) {
	const pluginName = 'slProductsList'
	const main = {}
	main.init = async function (options) {
		const $targets = this
		var count = 0;
		for (let i = 0; i &lt; $targets.length; i++) {
			options = $.extend(true, {}, $.fn[pluginName].defaults, typeof options == 'object' &amp;&amp; options)
			const $self = $($targets[i])
			let data = $self.data(pluginName)
			if (data) {
				return
			}
			data = {
				options: options
			}
			$self.data(pluginName, data)
			$self.attr(pluginName, '')
			var result = await main.plot.apply($targets[i])
			count = result.count;
		}
		return count
	}
	main.destroy = function () {
		const $self = $(this)
		const data = $self.data(pluginName)
		if (!data)
			return $self
		$self.off(`.${pluginName}`)
		$self.removeData(pluginName)
		$self.removeAttr(pluginName)
		$self.html('')
		return $self
	}
	main.plot = async function () {
		const $self = $(this)
		$self.html(main.templates.loading)
		main.attachEvents.apply(this)
		return await main.request.apply(this)
	}
	main.request = async function () {
		const $self = $(this)
		const options = $self.data(pluginName).options

		return await $sl.services.request.get({ url: `${$baseUrl}Products/List`, data: options.filters })
			.done((data) =&gt; main.plotProduct.apply(this, [data.listProducts]))
			.always(() =&gt; $self.find(`.${pluginName}-loading`).remove())
	}
	main.plotProduct = async function (data) {
		const $self = $(this)
		for (let i = 0; i &lt; data.length; i++) {
			const item = data[i]
			const balance = item.balances.map(x =&gt; x.balance).reduce((a, b) =&gt; a + b, 0)
			const imageUrl = $sl.services.browsers.isSafari() ? item.iconUrlJpeg : item.iconUrlWebp
			const settings = await $sl.services.getStoreSettings()
			if (item.type == 2 || item.type == 4) { //tipo variável ou pizza
				var htmlTemplates = main.templates.variableProduct
					.replace(/{{priceOrUnavailability}}/gi, balance &gt; 0 ? item.price ? main.templates.priceProduct : main.templates.noProductPrince : main.templates.noBalanceProduct)
					.replace(/{{cashback}}/gi, item.cashbackPercent &gt; 0 ? main.templates.cashback.replace(/{{cashbackPercent}}/gi, `${item.cashbackPercent.toLocaleString('pt-BR')}%`) : '')
					.replace(/{{viewUrl}}/gi, `${$baseUrl}Produto/${item.id}`)
					.replace(/{{iconUrl}}/gi, imageUrl ? `url(${imageUrl})` : 'url(\'/assets/images/nophoto.png\')')
					.replace(/{{name}}/gi, item.name)
					.replace(/{{code}}/gi, item.code)
					.replace(/{{color}}/gi, settings.layout.current == 0 ? 'dimgray' : 'var(--theme-main-font-color)')
					.replace(/{{buyOrQuote}}/gi, item.price ? 'Comprar' : 'Cotar')
			}
			else {
				var htmlTemplates = main.templates.product
				.replace(/{{priceOrUnavailability}}/gi, balance &gt; 0 ? item.price ? main.templates.priceProduct : main.templates.noProductPrince : main.templates.noBalanceProduct)
				.replace(/{{cashback}}/gi, item.cashbackPercent &gt; 0 ? main.templates.cashback.replace(/{{cashbackPercent}}/gi, `${item.cashbackPercent.toLocaleString('pt-BR')}%`) : '')
				.replace(/{{viewUrl}}/gi, `${$baseUrl}Produto/${item.id}`)
				.replace(/{{iconUrl}}/gi, imageUrl ? `url(${imageUrl})` : 'url(\'/assets/images/nophoto.png\')')
				.replace(/{{name}}/gi, item.name)
				.replace(/{{code}}/gi, item.code)
				.replace(/{{color}}/gi, settings.layout.current == 0 ? 'dimgray' : 'var(--theme-main-font-color)')
				.replace(/{{showPrice}}/gi, item.price ? 'inline-block' : 'none')
				.replace(/{{buyOrQuote}}/gi, item.price ? 'Comprar' : 'Cotar')
			}

			const html = htmlTemplates;
			
			let $html = $(html)
			if (item.price) {
				$html = $(html
					.replace(/{{priceWithoutDiscount}}/gi, item.price.priceWithoutDiscount ? item.price.priceWithoutDiscount.money() : null)
					.replace(/{{discount}}/gi, item.price.discount ? Math.floor(item.price.discount) : 0)
					.replace(/{{price}}/gi, item.price.price.money())
					.replace(/{{installmentAmount}}/gi, item.price.installmentAmount)
					.replace(/{{installmentPrice}}/gi, item.price.installmentPrice ? item.price.installmentPrice.money() : null))

				if (!item.price.installmentAmount || !item.price.installmentPrice)
					$html.find('[name=installment]').hide()

				if (!item.price.discount || (item.price.discount &lt; 0.1))
					$html.find('[name=discount]').hide()

				if (item.type != 2 &amp;&amp; item.type != 4)
					$html.find('[name=minimum-price]').hide()

				if (item.type == 2 || item.type == 4 || balance &lt;= 0)
					$html.find('[name=controls]').hide()
			}else if(balance &lt;= 0){
				$html.find('[name=add-to-cart]').hide()
				$html.find('[name=buy]').hide()
			}

			if (settings.showProductCode == false)
				$html.find('[name=code]').hide()

			$html.data('id', item.id)
			$self.append($html)
		}
	}
	main.attachEvents = function () {
		const $self = $(this)
		const suffix = `.sl.${pluginName}`
		$self.off(suffix)

		$self.on(`click${suffix}`, '[name=add-to-cart]', main.events.ocClickAddToCart)
		$self.on(`click${suffix}`, '[name=buy]', main.events.onClickBuy)
	}
	main.events = {
		ocClickAddToCart: function (e) {
			e.preventDefault()
			const $product = $(this).closest('[name=product]')
			$sl.apps.shoppingCart.addProduct($product.data('id'))
			$sl.apps.shoppingCart.showModal()
		},
		onClickBuy: async function (e) {
			e.preventDefault()
			const $product = $(this).closest('[name=product]')
			$sl.apps.shoppingCart.setProduct($product.data('id'))
			await $sl.apps.shoppingCart.getProducts()
			window.location = `${$baseUrl}Vendas/FinalizarPedido/Entrega`
		}
	}
	main.templates = {
		loading: `
    &lt;div class="${pluginName}-loading"&gt;
      &lt;i class="fa fa-spinner fa-pulse"&gt;&lt;/i&gt;
    &lt;/div&gt;`,
		priceProduct: `
    &lt;div id="showPrices" style="display: {{showPrice}}"&gt;
      &lt;p name="minimum-price" class="minimum-price"&gt;A partir de&lt;/p&gt;
      &lt;p class="priceBefore" name="discount"&gt;{{priceWithoutDiscount}} &lt;span class="tag fa fa-arrow-down"&gt;-{{discount}}%&lt;/span&gt;&lt;/p&gt;
      &lt;div class="product-price"&gt;
        &lt;p class="price"&gt;{{price}} &lt;span name="installment"&gt;à vista ou&lt;/span&gt;&lt;/p&gt;
        &lt;p class="parcel" name="installment"&gt;{{installmentAmount}}x de &lt;b&gt;{{installmentPrice}}&lt;/b&gt;&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;`,
		noBalanceProduct: '&lt;p class="indisponivel"&gt;Indisponível&lt;/p&gt;',
		noProductPrince: '&lt;p class="indisponivel"&gt;Sob Consulta&lt;/p&gt;',
		product: `
    &lt;a class="bgProduct" href="{{viewUrl}}" name="product"&gt;
      &lt;div class="bgImage"&gt;
        &lt;div class="image" style="background-image: {{iconUrl}}"&gt;&lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="contentProduct"&gt;
        &lt;div&gt;
            &lt;h5 class="product-name" title="{{name}}"&gt;{{name}}&lt;/h5&gt;
            &lt;h6 style="color:{{color}}" name="code"&gt;Ref: {{code}}&lt;/h6&gt;             
        &lt;/div&gt;
         {{priceOrUnavailability}}
      &lt;/div&gt;
      {{cashback}}
      &lt;div class="controls" name="controls"&gt;
        &lt;button type="button" name="buy" id="buy"&gt;{{buyOrQuote}}&lt;/button&gt;
        &lt;button type="button" title="Adicionar ao Carrinho" name="add-to-cart"&gt;
          &lt;i class="fa fa-cart-plus"&gt;&lt;/i&gt;
        &lt;/button&gt;
      &lt;/div&gt;
    &lt;/a&gt;`,
		variableProduct: `
	&lt;a class="bgProduct" href="{{viewUrl}}" name="product"&gt;
		  &lt;div class="bgImage" &gt;
			&lt;div class="image" style="background-image: {{iconUrl}}"&gt;&lt;/div&gt;
		  &lt;/div&gt;
		  &lt;div class="contentProduct"&gt;
			&lt;div&gt;
				&lt;h5 class="product-name"&gt;{{name}}&lt;/h5&gt;
				&lt;h6 style="color:{{color}}" name="code"&gt;Ref: {{code}}&lt;/h6&gt;             
			&lt;/div&gt;
			 {{priceOrUnavailability}}
		  &lt;/div&gt;
		  {{cashback}}
		  &lt;div class="controls"&gt;
			&lt;button type="button" title="Selecionar Variação" style="border-radius: 5px"&gt;
			  &lt;i class="fa fa-cart-plus" disabled&gt;&lt;/i&gt;
			&lt;/button&gt;
		  &lt;/div&gt;
	&lt;/a&gt;`,
		cashback: '&lt;div class="cashback"&gt;&lt;p&gt;Oferta de {{cashbackPercent}} de Cashback&lt;/p&gt;&lt;/div&gt;'
	}
	const pb = {
		init: main.init,
		destroy: main.destroy,
		count: main.count
	}
	$.fn[pluginName] = async function (method) {
		if (typeof pb[method] == 'function') {
			return await pb[method].apply(this, Array.prototype.slice.call(arguments, 1))
		} else if (typeof pb[method] != 'undefined') {
			return pb[method]
		} else if (typeof method === 'object' || !method) {
			return await pb.init.apply(this, arguments)
		} else {
			throw $.error(`Method ${method} does not exist on jQuery.${pluginName}`)
		}
	}
	$.fn[pluginName].defaults = {}
})(window.jQuery, window.$sl, window.$baseUrl)
</pre></body></html>