var _____WB$wombat$assign$function_____=function(name){return (globalThis._wb_wombat && globalThis._wb_wombat.local_init && globalThis._wb_wombat.local_init(name))||globalThis[name];};if(!globalThis.__WB_pmw){globalThis.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}var window = _____WB$wombat$assign$function_____("window");
var self = _____WB$wombat$assign$function_____("self");
var document = _____WB$wombat$assign$function_____("document");
var location = _____WB$wombat$assign$function_____("location");
var top = _____WB$wombat$assign$function_____("top");
var parent = _____WB$wombat$assign$function_____("parent");
var frames = _____WB$wombat$assign$function_____("frames");
var opener = _____WB$wombat$assign$function_____("opener");
import{bk as q,bW as D,a as t,S as g,d as L,bX as j,i as E,aB as _,bm as W,a2 as X,I as F,E as T,bA as G,e as x,a0 as J,bY as K,bZ as w,K as B,b_ as N,m as Q,j as V,k as A,n as Y,b$ as y,aX as h,a7 as k,A as Z,U as $,c0 as H,c1 as ee,c2 as ne,c3 as C,bj as te}from"./app.ZXowmuNl.js";function I({progressing:n,onClick:e,cartEmpty:r}){const o=E();return t(_,{variant:"primary",disabled:n,loading:n,onClick:e,children:r?o("stock.return_to_store_label","Return to store"):o("stock.continue_cta_label","Continue checkout")})}function ae({progressing:n,onSecondaryClick:e}){const r=W(),o=E(),i=X();return t(_,{onClick:async()=>{try{await e()}catch(u){i.leaveBreadcrumb("Error negotiating before returning to cart",{error:u})}finally{window.location.replace(r.cart())}},variant:"plain",disabled:n,children:t(F,{spacing:"small200",blockAlignment:"center",children:t(T,{children:o("general.back_to_cart","Return to cart")})})})}function re(n){const e=q(),r=D();if(!e.hasStorefront&&n.cartEmpty)return null;const{primary:o,secondary:i}=se(e.hasStorefront,n,r);return t(j,{blockAlignment:"center",columns:g.when({viewportInlineSize:{min:"extraSmall"}},["auto","auto"]),inlineAlignment:g.when({viewportInlineSize:{min:"extraSmall"}},"end"),rows:"auto",spacing:"large300",children:[t(L,{display:g.default("none").when({viewportInlineSize:{min:"extraSmall"}},"auto"),children:i}),o,t(L,{display:g.default("auto").when({viewportInlineSize:{min:"extraSmall"}},"none"),inlineAlignment:"center",children:i})]})}function se(n,e,r){return n?{primary:e.cartEmpty&&r?null:t(I,{...e}),secondary:e.cartEmpty||r&&!e.cartEmpty?null:t(ae,{...e})}:!n&&!e.cartEmpty?{primary:t(I,{...e})}:{}}function oe({lineItems:n,cartEmpty:e,type:r,subtitle:o}){const{loading:i,value:c}=G(),{progress:u,progressing:z,negotiate:f}=x(),l=J().merchandiseLines,S=K(),m=w(()=>c?.lines??[],[c]),[b,O]=B(i),M=N();Q(M),V({stage:b?A.Loading:A.Complete,id:"StockProblems"});const R=Y(M,async()=>{const s=n.filter(({problem:a})=>a.type===y.Unshippable||a.type===y.Unfulfillable).map(({line:a})=>a.stableId);s.length&&p(s),await u()}),p=h(s=>{const a=l.peek();l.value=a.filter(({stableId:d})=>!s.includes(d))},[l]),P=w(()=>m.reduce((s,a)=>({...s,[a.stableId]:a}),{}),[m]),U=h(async()=>{const s=n.filter(({problem:a})=>a.type===y.OutOfStock).map(({line:a})=>a.stableId);s.length&&(p(s),await f({}))},[n,f,p]),v=h(()=>{const s=l.peek();l.value=s.flatMap(a=>{const d=P[a.stableId];return d?d.quantity===0?[]:[{...a,quantity:d.quantity}]:[]})},[P,l]);return k(function(){v()},[m,p,v]),k(()=>{i||(O(!1),S.notify({checkout_in_progress:!1}))},[i,b,S]),t(ee,{message:o,errorType:Z.InventoryError,children:t($,{spacing:"loose",children:[t(T,{children:o}),n.length>0?t(H,{lineItems:n,loading:b,type:r}):null,t(re,{cartEmpty:e,progressing:z,onClick:R,onSecondaryClick:U})]})})}function le(){const{canBeDismissed:n,...e}=ne(),{progress:r}=x(),[o,i]=B(!0),c=h(()=>{r(()=>{i(!1)})},[r]),u=n?{blocking:!1,onClose:c}:{blocking:!0};return k(()=>()=>{C.value="none"},[]),t(te,{id:"stock-problems-modal",padding:!0,open:o,title:e.title,size:"large",accessibilityLabel:e.title,onOpen:()=>{C.value="stockProblems"},...u,children:t(oe,{...e})})}export{le as default};