{"version":3,"file":"addFromTag.js","mappings":";AAAA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA,cAAc,SAAS,EAAE;AACzB;AACA;AACA,2BAA2B,EAAE,gBAAgB;AAC7C,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,MAAM;AACN;AACA;AACA,4BAA4B;AAC5B;AACA,UAAU,aAAa,8BAA8B;AACrD,QAAQ;AACR;AACA;;AAEA;AACA;AACA;AACA,iCAAiC,aAAa,OAAO;AACrD;AACA,YAAY;AACZ,SAAS;AACT,QAAQ;AACR;AACA;AACA;AACA,WAAW;AACX;AACA;AACA;;AAEA;AACA;AACA,KAAK;AACL,GAAG;;AAEH;AACA;;AAEA;AACA;AACA;;AAEA,0BAA0B,uBAAuB;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,GAAG;;AAEH;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,QAAQ;AACR;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA,GAAG;;AAEH;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA,0BAA0B,mCAAmC;AAC7D;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA,KAAK;;AAEL;AACA,GAAG;;AAEH;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,OAAO;AACP,GAAG;;AAEH;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,QAAQ;AACR;AACA;AACA,KAAK;AACL,GAAG;;AAEH;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA,KAAK;AACL,GAAG;;AAEH;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO;AACP,GAAG;;AAEH;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GAAG;AACH","sources":["webpack://build/../vincishoes2/assets/javascripts/addFromTag.js"],"sourcesContent":["window.addFromTag = {\n language: $(\"html\").attr(\"lang\"),\n\n formatMoney: function (value) {\n //Cifra\n let currency = \"R$ \";\n if (this.language != \"pt-BR\") currency = \"$\";\n\n // FORMATA UM VALOR\n return `${currency}${value\n .toFixed(2)\n .replace(\".\", \",\")\n .replace(/(\\d)(?=(\\d{3})+\\,)/g, \"$1.\")}`;\n },\n\n updatePrice: function (\n sale_price,\n price,\n elements,\n intl_price,\n installments = 0,\n parcel_price,\n parcels_elements\n ) {\n const _this = this;\n let htmlPrice = null;\n\n if (_this.language != \"pt-BR\") {\n // Preço Internacional\n htmlPrice = _this.formatMoney(intl_price);\n } else {\n // Preço pt-BR\n if (sale_price != price) {\n htmlPrice = `${_this.formatMoney(\n price\n )}${_this.formatMoney(sale_price)}`;\n } else {\n htmlPrice = _this.formatMoney(price);\n }\n\n // parcelamento\n if (installments > 0) {\n parcels_elements.forEach((element) => {\n element.innerHTML = `${installments}x de ${_this.formatMoney(\n parcel_price\n )}`;\n });\n } else {\n if (parcels_elements && parcels_elements.length > 0) {\n parcels_elements.forEach((element) => {\n element.innerHTML = \"\";\n });\n }\n }\n }\n\n return elements.forEach((element) => {\n element.innerHTML = htmlPrice;\n });\n },\n\n updateSelectedAttributes: function (form) {\n const attributes = form.querySelectorAll(\"[data-attribute]\");\n\n attributes.forEach((attribute) => {\n const mainInput = attribute.querySelector(\"[data-attribute-name]\");\n const inputs = attribute.querySelectorAll(\".input\");\n\n for (let index = 0; index < inputs.length; index++) {\n const input = inputs[index];\n\n if (input.checked) {\n mainInput.value = input.value;\n break;\n }\n }\n });\n },\n\n setAvailable: function (form, variant) {\n const _this = this;\n const button = form.querySelector(\"[add-from-tag-button]\");\n let availableText = button.getAttribute(\"data-text-available\");\n let unavailableText = button.getAttribute(\"data-text-unavailable\");\n\n if (variant && variant != null) {\n button.classList.remove(\"hidden\");\n\n // Busca dados de preço e parcelamento para atualizar o valor no product_block\n const available = variant.getAttribute(\"available\");\n const price = Number(variant.getAttribute(\"price\"));\n const salePrice = Number(variant.getAttribute(\"sale-price\"));\n const intlPrice = Number(variant.getAttribute(\"intl-price\"));\n const installments = Number(variant.getAttribute(\"installments\"));\n const parcelPrice = Number(variant.getAttribute(\"parcel-price\"));\n const priceElements = [\n form.parentElement.querySelector(\n \"[data-update-price] [data-update-price]\"\n ),\n form.parentElement.querySelector(\"[data-update-price-extra]\"),\n ];\n const parcelsElements = [\n form.parentElement.querySelector(\n \"[data-update-price] [data-update-parcels]\"\n ),\n form.parentElement.querySelector(\"[data-update-parcels-extra]\"),\n ];\n\n _this.updatePrice(\n salePrice,\n price,\n priceElements,\n intlPrice,\n installments,\n parcelPrice,\n parcelsElements\n );\n\n // Verifica se a variante está disponível\n if (available == \"true\") {\n button.classList.remove(\"disabled\");\n button.innerHTML = availableText;\n } else {\n button.classList.add(\"disabled\");\n button.innerHTML = unavailableText;\n }\n } else {\n button.classList.add(\"disabled\");\n button.innerHTML = unavailableText;\n }\n },\n\n setVariant: function (form) {\n const _this = this;\n const selectedAttributes = form.querySelectorAll(\"[data-attribute-name]\");\n const variants = form.querySelectorAll(\"[data-product-variant]\");\n const sku = form.querySelector(\"[data-sku]\");\n let selectedVariant = null;\n\n variants.forEach((variant) => {\n const attr1 = variant.getAttribute(\"property-1\");\n const attr2 = variant.getAttribute(\"property-2\");\n const attr3 = variant.getAttribute(\"property-3\");\n\n let hasAttr1 = (hasAttr2 = hasAttr3 = false);\n\n for (let index = 0; index < selectedAttributes.length; index++) {\n const element = selectedAttributes[index];\n const value = element.value;\n if (index == 0 && attr1 == value) hasAttr1 = true;\n if (index == 1 && attr2 == value) hasAttr2 = true;\n if (index == 2 && attr3 == value) hasAttr3 = true;\n }\n\n if (hasAttr1 && hasAttr2 && hasAttr3) {\n sku.value = variant.getAttribute(\"sku\");\n selectedVariant = variant;\n }\n });\n\n _this.setAvailable(form, selectedVariant);\n },\n\n setListeners: function (form) {\n const _this = this;\n const options = form.querySelectorAll(\"[data-attribute-option]\");\n\n if (options.length > 0)\n options.forEach((option) => {\n option.addEventListener(\"change\", () => {\n _this.updateSelectedAttributes(form);\n _this.setVariant(form);\n });\n });\n },\n\n setSubmit: function (form) {\n form.addEventListener(\"submit\", (event) => {\n event.preventDefault();\n\n var $form = $(form);\n var $parent = $(form);\n var respValidated = store.validateFormProduct($form);\n\n if (respValidated.validated) {\n store.addItem($form, $parent);\n } else {\n // console.info(\"não foi\");\n }\n });\n },\n\n setFirstOptions: function (form) {\n const attributes = form.querySelectorAll(\"[data-attribute]\");\n\n // Esconde os atributos que possuem somente uma opção e marca esta opção\n attributes.forEach((attribute) => {\n const options = attribute.querySelectorAll(\".label\");\n\n if (options.length == 1) attribute.classList.add(\"-hidden\");\n\n options[0].click();\n });\n },\n\n // Init geral, para rodar de uma única vez todos os produtos\n init: function () {\n const _this = this;\n const forms = document.querySelectorAll(\"[add-from-tag]\");\n\n if (forms.length > 0)\n forms.forEach((form) => {\n const processed = form.getAttribute(\"data-processed\");\n\n // Executa as ações somente nos forms que ainda não foram processados\n // Útil para infinite scroll\n if (processed == \"false\") {\n _this.setListeners(form);\n _this.setSubmit(form);\n _this.setFirstOptions(form);\n form.setAttribute(\"data-processed\", \"true\");\n }\n });\n },\n\n // Para rodar individualmente por produto. Roda quando getPriceProd() é chamado\n initSingle: function (element = null) {\n const _this = this;\n\n if (element != null) {\n const form = element.querySelector(\"[add-from-tag]\");\n if (form != null) {\n const processed = form.getAttribute(\"data-processed\");\n\n if (processed == \"false\") {\n _this.setListeners(form);\n _this.setSubmit(form);\n _this.setFirstOptions(form);\n form.setAttribute(\"data-processed\", \"true\");\n }\n }\n }\n },\n};\n"],"names":[],"sourceRoot":""}