PageSourceSearch

https://pretavoir.us/cdn/shop/t/285/assets/lenzadvisor-new-layout-jtpl.js?v=150153233853455309891790658682

js pretavoir.us collected 2026-10-02 20:25:15 UTC 188,301 bytes, 4,161 lines download raw bytes

1/** Shopify CDN: Minification failed
2
3Line 17:2 Transforming const to the configured target environment ("es5") is not supported yet
4Line 18:2 Transforming const to the configured target environment ("es5") is not supported yet
5Line 19:2 Transforming const to the configured target environment ("es5") is not supported yet
6Line 20:2 Transforming const to the configured target environment ("es5") is not supported yet
7Line 21:2 Transforming const to the configured target environment ("es5") is not supported yet
8Line 22:2 Transforming const to the configured target environment ("es5") is not supported yet
9Line 35:2 Transforming const to the configured target environment ("es5") is not supported yet
10Line 38:4 Transforming let to the configured target environment ("es5") is not supported yet
11Line 78:2 Transforming const to the configured target environment ("es5") is not supported yet
12Line 117:2 Transforming const to the configured target environment ("es5") is not supported yet
13... and 422 more hidden warnings
14
15**/
16if (document.body.classList.contains("fe-flow-jtpl")) {
17  const Symbolcurrency = document.body.getAttribute('theme-currency');
18  const EnableDescription = true;
19  const EnableDiscount = false;
20  const EnableTitle = true;
21  const Enablepreselect = "";
22  const currentCountry = Shopify.country ;
23  var selectedlens = false;
24  var nextDay = true;
25
26document.addEventListener('LensAdvizor:prescriptionTypes:rendered', function () {
27
28  hiddenInputText = `<input id="hiddenordernoteProperty" type="hidden" name='la-properties[Order Note]' value="">`;
29  DeliveryInputText = `<input id="nextdayProperty" type="hidden" name='la-properties[Delivery]' value="Next Day Available">`;
30    wrapper = document.querySelector('.la-prescription-modal-wrapper')
31    wrapper.insertAdjacentHTML('beforeend', hiddenInputText);  
32    wrapper.insertAdjacentHTML('beforeend', DeliveryInputText);
33
34  if (document.querySelector('.la-custom-trust-bar')) return;
35  const header = document.querySelector('.la-error-box');
36
37  if (header) {
38    let ship_country_html = ""
39    if (currentCountry=="US") {
40      ship_country_html = ' <div class="text-block la-label-description">Free Tracked Delivery</div>'
41    }
42    else if(currentCountry == "GB"){
43      ship_country_html = ' <div class="text-block la-label-description">Free Tracked Delivery</div>'
44    }
45
46    header.insertAdjacentHTML('afterend', `
47      <div class="la-custom-trust-bar">
48      <!--
49        <div class="la-custom-reviews ">
50            <div class="trustpilot">
51              <span class="excellent">Our customer say <strong>Excellent</strong></span>
52
53              <div class="stars">
54                  <span class="star">★</span>
55                  <span class="star">★</span>
56                  <span class="star">★</span>
57                  <span class="star">★</span>
58                  <span class="star star-half">★</span>
59              </div>
60
61              <div class="reviews">4.7 out of 5 based on <strong>34,000+ reviews</strong></div>
62
63              <div class="trustpilot-brand">
64                  <span class="trustpilot-logo">★</span>
65                  <span>Trustpilot</span>
66              </div>
67          </div>
68        </div>
69        -->
70        <div class="la-custom-reviews la-custom-text-block">
71            <div class="text-block la-label-description">100% Authentic</div>
72            ${ship_country_html}
73            <div class="text-block la-label-description">24-Month Warranty</div>
74        </div>
75      </div>
76    `);
77  }
78  const progress = document.querySelector(
79  ".la-prescription-modal-header .la-progress-bar .la-step-bar"
80);
81
82if (progress) {
83  progress.innerHTML = `
84    <ul class="la-steps-list">
85      <li class="la-step-item is-active">
86        <div class="la-step-item-bar">
87          <div class="la-step-bar-inner"></div>
88        </div>
89      </li>
90      <li class="la-step-item">
91        <div class="la-step-item-bar">
92          <div class="la-step-bar-inner"></div>
93        </div>
94      </li>
95      <li class="la-step-item">
96        <div class="la-step-item-bar">
97          <div class="la-step-bar-inner"></div>
98        </div>
99      </li>
100      <li class="la-step-item">
101        <div class="la-step-item-bar">
102          <div class="la-step-bar-inner"></div>
103        </div>
104      </li>
105      <li class="la-step-item">
106        <div class="la-step-item-bar">
107          <div class="la-step-bar-inner"></div>
108        </div>
109      </li>
110    </ul>
111  `;
112}
113});
114var Addon = false;
115//*********************** Display the size under the product title start *******************************/ 
116function productTitle(){
117  const mainTitle = document.getElementById('la-footer-frame-title');
118    const Ptitle = document.querySelector('.la-footer-text.la-footer-frame-variant-title');
119        if (Ptitle) {
120            const text = Ptitle.textContent.trim();
121            const match = text.match(/\(([^()]*)\)\s*$/);
122
123            if (match) {
124                const variantText = match[1];
125                const titleText = text.replace(/\(([^()]*)\)\s*$/, '').trim();
126                mainTitle.innerHTML = `
127                    <span class="product-title">${titleText}</span>
128                    <span class="product-selected-variant">${variantText}</span>
129                `;
130            }
131        }   
132}
133//*********************** Display the size under the product title end *******************************/ 
134
135//*********************** Your Build summary and add step class start *******************************/ 
136let currentStep = 0;
137let summary = false;
138document.addEventListener('LensAdvizor:component:DidMount', function (i) {
139  console.log(i.detail.method);
140setTimeout(() => {
141  productTitle();
142  const removeSpaceAfterCurrency = selector => {
143            document.querySelectorAll(selector).forEach(el => {
144              el.textContent = el.textContent.replace(/([£$€¥])\s+/g, '$1');
145              });
146            };
147
148          removeSpaceAfterCurrency('.la-frame-price');
149          removeSpaceAfterCurrency('.la-footer-addon-price');
150          removeSpaceAfterCurrency('.la-subtotal-price');
151          removeSpaceAfterCurrency('.la-label-price');
152           var discount = false;
153          if(discount == true){
154            document.querySelectorAll(".la-label-price").forEach(function (el) {
155              const text = el.textContent.trim();
156              // console.log(text);
157              // Match currency and price
158              const match = text.match(/^(\D+)\s*([\d,.]+)/);
159          
160              // if (!match) return;
161              if (match){
162
163              const currency = match[1].trim();
164              const originalPrice = parseFloat(match[2].replace(/,/g, ""));
165              
166              if(originalPrice > 0){
167                if (isNaN(originalPrice)) return;
168                
169                const discount = `25`;
170                const discountedPrice = (originalPrice * (100 - discount) / 100).toFixed(2);
171            
172                el.innerHTML = `
173                  <div class="price-box price-discount">
174                  <div class="price-row">
175                  <span class="old-price">${currency}${originalPrice.toFixed(2)}</span>
176                  <span class="new-price">${currency}${discountedPrice}</span>
177                  </div>
178                  <div class="offer-text">
179                      <p>25% off with LENSES25</p>
180                  </div>
181                  </div>
182                `;
183              } else{
184                el.innerHTML = `
185                  <div class="price-box applied-discount">
186                    <div class="offer-text applied-text">Included</div>
187                  </div>
188                `;
189              }
190            } else{
191              el.innerHTML = `
192                  <div class="price-box applied-discount">
193                    <div class="offer-text applied-text">Included</div>
194                  </div>
195                `;
196            }
197            });
198          }
199}, 10);
200const removeSpaceAfterCurrency = selector => {
201            document.querySelectorAll(selector).forEach(el => {
202              el.textContent = el.textContent.replace(/([£$€¥])\s+/g, '$1');
203              });
204            };
205
206          removeSpaceAfterCurrency('.la-frame-price');
207          removeSpaceAfterCurrency('.la-footer-addon-price');
208          removeSpaceAfterCurrency('.la-subtotal-price');
209          removeSpaceAfterCurrency('.la-label-price');
210
211    const wrapper = document.querySelector('.la-prescription-modal-content');
212    if (!wrapper) return;
213      currentStep++;
214      updateStepClass(wrapper);
215    if(summary == false){
216      
217    if(window.outerWidth <= 767){
218      var productImage = document.querySelector('.la-subtotal-modal-trigger').innerHTML;
219    }
220      summary = true;
221        document.querySelector('.la-boxy-layout-modal').insertAdjacentHTML(
222          'afterbegin',
223          `
224           ${
225              productImage
226                ? `<div class="summary-product-info">
227                    ${productImage}
228                  </div>`
229                : ''
230            }
231          <div class="la-footer-row-wrapper jtpl-cart-summary">
232              <h3 class="la-translate">Your Build</h3>
233                  <div class="la-footer-row summary-prescription-wrapper prescription-value-1 hide-prescription">
234                      <div class="la-footer-text summary-prescription-heading la-translate la-footer-frame-prescription prescription-heading-1">Used For</div>
235                      <div class="la-footer-text summary-prescription-title la-translate la-footer-frame-prescription value-option value1">—</div>
236                  </div>
237                  <div class="la-footer-row summary-prescription-wrapper prescription-value-2 hide-prescription">
238                      <div class="la-footer-text summary-prescription-heading la-translate la-footer-frame-prescription prescription-heading-2">Method</div>
239                      <div class="la-footer-text summary-prescription-title la-translate la-footer-frame-prescription value-option value2">—</div>
240                  </div>
241                  <div class="la-footer-row summary-prescription-wrapper prescription-value-3 hide-prescription">
242                      <div class="la-footer-text summary-prescription-heading la-translate la-footer-frame-prescription prescription-heading-3">Lens type</div>
243                      <div class="la-footer-text summary-prescription-title la-translate la-footer-frame-prescription value-option value3">—</div>
244                  </div>
245                  <div class="la-footer-row summary-prescription-wrapper prescription-value-4 hide-prescription">
246                      <div class="la-footer-text summary-prescription-heading la-translate la-footer-frame-prescription prescription-heading-4">Lens</div>
247                      <div class="la-footer-text summary-prescription-title la-translate la-footer-frame-prescription value-option value4">—</div>
248                  </div>
249                  <div class="la-footer-row summary-prescription-wrapper prescription-value-5 hide-prescription">
250                      <div class="la-footer-text summary-prescription-heading la-translate la-footer-frame-prescription prescription-heading-5">Thickness</div>
251                      <div class="la-footer-text summary-prescription-title la-translate la-footer-frame-prescription value-option value5">—</div>
252                  </div>
253                  <div class="la-footer-row summary-prescription-wrapper prescription-value-6 hide-prescription">
254                      <div class="la-footer-text summary-prescription-heading la-translate la-footer-frame-prescription prescription-heading-6">Color</div>
255                      <div class="la-footer-text summary-prescription-title la-translate la-footer-frame-prescription value-option value6">—</div>
256                  </div>
257                  <div class="la-footer-row summary-prescription-wrapper prescription-value-7 hide-prescription">
258                      <div class="la-footer-text summary-prescription-heading la-translate la-footer-frame-prescription prescription-heading-7">Coating</div>
259                      <div class="la-footer-text summary-prescription-title la-translate la-footer-frame-prescription value-option value7">—</div>
260                  </div>
261                  <div class="la-footer-row summary-prescription-wrapper prescription-value-8 hide-prescription">
262                      <div class="la-footer-text summary-prescription-heading la-translate la-footer-frame-prescription prescription-heading-8">Add-on</div>
263                      <div class="la-footer-text summary-prescription-title la-translate la-footer-frame-prescription value-option value8">—</div>
264                  </div>
265                  <div class="la-footer-row summary-prescription-wrapper prescription-value-9 hide-prescription">
266                      <div class="la-footer-text summary-prescription-heading la-translate la-footer-frame-prescription prescription-heading-9">Dispatch Time</div>
267                      <div class="la-footer-text summary-prescription-title la-translate la-footer-frame-prescription value-option value9" style="color: #1f7a4d !important;">Next Day Available</div>
268                  </div>
269                  <div class="discount-summary-cart hide-summary">
270                    <div class="summary-discount-inner"><p>🏷 <strong>LENSES25</strong> · 25% off lenses</p> <span class="discount-ammount"></span></div>
271                  </div>
272          </div>
273          
274          ` 
275      );
276            }
277
278      setTimeout(function(){
279
280        document.querySelectorAll("label.la-label-btn").forEach(label => {
281            const contentBox = label.querySelector(".la-label-content-box");
282            const priceBox = label.querySelector(".la-label-price");
283
284            if (contentBox && priceBox) {
285                const wrapper = document.createElement("div");
286                wrapper.className = "la-label-content-wrapper";
287                contentBox.before(wrapper);
288                wrapper.appendChild(contentBox);
289                wrapper.appendChild(priceBox);
290            }
291        });
292
293
294
295     //    document.querySelectorAll('.la-footer-row-wrapper.jtpl-cart-summary .la-footer-row la-subtotal').insertAdjacentHTML('afterbegin',`<
295div class="prescription-dispatch-message">Next-day delivery available on most lenses (order by 3pm). Varifocals and stronger prescriptions are made to order 7-10 working days. </div>`);
296      var discount = false;
297        if(discount == true){
298          document.querySelectorAll('.la-footer-row').forEach(function (row) {
299
300            const symbolEl = row.querySelector('.currency-symbol');
301            const priceEl = row.querySelector('.la-footer-lens-price');
302
303            if (!symbolEl || !priceEl) return; // Element nahi mila to skip
304
305            const symbol = symbolEl.textContent.trim();
306            const price = parseFloat(priceEl.textContent.trim());
307
308            if (isNaN(price)) return;
309
310            const discount = `25`;
311            const discountedPrice = (price * (100 - discount) / 100).toFixed(2);
312
313            var disamount = price.toFixed(2) - discountedPrice;
314            document.querySelector(".discount-ammount").textContent = `- ${symbol}${disamount.toFixed(2)}`;
315            document.querySelector(".discount-ammount").setAttribute("data-price", disamount.toFixed(2));
316
317            const parentLabel = document.querySelector(".la-choose-prescription-wrapper");
318            if (parentLabel && parentLabel.classList.contains("la-render-review")) {
319                document.querySelector(".lens-discount-price").textContent = `- ${symbol}${disamount.toFixed(2)}`;
320            }
321
322            priceEl.innerHTML = `
323              <div class="lenses-discount-price">
324                <span class="old-price">
325                    ${symbol}${price.toFixed(2)}
326                </span>
327                <span class="final-price">
328                    ${symbol}${discountedPrice}
329                </span>
330              </div>
331            `;
332          }); 
333
334          if(Addon == true){
335            // const addonPriceEl = document.querySelector(".la-footer-addon-price");
336            // const Priceaddon = document.querySelector(".la-footer-addon-price").textContent;
337            // const currencySymbol = document.body.getAttribute('theme-currency');
338
339            // if (addonPriceEl) {
340            //     let addonPrice = parseFloat(
341            //         addonPriceEl.textContent.replace(/[^\d.]/g, "")
342            //     );
343                
344            //     const discountt = Number(`25`);
345            //     let finalPrice = addonPrice - (addonPrice * (discountt / 100));
346            //     if(finalPrice > 0){
347            //       addonPriceEl.innerHTML = `
348            //       <div class="lenses-discount-price">
349            //         <span class="old-price">
350            //             ${Priceaddon}
351            //         </span>
352            //         <span class="final-price">
353            //             ${currencySymbol}${finalPrice.toFixed(2)}
354            //         </span>
355            //       </div>
356            //       `;
357            //     }
358            // }
359            const addonPriceEl = document.querySelectorAll(".la-footer-addon-price");
360            addonPriceEl.forEach(function (addonPriceEl) {
361            const discountAmountEl = document.querySelector(".discount-ammount");
362            if(addonPriceEl){
363              const Priceaddon = addonPriceEl.textContent;
364              const currencySymbol = document.body.getAttribute("theme-currency");
365
366              if (addonPriceEl) {
367                  let addonPrice = parseFloat(
368                      addonPriceEl.textContent.replace(/[^\d.]/g, "")
369                  );
370
371                  const discountt = Number(`25`);
372
373                  let finalPrice = addonPrice - (addonPrice * (discountt / 100));
374
375                  if (finalPrice > 0) {
376
377                      // Addon discount
378                      const addonDiscount = addonPrice - finalPrice;
379
380                      // Existing discount amount (-£114.00)
381                      if (discountAmountEl) {
382                          let existingDiscount = parseFloat(
383                              discountAmountEl.textContent.replace(/[^\d.]/g, "")
384                          );
385
386                          let totalDiscount = existingDiscount + addonDiscount;
387
388                          discountAmountEl.textContent = `- ${currencySymbol}${totalDiscount.toFixed(2)}`;
389                          discountAmountEl.setAttribute("data-price", totalDiscount.toFixed(2));
390
391                          const parentLabel = document.querySelector(".la-choose-prescription-wrapper");
392                          if (parentLabel && parentLabel.classList.contains("la-render-review")) {
393                              document.querySelector(".lens-discount-price").textContent = `- ${currencySymbol}${totalDiscount.toFixed(2)}`;
394                          }
395
396                      }
397
398                      addonPriceEl.innerHTML = `
399                          <div class="lenses-discount-price">
400                              <span class="old-price">
401                                  ${Priceaddon}
402                              </span>
403                              <span class="final-price">
404                                  ${currencySymbol}${finalPrice.toFixed(2)}
405                              </span>
406                          </div>
407                      `;
408                  }
409              }
410            }
411
412          });
413
414
415
416          }
417          var SubtotalPrice = '';
418          document.querySelectorAll(".la-subtotal-price").forEach((priceEl) => {
419              let price = parseFloat(
420                  priceEl.textContent.replace(/[^\d.]/g, "")
421              );
422              let discountEl = document.querySelector(".discount-ammount");
423              if (discountEl && discountEl.textContent.trim() !== "") {
424                  let discount = parseFloat(
425                      discountEl.textContent.replace(/[^\d.]/g, "")
426                  );
427                  let finalPrice = price - discount;
428                  priceEl.textContent = `${Symbolcurrency}${finalPrice.toFixed(2)}`;
429                  SubtotalPrice = finalPrice.toFixed(2) / 3;
430
431                  const parentLabel = document.querySelector(".la-choose-prescription-wrapper");
432                  if (parentLabel && parentLabel.classList.contains("la-render-review")) {
433                    document.querySelector(".la-lens-total-price strong").textContent = `${Symbolcurrency}${finalPrice.toFixed(2)}`;
434                  }
435
436              }
437          });
438        }
439
440        //**********************  Add-on sum  ***************************/
441                var discount = false;
442                let total = 0;
443                if(discount == true){
444                  const oldPrices = document.querySelectorAll(".la-footer-addon-price span.old-price");
445                      oldPrices.forEach(el => {
446                          const text = el.textContent.trim();
447
448                          const price = parseFloat(text.replace(/[^0-9.]/g, ""));
449
450                          if (!isNaN(price)) {
451                              total += price;
452                          }
453                      });
454                } else{
455                  const oldPrices = document.querySelectorAll(".la-footer-addon-price");
456                      oldPrices.forEach(el => {
457                          const text = el.textContent.trim();
458
459                          const price = parseFloat(text.replace(/[^0-9.]/g, ""));
460
461                          if (!isNaN(price)) {
462                              total += price;
463                          }
464                      });
465                }
466                
467                  const totalDiv = document.createElement("div");
468                  totalDiv.className = "la-addon-price";
469                  // totalDiv.textContent = `${Symbolcurrency}${total.toFixed(2)}`;
470
471                  
472                  const container = document.querySelector(".la-footer-addon-wrapper");
473                  if (container) {
474                    // if exist then remove
475                    container.querySelector(".la-addon-price")?.remove();
476
477                    const totalDiv = document.createElement("div");
478                    totalDiv.className = "la-addon-price";
479
480                    var discount = false;
481                    if(discount == true){
482                      const discounttt = `25`;
483                      const discountedPricee = (total.toFixed(2) * (100 - discounttt) / 100).toFixed(2);
484                      
485                      totalDiv.innerHTML = `
486                              <div class="la-addon-discount-price">
487                                  <span class="old-price">${Symbolcurrency}${total.toFixed(2)}</span>
488                                  <span class="final-price">
489                                      ${Symbolcurrency}${discountedPricee}
490                                  </span>
491                              </div>
492                          `;
493
494                    }else{
495                      totalDiv.textContent = `${Symbolcurrency}${total.toFixed(2)}`;
496                    }
497
498                    container.insertAdjacentElement("afterbegin", totalDiv);
499                  }
500            //********************************* Add-on Sum  *******************************/
501
502        const interval = setInterval(() => {
503          // console.log("SubtotalPrice", SubtotalPrice);
504      const klarna = document.querySelectorAll("klarna-placement")[2];
505
506      if (klarna && klarna.shadowRoot) {
507        const message = klarna.shadowRoot.querySelector(".osm-message");
508
509        if (message) {
510          const strong = message.querySelector("strong")?.textContent || "";
511
512          message.innerHTML = `
513          ${
514              SubtotalPrice
515                ? `or 3× <strong>${Symbolcurrency}${SubtotalPrice.toFixed(2)}</strong> with`
516                : `or 3× <strong>${strong}</strong> with`
517            }
518          `;
519
520          // clearInterval(interval);
521        }
522      }
523
524    }, 500);
525
526    const element = document.querySelector(
527  '#la-boxy-footer-modal'
528);
529
530if (element) {
531   element.querySelectorAll('.prescription-dispatch-message').forEach((el) => {
532  el.remove();
533});
534
535  const element1 = document.querySelector(
536  '#la-boxy-footer-modal .la-boxy-layout-modal'
537);
538  element1.insertAdjacentHTML(
539    'afterend',
540    `<div class="prescription-dispatch-message">Next-day delivery available on most lenses (order by 3pm). Varifocals and stronger prescriptions are made to order 7-10 working days.</div>`
541  );
542  
543}
544
545    }, 10);
546
547 function handleResize() {
548    const modal = document.getElementById("la-boxy-footer-modal");
549
550    if (!modal) return;
551
552    if (window.outerWidth <= 767) {
553        modal.style.display = "none";
554    } else {
555        modal.style.display = "flex";
556    }
557}
558
559window.addEventListener("resize", handleResize);
560
561
562});
563document.addEventListener('LensAdvizor:render:uploadForm', function() {
564  document.getElementById("wrapper-lensadvisor-jtpl").classList.add("review-page");
565  document.getElementById("wrapper-lensadvisor-jtpl").classList.add("upload-page");
566  if(EnableDescription == true){
567    const description3 = `PD (pupillary distance) is the gap between your pupils — it centres your lenses correctly.`;
568    document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
569          'afterend', `<p class="la-prescription-description text-center">${description3}</p>`
570    );
571  }
572  if(EnableTitle == true){
573    const title3 = ``;
574    if(title3 != ''){
575      document.getElementById("la_prescriptionSelect_title").textContent = title3;
576    }
577  }
578
579});
580// document.addEventListener('LensAdvizor:render:readingForm', function() {
581//    console.log("readingForm");
582// });
583document.addEventListener('LensAdvizor:render:manualEntryForm', function() {
584 document.getElementById("wrapper-lensadvisor-jtpl").classList.add("review-page");
585 document.getElementById("wrapper-lensadvisor-jtpl").classList.remove("upload-page");
586
587 if(EnableDescription == true){
588  const description4 = `If you know your values, pop them in below. Not sure on any box? Leave it — our opticians will check.`;
589    document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
590          'afterend', `<p class="la-prescription-description text-center">${description4}</p>`
591    );
592 }
593
594 if(EnableTitle == true){
595  const title4 = ``;
596  if(title4 != ''){
597    document.getElementById("la_prescriptionSelect_title").textContent = title4;
598  }
599}
600
601//************************   SPH CYL Start     **************************/ 
602
603const USEDFORVALUE1 = document.querySelector(".la-footer-frame-prescription.value1").textContent;
604const USEDPRESVALUE3 = document.querySelector(".la-footer-frame-prescription.value3").textContent;
605if (
606    !USEDPRESVALUE3.includes("Mirror") &&
607    !USEDPRESVALUE3.includes("mirror") &&
608    !USEDFORVALUE1.includes("Occupational") &&
609    !USEDFORVALUE1.includes("Varifocal")
610) {
611  const LeadTime = document.querySelector(".la-footer-frame-prescription.value9").textContent;
612  function updatePrescriptionAvailability() {
613      const ODSPH = parseFloat(document.getElementById('la-od_right-sph').value);
614      const ODCYL = parseFloat(document.getElementById('la-od_right-cyl').value);
615
616      const OSSPH = parseFloat(document.getElementById('la-os_left-sph').value);
617      const OSCYL = parseFloat(document.getElementById('la-os_left-cyl').value);
618
619      const hasNaN =
620          isNaN(ODSPH) ||
621          isNaN(ODCYL) ||
622          isNaN(OSSPH) ||
623          isNaN(OSCYL);
624
625      const odInRange =
626          ODSPH >= -6 && ODSPH <= 0 &&
627          ODCYL >= -2 && ODCYL <= 0;
628
629      const osInRange =
630          OSSPH >= -6 && OSSPH <= 0 &&
631          OSCYL >= -2 && OSCYL <= 0;
632
633      if (hasNaN || (odInRange && osInRange)) {
634          document.querySelector(".la-footer-frame-prescription.value9").textContent = LeadTime;
635      } else {
636          document.querySelector(".la-footer-frame-prescription.value9").textContent = "3-5 Days";
637      }
638  }
639
640  // Initial check
641  updatePrescriptionAvailability();
642
643  // Check whenever value changes
644  [
645      'la-od_right-sph',
646      'la-od_right-cyl',
647      'la-os_left-sph',
648      'la-os_left-cyl'
649  ].forEach(function(id) {
650      document.getElementById(id).addEventListener('change', updatePrescriptionAvailability);
651  });
652}
653//************************   SPH CYL End     **************************/
654
655document.querySelector('[name="la-pd-value"] [value="60.00"]').innerText = '60 (average female)';
656document.querySelector('[name="la-pd-value"] [value="63.00"]').innerText = '63 (average male)';
657
658});
659function updateStepClass(wrapper) {
660    wrapper.classList.forEach(cls => {
661        if (cls.startsWith('step-')) {
662            wrapper.classList.remove(cls);
663        }
664    });
665
666    wrapper.classList.add(`step-${currentStep}`);
667}
668
669document.addEventListener('click', function (e) {
670    if (e.target.matches('.la-steeper-back')) {
671      if(document.querySelector(".la-choose-prescription-wrapper").classList.contains("la-render-addons")){
672            if(nextDay == false){
673              nextDay = false;
674            }else{
675              nextDay = true;
676            }
677        }else{
678          nextDay = true;
679        }
680       setTimeout(() => {
681        if(document.querySelector(".la-choose-prescription-wrapper").classList.contains("la-render-addons")){
682            if(nextDay == false){
683              nextDay = false;
684            }else{
685              nextDay = true;
686            }
687        }else{
688          nextDay = true;
689        }
690        const wrapper = document.querySelector('.la-prescription-modal-content');
691        if (!wrapper) return;
692
693        currentStep = Math.max(1, currentStep - 2);
694
695        updateStepClass(wrapper);
696       }, 20);
697       document.getElementById("wrapper-lensadvisor-jtpl").classList.remove("review-page");
698       document.addEventListener('LensAdvizor:prescriptionTypes:rendered', function () {
699        // document.querySelector(".la-footer-frame-prescription.value1").textContent = `—`;
700        document.querySelector(".la-footer-frame-prescription.value3").textContent = `—`;
701        document.querySelector(".prescription-value-1").classList.add("hide-prescription");
702        document.querySelector(".prescription-value-9").classList.add("hide-prescription");
703        nextDay = true;
704       });
705       document.addEventListener('LensAdvizor:render:submissionMethods', function() {
706        // document.querySelector(".la-footer-frame-prescription.value2").textContent = `—`;
707        document.querySelector(".prescription-value-2").classList.add("hide-prescription");
708       });
709       document.addEventListener('LensAdvizor:lens:rendered', function(e) {
710        if (e.detail.method == 'renderLensGroup') {
711          // document.querySelector(".la-footer-frame-prescription.value3").textContent = `—`;
712          document.querySelector(".prescription-value-3").classList.add("hide-prescription");
713
714          // document.querySelector(".la-footer-frame-prescription.value4").textContent = `—`;
715           document.querySelector(".prescription-value-4").classList.add("hide-prescription");
716
717          //  document.querySelector(".la-footer-frame-prescription.value5").textContent = `—`;
718         document.querySelector(".prescription-value-5").classList.add("hide-prescription");
719
720        //  document.querySelector(".la-footer-frame-prescription.value6").textContent = `—`;
721        document.querySelector(".prescription-value-6").classList.add("hide-prescription");
722
723        // document.querySelector(".la-footer-frame-prescription.value7").textContent = `—`;
724        document.querySelector(".prescription-value-7").classList.add("hide-prescription");
725
726        // document.querySelector(".la-footer-frame-prescription.value8").textContent = `—`;
727        document.querySelector(".prescription-value-8").classList.add("hide-prescription");
728        document.querySelector(".prescription-value-9").classList.add("hide-prescription");
729        }
730        if (e.detail.method == 'renderLenses') {
731          //  document.querySelector(".la-footer-frame-prescription.value4").textContent = `—`;
732           document.querySelector(".prescription-value-4").classList.add("hide-prescription");
733
734          //  document.querySelector(".la-footer-frame-prescription.value5").textContent = `—`;
735         document.querySelector(".prescription-value-5").classList.add("hide-prescription");
736
737        //  document.querySelector(".la-footer-frame-prescription.value6").textContent = `—`;
738        document.querySelector(".prescription-value-6").classList.add("hide-prescription");
739
740        // document.querySelector(".la-footer-frame-prescription.value7").textContent = `—`;
741        document.querySelector(".prescription-value-7").classList.add("hide-prescription");
742
743        // document.querySelector(".la-footer-frame-prescription.value8").textContent = `—`;
744        document.querySelector(".prescription-value-8").classList.add("hide-prescription");
745        document.querySelector(".prescription-value-9").classList.remove("hide-prescription");
746        }
747       });
748       document.addEventListener('LensAdvizor:lensOption1:rendered', function() {
749        //  document.querySelector(".la-footer-frame-prescription.value5").textContent = `—`;
750         document.querySelector(".prescription-value-5").classList.add("hide-prescription");
751
752        //  document.querySelector(".la-footer-frame-prescription.value6").textContent = `—`;
753        document.querySelector(".prescription-value-6").classList.add("hide-prescription");
754
755        // document.querySelector(".la-footer-frame-prescription.value7").textContent = `—`;
756        document.querySelector(".prescription-value-7").classList.add("hide-prescription");
757
758        // document.querySelector(".la-footer-frame-prescription.value8").textContent = `—`;
759        document.querySelector(".prescription-value-8").classList.add("hide-prescription");
760        document.querySelector(".prescription-value-9").classList.remove("hide-prescription");
761       });
762       document.addEventListener('LensAdvizor:lensOption2:rendered', function() {
763        // document.querySelector(".la-footer-frame-prescription.value6").textContent = `—`;
764        document.querySelector(".prescription-value-6").classList.add("hide-prescription");
765
766        // document.querySelector(".la-footer-frame-prescription.value7").textContent = `—`;
767        document.querySelector(".prescription-value-7").classList.add("hide-prescription");
768
769        // document.querySelector(".la-footer-frame-prescription.value8").textContent = `—`;
770        document.querySelector(".prescription-value-8").classList.add("hide-prescription");
771        document.querySelector(".prescription-value-9").classList.remove("hide-prescription");
772       });
773       document.addEventListener('LensAdvizor:lensOption3:rendered', function() {
774        // document.querySelector(".la-footer-frame-prescription.value7").textContent = `—`;
775        document.querySelector(".prescription-value-7").classList.add("hide-prescription");
776
777        // document.querySelector(".la-footer-frame-prescription.value8").textContent = `—`;
778        document.querySelector(".prescription-value-8").classList.add("hide-prescription");
779        document.querySelector(".prescription-value-9").classList.remove("hide-prescription");
780       });
781       document.addEventListener('LensAdvizor:addOns:rendered', function() {
782        //  document.querySelector(".la-footer-frame-prescription.value8").textContent = `—`;
783         document.querySelector(".prescription-value-8").classList.add("hide-prescription");
784         document.querySelector(".prescription-value-9").classList.remove("hide-prescription");
785       });
786
787
788    }
789    if (e.target.matches('.la-prescription-modal-close')) {
790        currentStep = 0;
791        summary = false;
792        lensPrice = false;
793         LensAdvizor.prevSelections = {};
794         selectedlens = false;
795
796        const wrapper = document.getElementById("wrapper-lensadvisor-jtpl");
797        if (wrapper) {
798            wrapper.remove();
799        }
800    }
801    // if (e.target.matches('.la-skip-add-on')) {
802    //   document.querySelector(".prescription-value-8").classList.add("hide-prescription"); 
803    // }
804
805});
806//*********************** Your Build summary and add step class end *******************************/ 
807
808//*********************** Add currency symbol for lens start *******************************/ 
809let lensPrice = false;
810let lensPriceDiv;
811document.addEventListener('LensAdvizor:lensOptions:rendered', function() {
812  if(lensPrice == false){
813    var currency = document.body.getAttribute('theme-currency');
814    lensPrice = true;
815    if(window.outerWidth >= 768){
816    lensPriceDiv = document.querySelector(
817          '.fe-flow-jtpl .la-footer-row-wrapper:nth-of-type(4):not(.la-d-none) .la-footer-lens-price'
818        );
819      } else{
820        lensPriceDiv = document.querySelector(
821          '.fe-flow-jtpl .la-footer-row-wrapper:nth-of-type(5):not(.la-d-none) .la-footer-lens-price'
822        );
823      }
824        if (lensPriceDiv) {
825          const hasCurrencyelement = document.querySelector('.currency-symbol');
826          if(!hasCurrencyelement){
827            lensPriceDiv.insertAdjacentHTML(
828              'beforebegin',
829              `<div class="currency-symbol">${currency}</div>`
830            );
831          }
832        }
833    }
834    var discount = false;
835    if(discount == true){
836      document.querySelector(".discount-summary-cart").classList.remove("hide-summary");
837    }
838});
839//*********************** Add currency symbol for lens end *******************************/ 
840
841//*********************** Update value for Used For start *******************************/ 
842document.addEventListener('LensAdvizor:prescriptionTypes:rendered', function () {
843  // hiddenInputTextt = `
844  //     <input id="hiddenTryOnProperty" type="hidden" name='la-properties[_modelcode]' value="true" >
845  //   `
846  //   wrapperr = document.querySelector('.la-prescription-modal-wrapper')
847  //   wrapperr.insertAdjacentHTML('beforeend', hiddenInputTextt)    
848document.querySelector(".la-prescription-modal-content-body").classList.remove("la-render-addons-jtpl");
849  document.querySelector(".la-prescription-modal-content-body").classList.remove("la-render-group");
850  document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
851    el.addEventListener("click", function () {
852        const text = this.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
853            document.querySelector(".la-footer-frame-prescription.value1").textContent = text;
854            document.querySelector(".prescription-value-1").classList.remove("hide-prescription");
855        });
856  });
857      setInterval(() => {
858        const priceText = document
859          .querySelector(".la-footer-row.la-subtotal .la-subtotal-price")
860          ?.textContent.trim();
861
862        const price = priceText
863          ?.replace(/[^\d.]/g, "")
864          .replace(".", "");
865
866        const elements = document.querySelectorAll("[data-purchase-amount]");
867
868          if (price) {
869            elements.forEach((element) => {
870              element.setAttribute("data-purchase-amount", price);
871            });
872          }
873         const klarnaElements = document.querySelectorAll("#wrapper-lensadvisor-jtpl klarna-placement");
874
875        klarnaElements.forEach((klarnaElement) => {
876          const shadowRoot = klarnaElement.shadowRoot;
877
878          if (!shadowRoot) return;
879
880          // Style sirf ek baar add hogi har shadowRoot me
881          if (!shadowRoot.querySelector("#klarna-custom-style")) {
882            const style = document.createElement("style");
883            style.id = "klarna-custom-style";
884            style.textContent = `
885                  .container {
886                    flex-direction: row-reverse !important;
887                    background: transparent !important; 
888                    border: 0 !important;
889                    padding: 0 !important;
890                    justify-content: flex-end !important;
891                    position: relative;
892                  }
893                  .container.order-summary-klarna{
894                    justify-content: center !important;
895                  }
896                  .container button.link {
897                    position: absolute;
898                    inset: 0;
899                    width: 100%;
900                    height: auto;
901                    font-size: 0;
902                  }
903                  .container .text-wrapper p.legal{
904                    display:none !important;
905                  }
906                  .container .text-wrapper {
907                    margin-left: 0;
908                    color: #8a857d;
909                    font-size: 12px;
910                    line-height: normal;
911                    margin-right: 3px;
912                  }
913                  .container .text-wrapper strong {
914                    font-weight: normal;
915                  }
916                  .container .badge svg {
917                    height: 18px;
918                    width: 40px;
919                    // transform: translateY(1px);
920                  }
921                  @media (max-width: 1140px) {
922                    .container .text-wrapper {
923                      font-size: 10px;
924                    }
925                  }
926                  @media (max-width: 994px) {
927                    .container .text-wrapper {
928                      font-size: 8.5px;
929                    }
930                  }
931                  @media (max-width: 767px) {
932                   .desktop-klarna .container {
933                      justify-content: center !important;
934                    }
935                    .container .text-wrapper {
936                      font-size: 11px;
937                    }
938                  }
939                `;
940
941                klarnaElement.shadowRoot.appendChild(style);
942            }
943          });
944      }, 10);
945      if(document.querySelector(".la-progress-bar-step")){
946        document.querySelector(".la-progress-bar-step").textContent = "Step 1 of 8";
947      }else{
948        document.querySelector(".la-progress-bar.la-transparent-bg").insertAdjacentHTML(
949            'afterend', `<div class="la-progress-bar-step">Step 1 of 8</div>`);
950      }
951
952      if(EnableDescription == true){
953        const description1 = `Choose Your Prescription Type`;
954        document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
955              'afterend', `<p class="la-prescription-description text-center">${description1}</p>`
956        );
957      }
958      if(EnableTitle == true){
959        const title1 = `What are you using your glasses for?`;
960        if(title1 != ''){
961          document.getElementById("la_prescriptionSelect_title").textContent = title1;
962        }
963      }
964      
965});
966//*********************** Update value for Used For end *******************************/ 
967
968//*********************** Update value for Method start *******************************/ 
969var submissionMethods = false;
970document.addEventListener('LensAdvizor:render:submissionMethods', function() {
971  document.getElementById("wrapper-lensadvisor-jtpl").classList.remove("upload-page");
972  document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
973    el.addEventListener("click", function () {
974        const text = this.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
975        let cleanedTextt = text;
976          if(cleanedTextt.includes('Email') || cleanedTextt.includes('email')){
977            cleanedTextt = "Email Later";
978          }
979            document.querySelector(".la-footer-frame-prescription.value2").textContent = cleanedTextt;
980            document.querySelector(".prescription-value-2").classList.remove("hide-prescription");
981        });
982  });
983    setInterval(() => {
984  const priceText = document
985    .querySelector(".la-footer-row.la-subtotal .la-subtotal-price")
986    ?.textContent.trim();
987
988  const price = priceText
989    ?.replace(/[^\d.]/g, "")
990    .replace(".", "");
991
992  const elements = document.querySelectorAll("[data-purchase-amount]");
993
994  if (price) {
995    elements.forEach((element) => {
996      element.setAttribute("data-purchase-amount", price);
997    });
998  }
999  const klarnaElements = document.querySelectorAll("#wrapper-lensadvisor-jtpl klarna-placement");
1000
1001        klarnaElements.forEach((klarnaElement) => {
1002          const shadowRoot = klarnaElement.shadowRoot;
1003
1004          if (!shadowRoot) return;
1005
1006          // Style sirf ek baar add hogi har shadowRoot me
1007          if (!shadowRoot.querySelector("#klarna-custom-style")) {
1008            const style = document.createElement("style");
1009            style.id = "klarna-custom-style";
1010            style.textContent = `
1011                  .container {
1012                    flex-direction: row-reverse !important;
1013                    background: transparent !important;
1014                    border: 0 !important;
1015                    padding: 0 !important;
1016                    justify-content: flex-end !important;
1017                    position: relative;
1018                  }
1019                  .container.order-summary-klarna{
1020                    justify-content: center !important;
1021                  }
1022                  .container button.link {
1023                    position: absolute;
1024                    inset: 0;
1025                    width: 100%;
1026                    height: auto;
1027                    font-size: 0;
1028                  }
1029                  .container .text-wrapper p.legal{
1030                    display:none !important;
1031                  }
1032                  .container .text-wrapper {
1033                    margin-left: 0;
1034                    color: #8a857d;
1035                    font-size: 12px;
1036                    line-height: normal;
1037                    margin-right: 3px;
1038                  }
1039                  .container .text-wrapper strong {
1040                    font-weight: normal;
1041                  }
1042                  .container .badge svg {
1043                    height: 18px;
1044                    width: 40px;
1045                    // transform: translateY(1px);
1046                  }
1047                  @media (max-width: 1140px) {
1048                    .container .text-wrapper {
1049                      font-size: 10px;
1050                    }
1051                  }
1052                  @media (max-width: 994px) {
1053                    .container .text-wrapper {
1054                      font-size: 8.5px;
1055                    }
1056                  }
1057                  @media (max-width: 767px) {
1058                   .desktop-klarna .container {
1059                      justify-content: center !important;
1060                    }
1061                    .container .text-wrapper {
1062                      font-size: 11px;
1063                    }
1064                  }
1065                `;
1066
1067                klarnaElement.shadowRoot.appendChild(style);
1068            }
1069          });
1070}, 10);
1071document.querySelector(".la-progress-bar-step").textContent = "Step 2 of 8";
1072
1073    if(EnableDescription == true){
1074      const description2 = `Do it now, or check out and send it later — whatever’s easiest.`;
1075      document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
1076            'afterend', `<p class="la-prescription-description text-center">${description2}</p>`
1077      );
1078    }
1079    if(EnableTitle == true){
1080      const title2 = ``;
1081      if(title2 != ''){
1082        document.getElementById("la_prescriptionSelect_title").textContent = title2;
1083      }
1084    }
1085  submissionMethods = true;
1086  setTimeout(function(){
1087    const valueDelivery = document.querySelector(".summary-prescription-title.value-option.value9").textContent;
1088    document.getElementById("nextdayProperty").value = valueDelivery;
1089    if (window.LensAdvizor) {
1090        if (!window.LensAdvizor.customFieldData) {
1091            window.LensAdvizor.customFieldData = {};
1092        }
1093        window.LensAdvizor.customFieldData["Delivery"] = valueDelivery;
1094    }
1095  }, 10);
1096});
1097//*********************** Update value for Method end *******************************/ 
1098
1099document.addEventListener('LensAdvizor:lens:rendered', function(e) {
1100  console.log(e.detail.method);
1101  if (e.detail.method == 'renderHeaderLenses') {
1102      document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
1103        el.addEventListener("click", function () {
1104            const text = this.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
1105                document.querySelector(".la-footer-frame-prescription.value4").textContent = text;
1106
1107                if(EnableDiscount == false){
1108                  let OrignalpriceBox;
1109                    OrignalpriceBox = this.querySelector(".la-label-price").textContent;
1110                  //  console.log(OrignalpriceBox);
1111                  if (OrignalpriceBox !== null && OrignalpriceBox !== undefined && OrignalpriceBox !== ""){
1112                    document.querySelector(".la-footer-frame-prescription.value4").setAttribute("new-price", OrignalpriceBox);
1113                  }
1114                } else{
1115                  const priceRow = this.querySelector(".la-label-price .price-box");
1116                  if (priceRow) {
1117                      document.querySelector(".la-footer-frame-prescription.value4").setAttribute("new-price", priceRow.outerHTML);
1118                    }
1119                }
1120                document.querySelector(".prescription-value-4").classList.remove("hide-prescription");
1121            });
1122      });
1123  }
1124
1125    if (e.detail.method == 'renderLensGroup') {
1126      document.querySelector(".la-prescription-modal-content-body").classList.add("la-render-group");
1127      document.querySelector(".la-prescription-modal-content-body").classList.remove("la-render-products");
1128        document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
1129          el.addEventListener("click", function () {
1130              const text = this.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
1131                  document.querySelector(".la-footer-frame-prescription.value3").textContent = text;
1132
1133                    document.querySelector(".prescription-value-3").classList.remove("hide-prescription");
1134                  
1135              });
1136        });
1137          setInterval(() => {
1138            const priceText = document
1139              .querySelector(".la-footer-row.la-subtotal .la-subtotal-price")
1140              ?.textContent.trim();
1141
1142            const price = priceText
1143              ?.replace(/[^\d.]/g, "")
1144              .replace(".", "");
1145
1146            const elements = document.querySelectorAll("[data-purchase-amount]");
1147
1148          if (price) {
1149            elements.forEach((element) => {
1150              element.setAttribute("data-purchase-amount", price);
1151            });
1152          }
1153            const klarnaElements = document.querySelectorAll("#wrapper-lensadvisor-jtpl klarna-placement");
1154
1155        klarnaElements.forEach((klarnaElement) => {
1156          const shadowRoot = klarnaElement.shadowRoot;
1157
1158          if (!shadowRoot) return;
1159
1160          // Style sirf ek baar add hogi har shadowRoot me
1161          if (!shadowRoot.querySelector("#klarna-custom-style")) {
1162            const style = document.createElement("style");
1163            style.id = "klarna-custom-style";
1164            style.textContent = `
1165                  .container {
1166                    flex-direction: row-reverse !important;
1167                    background: transparent !important;
1168                    border: 0 !important;
1169                    padding: 0 !important;
1170                    justify-content: flex-end !important;
1171                    position: relative;
1172                  }
1173                  .container.order-summary-klarna{
1174                    justify-content: center !important;
1175                  }
1176                  .container button.link {
1177                    position: absolute;
1178                    inset: 0;
1179                    width: 100%;
1180                    height: auto;
1181                    font-size: 0;
1182                  }
1183                  .container .text-wrapper p.legal{
1184                    display:none !important;
1185                  }
1186                  .container .text-wrapper {
1187                    margin-left: 0;
1188                    color: #8a857d;
1189                    font-size: 12px;
1190                    line-height: normal;
1191                    margin-right: 3px;
1192                  }
1193                  .container .text-wrapper strong {
1194                    font-weight: normal;
1195                  }
1196                  .container .badge svg {
1197                    height: 18px;
1198                    width: 40px;
1199                    // transform: translateY(1px);
1200                  }
1201                  @media (max-width: 1140px) {
1202                    .container .text-wrapper {
1203                      font-size: 10px;
1204                    }
1205                  }
1206                  @media (max-width: 994px) {
1207                    .container .text-wrapper {
1208                      font-size: 8.5px;
1209                    }
1210                  }
1211                  @media (max-width: 767px) {
1212                   .desktop-klarna .container {
1213                      justify-content: center !important;
1214                    }
1215                    .container .text-wrapper {
1216                      font-size: 11px;
1217                    }
1218                  }
1219                `;
1220
1221                klarnaElement.shadowRoot.appendChild(style);
1222            }
1223          });
1224          }, 10);
1225
1226          if(submissionMethods == false){
1227            document.querySelector(".la-progress-bar-step").textContent = "Step 2 of 7";
1228          }else{
1229            document.querySelector(".la-progress-bar-step").textContent = "Step 3 of 8";
1230          }
1231
1232          if(EnableDescription == true){
1233            const description5 = `Choose Lens Group`;
1234            document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
1235                  'afterend', `<p class="la-prescription-description text-center">${description5}</p>`
1236            );
1237          }
1238          if(EnableTitle == true){
1239          const title5 = `How should your lenses behave in light?`;
1240          if(title5 != ''){
1241           document.getElementById("la_prescriptionSelect_title").textContent = title5;
1242          }
1243        }
1244        if(document.body.classList.contains("glasses-jtpl")){
1245
1246  // Only inject once — don't re-insert on every render
1247  if (!document.querySelector(".sunglasses-options")) {
1248
1249    const lensGroup = document.querySelectorAll(".la-label-btn-wrapper");
1250    lensGroup[lensGroup.length - 1].insertAdjacentHTML("afterend", `<div class="la-label-btn-wrapper  la-horizontal-boxy-label-wrapper sunglasses-options">
1251                <label class="la-label-btn sunglasses-options">
1252                    <div class="la-label-image-wapper">
1253                    <div class="la-label-image">
1254                        <img src="https://cdn.shopify.com/s/files/1/0522/1610/3083/files/frame-sunglasses.png?v=1788427251" alt="Sunglasses" loading="lazy" srcset="https://cdn.shopify.com/s/files/1/0522/1610/3083/files/frame-sunglasses.png?v=1788427251 60w,https://cdn.shopify.com/s/files/1/0522/1610/3083/files/frame-sunglasses.png?v=1788427251 90w,https://cdn.shopify.com/s/files/1/0522/1610/3083/files/frame-sunglasses.png?v=1788427251 45w" sizes="(max-width: 710px) 90px,(max-width: 475px) 45px,60px">
1255                    </div>
1256                    </div>
1257                    <div class="la-label-content-box">
1258                        <div class="la-label-title">
1259                            <la-translate data-la-translate-as="span" style="display: contents;">Sunglasses Options</la-translate>
1260                        </div>
1261                        <div class="la-label-description">
1262                            <la-translate data-la-translate-as="span" style="display: contents;">Prescription sunglasses from a clear frame.</la-translate>
1263                        </div>
1264                    </div>
1265                </label>
1266            </div>
1267
1268            <div class="la-label-btn-wrapper  la-horizontal-boxy-label-wrapper glasses-options" style="display: none;">
1269                <label class="la-label-btn glasses-options">
1270                    <div class="la-label-image-wapper">
1271                    <div class="la-label-image">
1272                        <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" alt="Glasses" loading="lazy" srcset="https://cdn.shopify.com/s/files/1/0601/9045/8085/files/Glasses_fc64d67e-8ba2-46aa-b2f2-e3e565531213.jpg?v=1784360449 60w,https://cdn.shopify.com/s/files/1/0601/9045/8085/files/Glasses_fc64d67e-8ba2-46aa-b2f2-e3e565531213.jpg?v=1784360449 90w,https://cdn.shopify.com/s/files/1/0601/9045/8085/files/Glasses_fc64d67e-8ba2-46aa-b2f2-e3e565531213.jpg?v=1784360449 45w" sizes="(max-width: 710px) 90px,(max-width: 475px) 45px,60px">
1273                    </div>
1274                    </div>
1275                    <div class="la-label-content-box">
1276                        <div class="la-label-title">
1277                            <la-translate data-la-translate-as="span" style="display: contents;">Glasses Options</la-translate>
1278                        </div>
1279                        <div class="la-label-description">
1280                            <la-translate data-la-translate-as="span" style="display: contents;">Prescription glasses.</la-translate>
1281                        </div>
1282                    </div>
1283                </label>
1284            </div>`);
1285
1286    const sunglassesBtn = document.querySelector(".sunglasses-options");
1287    const glassesBtn = document.querySelector(".glasses-options");
1288
1289    sunglassesBtn.addEventListener("click", function (e) {
1290      e.preventDefault();
1291      this.style.display = "none";
1292
1293      const backButton = document.querySelector(".la-steeper-back");
1294      if (backButton) {
1295        backButton.style.display = "none";
1296        // Don't create a duplicate back-glasses button if one already exists
1297        if (!document.querySelector(".back-glasses")) {
1298          backButton.insertAdjacentHTML('afterend', `<button class="la-steeper-back back-glasses" aria-label="Back"></button>`);
1299        }
1300      }
1301
1302      const showLenses = ["Full Tint", "Gradient", "Polarised", "Mirror"];
1303      const hideLenses = ["Clear", "Light Sensitive"];
1304      document.querySelectorAll(".la-label-btn-wrapper").forEach(item => {
1305        const title = item.querySelector(".la-label-title")?.textContent.trim() || "";
1306        if (showLenses.some(l => title.includes(l))){
1307           item.style.display = "block";
1308           item.classList.add("show-lenses");
1309        }
1310        if (hideLenses.some(l => title.includes(l))){
1311           item.style.display = "none";
1312           item.classList.remove("show-lenses");
1313        }
1314      });
1315
1316      const backGlasses = document.querySelector(".back-glasses");
1317      if (backGlasses) {
1318        backGlasses.addEventListener("click", function () {
1319          const glassesOptions = document.querySelector(".glasses-options");
1320          if (glassesOptions) glassesOptions.click();   // ← guarded now
1321          this.remove();
1322          const backBtn = document.querySelector(".la-steeper-back");
1323          if (backBtn) backBtn.style.display = "block";
1324        });
1325      }
1326    });
1327
1328    if (glassesBtn) {
1329      glassesBtn.addEventListener("click", function (e) {
1330        e.preventDefault();
1331        this.style.display = "none";
1332        const sunglasses = document.querySelector(".sunglasses-options");
1333        if (sunglasses) sunglasses.style.display = "block";
1334
1335        const hideLenses = ["Full Tint", "Gradient", "Polarised", "Mirror"];
1336        const showLenses = ["Clear", "Light Sensitive"];
1337        document.querySelectorAll(".la-label-btn-wrapper").forEach(item => {
1338          const title = item.querySelector(".la-label-title")?.textContent.trim() || "";
1339          if (showLenses.some(l => title.includes(l))){
1340             item.style.display = "block";
1341             item.classList.add("show-lenses");
1342          }
1343          if (hideLenses.some(l => title.includes(l))){
1344             item.style.display = "none";
1345             item.classList.remove("show-lenses");
1346          }
1347        });
1348      }); 
1349    }
1350     const lensType = document.querySelector(".la-footer-frame-prescription.value3").textContent;
1351      const lenstitles = ["Full Tint","Gradient","Polarised", "Mirror"];
1352        setTimeout(()=> {
1353          if (lenstitles.includes(lensType)) {
1354                document.querySelector(".sunglasses-options").click();
1355            }
1356        }, 50);
1357  }
1358}
1359
1360  //************************  money format for fashion lens group  start  *****************************// 
1361    const isocurrency = document.body.getAttribute('current-isocode');
1362    // Market-specific rounding config
1363    const marketRounding = {
1364      // EUR markets — charm pricing (.95 endings, roll up)
1365      EUR: { nearest: 0.95, strategy: 'ceil' },  // Austria, Belgium, Cyprus, Germany, Estonia, Spain,
1366                                                  // Finland, Bulgaria, Eurozone, France, Ireland,
1367                                                  // Netherlands, Italy
1368    
1369      // GBP markets — base currency, no conversion needed
1370      GBP: { nearest: 1,    strategy: 'round' }, // United Kingdom, Croatia, Kuwait, Bahrain
1371    
1372      // USD
1373      USD: { nearest: 1,    strategy: 'ceil' },
1374    
1375      // Middle East
1376      SAR: { nearest: 1,    strategy: 'ceil' },  // Saudi Arabia
1377      AED: { nearest: 1,    strategy: 'ceil' },  // UAE
1378      QAR: { nearest: 1,    strategy: 'ceil' },  // Qatar
1379    
1380      // Oceania
1381      AUD: { nearest: 1,    strategy: 'ceil' },  // Australia
1382      NZD: { nearest: 1,    strategy: 'ceil' },  // New Zealand
1383    
1384      // Asia-Pacific
1385      SGD: { nearest: 1,    strategy: 'ceil' },  // Singapore
1386      HKD: { nearest: 1,    strategy: 'ceil' },  // Hong Kong SAR
1387      BND: { nearest: 1,    strategy: 'ceil' },  // Brunei
1388      THB: { nearest: 1,    strategy: 'ceil' },  // Thailand
1389      MYR: { nearest: 1,    strategy: 'ceil' },  // (International fallback)
1390      CNY: { nearest: 1,    strategy: 'ceil' },  // China
1391      JPY: { nearest: 100,  strategy: 'ceil' },  // Japan
1392      KRW: { nearest: 1000, strategy: 'ceil' },  // South Korea
1393      IDR: { nearest: 1000, strategy: 'ceil' },  // Indonesia
1394      VND: { nearest: 1000, strategy: 'ceil' },  // Vietnam
1395      INR: { nearest: 100,  strategy: 'ceil' },  // India/Zambia
1396    
1397      // Europe (non-EUR)
1398      CAD: { nearest: 0.9,  strategy: 'ceil' },  // Canada
1399      CHF: { nearest: 1,    strategy: 'ceil' },  // Switzerland
1400      SEK: { nearest: 1,    strategy: 'ceil' },  // Sweden
1401      NOK: { nearest: 1,    strategy: 'ceil' },  // Norway
1402      DKK: { nearest: 1,    strategy: 'ceil' },  // Denmark
1403      PLN: { nearest: 1,    strategy: 'ceil' },  // Poland
1404      CZK: { nearest: 1,    strategy: 'ceil' },  // Czechia
1405      HUF: { nearest: 100,  strategy: 'ceil' },  // Hungary
1406      RON: { nearest: 1,    strategy: 'ceil' },  // Romania
1407      TRY: { nearest: 1,    strategy: 'ceil' },  // Turkey
1408      ILS: { nearest: 0.9,  strategy: 'ceil' },  // Israel
1409    
1410      // Other
1411      ZAR: { nearest: 1,    strategy: 'ceil' },  // South Africa
1412      MUR: { nearest: 1,    strategy: 'ceil' },  // Mauritius
1413      ISK: { nearest: 100,  strategy: 'ceil' },  // Iceland
1414      KZT: { nearest: 100,  strategy: 'ceil' },  // Kazakhstan
1415      LBP: { nearest: 1000, strategy: 'ceil' },  // Lebanon
1416    };
1417
1418    
1419    function roundPrice(price, currency) {
1420      const config = marketRounding[currency] || { nearest: 0.01, strategy: 'round' };
1421      const { nearest, strategy } = config;
1422    
1423      if (nearest === 0.95) {
1424        // Charm pricing: round to nearest whole then subtract 0.05
1425        const base = Math.ceil(price);
1426        return base - 0.05;
1427      }
1428    
1429      const factor = 1 / nearest;
1430      switch (strategy) {
1431        case 'ceil':  return Math.ceil(price * factor) / factor;
1432        case 'floor': return Math.floor(price * factor) / factor;
1433        case 'round':
1434        default:      return Math.round(price * factor) / factor;
1435      }
1436    }
1437    
1438    document.querySelectorAll(".la-label-price.money").forEach(price => {
1439      const gbpPrice = parseFloat(price.textContent.replace(/[^\d.]/g, ""));
1440      const convertedPrice = gbpPrice * Number(Shopify.currency.rate);
1441      const finalPrice = roundPrice(convertedPrice, isocurrency);
1442    
1443      price.textContent = `${Symbolcurrency}${finalPrice.toFixed(2)}`;
1444    });
1445  //************************  money format for fashion lens group  end  *****************************// 
1446document.querySelector(".la-prescription-modal-content-body").classList.remove("la-render-addons-jtpl");
1447const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
1448  if(USEDFOR.includes("Fashion")){
1449    document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
1450    document.querySelector(".prescription-value-9").classList.remove("hide-prescription");
1451  }
1452    }
1453
1454    if (e.detail.method == 'renderLenses' || e.detail.method == 'renderHeaderLenses') {
1455
1456      setTimeout(function(){
1457        document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
1458            btn.addEventListener('click', function () {
1459                const contentWrapper = this.querySelector('.la-label-content-wrapper');
1460                if (contentWrapper?.querySelector('.delivery-badge')) {
1461                    nextDay = true;
1462                    document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
1463                }else{
1464                    nextDay = false;
1465                    const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
1466                    const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
1467
1468                    if(USEDFOR.includes("Varifocal")){
1469                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
1470                    } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
1471                      document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
1472                    } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
1473                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
1474                    } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
1475                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
1476                    } else if(USEDFOR.includes("Ready Reader")){
1477                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
1478                    } else{
1479                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
1480                    }
1481                      
1482                }
1483            });
1484        });
1485        const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
1486        const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
1487          if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Varifocal") || USEDFOR.includes("Occupational") || USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised") || USEDFOR.includes("Ready Reader") || USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
1488              nextDay = false;
1489          }
1490
1491        if(nextDay == false){
1492          document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
1493              const delvbadge = btn.querySelector('.delivery-badge');
1494              if (delvbadge) {
1495                  delvbadge.remove();
1496                    if(USEDFOR.includes("Varifocal")){
1497                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
1498                    } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
1499                      document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
1500                    } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
1501                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
1502                    } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
1503                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
1504                    } else if(USEDFOR.includes("Ready Reader")){
1505                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
1506                    } else{
1507                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
1508                    }
1509              }
1510              if(USEDFOR.includes("Varifocal")){
1511                document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
1512              } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
1513                document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
1514              } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
1515                document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
1516              } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
1517                document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
1518              } else if(USEDFOR.includes("Ready Reader")){
1519                document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
1520              } else{
1521                document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
1522              }
1523          });
1524        }else{
1525          document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
1526        }
1527      }, 10);
1528
1529       document.querySelector(".prescription-value-4").classList.add("hide-prescription");
1530       document.querySelector(".prescription-value-9").classList.remove("hide-prescription");
1531      const element = document.querySelector(".back-glasses");
1532      if (element) {
1533          element.remove();
1534      }
1535      const backButton = document.querySelector(".la-steeper-back");
1536      backButton.style.display = "block";
1537
1538     const usedForValue = document.querySelector(".value-option.value1")?.textContent.trim().toLowerCase();
1539     const modalBody = document.querySelector(".la-prescription-modal-content-body");
1540     modalBody.classList.remove("la-render-group", "la-render-addons-jtpl", "la-render-products");
1541
1542     if (usedForValue && (usedForValue.includes("blue light") || usedForValue.includes("ready reader"))){
1543       modalBody.classList.add("la-render-addons-jtpl");
1544       document.getElementById("la_prescriptionSelect_title").textContent ="Add Protection & Extras";
1545       document.querySelector(".la-choose-prescription-wrapper").classList.add("la-render-addons-lens");
1546       setTimeout(()=> {
1547        const elements = document.querySelector(".la-prescription-description");
1548        if (elements) {
1549          elements.style.display = "none";
1550        }
1551      }, 50);
1552
1553      const addonTitles = [
1554        `Do you use computers and screens a lot? Add a blue-light coating.`,
1555        `Accidental damage cover for scratches or breakage.`,
1556        ``
1557      ];
1558
1559      document.querySelectorAll(".la-label-btn-wrapper").forEach(function (item, index) {
1560        const title = addonTitles[index];
1561
1562        if (title && !item.querySelector(".addon-title")) {
1563          item.insertAdjacentHTML(
1564            "afterbegin",
1565            `<div class="addon-title">${title}</div>`
1566          );     
1567        }
1568      });
1569
1570     } else {
1571       modalBody.classList.add("la-render-products");
1572     }
1573    
1574        setTimeout(function(){
1575        document.querySelectorAll(".la-label-btn-wrapper").forEach(wrapper => {
1576          const priceDiv = wrapper.querySelector(".la-label-price");
1577          if (priceDiv && !wrapper.querySelector(".la-btn-group")) {
1578              const btnGroup = document.createElement("div");
1579              btnGroup.className = "la-btn-group";
1580
1581              btnGroup.innerHTML = `
1582                  <div type="button" class="choose-btn selected">Selected ✓</div>
1583                  <div type="button" class="choose-btn">Choose</div>
1584              `;
1585
1586              // Insert after .la-label-price
1587              priceDiv.insertAdjacentElement("afterend", btnGroup);
1588          }
1589          if (document.querySelector(".la-render-addons-jtpl")) {
1590    document.querySelectorAll(".la-btn-group").forEach(group => {
1591        group.style.display = "none";
1592    });
1593}
1594        });
1595
1596        const divs = document.querySelectorAll(".la-label-image");
1597            if (divs.length > 1) {
1598              divs[1].closest(".la-label-image-wapper").classList.add("badge-image-content");
1599                divs[1].insertAdjacentHTML("beforeend", "<div class='hero-badge-outer'><span class='hero-badge'>OPTICIAN'S CHOICE</span></div>");
1600                if (document.querySelector(".la-render-addons-jtpl")) {
1601                    divs[1].querySelector(".hero-badge-outer")?.style.setProperty("display", "none");
1602                }
1603            }
1604
1605         }, 10);
1606        document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
1607          el.addEventListener("click", function () {
1608              const text = this.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
1609                  document.querySelector(".la-footer-frame-prescription.value4").textContent = text;
1610
1611                  if(EnableDiscount == false){
1612                    let OrignalpriceBox;
1613                     OrignalpriceBox = this.querySelector(".la-label-price").textContent;
1614                    //  console.log(OrignalpriceBox);
1615                    if (OrignalpriceBox !== null && OrignalpriceBox !== undefined && OrignalpriceBox !== ""){
1616                      document.querySelector(".la-footer-frame-prescription.value4").setAttribute("new-price", OrignalpriceBox);
1617                    }
1618                  } else{
1619                    const priceRow = this.querySelector(".la-label-price .price-box");
1620                    if (priceRow) {
1621                        document.querySelector(".la-footer-frame-prescription.value4").setAttribute("new-price", priceRow.outerHTML);
1622                      }
1623                  }
1624
1625                // const oldPrice = this.querySelector(".la-label-price .price-row .old-price")?.textContent.trim();
1626                // const newPrice = this.querySelector(".la-label-price .price-row .new-price")?.textContent.trim();
1627                // document.querySelector(".la-footer-frame-prescription.value4").setAttribute("old-price", oldPrice);
1628                
1629
1630                  document.querySelector(".prescription-value-4").
1630classList.remove("hide-prescription");
1631              });
1632        });
1633          setInterval(() => {
1634            const priceText = document
1635              .querySelector(".la-footer-row.la-subtotal .la-subtotal-price")
1636              ?.textContent.trim();
1637
1638            const price = priceText
1639              ?.replace(/[^\d.]/g, "")
1640              .replace(".", "");
1641
1642            const elements = document.querySelectorAll("[data-purchase-amount]");
1643
1644          if (price) {
1645            elements.forEach((element) => {
1646              element.setAttribute("data-purchase-amount", price);
1647            });
1648          }
1649            const klarnaElements = document.querySelectorAll("#wrapper-lensadvisor-jtpl klarna-placement");
1650
1651        klarnaElements.forEach((klarnaElement) => {
1652          const shadowRoot = klarnaElement.shadowRoot;
1653
1654          if (!shadowRoot) return;
1655
1656          // Style sirf ek baar add hogi har shadowRoot me
1657          if (!shadowRoot.querySelector("#klarna-custom-style")) {
1658            const style = document.createElement("style");
1659            style.id = "klarna-custom-style";
1660            style.textContent = `
1661                  .container {
1662                    flex-direction: row-reverse !important;
1663                    background: transparent !important;
1664                    border: 0 !important;
1665                    padding: 0 !important;
1666                    justify-content: flex-end !important;
1667                    position: relative;
1668                  }
1669                  .container.order-summary-klarna{
1670                    justify-content: center !important;
1671                  }
1672                  .container button.link {
1673                    position: absolute;
1674                    inset: 0;
1675                    width: 100%;
1676                    height: auto;
1677                    font-size: 0;
1678                  }
1679                  .container .text-wrapper p.legal{
1680                    display:none !important;
1681                  }
1682                  .container .text-wrapper {
1683                    margin-left: 0;
1684                    color: #8a857d;
1685                    font-size: 12px;
1686                    line-height: normal;
1687                    margin-right: 3px;
1688                  }
1689                  .container .text-wrapper strong {
1690                    font-weight: normal;
1691                  }
1692                  .container .badge svg {
1693                    height: 18px;
1694                    width: 40px;
1695                    // transform: translateY(1px);
1696                  }
1697                  @media (max-width: 1140px) {
1698                    .container .text-wrapper {
1699                      font-size: 10px;
1700                    }
1701                  }
1702                  @media (max-width: 994px) {
1703                    .container .text-wrapper {
1704                      font-size: 8.5px;
1705                    }
1706                  }
1707                  @media (max-width: 767px) {
1708                   .desktop-klarna .container {
1709                      justify-content: center !important;
1710                    }
1711                    .container .text-wrapper {
1712                      font-size: 11px;
1713                    }
1714                  }
1715                `;
1716
1717                klarnaElement.shadowRoot.appendChild(style);
1718            }
1719          });
1720          }, 10);
1721          if(submissionMethods == false){
1722            document.querySelector(".la-progress-bar-step").textContent = "Step 3 of 7";
1723          }else{
1724            document.querySelector(".la-progress-bar-step").textContent = "Step 4 of 8";
1725          }
1726
1727        if(EnableDescription == true){
1728          const description6 = `Every package includes your lenses and coatings.`;
1729          document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
1730                'afterend', `<p class="la-prescription-description text-center">${description6}</p>`
1731          );
1732        }
1733        if(EnableTitle == true){
1734          const title6 = ``;
1735          if(title6 != ''){
1736           document.getElementById("la_prescriptionSelect_title").textContent = title6;
1737          }
1738        }
1739
1740        setTimeout(function () {
1741
1742          // if (Enablepreselect && Enablepreselect.trim() !== '') {
1743          //   const hasPrevSelected = document.querySelector(".la-label-btn-wrapper.la-prev-selected");
1744          //   if (!hasPrevSelected) {
1745          //       document.querySelectorAll(".la-label-btn-wrapper").forEach(wrapper => {
1746          //           const title = wrapper.querySelector(".la-label-title");
1747
1748          //           if (title && title.textContent.trim().toLowerCase().includes(Enablepreselect)) {
1749          //               wrapper.classList.add("la-prev-selected");
1750                        
1751          //           }
1752          //       });
1753          //   }
1754          // }
1755          if (Enablepreselect && Enablepreselect.trim() !== '') {
1756            const hasPrevSelected = document.querySelector(".la-label-btn-wrapper.la-prev-selected");
1757            if (!hasPrevSelected) {
1758                const wrappers = document.querySelectorAll(".la-label-btn-wrapper");
1759
1760                for (const wrapper of wrappers) {
1761                    const title = wrapper.querySelector(".la-label-title");
1762
1763                    if (title && title.textContent.trim().toLowerCase().includes(Enablepreselect)) {
1764                        wrapper.classList.add("la-prev-selected");
1765                        break;
1766                    }
1767                }
1768            }
1769          }
1770      }, 110);
1771    }   
1772
1773});
1774
1775document.addEventListener('LensAdvizor:lensOption1:rendered', function(e) {
1776  document.querySelector(".la-prescription-modal-content-body").classList.remove("la-render-addons-jtpl");
1777document.querySelector(".la-prescription-modal-content-body").classList.remove("la-render-products");
1778  const title = document.getElementById('la_prescriptionSelect_title').textContent.trim();
1779  
1780  const html = document.getElementById('la_prescriptionSelect_title').innerHTML;
1781    const div = document.createElement('div');
1782    div.innerHTML = html;
1783
1784    const text = [...div.childNodes]
1785        .filter(node => node.nodeType === Node.TEXT_NODE)
1786        .map(node => node.textContent.trim())
1787        .filter(Boolean)[0];
1788
1789    // console.log(text);
1790
1791    let cleanedText = text
1792    .toLowerCase()
1793    .replace(/\b(choose|your|lens|lenses|chose|additional)\b/g, "")
1794    .replace(/\s+/g, " ")
1795    .trim();
1796
1797    // console.log(cleanedText);
1798    if(cleanedText == "tint"){
1799      cleanedText = "Colour"
1800    } else if(cleanedText.includes('color') || cleanedText.includes('colour')){
1801      cleanedText = "Colour"
1802    } else if(cleanedText.includes('thickness')){
1803      cleanedText = "Thickness"
1804    } else if(cleanedText.includes('coating')){
1805      cleanedText = "Coating"
1806    } else if(cleanedText.includes('occupational')){
1807      cleanedText = "Occupational"
1808    }
1809
1810    document.querySelector(".prescription-heading-5").textContent = cleanedText;
1811
1812        document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
1813          el.addEventListener("click", function () {
1814              const text = this.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
1815                  document.querySelector(".la-footer-frame-prescription.value5").textContent = text;
1816
1817                  if(EnableDiscount == false){
1818                    let OrignalpriceBox;
1819                     OrignalpriceBox = this.querySelector(".la-label-price").textContent;
1820                    //  console.log(OrignalpriceBox);
1821                    if (OrignalpriceBox !== null && OrignalpriceBox !== undefined && OrignalpriceBox !== ""){
1822                      document.querySelector(".la-footer-frame-prescription.value5").setAttribute("new-price", OrignalpriceBox);
1823                    }
1824                  } else{
1825                   const priceRow = this.querySelector(".la-label-price .price-box");
1826                    if (priceRow) {
1827                        document.querySelector(".la-footer-frame-prescription.value5").setAttribute("new-price", priceRow.outerHTML);
1828                      }
1829                  }
1830
1831                  document.querySelector(".prescription-value-5").classList.remove("hide-prescription");
1832              });
1833        });
1834
1835          setInterval(() => {
1836            const priceText = document
1837              .querySelector(".la-footer-row.la-subtotal .la-subtotal-price")
1838              ?.textContent.trim();
1839
1840            const price = priceText
1841              ?.replace(/[^\d.]/g, "")
1842              .replace(".", "");
1843
1844            const elements = document.querySelectorAll("[data-purchase-amount]");
1845
1846          if (price) {
1847            elements.forEach((element) => {
1848              element.setAttribute("data-purchase-amount", price);
1849            });
1850          }
1851            const klarnaElements = document.querySelectorAll("#wrapper-lensadvisor-jtpl klarna-placement");
1852
1853        klarnaElements.forEach((klarnaElement) => {
1854          const shadowRoot = klarnaElement.shadowRoot;
1855
1856          if (!shadowRoot) return;
1857
1858          // Style sirf ek baar add hogi har shadowRoot me
1859          if (!shadowRoot.querySelector("#klarna-custom-style")) {
1860            const style = document.createElement("style");
1861            style.id = "klarna-custom-style";
1862            style.textContent = `
1863                  .container {
1864                    flex-direction: row-reverse !important;
1865                    background: transparent !important;
1866                    border: 0 !important;
1867                    padding: 0 !important;
1868                    justify-content: flex-end !important;
1869                    position: relative;
1870                  }
1871                  .container.order-summary-klarna{
1872                    justify-content: center !important;
1873                  }
1874                  .container button.link {
1875                    position: absolute;
1876                    inset: 0;
1877                    width: 100%;
1878                    height: auto;
1879                    font-size: 0;
1880                  }
1881                  .container .text-wrapper p.legal{
1882                    display:none !important;
1883                  }
1884                  .container .text-wrapper {
1885                    margin-left: 0;
1886                    color: #8a857d;
1887                    font-size: 12px;
1888                    line-height: normal;
1889                    margin-right: 3px;
1890                  }
1891                  .container .text-wrapper strong {
1892                    font-weight: normal;
1893                  }
1894                  .container .badge svg {
1895                    height: 18px;
1896                    width: 40px;
1897                    // transform: translateY(1px);
1898                  }
1899                  @media (max-width: 1140px) {
1900                    .container .text-wrapper {
1901                      font-size: 10px;
1902                    }
1903                  }
1904                  @media (max-width: 994px) {
1905                    .container .text-wrapper {
1906                      font-size: 8.5px;
1907                    }
1908                  }
1909                  @media (max-width: 767px) {
1910                   .desktop-klarna .container {
1911                      justify-content: center !important;
1912                    }
1913                    .container .text-wrapper {
1914                      font-size: 11px;
1915                    }
1916                  }
1917                `;
1918
1919                klarnaElement.shadowRoot.appendChild(style);
1920            }
1921          });
1922          }, 10);
1923          if(submissionMethods == false){
1924            document.querySelector(".la-progress-bar-step").textContent = "Step 4 of 7";
1925          } else{
1926            document.querySelector(".la-progress-bar-step").textContent = "Step 5 of 8";
1927          }
1928
1929          if(EnableDescription == true){
1930            if(cleanedText.includes('Colour')){
1931              const description7 = `All colours give the same protection — pick the look you love.`;
1932              document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
1933                    'afterend', `<p class="la-prescription-description text-center">${description7}</p>`
1934              );
1935            } else if(cleanedText.includes('Thickness')){
1936              const description8 = `Thinner lenses look slimmer and feel lighter. Stronger prescriptions benefit most.`;
1937              document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
1938                    'afterend', `<p class="la-prescription-description text-center">${description8}</p>`
1939              );
1940            } else{
1941              const description9 = ``;
1942              document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
1943                    'afterend', `<p class="la-prescription-description text-center">${description9}</p>`
1944              );
1945            }
1946          }
1947
1948          if(EnableTitle == true){
1949            if(cleanedText.includes('Colour')){
1950              const title7 = `Choose Your Colour for Lenses`;
1951              if(title7 != ''){
1952              document.getElementById("la_prescriptionSelect_title").textContent = title7;
1953              }
1954            } else if(cleanedText.includes('Thickness')){
1955              const title8 = `Lens Thickness`;
1956              if(title8 != ''){
1957              document.getElementById("la_prescriptionSelect_title").textContent = title8;
1958              }
1959            } else{
1960              const title9 = ``;
1961              if(title9 != ''){
1962                document.getElementById("la_prescriptionSelect_title").textContent = title9;
1963              }
1964            }
1965          }
1966
1967          setTimeout(function(){
1968            if(!cleanedText.includes('Colour')){
1969              document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
1970                  btn.addEventListener('click', function () {
1971                      const contentWrapper = this.querySelector('.la-label-content-wrapper');
1972                      if (contentWrapper?.querySelector('.delivery-badge')) {
1973                          nextDay = true;
1974                          document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
1975                      }else{
1976                          nextDay = false;
1977                          const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
1978                          const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
1979                          if(USEDFOR.includes("Varifocal")){
1980                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
1981                          } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
1982                            document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
1983                          } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
1984                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
1985                          } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
1986                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
1987                          } else if(USEDFOR.includes("Ready Reader")){
1988                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
1989                          } else{
1990                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
1991                          }
1992                            
1993                      }
1994                  });
1995              });
1996              const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
1997              const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
1998                if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Varifocal") || USEDFOR.includes("Occupational") || USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised") || USEDFOR.includes("Ready Reader") || USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
1999                    nextDay = false;
2000                }
2001
2002              if(nextDay == false){
2003                document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
2004                    const delvbadge = btn.querySelector('.delivery-badge');
2005                    if (delvbadge) {
2006                        delvbadge.remove();
2007                          if(USEDFOR.includes("Varifocal")){
2008                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2009                          } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2010                            document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2011                          } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2012                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2013                          } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2014                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2015                          } else if(USEDFOR.includes("Ready Reader")){
2016                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2017                          } else{
2018                            document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2019                          }
2020                    }
2021                    if(USEDFOR.includes("Varifocal")){
2022                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2023                    } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2024                      document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2025                    } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2026                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2027                    } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2028                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2029                    } else if(USEDFOR.includes("Ready Reader")){
2030                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2031                    } else{
2032                      document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2033                    }
2034                });
2035              }else{
2036                document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2037              }
2038            }
2039          }, 10);
2040
2041});
2042
2043document.addEventListener('LensAdvizor:lensOption2:rendered', function(e) {
2044   document.querySelector(".la-prescription-modal-content-body").classList.remove("la-render-addons-jtpl");
2045  const html = document.getElementById('la_prescriptionSelect_title').innerHTML;
2046    const div = document.createElement('div');
2047    div.innerHTML = html;
2048
2049    const text = [...div.childNodes]
2050        .filter(node => node.nodeType === Node.TEXT_NODE)
2051        .map(node => node.textContent.trim())
2052        .filter(Boolean)[0];
2053
2054    // console.log(text);
2055
2056    let cleanedText = text
2057    .toLowerCase()
2058    .replace(/\b(choose|your|lens|lenses|chose|additional)\b/g, "")
2059    .replace(/\s+/g, " ")
2060    .trim();
2061
2062    // console.log(cleanedText);
2063    if(cleanedText == "tint"){
2064      cleanedText = "Colour"
2065    } else if(cleanedText.includes('color') || cleanedText.includes('colour')){
2066      cleanedText = "Colour"
2067    } else if(cleanedText.includes('thickness')){
2068      cleanedText = "Thickness"
2069    } else if(cleanedText.includes('coating')){
2070      cleanedText = "Coating"
2071    } else if(cleanedText.includes('occupational')){
2072      cleanedText = "Occupational"
2073    }
2074
2075    document.querySelector(".prescription-heading-6").textContent = cleanedText;
2076
2077    document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
2078      el.addEventListener("click", function () {
2079          const text = this.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
2080              document.querySelector(".la-footer-frame-prescription.value6").textContent = text;
2081
2082              if(EnableDiscount == false){
2083                let OrignalpriceBox;
2084                     OrignalpriceBox = this.querySelector(".la-label-price").textContent;
2085                    //  console.log(OrignalpriceBox);
2086                    if (OrignalpriceBox !== null && OrignalpriceBox !== undefined && OrignalpriceBox !== ""){
2087                      document.querySelector(".la-footer-frame-prescription.value6").setAttribute("new-price", OrignalpriceBox);
2088                    }
2089              } else{
2090                const priceRow = this.querySelector(".la-label-price .price-box");
2091                if (priceRow) {
2092                  document.querySelector(".la-footer-frame-prescription.value6").setAttribute("new-price", priceRow.outerHTML);
2093                }
2094              }
2095
2096              document.querySelector(".prescription-value-6").classList.remove("hide-prescription");
2097          });
2098    });
2099
2100      setInterval(() => {
2101        const priceText = document
2102          .querySelector(".la-footer-row.la-subtotal .la-subtotal-price")
2103          ?.textContent.trim();
2104
2105        const price = priceText
2106          ?.replace(/[^\d.]/g, "")
2107          .replace(".", "");
2108
2109        const elements = document.querySelectorAll("[data-purchase-
2109amount]");
2110
2111          if (price) {
2112            elements.forEach((element) => {
2113              element.setAttribute("data-purchase-amount", price);
2114            });
2115          }
2116        const klarnaElements = document.querySelectorAll("#wrapper-lensadvisor-jtpl klarna-placement");
2117
2118        klarnaElements.forEach((klarnaElement) => {
2119          const shadowRoot = klarnaElement.shadowRoot;
2120
2121          if (!shadowRoot) return;
2122
2123          // Style sirf ek baar add hogi har shadowRoot me
2124          if (!shadowRoot.querySelector("#klarna-custom-style")) {
2125            const style = document.createElement("style");
2126            style.id = "klarna-custom-style";
2127            style.textContent = `
2128                  .container {
2129                    flex-direction: row-reverse !important;
2130                    background: transparent !important;
2131                    border: 0 !important;
2132                    padding: 0 !important;
2133                    justify-content: flex-end !important;
2134                    position: relative;
2135                  }
2136                  .container.order-summary-klarna{
2137                    justify-content: center !important;
2138                  }
2139                  .container button.link {
2140                    position: absolute;
2141                    inset: 0;
2142                    width: 100%;
2143                    height: auto;
2144                    font-size: 0;
2145                  }
2146                  .container .text-wrapper p.legal{
2147                    display:none !important;
2148                  }
2149                  .container .text-wrapper {
2150                    margin-left: 0;
2151                    color: #8a857d;
2152                    font-size: 12px;
2153                    line-height: normal;
2154                    margin-right: 3px;
2155                  }
2156                  .container .text-wrapper strong {
2157                    font-weight: normal;
2158                  }
2159                  .container .badge svg {
2160                    height: 18px;
2161                    width: 40px;
2162                    // transform: translateY(1px);
2163                  }
2164                  @media (max-width: 1140px) {
2165                    .container .text-wrapper {
2166                      font-size: 10px;
2167                    }
2168                  }
2169                  @media (max-width: 994px) {
2170                    .container .text-wrapper {
2171                      font-size: 8.5px;
2172                    }
2173                  }
2174                  @media (max-width: 767px) {
2175                   .desktop-klarna .container {
2176                      justify-content: center !important;
2177                    }
2178                    .container .text-wrapper {
2179                      font-size: 11px;
2180                    }
2181                  }
2182                `;
2183
2184                klarnaElement.shadowRoot.appendChild(style);
2185            }
2186          });
2187      }, 10);
2188      if(submissionMethods == false){
2189         document.querySelector(".la-progress-bar-step").textContent = "Step 5 of 7";
2190      } else{
2191         document.querySelector(".la-progress-bar-step").textContent = "Step 6 of 8";
2192      }
2193
2194      if(EnableDescription == true){
2195        if(cleanedText.includes('Colour')){
2196          const description7 = `All colours give the same protection — pick the look you love.`;
2197          document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
2198                'afterend', `<p class="la-prescription-description text-center">${description7}</p>`
2199          );
2200        } else if(cleanedText.includes('Thickness')){
2201          const description8 = `Thinner lenses look slimmer and feel lighter. Stronger prescriptions benefit most.`;
2202          document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
2203                'afterend', `<p class="la-prescription-description text-center">${description8}</p>`
2204          );
2205        } else{
2206          const description9 = ``;
2207          document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
2208                'afterend', `<p class="la-prescription-description text-center">${description9}</p>`
2209          );
2210        }
2211      }
2212
2213     
2214      if(EnableTitle == true){
2215        if(cleanedText.includes('Colour')){
2216          const title7 = `Choose Your Colour for Lenses`;
2217          if(title7 != ''){
2218          document.getElementById("la_prescriptionSelect_title").textContent = title7;
2219          }
2220        } else if(cleanedText.includes('Thickness')){
2221          const title8 = `Lens Thickness`;
2222          if(title8 != ''){
2223          document.getElementById("la_prescriptionSelect_title").textContent = title8;
2224          }
2225        } else{
2226          const title9 = ``;
2227          if(title9 != ''){
2228            document.getElementById("la_prescriptionSelect_title").textContent = title9;
2229          }
2230        }
2231      }
2232
2233      setTimeout(function(){
2234        if(!cleanedText.includes('Colour')){
2235          document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
2236              btn.addEventListener('click', function () {
2237                  const contentWrapper = this.querySelector('.la-label-content-wrapper');
2238                  if (contentWrapper?.querySelector('.delivery-badge')) {
2239                      nextDay = true;
2240                      document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2241                  }else{
2242                      nextDay = false;
2243                      const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
2244                      const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
2245
2246                      if(USEDFOR.includes("Varifocal")){
2247                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2248                      } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2249                        document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2250                      } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2251                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2252                      } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2253                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2254                      } else if(USEDFOR.includes("Ready Reader")){
2255                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2256                      } else{
2257                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2258                      }
2259                        
2260                  }
2261              });
2262          });
2263          const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
2264          const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
2265            if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Varifocal") || USEDFOR.includes("Occupational") || USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised") || USEDFOR.includes("Ready Reader") || USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2266                nextDay = false;
2267            }
2268
2269          if(nextDay == false){
2270            document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
2271                const delvbadge = btn.querySelector('.delivery-badge');
2272                if (delvbadge) {
2273                    delvbadge.remove();
2274                      if(USEDFOR.includes("Varifocal")){
2275                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2276                      } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2277                        document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2278                      } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2279                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2280                      } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2281                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2282                      } else if(USEDFOR.includes("Ready Reader")){
2283                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2284                      } else{
2285                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2286                      }
2287                }
2288                if(USEDFOR.includes("Varifocal")){
2289                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2290                } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2291                  document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2292                } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2293                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2294                } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2295                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2296                } else if(USEDFOR.includes("Ready Reader")){
2297                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2298                } else{
2299                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2300                }
2301            });
2302          }else{
2303            document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2304          }
2305        }
2306      }, 10);
2307
2308});
2309
2310document.addEventListener('LensAdvizor:lensOption3:rendered', function(e) {
2311
2312  const html = document.getElementById('la_prescriptionSelect_title').innerHTML;
2313    const div = document.createElement('div');
2314    div.innerHTML = html;
2315
2316    const text = [...div.childNodes]
2317        .filter(node =>
2317 node.nodeType === Node.TEXT_NODE)
2318        .map(node => node.textContent.trim())
2319        .filter(Boolean)[0];
2320
2321    // console.log(text);
2322
2323    let cleanedText = text
2324    .toLowerCase()
2325    .replace(/\b(choose|your|lens|lenses|chose|additional)\b/g, "")
2326    .replace(/\s+/g, " ")
2327    .trim();
2328
2329    // console.log(cleanedText);
2330    if(cleanedText == "tint"){
2331      cleanedText = "Colour"
2332    } else if(cleanedText.includes('color') || cleanedText.includes('colour')){
2333      cleanedText = "Colour"
2334    } else if(cleanedText.includes('thickness')){
2335      cleanedText = "Thickness"
2336    } else if(cleanedText.includes('coating')){
2337      cleanedText = "Coating"
2338    } else if(cleanedText.includes('occupational')){
2339      cleanedText = "Occupational"
2340    }
2341
2342  document.querySelector(".prescription-heading-7").textContent = cleanedText;
2343
2344    document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
2345      el.addEventListener("click", function () {
2346          const text = this.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
2347              document.querySelector(".la-footer-frame-prescription.value7").textContent = text;
2348
2349              if(EnableDiscount == false){
2350                let OrignalpriceBox;
2351                     OrignalpriceBox = this.querySelector(".la-label-price").textContent;
2352                    //  console.log(OrignalpriceBox);
2353                    if (OrignalpriceBox !== null && OrignalpriceBox !== undefined && OrignalpriceBox !== ""){
2354                      document.querySelector(".la-footer-frame-prescription.value7").setAttribute("new-price", OrignalpriceBox);
2355                    }
2356              } else{
2357                const priceRow = this.querySelector(".la-label-price .price-box");
2358                if (priceRow) {
2359                  document.querySelector(".la-footer-frame-prescription.value7").setAttribute("new-price", priceRow.outerHTML);
2360                }
2361              }
2362              document.querySelector(".prescription-value-7").classList.remove("hide-prescription");
2363          });
2364    });
2365
2366      setInterval(() => {
2367        const priceText = document
2368          .querySelector(".la-footer-row.la-subtotal .la-subtotal-price")
2369          ?.textContent.trim();
2370
2371        const price = priceText
2372          ?.replace(/[^\d.]/g, "")
2373          .replace(".", "");
2374
2375        const elements = document.querySelectorAll("[data-purchase-amount]");
2376
2377          if (price) {
2378            elements.forEach((element) => {
2379              element.setAttribute("data-purchase-amount", price);
2380            });
2381          }
2382        const klarnaElements = document.querySelectorAll("#wrapper-lensadvisor-jtpl klarna-placement");
2383
2384        klarnaElements.forEach((klarnaElement) => {
2385          const shadowRoot = klarnaElement.shadowRoot;
2386
2387          if (!shadowRoot) return;
2388
2389          // Style sirf ek baar add hogi har shadowRoot me
2390          if (!shadowRoot.querySelector("#klarna-custom-style")) {
2391            const style = document.createElement("style");
2392            style.id = "klarna-custom-style";
2393            style.textContent = `
2394                  .container {
2395                    flex-direction: row-reverse !important;
2396                    background: transparent !important;
2397                    border: 0 !important;
2398                    padding: 0 !important;
2399                    justify-content: flex-end !important;
2400                    position: relative;
2401                  }
2402                  .container.order-summary-klarna{
2403                    justify-content: center !important;
2404                  }
2405                  .container button.link {
2406                    position: absolute;
2407                    inset: 0;
2408                    width: 100%;
2409                    height: auto;
2410                    font-size: 0;
2411                  }
2412                  .container .text-wrapper p.legal{
2413                    display:none !important;
2414                  }
2415                  .container .text-wrapper {
2416                    margin-left: 0;
2417                    color: #8a857d;
2418                    font-size: 12px;
2419                    line-height: normal;
2420                    margin-right: 3px;
2421                  }
2422                  .container .text-wrapper strong {
2423                    font-weight: normal;
2424                  }
2425                  .container .badge svg {
2426                    height: 18px;
2427                    width: 40px;
2428                    // transform: translateY(1px);
2429                  }
2430                  @media (max-width: 1140px) {
2431                    .container .text-wrapper {
2432                      font-size: 10px;
2433                    }
2434                  }
2435                  @media (max-width: 994px) {
2436                    .container .text-wrapper {
2437                      font-size: 8.5px;
2438                    }
2439                  }
2440                  @media (max-width: 767px) {
2441                   .desktop-klarna .container {
2442                      justify-content: center !important;
2443                    }
2444                    .container .text-wrapper {
2445                      font-size: 11px;
2446                    }
2447                  }
2448                `;
2449
2450                klarnaElement.shadowRoot.appendChild(style);
2451            }
2452          });
2453      }, 10);
2454      if(submissionMethods == false){
2455        document.querySelector(".la-progress-bar-step").textContent = "Step 6 of 7";
2456      } else{
2457        document.querySelector(".la-progress-bar-step").textContent = "Step 7 of 8";
2458      }
2459
2460      if(EnableDescription == true){
2461        if(cleanedText.includes('Colour')){
2462          const description7 = `All colours give the same protection — pick the look you love.`;
2463          document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
2464                'afterend', `<p class="la-prescription-description text-center">${description7}</p>`
2465          );
2466        } else if(cleanedText.includes('Thickness')){
2467          const description8 = `Thinner lenses look slimmer and feel lighter. Stronger prescriptions benefit most.`;
2468          document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
2469                'afterend', `<p class="la-prescription-description text-center">${description8}</p>`
2470          );
2471        } else{
2472          const description9 = ``;
2473          document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
2474                'afterend', `<p class="la-prescription-description text-center">${description9}</p>`
2475          );
2476        }
2477      }
2478
2479     
2480      if(EnableTitle == true){
2481        if(cleanedText.includes('Colour')){
2482          const title7 = `Choose Your Colour for Lenses`;
2483          if(title7 != ''){
2484          document.getElementById("la_prescriptionSelect_title").textContent = title7;
2485          }
2486        } else if(cleanedText.includes('Thickness')){
2487          const title8 = `Lens Thickness`;
2488          if(title8 != ''){
2489          document.getElementById("la_prescriptionSelect_title").textContent = title8;
2490          }
2491        } else{
2492          const title9 = ``;
2493          if(title9 != ''){
2494            document.getElementById("la_prescriptionSelect_title").textContent = title9;
2495          }
2496        }
2497      }
2498
2499      setTimeout(function(){
2500        if(!cleanedText.includes('Colour')){
2501          document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
2502              btn.addEventListener('click', function () {
2503                  const contentWrapper = this.querySelector('.la-label-content-wrapper');
2504                  if (contentWrapper?.querySelector('.delivery-badge')) {
2505                      nextDay = true;
2506                      document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2507                  }else{
2508                      nextDay = false;
2509                      const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
2510                      const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
2511                      if(USEDFOR.includes("Varifocal")){
2512                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2513                      } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2514                        document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2515                      } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2516                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2517                      } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2518                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2519                      } else if(USEDFOR.includes("Ready Reader")){
2520                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2521                      } else{
2522                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2523                      }
2524                        
2525                  }
2526              });
2527          });
2528          const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
2529          const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
2530            if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Varifocal") || USEDFOR.includes("Occupational") || USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised") || USEDFOR.includes("Ready Reader") || USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2531                nextDay = false;
2532            }
2533
2534          if(nextDay == false){
2535            document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
2536                const delvbadge = btn.querySelector('.delivery-badge');
2537                if (delvbadge) {
2538                    delvbadge.remove();
2539                      if(USEDFOR.includes("Varifocal")){
2540                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2541                      } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2542                        document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2543                      } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2544                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2545                      } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2546                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2547                      } else if(USEDFOR.includes("Ready Reader")){
2548                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2549                      } else{
2550                        document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2551                      }
2552                }
2553                if(USEDFOR.includes("Varifocal")){
2554                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2555                } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2556                  document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2557                } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2558                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2559                } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2560                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2561                } else if(USEDFOR.includes("Ready Reader")){
2562                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2563                } else{
2564                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2565                }
2566            });
2567          }else{
2568            document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2569          }
2570        }
2571      }, 10);
2572
2573});
2574document.addEventListener('LensAdvizor:addOns:rendered', function(e) {
2575  document.getElementById("wrapper-lensadvisor-jtpl").classList.remove("upload-page");
2576  setTimeout(function(){
2577    document.querySelector(".prescription-value-9").classList.remove("hide-prescription");
2578    document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
2579        btn.addEventListener('click', function () {
2580            const contentWrapper = this.querySelector('.la-label-content-wrapper');
2581            if (contentWrapper?.querySelector('.delivery-badge')) {
2582                nextDay = true;
2583                document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2584            }else{
2585                nextDay = false;
2586                const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
2587                const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
2588                if(USEDFOR.includes("Varifocal")){
2589                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2590                } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2591                  document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2592                } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2593                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2594                } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2595                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2596                } else if(USEDFOR.includes("Ready Reader")){
2597                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2598                } else{
2599                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2600                }
2601                  
2602            }
2603        });
2604    });
2605    const USEDFOR = document.querySelector(".la-footer-frame-prescription.value1").textContent;
2606    const USEDPRES = document.querySelector(".la-footer-frame-prescription.value3").textContent;
2607      if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Varifocal") || USEDFOR.includes("Occupational") || USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised") || USEDFOR.includes("Ready Reader") || USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2608          nextDay = false;
2609      }
2610
2611    if(nextDay == false){
2612      document.querySelectorAll('.la-label-btn-wrapper').forEach(function (btn) {
2613          const delvbadge = btn.querySelector('.delivery-badge');
2614          if (delvbadge) {
2615              delvbadge.remove();
2616                if(USEDFOR.includes("Varifocal")){
2617                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2618                } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2619                  document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2620                } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2621                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2622                } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2623                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2624                } else if(USEDFOR.includes("Ready Reader")){
2625                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2626                } else{
2627                  document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2628                }
2629          }
2630          if(USEDFOR.includes("Varifocal")){
2631            document.querySelector(".la-footer-frame-prescription.value9").textContent = `7-10 Days`;
2632          } else if(USEDFOR.includes("Fashion") || USEDFOR.includes("Blue Light")){
2633            document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2634          } else if(USEDPRES.includes("Mirror") || USEDPRES.includes("mirror") || USEDFOR.includes("Occupational")){
2635            document.querySelector(".la-footer-frame-prescription.value9").textContent = `5-7 Days`;
2636          } else if(USEDPRES.includes("Gradient") || USEDPRES.includes("Polarised")){
2637            document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2638          } else if(USEDFOR.includes("Ready Reader")){
2639            document.querySelector(".la-footer-frame-prescription.value9").textContent = `1-3 Days`;
2640          } else{
2641            document.querySelector(".la-footer-frame-prescription.value9").textContent = `3-5 Days`;
2642          }
2643      });
2644    }else{
2645      document.querySelector(".la-footer-frame-prescription.value9").textContent = "Next Day Available";
2646    }
2647  }, 10);
2648
2649setTimeout(() => {
2650  const SkipButton = document.querySelector(".la-skip-add-on-wrapper");
2651  if(SkipButton){
2652    SkipButton.insertAdjacentHTML('beforebegin', `<div class="add-on-selector text-center">None selected</div>`);
2653  }
2654  document.querySelectorAll(".la-label-btn-wrapper").forEach(function (item) {
2655    const input = item.querySelector("input");
2656
2657    item.classList.toggle("la-prev-selected", input && input.checked);
2658    if(input && input.checked){
2659      document.querySelector(".prescription-value-8").classList.remove("hide-prescription"); 
2660      let totalPrice = 0;
2661                  let totalAdded = 0;       
2662                  document.querySelectorAll(".la-label-btn-wrapper").forEach(function (item) {
2663                      const input = item.querySelector('input[type="checkbox"], input[type="radio"]');
2664                      if (input && input.checked) {
2665                          totalAdded++;
2666                          let priceEl = 0;
2667                          if(EnableDiscount == true){
2668                            priceEl = item.querySelector(".new-price"); 
2669                           } else{
2670                            priceEl = item.querySelector(".la-label-price"); 
2671                           }
2672                          if (priceEl) {
2673                              const price = parseFloat(
2674                                  priceEl.textContent.replace(/[^0-9.-]+/g, "")
2675                              ) || 0;
2676                              totalPrice += price;
2677                          }
2678                      }
2679                  });
2680                  
2681                  let currency = "";
2682                  let firstPrice = 0;
2683                  if(EnableDiscount == true){
2684                  firstPrice = document.querySelector(".la-label-btn-wrapper .new-price");
2685                  } else{
2686                    firstPrice = document.querySelector(".la-label-btn-wrapper .la-label-price");
2687                  }
2688                  if (firstPrice) {
2689                      const match = firstPrice.textContent.trim().match(/^[^\d-]+/);
2690                      currency = match ? match[0] : "";
2691                  }
2692                  if(totalAdded == 0){
2693                    document.querySelector(".add-on-selector").textContent = `None selected`;
2694                    // document.querySelector(".prescription-value-8").classList.add("hide-prescription");
2695                    document.querySelector(".add-on-selector").classList.remove("add-on-added");
2696                  } else{
2697                     document.querySelector(".add-on-selector").classList.add("add-on-added");
2698                    document.querySelector(".add-on-selector").textContent = `${totalAdded} added · +${currency}${totalPrice.toFixed(2)}`;
2699                  }
2700    }
2701});
2702//**************   Addon Product Title description start   *************/ 
2703// const EnableAddOnTitle = true;
2704// if(EnableAddOnTitle == true){
2705//   const addonTitles = [
2706//     `Do you use computers and screens a lot? Add a blue-light coating.`,
2707//     `Accidental damage cover for scratches or breakage.`,
2708//     ``
2709//   ];
2710
2711//   document.querySelectorAll(".la-label-btn-wrapper").forEach(function (item, index) {
2712//     const title = addonTitles[index];
2713
2714//     if (title && !item.querySelector(".addon-title")) {
2715//       item.insertAdjacentHTML(
2716//         "afterbegin",
2717//         `<div class="addon-title">${title}</div>`
2718//       );     
2719//     }
2720//   });
2721//   const wrappers = document.querySelectorAll(".la-label-btn-wrapper .addon-title");
2722//   // console.log(wrappers);
2723//   const titleToShow =
2724//     wrappers.length === 1
2725//       ? addonTitles[1]
2726//       : null;
2727//       // console.log(titleToShow);
2728//   if(titleToShow !== null){
2729//   document.querySelector(".la-label-btn-wrapper .addon-title").textContent = titleToShow;
2730
2731//   }
2732// }
2733//**************   Addon Product Title description end   *************/ 
2734
2735}, 30);
2736setTimeout(() => {
2737  let lensPriceDiv;
2738    if(window.outerWidth >= 768){
2739    lensPriceDiv = document.querySelector(
2740          '.fe-flow-jtpl .la-footer-row-wrapper:nth-of-type(4):not(.la-d-none) .la-footer-lens-price'
2741        );
2742      } else{
2743        lensPriceDiv = document.querySelector(
2744          '.fe-flow-jtpl .la-footer-row-wrapper:nth-of-type(5):not(.la-d-none) .la-footer-lens-price'
2745        );
2746      }
2747      if (lensPriceDiv && !lensPriceDiv.parentElement.querySelector('.currency-symbol')) {
2748        lensPriceDiv.insertAdjacentHTML(
2749          'beforebegin',
2750          `<div class="currency-symbol">${Symbolcurrency}</div>`
2751        );
2752      }
2753}, 10);
2754  const html = document.getElementById('la_prescriptionSelect_title').innerHTML;
2755    const div = document.createElement('div');
2756    div.innerHTML = html;
2757
2758    const text = [...div.childNodes]
2759        .filter(node =>
2759 node.nodeType === Node.TEXT_NODE)
2760        .map(node => node.textContent.trim())
2761        .filter(Boolean)[0];
2762
2763    // console.log(text);
2764
2765    let cleanedText = text
2766    .toLowerCase()
2767    .replace(/\b(choose|your|lens|lenses|chose|additional)\b/g, "")
2768    .replace(/\s+/g, " ")
2769    .trim();
2770
2771    // console.log(cleanedText);
2772    if(cleanedText == "tint"){
2773      cleanedText = "Colour"
2774    } else if(cleanedText.includes('color') || cleanedText.includes('colour')){
2775      cleanedText = "Colour"
2776    } else if(cleanedText.includes('thickness')){
2777      cleanedText = "Thickness"
2778    } else if(cleanedText.includes('coating')){
2779      cleanedText = "Coating"
2780    } else if(cleanedText.includes('occupational')){
2781      cleanedText = "Occupational"
2782    }
2783
2784  document.querySelector(".prescription-heading-8").textContent = cleanedText;
2785
2786    document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
2787      el.addEventListener("click", function (e) {
2788
2789        const titles = [];
2790        const Checked = false;
2791
2792        document.querySelectorAll(".la-label-btn-wrapper").forEach(function (item) {
2793            const input = item.querySelector("input");
2794
2795            if (input && input.checked) {
2796              Checked = true;
2797                const title = item.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
2798                if (title) {
2799                    titles.push(title);
2800                }
2801            }
2802            
2803        });
2804
2805        // document.querySelector(".la-footer-frame-prescription.value8").innerHTML = titles.join("<br>");
2806
2807        // if(Checked == false){
2808        //   const text = this.querySelector(".la-label-content-box .la-label-title")?.textContent.trim();
2809        //   document.querySelector(".la-footer-frame-prescription.value8").textContent = text;
2810        // }
2811
2812        //       const inputVal = this.querySelector("input").value;
2813        //       document.querySelector(".la-footer-frame-prescription.value8").setAttribute("addOn", inputVal);
2814
2815        //       if(EnableDiscount == false && Checked == false){
2816        //         let OrignalpriceBox;
2817        //              OrignalpriceBox = this.querySelector(".la-label-price").textContent;
2818        //             //  console.log(OrignalpriceBox);
2819        //             if (OrignalpriceBox !== null && OrignalpriceBox !== undefined && OrignalpriceBox !== ""){
2820        //               document.querySelector(".la-footer-frame-prescription.value8").setAttribute("new-price", OrignalpriceBox);
2821        //             }
2822        //       // } else{
2823        //       //   const priceRow = this.querySelector(".la-label-price .price-box");
2824        //       //   if (priceRow) {
2825        //       //     document.querySelector(".la-footer-frame-prescription.value8").setAttribute("new-price", priceRow.outerHTML);
2826        //       //   }
2827        //       }
2828              
2829              document.querySelector(".prescription-value-8").classList.remove("hide-prescription");   
2830
2831              setTimeout(() => {  
2832
2833                //************************   Add-on selection text when add-on select   *******************************/
2834
2835                  let totalPrice = 0;
2836                  let totalAdded = 0;       
2837                  document.querySelectorAll(".la-label-btn-wrapper").forEach(function (item) {
2838                      const input = item.querySelector('input[type="checkbox"], input[type="radio"]');
2839                      if (input && input.checked) {
2840                          totalAdded++;
2841                          let priceEl = 0;
2842                          if(EnableDiscount == true){
2843                            priceEl = item.querySelector(".new-price"); 
2844                           } else{
2845                            priceEl = item.querySelector(".la-label-price"); 
2846                           }
2847                          if (priceEl) {
2848                              const price = parseFloat(
2849                                  priceEl.textContent.replace(/[^0-9.-]+/g, "")
2850                              ) || 0;
2851                              totalPrice += price;
2852                          }
2853                      }
2854                  });
2855                  
2856                  let currency = "";
2857                  let firstPrice = 0;
2858                  if(EnableDiscount == true){
2859                  firstPrice = document.querySelector(".la-label-btn-wrapper .new-price");
2860                  } else{
2861                    firstPrice = document.querySelector(".la-label-btn-wrapper .la-label-price");
2862                  }
2863                  if (firstPrice) {
2864                      const match = firstPrice.textContent.trim().match(/^[^\d-]+/);
2865                      currency = match ? match[0] : "";
2866                  }
2867                  if(totalAdded == 0){
2868                    document.querySelector(".add-on-selector").textContent = `None selected`;
2869                    // document.querySelector(".prescription-value-8").classList.add("hide-prescription");
2870                    document.querySelector(".add-on-selector").classList.remove("add-on-added");
2871                  } else{
2872                     document.querySelector(".add-on-selector").classList.add("add-on-added");
2873                    document.querySelector(".add-on-selector").textContent = `${totalAdded} added · +${currency}${totalPrice.toFixed(2)}`;
2874                  }
2875
2876                  //************************   Add-on selection text when add-on end   *******************************/
2877
2878                  var discount = false;
2879                  if(discount == true){
2880
2881                  //************************    LensPrices with discount when add-on select   *******************************/ 
2882
2883                    document.querySelectorAll('.la-footer-row').forEach(function (row) {
2884
2885                      const symbolEl = row.querySelector('.currency-symbol');
2886                      const priceEl = row.querySelector('.la-footer-lens-price');
2887
2888                      if (!symbolEl || !priceEl) return; // Element nahi mila to skip
2889
2890                      const symbol = symbolEl.textContent.trim();
2891                      const price = parseFloat(priceEl.textContent.trim());
2892
2893                      if (isNaN(price)) return;
2894
2895                      const discount = `25`;
2896                      const discountedPrice = (price * (100 - discount) / 100).toFixed(2);
2897
2898                      var disamount = price.toFixed(2) - discountedPrice;
2899                      document.querySelector(".discount-ammount").textContent = `- ${symbol}${disamount.toFixed(2)}`;
2900                      document.querySelector(".discount-ammount").setAttribute("data-price", disamount.toFixed(2));
2901
2902                      const parentLabel = document.querySelector(".la-choose-prescription-wrapper");
2903                      if (parentLabel && parentLabel.classList.contains("la-render-review")) {
2904                          document.querySelector(".lens-discount-price").textContent = `- ${symbol}${disamount.toFixed(2)}`;
2905                      }
2906
2907                      priceEl.innerHTML = `
2908                        <div class="lenses-discount-price">
2909                          <span class="old-price">
2910                              ${symbol}${price.toFixed(2)}
2911                          </span>
2912                          <span class="final-price">
2913                              ${symbol}${discountedPrice}
2914                          </span>
2915                        </div>
2916                      `;
2917                    }); 
2918
2919                    //************************    LensPrices with discount when add-on end   *******************************/  
2920                    
2921                    //************************    Add-On Prices with discount when add-on select    *******************************/ 
2922
2923                    const addonPriceEl = document.querySelectorAll(".la-footer-addon-price");
2924                    addonPriceEl.forEach(function (addonPriceEl) {
2925
2926                        // Already discounted? Skip this element
2927                        if (addonPriceEl.querySelector(".lenses-discount-price")) {
2928                            return;
2929                        }
2930
2931                        const discountAmountEl = document.querySelector(".discount-ammount");
2932
2933                        if (addonPriceEl) {
2934                            const Priceaddon = addonPriceEl.textContent;
2935                            const currencySymbol = document.body.getAttribute("theme-currency");
2936
2937                            let addonPrice = parseFloat(
2938                                addonPriceEl.textContent.replace(/[^\d.]/g, "")
2939                            );
2940
2941                            const discountt = Number(`25`);
2942
2943                            let finalPrice = addonPrice - (addonPrice * (discountt / 100));
2944
2945                            if (finalPrice > 0) {
2946
2947                                const addonDiscount = addonPrice - finalPrice;
2948
2949                                if (discountAmountEl) {
2950                                    let existingDiscount = parseFloat(
2951                                        discountAmountEl.textContent.replace(/[^\d.]/g, "")
2952                                    );
2953
2954                                    let totalDiscount = existingDiscount + addonDiscount;
2955
2956                                    discountAmountEl.textContent = `- ${currencySymbol}${totalDiscount.toFixed(2)}`;
2957                                    discountAmountEl.setAttribute("data-price", totalDiscount.toFixed(2));
2958
2959                                    const parentLabel = document.querySelector(".la-choose-prescription-wrapper");
2960                                    if (parentLabel && parentLabel.classList.contains("la-render-review")) {
2961                                        document.querySelector(".lens-discount-price").textContent =
2962                                            `- ${currencySymbol}${totalDiscount.toFixed(2)}`;
2963                                    }
2964                                }
2965
2966                                addonPriceEl.innerHTML = `
2967                                    <div class="lenses-discount-price">
2968                                        <span class="old-price">${Priceaddon}</span>
2969                                        <span class="final-price">
2970                                            ${currencySymbol}${finalPrice.toFixed(2)}
2971                                        </span>
2972                                    </div>
2973                                `;
2974                            }
2975                        }
2976                    });
2977                    //************************    Add-On Prices with discount when add-on select end   *******************************/ 
2978                  }
2979
2980                  //**********************  Add-on sum  ***************************/
2981                      var discount = false;
2982                      let total = 0;
2983                      if(discount == true){
2984                        const oldPrices = document.querySelectorAll(".la-footer-addon-price span.old-price");
2985                            oldPrices.forEach(el => {
2986                                const text = el.textContent.trim();
2987
2988                                const price = parseFloat(text.replace(/[^0-9.]/g, ""));
2989
2990                                if (!isNaN(price)) {
2991                                    total += price;
2992                                }
2993                            });
2994                      } else{
2995                        const oldPrices = document.querySelectorAll(".la-footer-addon-price");
2996                            oldPrices.forEach(el => {
2997                                const text = el.textContent.trim();
2998
2999                                const price = parseFloat(text.replace(/[^0-9.]/g, ""));
3000
3001                                if (!isNaN(price)) {
3002                                    total += price;
3003                                }
3004                            });
3005                      }
3006                        
3007                        const totalDiv = document.createElement("div");
3008                        totalDiv.className = "la-addon-price";
3009                        // totalDiv.textContent = `${Symbolcurrency}${total.toFixed(2)}`;
3010
3011                        
3012                        const container = document.querySelector(".la-footer-addon-wrapper");
3013                        if (container) {
3014                          // if exist then remove
3015                          container.querySelector(".la-addon-price")?.remove();
3016
3017                          const totalDiv = document.createElement("div");
3018                          totalDiv.className = "la-addon-price";
3019
3020                          
3021                          if(discount == true){
3022                            const discounttt = `25`;
3023                            const discountedPricee = (total.toFixed(2) * (100 - discounttt) / 100).toFixed(2);
3024                            
3025                            totalDiv.innerHTML = `
3026                                    <div class="la-addon-discount-price">
3027                                        <span class="old-price">${Symbolcurrency}${total.toFixed(2)}</span>
3028                                        <span class="final-price">
3029                                            ${Symbolcurrency}${discountedPricee}
3030                                        </span>
3031                                    </div>
3032                                `;
3033
3034                          }else{
3035                            totalDiv.textContent = `${Symbolcurrency}${total.toFixed(2)}`;
3036                          }
3037
3038                          container.insertAdjacentElement("afterbegin", totalDiv);
3039                      }
3040                  //************************ Add-on Sum  ***************************/  
3041                
3042              const addOnprices = document.querySelector(".la-addon-price").innerHTML;
3043              document.querySelector(".la-footer-frame-prescription.value8").setAttribute("new-price", addOnprices);
3044
3045              }, 0);
3046          });
3047
3048
3049          document.querySelectorAll(".la-label-btn-wrapper").forEach(function (el) {
3050            el.addEventListener("click", function (e) {
3051              setTimeout(function(){
3052                const footer = document.querySelector(".la-footer-addon-wrapper");
3053                const target = document.querySelector(".la-footer-frame-prescription.value8");
3054
3055                // if (!footer || !target) return;
3056
3057                // Get all addon text values
3058                const texts = Array.from(
3059                    footer.querySelectorAll(".la-footer-text")
3060                )
3061                .map(function (item) {
3062                    return item.textContent.trim();
3063                })
3064                .filter(Boolean);
3065
3066                // Get addon price
3067                const priceElement = footer.querySelector(".la-addon-price");
3068                const price = priceElement ? priceElement.textContent.trim() : "";
3069
3070                // Set text with <br> between multiple values
3071                target.innerHTML = texts.join("<br>");
3072
3073                // Set new-price attribute
3074                target.setAttribute("new-price", price);
3075                }, 200);
3076            });
3077        });
3078
3079    });
3080
3081    var SumAddOntitle = document.querySelector(".la-footer-frame-prescription.value8").textContent;
3082    document.querySelectorAll(".la-label-content-box .la-label-title").forEach(function (el) {
3083      var AddOntitle = el.textContent.trim();
3084      if(SumAddOntitle === AddOntitle){
3085        const parent = el.closest('.la-label-btn-wrapper');
3086        if (parent) {
3087            setTimeout(function(){
3088             parent.classList.add('la-prev-selected');
3089            }, 50);
3090        }
3091      }
3092    });
3093
3094
3095      setInterval(() => {
3096        const priceText = document
3097          .querySelector(".la-footer-row.la-subtotal .la-subtotal-price")
3098          ?.textContent.trim();
3099
3100        const price = priceText
3101          ?.replace(/[^\d.]/g, "")
3102          .replace(".", "");
3103
3104        const elements = document.querySelectorAll("[data-purchase-
3104amount]");
3105
3106          if (price) {
3107            elements.forEach((element) => {
3108              element.setAttribute("data-purchase-amount", price);
3109            });
3110          }
3111        const klarnaElements = document.querySelectorAll("#wrapper-lensadvisor-jtpl klarna-placement");
3112
3113        klarnaElements.forEach((klarnaElement) => {
3114          const shadowRoot = klarnaElement.shadowRoot;
3115
3116          if (!shadowRoot) return;
3117
3118          // Style sirf ek baar add hogi har shadowRoot me
3119          if (!shadowRoot.querySelector("#klarna-custom-style")) {
3120            const style = document.createElement("style");
3121            style.id = "klarna-custom-style";
3122            style.textContent = `
3123                  .container {
3124                    flex-direction: row-reverse !important;
3125                    background: transparent !important;
3126                    border: 0 !important;
3127                    padding: 0 !important;
3128                    justify-content: flex-end !important;
3129                    position: relative;
3130                  }
3131                  .container.order-summary-klarna{
3132                    justify-content: center !important;
3133                  }
3134                  .container button.link {
3135                    position: absolute;
3136                    inset: 0;
3137                    width: 100%;
3138                    height: auto;
3139                    font-size: 0;
3140                  }
3141                  .container .text-wrapper p.legal{
3142                    display:none !important;
3143                  }
3144                  .container .text-wrapper {
3145                    margin-left: 0;
3146                    color: #8a857d;
3147                    font-size: 12px;
3148                    line-height: normal;
3149                    margin-right: 3px;
3150                  }
3151                  .container .text-wrapper strong {
3152                    font-weight: normal;
3153                  }
3154                  .container .badge svg {
3155                    height: 18px;
3156                    width: 40px;
3157                    // transform: translateY(1px);
3158                  }
3159                  @media (max-width: 1140px) {
3160                    .container .text-wrapper {
3161                      font-size: 10px;
3162                    }
3163                  }
3164                  @media (max-width: 994px) {
3165                    .container .text-wrapper {
3166                      font-size: 8.5px;
3167                    }
3168                  }
3169                  @media (max-width: 767px) {
3170                   .desktop-klarna .container {
3171                      justify-content: center !important;
3172                    }
3173                    .container .text-wrapper {
3174                      font-size: 11px;
3175                    }
3176                  }
3177                `;
3178
3179                klarnaElement.shadowRoot.appendChild(style);
3180            }
3181          });
3182      }, 10);
3183
3184        document.querySelector(".la-progress-bar-step").textContent = "Step 8 of 9";
3185        Addon = true;
3186
3187      if(EnableDescription == true){
3188        const description10 = ``;
3189        document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
3190              'afterend', `<p class="la-prescription-description text-center">${description10}</p>`
3191        );
3192      }
3193      if(EnableTitle == true){
3194        const title10 = ``;
3195        if(title10 != ''){
3196          document.getElementById("la_prescriptionSelect_title").textContent = title10;
3197        }
3198      }
3199});
3200
3201document.addEventListener('LensAdvizor:review:rendered', function(e) {
3202document.getElementById("wrapper-lensadvisor-jtpl").classList.remove("upload-page");
3203  if(Addon == true){
3204    document.querySelector(".la-progress-bar-step").textContent = "Step 9 of 9";
3205  }else if(submissionMethods == false){
3206    document.querySelector(".la-progress-bar-step").textContent = "Step 7 of 7";
3207  } else{
3208    document.querySelector(".la-progress-bar-step").textContent = "Step 8 of 8";
3209  }
3210  
3211  document.getElementById("wrapper-lensadvisor-jtpl").classList.add("review-page");
3212
3213    const removeSpaceAfterCurrency = (selector) => {
3214    document.querySelectorAll(selector).forEach(el => {
3215        el.childNodes.forEach(node => {
3216          if (node.nodeType === Node.TEXT_NODE) {
3217            node.textContent = node.textContent.replace(/([£$€¥])\s+/g, '$1');
3218          }
3219        });
3220      });
3221    };
3222    removeSpaceAfterCurrency('.la-label-title');
3223    removeSpaceAfterCurrency('.la-compare-at-price del');
3224
3225    setTimeout(function(){
3226      var discount = false;
3227        if(discount == true){
3228           const currencySymbol = document.body.getAttribute('theme-currency');
3229          document.querySelectorAll(".la-review-right.la-label-title").forEach((el) => {
3230              let price = parseFloat(
3231                  el.textContent.replace(/[^\d.]/g, "")
3232              );
3233
3234              if (!isNaN(price)) {
3235
3236                const discount = `25`;
3237                let finalPrice = price - (price * discount / 100);
3238                  el.innerHTML = `
3239                  <div class="lenses-discount-price">
3240                      <span class="final-price">
3241                          ${currencySymbol}${finalPrice.toFixed(2)}
3242                      </span>
3243                      <span class="old-price">
3244                          ${currencySymbol}${price.toFixed(2)}
3245                      </span>
3246                  </div>`;
3247              }
3248          });
3249        }
3250
3251        var consentenable = false;
3252          var consentenable = false;
3253        var consentHTML = `<div class="prescription-dispatch-message review-summary">Next-day delivery available on most lenses (order by 3pm). Varifocals and stronger prescriptions are made to order 7-10 working days.</div>
3254            <div class="prescription-order-consent-wrapper">
3255              <div class="prescription-order-note-wrapper">
3256                <label for="notes">Anything else on your prescription? (optional)</label>
3257                  <textarea id="notes" class="order-note-box" placeholder="e.g. prism values, or a note for our optical team"></textarea>
3258              </div>`;
3259
3260          if(consentenable == true){
3261          consentHTML += `
3262              <div class="checkbox-container">
3263                <input type="checkbox" id="confirm" class="consent-text-input">
3264                <label for="confirm" class="consent-text-wrapper">
3265                  <p>I confirm these glasses are for someone over 16, not registered blind, with a prescription under 2 years old, and I agree to the <a href="/policies/terms-of-service" target="_blank" title="Terms of Service"><strong>Terms & Conditions</strong></a>.</p>
3266                </label>
3267              </div>
3268            `;
3269          }
3270          consentHTML +=`</div>`;
3271             const orderReview = document.querySelector(".la-review-main-wrapper");
3272         orderReview.insertAdjacentHTML('beforeend',consentHTML); 
3273
3274
3275          
3276          // const orderReview = document.querySelector(".la-review-main-wrapper");
3277          // orderReview.insertAdjacentHTML('beforeend', `<div class="prescription-dispatch-message">Next-day delivery available on most lenses (order by 3pm). Varifocals and stronger prescriptions are made to order 7-10 working days.</div>
3278          //   <div class="prescription-order-consent-wrapper">
3279          //     <div class="prescription-order-note-wrapper">
3280          //       <label for="notes">Anything else on your prescription? (optional)</label>
3281          //         <textarea id="notes" class="order-note-box" placeholder="e.g. prism values, or a note for our optical team"></textarea>
3282          //     </div>
3283          //     <div class="checkbox-container">
3284          //       <input type="checkbox" id="confirm" class="consent-text-input">
3285          //       <label for="confirm" class="consent-text-wrapper">
3286          //         <p>I confirm these glasses are for someone over 16, not registered blind, with a prescription under 2 years old, and I agree to the <a href="/policies/terms-of-service" target="_blank" title="Terms of Service"><strong>Terms & Conditions</strong></a>.</p>
3287          //       </label>
3288          //     </div>
3289          //   </div>
3290          //   `);
3291
3292          document.addEventListener("input", function (e) {
3293              if (e.target.id === "notes") {
3294                  const value = e.target.value;
3295
3296                  document.getElementById("hiddenordernoteProperty").value = value;
3297
3298                  if (window.LensAdvizor) {
3299                      if (!window.LensAdvizor.customFieldData) {
3300                          window.LensAdvizor.customFieldData = {};
3301                      }
3302                      window.LensAdvizor.customFieldData["Order Note"] = value;
3303                      // const steps = LensAdvizor.navigationSteps.length;
3304                      // const index = LensAdvizor.stepIndex;
3305                      // LensAdvizor.renderReview();
3306                      // LensAdvizor.navigationSteps.length = steps;
3307                      // LensAdvizor.stepIndex = index;
3308                  }
3309              }
3310          });
3311
3312          const valueDelivery = document.querySelector(".summary-prescription-title.value-option.value9").textContent;
3313          document.getElementById("nextdayProperty").value = valueDelivery;
3314          if (window.LensAdvizor) {
3315              if (!window.LensAdvizor.customFieldData) {
3316                  window.LensAdvizor.customFieldData = {};
3317              }
3318              window.LensAdvizor.customFieldData["Delivery"] = valueDelivery;
3319          }
3320
3321            document.querySelectorAll('.la-label-description').forEach(function(el) {
3322                let lines = el.innerHTML.split('<br>');
3323                lines = lines.filter(function(line) {
3324                    return !line.trim().startsWith('Order Note:');
3325                });
3326                el.innerHTML = lines.join('<br>');
3327            });
3328            if(consentenable == true){
3329            document.querySelector(".la-prescription-form-btn.la-translate").setAttribute("disabled", "disabled");
3330              const checkbox = document.getElementById("confirm");
3331              const button = document.querySelector(".la-prescription-form-btn.la-translate");
3332
3333              checkbox.addEventListener("change", function () {
3334                if (this.checked) {
3335                    button.removeAttribute("disabled");
3336                } else {
3337                    button.setAttribute("disabled", "disabled");
3338                }
3339            });
3340          }
3341           
3342    }, 10);
3343    var enableconsent = false;
3344      if(enableconsent == true){
3345        document.querySelector(".la-prescription-form-btn.la-translate").setAttribute("disabled", "disabled");
3346      }
3347
3348      if(EnableDescription == true){
3349        const description11 = `Quick check of your build, then add it to your bag.`;
3350        document.getElementById("la_prescriptionSelect_title").insertAdjacentHTML(
3351              'afterend', `<p class="la-prescription-description text-center">${description11}</p>`
3352        );
3353      }
3354      if(EnableTitle == true){
3355        const title11 = ``;
3356        if(title11 != ''){
3357          document.getElementById("la_prescriptionSelect_title").textContent = title11;
3358        }
3359      }
3360
3361      const priceEl = document.querySelector('.la-footer-lens-price');
3362      if (priceEl) {
3363        const priceText = priceEl.textContent.trim();
3364        const hasCurrencySymbol = /[$€£₹¥₽₩₺₴₦₫₲₵₡₱฿₪₭₮₸₼₾]/.test(priceText);
3365        const hasCurrencyElement = document.querySelector('.currency-symbol');
3366
3367        if (!hasCurrencySymbol && !hasCurrencyElement) {
3368          if (Symbolcurrency) {
3369            priceEl.insertAdjacentHTML(
3370              'beforebegin',
3371              `<div class="currency-symbol">${Symbolcurrency}</div>`
3372            );
3373          }
3374        }
3375      }
3376
3377});
3378
3379
3380var openPopup = false;
3381document.addEventListener('LensAdvizor:selectLensModal:open', function() {
3382    setTimeout(function(){
3383    const div1 = document.getElementById("la-boxy-footer-modal");
3384        const div2 = document.getElementById("la-tooltip-modal");
3385        const div3 = document.getElementById("lensadvizor-prescription-modal");
3386
3387        const wrapper = document.createElement("div");
3388        wrapper.id = "wrapper-lensadvisor-jtpl";
3389
3390        const outerWrapper = document.createElement("div");
3391        outerWrapper.id = "outer-wrapper";
3392
3393        div1.parentNode.insertBefore(wrapper, div1);
3394
3395        wrapper.appendChild(outerWrapper);
3396
3397        outerWrapper.appendChild(div1);
3398        outerWrapper.appendChild(div2);
3399        outerWrapper.appendChild(div3);
3400
3401    //     let html = `
3402    // <div class="la-metafield-wrapper">
3403    //   <div class="la-metafield-inner-wrapper">
3404    //     <div class="la-item la-metafield-item">Free Tracked UK Delivery</div> 
3405    //     <div class="la-itemla-metafield-dot">·</div>
3406    //     <div class="la-item la-metafield-item">Fitted by Qualified Opticians</div>
3407    //     <div class="la-itemla-metafield-dot">·</div>
3408    //     <div class="la-item la-metafield-item" style="color: #ffd34e;">★ 30% Off Lenses · Code: LENSES30</div>
3409    //   </div>
3410    //   <div class="la-metafield-inner-wrapper la-mobile-wrapper">
3411    //     <div class="la-itemla-metafield-dot">·</div>
3412    //     <div class="la-item la-metafield-item">Free Tracked UK Delivery</div> 
3413    //     <div class="la-itemla-metafield-dot">·</div>
3414    //     <div class="la-item la-metafield-item">Fitted by Qualified Opticians</div>
3415    //     <div class="la-itemla-metafield-dot">·</div>
3416    //     <div class="la-item la-metafield-item" style="color: #ffd34e;">★ 30% Off Lenses · Code: LENSES30</div>
3417    //   </div>
3418    // </div>`;
3419    let ship_country_txt = "";
3420    if (currentCountry=="US") {
3421      ship_country_txt = '<div class="la-item la-metafield-item">Free Shipping in the USA</div>';
3422    }
3423    else if(currentCountry == "GB"){
3424      ship_country_txt = '<div class="la-item la-metafield-item">Free Tracked UK Delivery</div>';
3425    }
3426      let html = `
3427    <div class="la-metafield-wrapper" data-cc="${currentCountry}">
3428      <div class="la-metafield-inner-wrapper">
3429        ${ship_country_txt}
3430        <div class="la-item la-metafield-item" style="color: #f3f90a;">★ 50% Off TRUOPTICS Sun Lenses · Code: SUNLENSES50</div>
3431        <div class="la-item la-metafield-item" style="color: #f3f90a;">★ 33% Off Optical Lenses · Code: LENSES33</div>
3432      </div>
3433    </div>
3434  <style>
3435@media (max-width: 767px) {
3436  .fe-flow-jtpl .la-metafield-wrapper .la-metafield-inner-wrapper {
3437    min-height: 20px;
3438    min-width:${window.outerWidth-10}px;
3439  }
3440}
3441</style>
3442  `;
3443    document
3444      .getElementById('outer-wrapper')
3445      .insertAdjacentHTML('afterbegin', html);
3446      if(window.outerWidth >= 768){
3447      // const footer = document.getElementById("la-boxy-footer-modal");
3448      // const information = document.querySelector(".la-boxy-layout-modal-wrapper");
3449      //   information.appendChild(footer);
3450
3451      // const footer = document.getElementById("la-boxy-footer-modal");
3452      // const information = document.querySelector(".la-subtotal-modal-trigger");
3453      //   information.before(footer);
3454      }
3455
3456        document.querySelector(".la-footer-row.la-subtotal .la-footer-text.la-translate").textContent = "Total";
3457
3458        const priceText = document.querySelector(".la-footer-row.la-subtotal .la-subtotal-price")?.textContent.trim();
3459      const price = priceText
3460        ?.replace(/[^\d.]/g, "")
3461        .replace(".", "");       
3462
3463        
3464        const currencyCode = document.body.getAttribute('currency-code');
3465          const klarna =`
3466        <klarna-placement
3467           data-key="credit-promotion-badge"
3468           data-locale="en-${ currencyCode }"
3469           data-purchase-amount="${price}"
3470           data-message-preference="prequalification"
3471        ></klarna-placement> `
3472         document.querySelector(".la-footer-row.la-subtotal").insertAdjacentHTML('afterend', klarna);
3473        if(window.outerWidth <= 767){
3474          // console.log("yes",window.outerWidth);
3475          const klarna =`
3476          <div class="mobile-footer-wrapper"><klarna-placement
3477           data-key="credit-promotion-badge"
3478           data-locale="en-${ currencyCode }"
3479           data-purchase-amount="${price}"
3480           data-message-preference="prequalification"
3481        ></klarna-placement>
3482        <div class="mobile-summary-wrapper"><div class="mobile-footer-sum show-icon">Summary ▲</div><div class="mobile-footer-sum hide-icon">Hide ▼</div></div>
3483        </div>`
3484        const totaltext = `<div class="la-footer-total">Your Total</div>`
3485         document.querySelectorAll(".la-subtotal-price-wrapper")[0].insertAdjacentHTML('afterend', klarna);
3486         document.querySelectorAll(".la-subtotal-price-wrapper")[0].insertAdjacentHTML('afterbegin', totaltext);
3487          if(document.querySelectorAll(".la-subtotal-price-wrapper")[1]){
3488         document.querySelectorAll(".la-subtotal-price-wrapper")[1].insertAdjacentHTML('afterend', klarna);
3489         document.querySelectorAll(".la-subtotal-price-wrapper")[1].insertAdjacentHTML('afterbegin', totaltext);
3490            }
3491         
3492        }
3493         window.dispatchEvent(new Event('resize')); 
3494         window.KlarnaOnsiteService = window.KlarnaOnsiteService || [];
3495          window.KlarnaOnsiteService.push({
3496            eventName: 'refresh-placements'
3497          });
3498        }, 20);
3499        setTimeout(function(){
3500         window.dispatchEvent(new Event('resize')); 
3501         window.KlarnaOnsiteService = window.KlarnaOnsiteService || [];
3502          window.KlarnaOnsiteService.push({
3503            eventName: 'refresh-placements'
3504          });
3505         
3506         const klarnaElements = document.querySelectorAll("#wrapper-lensadvisor-jtpl klarna-placement");
3507
3508        klarnaElements.forEach((klarnaElement) => {
3509          const shadowRoot = klarnaElement.shadowRoot;
3510
3511          if (!shadowRoot) return;
3512
3513          if (!shadowRoot.querySelector("#klarna-custom-style")) {
3514            const style = document.createElement("style");
3515            style.id = "klarna-custom-style";
3516            style.textContent = `
3517                  .container {
3518                    flex-direction: row-reverse !important;
3519                    background: transparent !important;
3520                    border: 0 !important;
3521                    padding: 0 !important;
3522                    justify-content: flex-end !important;
3523                    align-items: flex-end !important;
3524                    position: relative;
3525                  }
3526                  .container.order-summary-klarna{
3527                    justify-content: center !important;
3528                  }
3529                  .container button.link {
3530                    position: absolute;
3531                    inset: 0;
3532                    width: 100%;
3533                    height: auto;
3534                    font-size: 0;
3535                  }
3536                  .container .text-wrapper p.legal{
3537                    display:none !important;
3538                  }
3539                  .container .text-wrapper {
3540                    margin-left: 0;
3541                    color: #8a857d;
3542                    font-size: 12px;
3543                    line-height: normal;
3544                    margin-right: 3px;
3545                  }
3546                  .container .text-wrapper strong {
3547                    font-weight: normal;
3548                  }
3549                  .container .badge svg {
3550                    height: 18px;
3551                    width: 40px;
3552                    // transform: translateY(1px);
3553                  }
3554                  @media (max-width: 1140px) {
3555                    .container .text-wrapper {
3556                      font-size: 10px;
3557                    }
3558                  }
3559                  @media (max-width: 994px) {
3560                    .container .text-wrapper {
3561                      font-size: 8.5px;
3562                    }
3563                  }
3564                  @media (max-width: 767px) {
3565                   .desktop-klarna .container {
3566                      justify-content: center !important;
3567                    }
3568                    .container .text-wrapper {
3569                      font-size: 11px;
3570                    }
3571                  }
3572                `;
3573
3574                klarnaElement.shadowRoot.appendChild(style);
3575            }
3576          });
3577           window.dispatchEvent(new Event('resize'));
3578           window.KlarnaOnsiteService = window.KlarnaOnsiteService || [];
3579            window.KlarnaOnsiteService.push({
3580            eventName: 'refresh-placements'
3581          });
3582        }, 25);
3583
3584        if(window.outerWidth > 767){
3585        if(openPopup == false){
3586          setTimeout(function(){
3587            openPopup = true;
3588            document.getElementById("la-boxy-footer-modal").setAttribute("style", "display: flex !important");
3589            document.querySelector(".la-prescription-boxy-footer").setAttribute("style", "display: flex !important");
3590            document.querySelector(".la-prescription-modal-close").setAttribute("style", "display: flex !important");
3591          }, 700);
3592        }else{
3593          setTimeout(function(){
3594            document.getElementById("la-boxy-footer-modal").setAttribute("style", "display: flex !important");
3595            document.querySelector(".la-prescription-boxy-footer").setAttribute("style", "display: flex !important");
3596            document.querySelector(".la-prescription-modal-close").setAttribute("style", "display: flex !important");
3597          }, 10);
3598        }
3599      }
3600
3601      setInterval(() => {
3602        const priceText = document
3603          .querySelector(".la-footer-row.la-subtotal .la-subtotal-price")
3604          ?.textContent.trim();
3605
3606        const price = priceText
3607          ?.replace(/[^\d.]/g, "")
3608          .replace(".", "");
3609
3610        const elements = document.querySelectorAll("[data-purchase-amount]");
3611
3612          if (price) {
3613            elements.forEach((element) => {
3614              element.removeAttribute("data-purchase-amount");
3615              element.setAttribute("data-purchase-amount", price);
3616            });
3617          }
3618        }, 15);
3619
3620});
3621//****************  Hightlight last selected item start ***************/
3622
3623// Records every choice the customer makes in the widget (prescription type, submission
3624// method, lens group, lens, lens options, add-ons). When a step is re-rendered after
3625// pressing Back, the previously chosen card gets a highlight and a "Your previous choice" badge.
3626// The widget's own state resets on back navigation, so selections are tracked here.
3627document.addEventListener("DOMContentLoaded", function () {
3628LensAdvizor.prevSelectionBadgeText = "✓";
3629LensAdvizor.prevSelections = {};
3630// Work out which step (and sub-step) an input belongs to, so selections
3631// for one lens/step never leak onto another.
3632LensAdvizor.prevSelectionStepKey = function(input) {
3633    const response = LensAdvizor.response || {};
3634    if (input.closest('.la-render-addons')) {
3635        const lensId = response.lens && response.lens.id ? response.lens.id : 'flow';
3636        return 'addons:' + lensId + ':' + (response.addOnsStep || 0);
3637    }
3638    if (input.closest('.la-render-options')) {
3639        const lensId = response.lens && response.lens.id ? response.lens.id : '';
3640        return 'options:' + lensId + ':' + (input.dataset.optionType || input.name);
3641    }
3642    const lensesStep = input.closest('.la-render-lenses');
3643    if (lensesStep) {
3644        if (lensesStep.classList.contains('x-pro')) return 'lensGroup';
3645        const pt = response.selectedPrescriptionType;
3646        return 'lens:' + (pt ? pt.id : '');
3647    }
3648    if (input.closest('.la-label-btn-wrapper') && input.closest('.la-label-btn-wrapper').classList.contains('la-submission-method')) {
3649        return 'submissionMethod';
3650    }
3651    if ((LensAdvizor.prescriptionTypes || []).some(pt => String(pt.id) === String(input.value))) {
3652        return 'prescriptionType';
3653    }
3654    return null;
3655};
3656// Record selections as they happen (click covers taps on the card labels too,
3657// keydown covers Enter/Space selection).
3658LensAdvizor.prevSelectionCapture = function(e) {
3659    const input = e.target;
3660    if (!input || input.tagName !== 'INPUT' || input.disabled) return;
3661    if (input.type !== 'radio' && input.type !== 'checkbox') return;
3662    if (!input.closest('#lensadvizor-prescription-modal')) return;
3663    if (!input.closest('.la-label-btn-wrapper')) return;
3664    if (e.type === 'keydown' && !(LensAdvizor.clickKeycodes || ['Enter', 'Space']).includes(e.code)) return;
3665    const key = LensAdvizor.prevSelectionStepKey(input);
3666    if (!key) return;
3667    if (input.type === 'checkbox') {
3668        // Read the checkbox state on the next tick so it reflects the toggle
3669        setTimeout(function() {
3670            const list = LensAdvizor.prevSelections[key] || [];
3671            const idx = list.indexOf(input.value);
3672            if (input.checked && idx === -1) list.push(input.value);
3673            if (!input.checked && idx > -1) list.splice(idx, 1);
3674            LensAdvizor.prevSelections[key] = list;
3675        }, 0);
3676    } else {
3677        LensAdvizor.prevSelections[key] = [input.value];
3678    }
3679};
3680document.addEventListener('click', LensAdvizor.prevSelectionCapture, true);
3681document.addEventListener('keydown', LensAdvizor.prevSelectionCapture, true);
3682// Re-apply highlights whenever a step is (re)rendered. Skips inputs that are
3683// already checked - the current selection is styled via CSS on :checked instead.
3684LensAdvizor.prevSelectionApply = function() {
3685    const modal = document.querySelector('#lensadvizor-prescription-modal');
3686    if (!modal) return;
3687    modal.querySelectorAll('.la-label-btn-wrapper').forEach(function(wrapper) {
3688        const input = wrapper.querySelector('input[type="radio"], input[type="checkbox"]');
3689        let isPrevious = false;
3690        let isAddon;
3691        if (input && !input.disabled && !input.checked) {
3692            const key = LensAdvizor.prevSelectionStepKey(input);
3693            const list = key ? LensAdvizor.prevSelections[key] : null;
3694            isPrevious = !!(list && list.indexOf(input.value) > -1);
3695            isAddon = list;
3696        }
3697        
3698        wrapper.classList.toggle('la-prev-selected', isPrevious);
3699        const label = wrapper.querySelector('.la-label-btn');
3700        let badge = wrapper.querySelector('.la-prev-selected-badge');
3701        
3702        if (isPrevious && !badge && label) {
3703            badge = document.createElement('span');
3704            badge.className = 'la-prev-selected-badge';
3705            badge.textContent = LensAdvizor.Translation && LensAdvizor.Translation.getTranslatedText ?
3706                LensAdvizor.Translation.getTranslatedText(LensAdvizor.prevSelectionBadgeText) :
3707                LensAdvizor.prevSelectionBadgeText;
3708            label.appendChild(badge);
3709        } else if (!isPrevious && badge) {
3710            badge.remove();
3711        }
3712
3713        const parentLabel = document.querySelector(".la-choose-prescription-wrapper");
3714        if (parentLabel && parentLabel.classList.contains("la-render-addons")) {
3715            document.querySelectorAll(".la-tap-select").forEach(function (addON) {
3716
3717              var addOntrue = document.querySelector(".la-footer-frame-prescription.value8").getAttribute("addOn");
3718                const AddOnVal = addON.value;
3719                
3720                if (AddOnVal === addOntrue) {
3721                    // console.log(addON);
3722
3723                    const parent = addON.closest(".la-label-btn-wrapper");
3724                    if (parent) {
3725                        parent.classList.add("la-prev-selected");
3726                    }
3727                }
3728            });
3729        }
3730
3731    });
3732};
3733LensAdvizor.prevSelectionScheduled = false;
3734LensAdvizor.prevSelectionSchedule = function() {
3735    if (LensAdvizor.prevSelectionScheduled) return;
3736    LensAdvizor.prevSelectionScheduled = true;
3737    requestAnimationFrame(function() {
3738        LensAdvizor.prevSelectionScheduled = false;
3739        LensAdvizor.prevSelectionApply();
3740    });
3741};
3742// Every step fires component:DidMount after its DOM is in place
3743document.addEventListener('LensAdvizor:component:DidMount', LensAdvizor.prevSelectionSchedule);
3744
3745// Grouped-lens layout: lens cards live inside collapsed accordions where their inputs
3746// are DISABLED and hidden, and expanding is a style change the observer below misses.
3747// On the lens step, expand the group holding the previously chosen lens, then re-apply.
3748LensAdvizor.prevSelectionExpandLensGroup = function() {
3749    const modal = document.querySelector('#lensadvizor-prescription-modal');
3750    const lensesStep = modal && modal.querySelector('.la-render-lenses');
3751    if (!lensesStep) return;
3752    const inputs = lensesStep.querySelectorAll('.la-tap-select');
3753    if (!inputs.length) return;
3754    const key = LensAdvizor.prevSelectionStepKey(inputs[0]);
3755    const list = key ? LensAdvizor.prevSelections[key] : null;
3756    if (list && list.length) {
3757        const input = Array.prototype.find.call(inputs, function(i) {
3758            return list.indexOf(i.value) > -1;
3759        });
3760        const wrapper = input && input.closest('.la-accordion-wrapper');
3761        if (wrapper) {
3762            const body = wrapper.querySelector('.la-accordion-body');
3763            if (body && body.offsetHeight === 0 && wrapper.firstElementChild) wrapper.firstElementChild.click();
3764        }
3765    }
3766    LensAdvizor.prevSelectionSchedule();
3767};
3768
3769});
3770
3771document.addEventListener('LensAdvizor:lens:rendered', function() {
3772    setTimeout(LensAdvizor.prevSelectionExpandLensGroup, 0);
3773});
3774// Safety net for re-renders that do not fire DidMount (for example add-on updates)
3775document.addEventListener('LensAdvizor:selectLensModal:open', function() {
3776    const contentBox = document.querySelector('.la-prescription-modal-content-body');
3777    if (!contentBox || contentBox._prevSelectionObserved) return;
3778    contentBox._prevSelectionObserved = true;
3779    new MutationObserver(LensAdvizor.prevSelectionSchedule).observe(contentBox, {
3780        childList: true,
3781        subtree: true
3782    });
3783    LensAdvizor.prevSelectionSchedule();
3784});
3785// Start fresh once the item has been added to the cart
3786document.addEventListener('LensAdvizor:addToCart:success', function() {
3787    LensAdvizor.prevSelections = {};
3788});
3789//*******************************  Hightlight last selected item end **********************************/
3790
3791
3792//****************************  Order Summary layout start ********************************/
3793document.addEventListener("LensAdvizor:review:rendered", function (e) {
3794  // console.log(e);
3795  const Ptitle = document.querySelector(
3796    ".la-footer-text.la-footer-frame-variant-title"
3797  ).textContent;
3798
3799  const Pprice = document.querySelector(
3800    ".la-footer-row .la-frame-price"
3801  ).textContent.replace(/\s+/g, "");
3802
3803  const summaryItems = document.querySelectorAll(
3804    ".summary-prescription-wrapper:not(.hide-prescription)"
3805  );
3806let pdValue;
3807  document.querySelectorAll('.la-label-description').forEach(function (desc) {
3808    const text = desc.innerHTML;
3809
3810    // check PD is exits
3811    const match = text.match(/PD:\s*([^<]+)/i);
3812
3813    if (match) {
3814        pdValue = match[1].trim();
3815    }
3816});
3817
3818  let reviewHTML = `
3819    <div class="la-review-main-wrapper">
3820
3821      <div class="la-review-inner">
3822        <div class="la-lens-details la-lens-wrapper frame-main-wrapper">
3823          <div class="la-lens-title">
3824            <strong>Frame</strong>
3825            <p class="la-label-description la-lens-option-text frame-title">${Ptitle}</p>
3826          </div>
3827          <div class="la-lens-price">
3828            <div class="la-lens-price-inner frame-price">
3829              <strong>${Pprice}</strong>
3830            </div>
3831          </div>
3832        </div>
3833      </div>
3834  `;
3835
3836  summaryItems.forEach((item) => {
3837    const heading = item.querySelector(".summary-prescription-heading")?.textContent.trim() || "";
3838    const title = item.querySelector(".summary-prescription-title")?.innerHTML || "";
3839    const price = item
3840    .querySelector(".summary-prescription-title")
3841    ?.getAttribute("new-price") || "";
3842
3843    reviewHTML += `
3844      <div class="la-review-inner">
3845        <div class="la-lens-details la-lens-wrapper">
3846          <div class="la-lens-title">
3847            <strong>${heading}</strong>
3848            <p class="la-label-description la-lens-option-text lens-options-title">
3849              ${title}
3850            </p>
3851          </div>
3852          <div class="la-lens-price">
3853            <div class="la-lens-price-inner">
3854              ${price}
3855            </div>
3856          </div>
3857        </div>
3858      </div>
3859    `;
3860  });
3861
3862document.querySelectorAll('.la-label-description').forEach(function (item) {
3863
3864    const text = item.innerHTML.replace(/<br\s*\/?>/gi, "\n");
3865    const odMatch = text.match(/OD Right:\s*([^\n]+)/i);
3866    const osMatch = text.match(/OS Left:\s*([^\n]+)/i);
3867
3868    if (odMatch) {
3869        reviewHTML += `
3870        <div class="la-review-inner">
3871            <div class="la-lens-details la-lens-wrapper la-lens-manually">
3872                <div class="la-lens-title">
3873                    <strong>OD Right</strong>
3874                    <p class="la-label-description la-lens-option-text lens-options-manully">
3875                        ${odMatch[1].trim()}
3876                    </p>
3877                </div>
3878                <div class="la-lens-price">
3879                    <div class="la-lens-price-inner"></div>
3880                </div>
3881            </div>
3882        </div>`;
3883    }
3884
3885    if (osMatch) {
3886        reviewHTML += `
3887        <div class="la-review-inner">
3888            <div class="la-lens-details la-lens-wrapper la-lens-manually">
3889                <div class="la-lens-title">
3890                    <strong>OS Left</strong>
3891                    <p class="la-label-description la-lens-option-text lens-options-manully">
3892                        ${osMatch[1].trim()}
3893                    </p>
3894                </div>
3895                <div class="la-lens-price">
3896                    <div class="la-lens-price-inner"></div>
3897                </div>
3898            </div>
3899        </div>`;
3900    }
3901});
3902
3903
3904if(pdValue != null){
3905  reviewHTML += `
3906      <div class="la-review-inner">
3907        <div class="la-lens-details la-lens-wrapper">
3908          <div class="la-lens-title">
3909            <strong>PD</strong>
3910            <p class="la-label-description la-lens-option-text lens-options-pd">${pdValue}</p>
3911          </div>
3912          <div class="la-lens-price">
3913            <div class="la-lens-price-inner">
3914            </div>
3915          </div>
3916        </div>
3917      </div>
3918    `;
3919}
3920
3921document.querySelectorAll('.la-review-item').forEach(function (item) {
3922    const descriptions = item.querySelectorAll('.la-label-description');
3923    descriptions.forEach(function (description) {
3924        const text = description.textContent.trim();
3925        if (text.includes('Prescriptions over SPH')) {
3926
3927            const priceSource = item.querySelector('.la-review-right.la-label-title');
3928
3929            reviewHTML += `
3930            <div class="la-review-inner">
3931              <div class="la-lens-details la-lens-wrapper">
3932                <div class="la-lens-title">
3933                  <strong>Prescriptions SPH or CYL Charges</strong>
3934                  <p class="la-label-description la-lens-option-text lens-options-over-charges">${text}</p>
3935                </div>
3936                <div class="la-lens-price">
3937                  <div class="la-lens-price-inner lens-options-over-charges-prices">
3938                   ${priceSource.textContent.trim()}
3939                  </div>
3940                </div>
3941              </div>
3942            </div>
3943          `;
3944          document.querySelector(".la-footer-row.la-subtotal").insertAdjacentHTML(
3945          'beforebegin', `
3946          <div class="la-footer-row-wrapper prescriptions-overcharge">
3947              <h3 class="la-translate">Prescriptions SPH or CYL Charges</h3>
3948              <div class="la-footer-row la-footer-lens-wrapper">
3949                  <div class="la-footer-lens-price">${priceSource.textContent.trim()}</div>
3950              </div>
3951          </div>
3952                    `);
3953        }
3954    });
3955});
3956
3957 var discount = false;
3958  if(discount == true){
3959
3960    const discountMessage = `<p><strong>LENSES25 applied</strong> 25% off your lenses</p>`;
3961  const temp = document.createElement("div");
3962  temp.innerHTML = discountMessage;
3963
3964  const boldText = temp.querySelector("strong")?.textContent.trim() || "";
3965  const description = temp.querySelector("p")?.textContent.replace(boldText, "").trim() || "";
3966
3967  reviewHTML += `
3968      <div class="la-review-inner">
3969        <div class="la-lens-details la-lens-wrapper">
3970          <div class="la-lens-title">
3971            <strong>${boldText}</strong>
3972            <p class="la-label-description la-lens-option-text lens-options-title">
3973              ${description}
3974            </p>
3975          </div>
3976          <div class="la-lens-price">
3977            <div class="la-lens-price-inner lens-discount-price">
3978            </div>
3979          </div>
3980        </div>
3981      </div>
3982    `;
3983  }
3984    reviewHTML += `
3985      <div class="la-review-inner total-review">
3986        <div class="la-lens-total la-lens-wrapper">
3987          <div class="la-lens-title">
3988            <strong>Total</strong>
3989          </div>
3990          <div class="la-lens-price">
3991            <div class="la-lens-total-price">
3992             <strong></strong>
3993            </div>
3994          </div>
3995        </div>
3996      </div>
3997    `;
3998
3999  reviewHTML += `</div>`;
4000
4001  document
4002    .querySelector(".la-review-details-wrapper")
4003    .insertAdjacentHTML("afterend", reviewHTML);
4004
4005    if(EnableDiscount == true){
4006        document.querySelectorAll('.old-price, .new-price').forEach(function(el) {
4007          el.textContent = el.textContent.replace(/[+-]/g, '');
4008        });
4009    } else{
4010      document.querySelectorAll('.la-lens-price-inner').forEach(function(el) {
4011          el.textContent = el.textContent.replace(/[+-]/g, '');
4012      });
4013    }
4014    
4015
4016    const parentLabel = document.querySelector(".la-subtotal-price").textContent;
4017      document.querySelector(".la-lens-total-price strong").textContent = `${parentLabel.replace(/\s+/g, "")}`;
4018
4019
4020    const priceText = document.querySelector(".la-footer-row.la-subtotal .la-subtotal-price")?.textContent.trim();
4021      const price = priceText
4022        ?.replace(/[^\d.]/g, "")
4023        .replace(".", "");       
4024
4025        
4026        const currencyCode = document.body.getAttribute('currency-code');
4027          const klarna =`
4028        <klarna-placement
4029           data-key="credit-promotion-badge"
4030           data-locale="en-${ currencyCode }"
4031           data-purchase-amount="${price}"
4032           class="total-summary-klarna"
4033           data-message-preference="prequalification"
4034        ></klarna-placement> `
4035         document.querySelector(".la-review-inner.total-review").insertAdjacentHTML('afterend', klarna);
4036        setInterval(function(){
4037         const klarnaElement = document.querySelector('klarna-placement.total-summary-klarna');
4038          if (klarnaElement?.shadowRoot) {
4039            const container = klarnaElement.shadowRoot.querySelector('.container');
4040            if (container) {
4041              container.classList.add('order-summary-klarna');
4042            }
4043          }
4044        }, 10);
4045
4046});
4047//****************  Order Summary layout end ***************/
4048
4049}
4050(function ($) {
4051
4052  function loadSlick(callback) {
4053
4054    // Slick already available
4055    if (typeof $.fn.slick === 'function') {
4056      callback();
4057      return;
4058    }
4059
4060    // Load Slick CSS
4061    if (!$('link[data-slick-css]').length) {
4062      $('<link>', {
4063        rel: 'stylesheet',
4064        type: 'text/css',
4065        href: 'https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.css',
4066        'data-slick-css': 'true'
4067      }).appendTo('head');
4068    }
4069
4070    // Check if Slick JS is already being loaded
4071    var $slickScript = $('script[data-slick-js]');
4072
4073    if ($slickScript.length) {
4074
4075      // Wait until existing script finishes loading
4076      $slickScript.off('load.slickInit').one('load.slickInit', function () {
4077        console.log('Slick library loaded');
4078        callback();
4079      });
4080
4081      return;
4082    }
4083
4084    // Load Slick JS
4085    $('<script>', {
4086      src: 'https://cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js',
4087      'data-slick-js': 'true'
4088    })
4089    .on('load', function () {
4090      console.log('Slick library loaded');
4091      callback();
4092    })
4093    .on('error', function () {
4094      console.log('Failed to load Slick library');
4095    })
4096    .appendTo('body');
4097  }
4098
4099
4100  function initSlick() {
4101    // Mobile only
4102    if (window.innerWidth >= 768) {
4103      return;
4104    }
4105    var $elem = $('.la-metafield-inner-wrapper');
4106    if (!$elem.length) {
4107      console.log('Slider element not found');
4108      return;
4109    }
4110    // Slick must be available
4111    if (typeof $.fn.slick !== 'function') {
4112      console.log('Slick is not loaded');
4113      return;
4114    }
4115    // Destroy existing slider before reinitializing
4116    if ($elem.hasClass('slick-initialized')) {
4117      $elem.slick('unslick');
4118    }
4119    // Small delay so LensAdvisor DOM is completely rendered
4120    setTimeout(function () {
4121      if (!$elem.length) {
4122        return;
4123      }
4124     $elem.slick({
4125        centerMode: false,
4126        infinite: true,
4127        autoplay: true,
4128        autoplaySpeed: 5000,
4129        arrows: false,
4130        dots: false,
4131        slidesToShow: 1,
4132        slidesToScroll: 1,
4133        adaptiveHeight: true
4134      });
4135    }, 100);
4136  }
4137  function waitForjQuery() {
4138    if (typeof window.jQuery === 'undefined') {
4139      setTimeout(waitForjQuery, 200);
4140      return;
4141    }
4142    loadSlick(initSlick);
4143  }
4144  // Initial page load
4145  if (document.readyState === 'loading') {
4146    document.addEventListener('DOMContentLoaded', function () {
4147      waitForjQuery();
4148    });
4149  } else {
4150    waitForjQuery();
4151  }
4152  // LensAdvisor content rendered
4153  document.addEventListener(
4154    'LensAdvizor:prescriptionTypes:rendered',
4155    function () {
4156      console.log('LensAdvisor prescription types rendered');
4157      // Re-run Slick initialization
4158      waitForjQuery();
4159    }
4160  );
4161})(window.jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.