1import{B as e}from"./BaseElement.wji90fuE.min.js";import{i as t,a as i}from"./cart-lines.DmR2f2C6.min.js";import{r as n,c as r}from"./resolve-skus-batcher.Ya6AHsM6.min.js";import{i as s}from"./storefront-availability.DBaqX5PG.min.js";import{W as o}from"./WithApiClient.B8AOHZZP.min.js";import{W as c}from"./WithShopifyCart.Dy1sQhoJ.min.js";import{x as a,t as h}from"./vendor-lit.2u3dzq2T.min.js";import"./fetchWithCache.BJ12kVQ7.min.js";import"./vendor.D2HIaoTS.min.js";import"./cart-sections.BcMbGr3r.min.js";import"./debounce.uPZYEJlg.min.js";const d=e=>!t(e.properties),l=e=>((null==e?void 0:e.items)??[]).filter(d).map(e=>({key:e.key,sku:String(e.sku??"").trim()})).filter(e=>e.sku.length>0);Object.getOwnPropertyDescriptor;const u=e=>{const t=document.createElement("textarea");return t.innerHTML=e,t.value};let m=class extends(c(o(e))){constructor(){super(...arguments),this.checkInFlight=!1,this.hasPendingCheck=!1,this.checkGeneration=0,this.debounceTimer=null,this.oosNoticeUntil=0,this.boundOnCartUpdated=e=>{const t=e.detail;this.scheduleCheck(i(t)?t:void 0)}}connectedCallback(){super.connectedCallback(),document.addEventListener("cart:updated",this.boundOnCartUpdated),this.observeCartRerenders(),this.renderOosNotice(),this.scheduleCheck()}disconnectedCallback(){var e;super.disconnectedCallback(),document.removeEventListener("cart:updated",this.boundOnCartUpdated),null==(e=this.cartObserver)||e.disconnect(),this.debounceTimer&&clearTimeout(this.debounceTimer),this.checkGeneration+=1}render(){return a``}get proxyBase(){return window.__T1_PROXY_BASE__||"/apps/talonone-proxy/api/public"}scheduleCheck(e){this.debounceTimer&&clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.check(e)},200)}async check(e){if(!this.isConnected)return;if(this.checkInFlight)return this.hasPendingCheck=!0,this.pendingCart=e,void(this.checkGeneration+=1);this.checkInFlight=!0;const t=this.checkGeneration;try{const s=e??await this.getCart();if(!this.isConnected||t!==this.checkGeneration)return;const o=l(s);if(!o.length)return void this.renderOosNotice();const c=[...new Set(o.map(e=>e.sku))];let a;try{a=await n(c,r(this.proxyBase),{includeOutOfStock:!0,bypassCache:!0})}catch(i){return}if(!this.isConnected||t!==this.checkGeneration)return;const h=await this.confirmOutOfStock(((e,t)=>{const i=[];for(const n of e){const e=t.get(n.sku);e&&e.availableForSale||i.push(n.key)}return i})(o,a),o,a);if(!this.isConnected||t!==this.checkGeneration)return;if(!h.length)return void this.renderOosNotice();const d=await this.getCart();if(!this.isConnected||t!==this.checkGeneration)return;const u=new Set(l(d).map(e=>e.key)),m=h.filter(e=>u.has(e));if(!m.length)return;const p=m.length===d.items.length;try{await this.removeItemFromCart(m,{sections:p}),this.oosNoticeUntil=Date.now()+8e3,this.isConnected&&this.renderOosNotice()}catch(i){}}finally{if(this.checkInFlight=!1,this.hasPendingCheck&&this.isConnected){this.hasPendingCheck=!1;const e=this.pendingCart;this.pendingCart=void 0,this.scheduleCheck(e)}}}async confirmOutOfStock(e,t,i){if(!e.length)return[];const n=new Set(e);return(await Promise.all(t.filter(e=>n.has(e.key)).map(async e=>{const t=i.get(e.sku);return t?!1===await s(t.productHandle,t.variantId)?e.key:null:e.key}))).filter(e=>null!==e)}observeCartRerenders(){const e=document.querySelector('cart-sections[section-id="cart-drawer"]');e&&(this.cartObserver=new MutationObserver(()=>{var t,i;null==(t=this.cartObserver)||t.disconnect(),this.isConnected&&this.renderOosNotice(),null==(i=this.cartObserver)||i.observe(e,{childList:!0,subtree:!0})}),this.cartObserver.observe(e,{childList:!0,subtree:!0}))}renderOosNotice(){if(!this.isConnected)return;const e=document.querySelector("[data-addon-oos]");if(!e)return;const t=this.oosNoticeUntil-Date.now();if(t<=0)return void e.replaceChildren();if(e.querySelector("alert-banner"))return;const i=document.createElement("alert-banner");i.setAttribute("type","error"),i.setAttribute("variant","default"),i.setAttribute("description",u(e.dataset.message??"")),i.setAttribute("close-label",u(e.dataset.closeLabel??"Close")),i.setAttribute("auto-dismiss",""),i.setAttribute("auto-dismiss-after",String(Math.ceil(t/1e3))),i.addEventListener("alert-banner::dismiss",()=>{this.oosNoticeUntil=0}),e.appendChild(i)}};m=((e,t)=>{for(var i,n=t,r=e.length-1;r>=0;r--)(i=e[r])&&(n=i(n)||n);return n})([h("cart-addon-availability")],m);export{m as CartAddonAvailability};
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.