import{c as d,u as e,b as A,h as E,q as N,y as S}from"./vendor.CynPCimz.js";import{d as h,ah as g,ai as P,b as C,aj as I,R as B,$ as O,f as R,ak as m,al as v,am as V,an as U,U as b,ao as L,ap as M,aq as w,ar as D}from"./app.BXvw8ij6.js";import{R as k,S as x}from"./SeparatePaymentsNotice.B_PhZdgP.js";import{S as Y}from"./ShopPayOptInDisclaimer.gFY0wGc4.js";const q=t=>e(v,{children:t}),W="disable-view-transitions-for-pay-button-section",T="checkout-pay-button-section";function X(){const t=document.createElement("style");return t.setAttribute("id",W),t.textContent=`
    #${T}, #${T} * {
      view-transition-name: none !important;
    }
  `,document.head.appendChild(t),t}function tt(){const t=h("Checkout::Actions::RenderBefore"),o=g(),{PayButton:a}=P(),{offsitePopupController:p}=C();return d(()=>{if(p.isOpen.value){const u=X();return()=>{u.remove()}}}),e(m,{target:"cart.paymentLines[0]",children:e(I,{impressionType:"pay_now_button",impressionFeatures:[],children:[t.length!==0&&e(A,{children:[e(B,{extensions:t,render:q}),e(O,{spacing:"base"})]}),e(R,{gap:"base",ref:o,id:T,children:[e($,{}),e(k,{children:e(a,{})}),e(Y,{}),e(x,{})]})]})})}const F=new Map([["PAYMENTS_UNACCEPTABLE_PAYMENT_AMOUNT",{status:"warning",priority:-1,negotiationStage:"completion"}],["TAX_NEW_TAX_MUST_BE_ACCEPTED",{status:"warning",priority:-2,negotiationStage:"completion"}]]);function $(){const t=V(),o=G(t.value,F);return e(m,{target:"cart.paymentLines[0]",children:o.map(a=>e(U,{notice:a,errorType:b.PaymentError},a.code))})}function G(t,o){const a=L(),[p,u]=E([]),l=N(({violations:i,negotiationStage:y})=>{const r=[],_=i.some(n=>D.has(n.code));for(const n of i)if(!j(n)&&!(_&&(n.code==="PAYMENTS_UNACCEPTABLE_PAYMENT_AMOUNT"||n.code==="TAX_NEW_TAX_MUST_BE_ACCEPTED"))&&o.has(n.code)){if(_)continue;const c=o.get(n.code);y&&y===c?.negotiationStage&&r.push({...n,tone:c?.tone,priority:c?.priority})}if(r.length>=1){const c=r.map(s=>s.priority??0).reduce((s,f)=>s>f?s:f);return r.filter(s=>(s.priority??0)>=c)}return r},[o]);return S(()=>{t&&u(l({violations:t}))},[l]),M(i=>{i.type==="complete"||i.type==="invalid"||i.type==="failed"||!a.current||u(l({violations:i.violations,negotiationStage:i.negotiationStage}))}),p.filter(w("localizedMessage"))}function j(t){return t.__typename!=="ConfirmChangeViolation"&&t.__typename!=="UnprocessableTermViolation"&&t.__typename!=="RemoveTermViolation"}export{tt as P};
