import{Jt as e,Pt as a,Wt as r,en as t,yt as n}from"./630ba094.L_X-5TXi.js";import{Bh as s,Dd as o,ET as i,FT as l,Hd as u,Hh as d,Iu as c,Md as p,Uh as m,Vh as v,Wb as _,Wd as y,Wh as g,_y as f,cT as h,dd as b,fT as E,fd as P,gb as T,gp as M,gu as S,gy as A,hg as I,hh as R,hy as w,lT as C,lf as B,lx as k,mT as D,nE as L,oT as O,pT as F,py as x,su as Y,tT as H,ud as N,vu as j,wb as U,xO as W,zh as z}from"./6ec9a0fa.rdcQt2v8.js";import{n as V,r as $,t as G}from"./402b40d8.CQI88cKn.js";function J({bannerId:e,errorType:a,children:t,...s}){const{observability:o}=W(),{tone:i,...l}=s;return r(()=>{o.log("error_log_banner_error_banner_rendered","[Displayed Error] Error banner was rendered",{bannerId:e})},[e,o]),n(u,{errorType:a,id:e,tone:i,...l,children:t})}function q(){const{checkout:e,i18n:r,shopPay:n}=W(),{value:s}=e.negotiator.current.fields.paymentMethods,{value:o}=e.negotiator.current.fields.managedByMarketsPro,i=R({managedByMarketsPro:o}),l=a(()=>_({checkout:e})),u=b(),{value:d}=e.negotiator.current.fields.deferredTotal,p=n.session.selectedPaymentMethods.value[0],m=n.session.paymentMethodOption.value,v=N(g(H)).value,y=p&&S(p)?c(p.paymentAttributes.brand):void 0,f=I(),h=t(()=>{if("SHOPIFY_INSTALLMENTS"!==m?.name){if(f.value)return!0;if(!p)return!0;if(u.value&&!d?.amount.amount)return!0;if(S(p)){if(v)return!1;const e=s?.filter(e=>"direct"===e.type).flatMap(e=>e.paymentBrands);if(e&&e.length>0){const a=Y(p.paymentAttributes);if(!a)return;return e.includes(a)}}return!j(p)||function(e,a,r){return!e&&a&&r?.some(e=>L(e,["ideal"]))}(l.value,i,s)}},[m?.name,f.value,p,u.value,d?.amount.amount,v,s,l.value,i]);return{paymentMethods:s,isSelectedPaymentMethodSupported:h,notSupportedError:t(()=>{if(p&&!1===h){if(S(p))return y?r.translate("payment.brand_not_available",{brand:y}):r.translate("payment.generic_incorrect_card_info");if(j(p))return l.value?r.translate("payment_errors.payment_method_unavailable_with_subscriptions"):r.translate("payment.shop_pay_ideal_unavailable_error")}},[h,p,y,r,l.value]),label:y}}function X(){const{i18n:r,checkout:{negotiator:t,latestReceipt:n,journey:u,configuration:c,installments:_},embed:y,shopPay:b}=W(),{delegatedPaymentInstrument:M,inventoryRecoverySignal:S}=t.context,{lastJourneyProgression:I}=t,{walletUsedForSubmissionSignal:R,inMemoryApplePayParts:{asPaymentMethod:L},receiptErrorSignal:Y}=T(),{paymentMethods:j}=t.current.fields,{notSupportedError:J}=q(),{violations:X}=g(H),K=N(g(C)).value,Q=N(g(F)).value,Z=N(g(O)).value,ee=N(g(E)).value,{violations:ae}=g(D),re=N({violations:X}).value,te=ae.value,ne=!(("success"===I.value.type||"error"===I.value.type)&&"completion"===I.value.negotiationStage)&&1===te.size&&"PAYMENTS_METHOD"===te.values().next().value?.code,se=N(g(i)).value,oe=p(),{hasError:ie,error:le}=m(h),{hasError:ue,error:de}=s(),{hasError:ce}=v(),{hasError:pe}=d(),me=P(le?{type:"payment",code:le}:void 0),ve=function(e){const{i18n:a}=W();if(e&&"SURVEY_EXITED"!==e.code)return a.translate("hsa_qualification_errors",{scope:e.code.toLowerCase()})}(de),_e=t.parts.generalPaymentError.value,ye=t.parts.generalPaymentErrorCode.value,ge=$(t.parts.directPaymentErrors),fe=V(t.parts.directPaymentErrors),he=e(!1),be=o(),Ee=G(_e,ye),Pe=Ee&&!x(ye)&&!A(ye)&&!f(ye)&&!w(ye),Te=r.translate("order_errors.inventory_reservation_failure"),Me=N(z(l)),Se=Boolean(k(j.value).length),Ae=U("billingAddress"),Ie=B().value,Re="APPLE_PAY"===R.value||Ie,we="INCORRECT_CVC"===le&&"CREDIT_CARD"===b?.session.selectedPaymentMethods.value[0]?.paymentMethod,Ce=S.value,Be=null!=Ce&&Ce.receiptId===n.value?.id,ke="failed"===I.value.type&&"completion"===I.value.negotiationStage,De=Boolean(Pe||ge||oe||ke),Le=Be&&!Ce.dismissed&&!De,Oe=b.installments.failedAttempt.value,Fe=Oe?.retryable&&Oe.recoveryAction,xe=a(()=>Boolean(y&&c.isPaymentInstrumentsDelegationEnabled&&M.value&&Me.value&&!Ae.value)).value;if(u.progressing.value)return{tone:"auto"};let Ye,He,Ne="critical";if(xe&&(Ye=r.translate("payment_errors.payment_method_billing_address")),Pe&&(he.current=!0,Ne="warning",Ye=Ee),oe&&(he.current=!0,Ye=oe),ge&&(Ye=r.translate("payment.generic_incorrect_card_info")),!(ie&&le&&me)||he.current||"GOOGLE_PAY"===R.value||Re&&!L.value||Y.value||be||we||(Ye=me),ke&&"failed"===I.value.type&&(Ye=I.value.fetchFailed?r.translate("order_errors.network_failure"):"decision_rule_block"===I.value.reason?r.translate("payment_errors.generic_error"):r.translate("order_errors.creation_failure")),pe&&!he.current&&(Ye=r.translate("order_errors.creation_failure")),ce&&!De&&(Be?Le:!he.current)&&(Ye=Te,Le&&(Ne="critical")),ue&&ve&&!he.current&&(Ye=ve),Fe&&!_.isUnavailable.value&&b.session.isInstallmentsSelected.value&&!De&&!fe&&!Y.value&&!xe){const e=e=>r.translate("payment_errors.installments",{scope:`${Fe.toLowerCase()}.${e}`});Ye=e("body"),He={heading:e("heading"),message:Ye,tone:"RESTART_PAYMENT_METHOD"===Fe?"warning":"critical"}}if(se&&(Ye=r.translate("store_credit_errors.generic_error")),K&&(Ye=r.translate("payment.expired_payment_method")),re){const e=[...X.value][0]?.nonLocalizedMessage?.split(":")[1]?.toLowerCase().trim();Ye=void 0!==e&&"string"==typeof r.lookup(`payment_brand.${e}`)?r.translate("payment.brand_not_available",{brand:r.translate("payment_brand",{scope:e})}):r.translate("payment.generic_incorrect_card_info")}return Z&&(Ye=r.translate("payment.generic_incorrect_card_info")),ee&&(Ye=r.translate("payment_errors.method_not_available")),Q&&(Ye=r.translate("payment_errors.generic_error")),ne&&(Ye=r.translate("payment_errors.available_methods_updated"),Ne="info"),J&&(Ye=J,Ne="critical"),Se&&Me.value&&(Ye=r.translate("address_management.invalid_billing_address_selected")),He&&He.message===Ye?He:{message:Ye,tone:Ne,inventoryRecoveryReceiptId:Le&&Ye===Te?n.value?.id:void 0}}function K({heading:a,message:t,tone:s,inventoryRecoveryReceiptId:o}){const{observability:i}=W(),l=e(Boolean(o)).current;return r(()=>{o&&i.counter({name:"inventory_recovery_error_banner_displayed",value:1})},[o,i]),n(Z,{heading:a,identifier:"PaymentErrorBanner",tone:s,suppressAutoFocus:l,children:t})}function Q(){const e=X();return e.message?n(K,{...e}):null}function Z({heading:e,children:a,identifier:r,tone:t,suppressAutoFocus:s=!1}){return"critical"===t||"warning"===t?n(J,{errorType:y.PaymentError,bannerId:r,heading:e,tone:t,autoFocus:!s,focusable:s,children:a}):n(M,{heading:e,tone:t,children:a})}export{q as a,X as i,Q as n,J as o,K as r,Z as t};