import{T as re,U as oe,q as j,r as c,J as s,a1 as _,a2 as Pe,a3 as xe,a4 as ne,a5 as se,a6 as Ae,a7 as M,W as O,a8 as Q,a9 as Me,aa as ke,ab as b,X as Re}from"./nTjlm9u_.js";import{i as Ee,I as G}from"./eLjfAXB0.js";import{s as te}from"./CW3YPl1M.js";import{P as D}from"./CFAdZs5D.js";import{u as De}from"./CKd1e-q7.js";async function ie(n){return re("user/credit-cards",n)}async function ae(n){return oe("user/credit-card-create",n)}async function $e(){return(await(await fetch("https://api64.ipify.org?format=json")).json()).ip}const qe={visa:/^4[0-9]{6,}$/,mastercard:/^5[1-5][0-9]{5,}$/,americanExpress:/^3[47][0-9]{5,}$/,discover:/^6(?:011|5[0-9]{2})[0-9]{3,}$/,dinersclub:/^3(?:0[0-5]|[68][0-9])[0-9]{4,}$/,jcb:/^(?:2131|1800|35[0-9]{3})[0-9]{3,}$/,elo:/^(4011|4576|5067|5090)[0-9]{12}$/,hipercard:/^(6062|3841)[0-9]{12}$/,aura:/^50(?:40|41)[0-9]{10,12}$/,otherBrand:/^(?!4|5|3|6)[0-9]{12,19}$/,realcard:/^63[7-9][0-9]{13}$/,assomise:/^50[1-3][0-9]{12,}$/,fortbrasil:/^6281[0-9]{12}$/,hiper:/^6370[0-9]{10,12}$/,sorocred:/^6277[0-9]{12,}$/,banese:/^6361[0-9]{12}$/,credishop:/^6042[0-9]{12}$/,cabal:/^6043[0-9]{12}$/};function Le(n){for(const[v,I]of Object.entries(qe))if(I.test(n))return v;return"unknown"}async function Ne(n){return re("invoice/show",n)}async function Ve(n){return oe("invoice/payment",n)}const X=j("useMessageLoadingStore",()=>{const n=c(!1),v=c(""),I=c(""),f=c(()=>m),l=c(()=>m);function w(){}function o(g){v.value=g.title,I.value=g.message||"",f.value=g.callback||(()=>m),l.value=g.callback||(()=>m),n.value=!0}function m(){n.value=!1}async function T(){f.value&&await f.value(),m()}async function u(){l.value&&await l.value(),m()}return{isVisible:n,message:I,title:v,show:o,hide:m,confirm:T,cancel:u,init:w}}),z=j("useCheckoutConfirmCreditCardsStore",()=>{const n=ce(),v=s(()=>{var i,h,q;return(q=(h=(i=g.data)==null?void 0:i.value)==null?void 0:h.producer)==null?void 0:q.id}),I=c(),f=c(null),l=ne(),{data:w,reset:o,init:m,find:T,isLoading:u}=_({findService:ie,getPayload:()=>({...l.value,producerId:v.value})}),g=_({findService:xe,getPayload:()=>l.value});function p(){o(),I.value=null,g.init()}Pe(v,i=>{i&&m()});const $=s(()=>{var i,h;return f.value?[f.value,...(i=w.value)==null?void 0:i.items]:(h=w.value)==null?void 0:h.items});function S(i){return{Mastercard:"bandeira-master.svg",Visa:"visa.svg",Elo:"bandeira-elo.svg",Hipercard:"bandeira-hipercard.svg",Amex:"bandeira-amex.svg"}[i]??""}function k(i){return(i==null?void 0:i.slice(0,4))+" "+(i==null?void 0:i.slice(4,6))}async function L(i){var h;n.show(!0,!1,i,"Comprar com o cartão",(h=l==null?void 0:l.value)==null?void 0:h.invoiceId)}return{selectedCardId:I,getCardBrandIcon:S,formatFirstSixDigits:k,isLoading:u,data:$,init:p,find:T,cardNotSaved:f,goAddCreditCardModal:L}}),Ue=j("useCheckoutConfirmStore",()=>{const n=ne(),v=c(),I=c(),f=c(!1),l=c(!1),w=c({installments:1}),{data:o,init:m,reset:T}=_({findService:Ne,getPayload:()=>({invoiceId:n.value.invoiceId})}),{form:u,confirm:g}=se({confirmService:Ve}),{data:p,find:$}=_({findService:Ee,getPayload:()=>({invoiceId:n.value.invoiceId})});async function S(){q().then(e=>{var t;((t=k.value)==null?void 0:t.length)==1&&(u.value.paymentMethod=k.value[0].paymentMethod)}),h(),x()}const k=s(()=>{var e;return(e=o.value)==null?void 0:e.paymentMethods}),L=s(()=>Ae(u.value.paymentMethod)?!1:!!(u.value.paymentMethod==D.FREE||u.value.paymentMethod==D.PIX||u.value.paymentMethod==D.BILLET||u.value.paymentMethod==D.CREDIT_CARD&&z().selectedCardId));function i(){X().hide(),V()}async function h(){var A,Z,ee;await $();const e=(A=p.value)==null?void 0:A.status,t=(Z=p.value)==null?void 0:Z.paymentMethod,a=(ee=p.value)==null?void 0:ee.qrCode,r=e===G.PROCESSING,y=e===G.PAID,E=e===G.FAIL,F=(t==null?void 0:t.toLowerCase())==="pix";if(t==null||t.toLowerCase(),y){i(),C(),O("CheckoutSuccess",{invoiceId:n.value.invoiceId});return}if(E){i(),Q().show({title:"Falha no processamento do pagamento",message:"Verifique os dados de pagamento e tente novamente!",callbackConfirmLabel:"Fechar",callback:()=>{}});return}if(r&&F&&a){i(),O("CheckoutPix",{invoiceId:n.value.invoiceId,eventId:n.value.eventId});return}if(r){X().show({title:"Processando pagamento",message:"Aguarde enquanto confirmamos a compra..."});return}else i()}async function q(){var e,t;try{await m()}catch(a){((t=(e=a==null?void 0:a.response)==null?void 0:e.data)==null?void 0:t.code)=="InvoiceShowService.INVOICE_BOOKING_EXPIRED"&&N()}}function N(){Q().show({title:"Pedido expirado",message:"Atenção, atingiu tempo limite para realizar a compra do pedido",callback:()=>{},callbackConfirmLabel:"Fechar"}),d(),C(),V(),Y()}function d(){O("LandingHome")}async function P(e){var t,a;u.value.paymentMethod===D.CREDIT_CARD&&(e?u.value.creditCardId=e.cardId:u.value.creditCardId=z().selectedCardId),u.value.invoiceId=n.value.invoiceId,u.value.installments=w.value.installments||1;try{X().show({title:"Processando...",message:"Estamos enviando os dados para pagamento!"}),await g(),R(),C()}catch(r){console.log(r),X().hide(),Q().show({title:"Erro ao processar pagamento",message:(a=(t=r==null?void 0:r.message)==null?void 0:t.data)==null?void 0:a.message})}}function x(){I.value=te(()=>{var e,t,a;(e=o.value)!=null&&e.expiredAt&&((t=p.value)==null?void 0:t.status)!==G.PAID&&Me().value>new Date((a=o.value)==null?void 0:a.expiredAt)&&N()},1e3)}function C(){clearInterval(I.value)}function R(){v.value=te(()=>{h()},1e3)}function V(){clearInterval(v.value)}const H=s(()=>{var e,t;return(t=(e=o.value)==null?void 0:e.invoiceItems)==null?void 0:t.reduce((a,r)=>a+r.quantity,0)}),U=s(()=>{var e,t;return(t=(e=o.value)==null?void 0:e.invoiceItems)==null?void 0:t.reduce((a,r)=>{var y;return a+r.quantity*((y=r.eventTicketModel)==null?void 0:y.priceToCustomer)},0)}),B=s(()=>{var e,t;return(t=(e=o.value)==null?void 0:e.invoiceItems)==null?void 0:t.reduce((a,r)=>{var y;return a+r.quantity*((y=r.eventTicketModel)==null?void 0:y.taxToCustomer)},0)}),ue=s(()=>{var e,t;return(t=(e=o.value)==null?void 0:e.invoiceItems)==null?void 0:t.reduce((a,r)=>{var E;const y=((E=r.childrens)==null?void 0:E.reduce((F,A)=>F+A.quantity*A.priceToCustomer,0))||0;return a+y},0)}),le=s(()=>{var e,t;return(t=(e=o.value)==null?void 0:e.invoiceItems)==null?void 0:t.reduce((a,r)=>{var E;const y=((E=r.childrens)==null?void 0:E.reduce((F,A)=>F+A.quantity*A.taxToCustomer,0))||0;return a+y},0)}),de=s(()=>(U.value||0)+(B.value||0)+(ue.value||0)+(le.value||0)),ve=s(()=>{var e,t,a;return M(((a=(t=(e=o.value)==null?void 0:e.recurrenceSubscription)==null?void 0:t.recurrenceUsers)==null?void 0:a.map(r=>(r==null?void 0:r.totalRecurrence)||0))||[])}),fe=s(()=>{var e,t,a;return M(((a=(t=(e=o.value)==null?void 0:e.recurrenceSubscription)==null?void 0:t.recurrenceUsers)==null?void 0:a.map(r=>(r==null?void 0:r.totalRegistration)||0))||[])}),me=s(()=>{var e,t,a;return M(((a=(t=(e=o.value)==null?void 0:e.recurrenceSubscription)==null?void 0:t.recurrenceUserAggregates)==null?void 0:a.map(r=>(r==null?void 0:r.totalRecurrence)||0))||[])}),Ce=s(()=>{var e,t,a;return M(((a=(t=(e=o.value)==null?void 0:e.recurrenceSubscription)==null?void 0:t.recurrenceUserAggregates)==null?void 0:a.map(r=>(r==null?void 0:r.totalRegistration)||0))||[])}),J=s(()=>ve.value+me.value),K=s(()=>fe.value+Ce.value),pe=s(()=>J.value+K.value),he=s(()=>{var e,t;return M(((t=(e=o.value)==null?void 0:e.invoiceItems)==null?void 0:t.map(a=>a.priceToCustomer))||[])}),Ie=s(()=>{var e,t;return M(((t=(e=o.value)==null?void 0:e.invoiceItems)==null?void 0:t.map(a=>a.totalProduct))||[])}),ge=s(()=>{var e,t;return M(((t=(e=o.value)==null?void 0:e.invoiceItems)==null?void 0:t.map(a=>a.totalTax))||[])}),Se=s(()=>{var e,t;return M(((t=(e=o.value)==null?void 0:e.invoiceItems)==null?void 0:t.map(a=>a.quantity))||[])}),we=s(()=>{var e,t;return((e=o.value)==null?void 0:e.event)&&((t=o.value)==null?void 0:t.invoiceItems[0].eventTicketModel)}),W=s(()=>{var e;return(e=o.value)==null?void 0:e.recurrenceSubscription}),be=s(()=>{var e,t;return((e=o.value)==null?void 0:e.invoiceItems)&&!((t=o.value)!=null&&t.invoiceItems[0].eventTicketModel)&&!W.value});function ye(e){u.value.paymentMethod=e;const t=z();if(e===D.CREDIT_CARD||e===D.DEBIT_CARD)return t.find()}function Te(){f.value=!f.value,l.value=!l.value,f.value||(u.value.paymentMethod=null)}function Y(){T()}return{init:S,reset:Y,data:s(()=>o.value),quantityTotal:H,priceToCustomerTotal:U,taxToCustomerTotal:B,priceTotal:de,form:u,isValid:L,paymentMethods:k,showPaymentOptions:f,showUpArrow:l,dataInvoice:o,dataInvoiceStatus:p,subscriptionTotal:J,subscriptionTotalRegistrationTotal:K,priceTotalSubscription:pe,loadInvoiceStatus:h,setPaymentMethod:ye,goConfirm:P,goLandingHome:d,goExpire:N,paymentOptions:Te,creditCardInstallments:w,priceTotalProduct:he,isVisibleCheckoutConfirmEvent:we,isVisibleCheckoutConfirmRecurrencePlan:W,isVisibleCheckoutConfirmProduct:be,priceProduct:Ie,totalTaxProduct:ge,totalProductQuantity:Se}}),ce=j("useAccountCreditCardNewStore",()=>{const n=c(!1),v=c(),I=c(null),f=c(!1),l=c(!1),w=c(!1),o=c("Salvar"),m=c(!1),T=c(!1),u=c({}),g=c(!1),p=c({documentType:void 0,countryCode:void 0}),$=s(()=>{const d={number:[b.required,b.creditCard],expMonth:[b.required,b.expireCreditCard],verification:[b.required,b.cvvCreditCard],holderName:[b.required,b.onlyLetters],holderDocument:[b.none],brand:[b.none]};return p.value.documentType==ke.CPF&&d.holderDocument.push(b.required,b.cpf),d}),S=se({getRules:()=>$.value,confirmService:ae});function k(){w.value=!0,T.value=!0,S.init()}function L(d,P,x,C,R){n.value=!0,f.value=d,l.value=P,I.value=x||null,C&&(o.value=C),R&&(S.form.value.invoiceId=R)}function i(){n.value=!1}function h(){i(),S.reset()}async function q(){var C,R,V,H,U,B;const d=S.form,P=await $e(),x=Le(((C=d.value)==null?void 0:C.number)||"");d.value={brand:x,expMonth:(V=(R=d.value)==null?void 0:R.expMonth)==null?void 0:V.slice(0,2),expYear:(U=(H=d.value)==null?void 0:H.expMonth)==null?void 0:U.slice(2,4),holderDocument:d.value.holderDocument,holderName:d.value.holderName,number:d.value.number,verification:d.value.verification,remoteIp:P,invoiceId:(B=d.value)==null?void 0:B.invoiceId}}async function N(){var d,P,x;m.value=!0,v.value="";try{await q();const C=await ae(S.form.value);g.value?Be().find():await Ue().goConfirm({cardId:(d=C==null?void 0:C.data)==null?void 0:d.creditCardId}),await S.reset(),h()}catch(C){v.value="Ocorreu um erro ao adicionar o cartão, favor, revise os dados e tente novamente.",Re((x=(P=C==null?void 0:C.response)==null?void 0:P.data)==null?void 0:x.message)}finally{m.value=!1}}return{init:k,isVisible:n,show:L,hide:i,showSave:f,showMain:l,saveCard:w,setAsMainCard:T,form:s(()=>S.form.value),rules:S.rules,actionLabel:o,goConfirm:N,goBack:h,isValid:S.isValid,currentCard:u,loading:m,message:v,userDocument:p,isNewCard:g}}),Be=j("useAccountCardsStore",()=>{const n=ce(),v=De(),{data:I,init:f,find:l}=_({findService:ie});function w(p){return{mastercard:"logos:mastercard",visa:"logos:visa",elo:"logos:elo",hipercard:"logos:hipercard",amex:"logos:amex"}[p.toLowerCase()]??""}function o(){O("LandingHome")}async function m(){await f()}function T(){n.saveCard=!0,n.isNewCard=!0,n.show(!1,!1,l)}function u(p){O("AccountCreditCardRemove",{creditCardId:p})}function g(p){v.show(p,l)}return{data:I,init:m,find:l,goBack:o,getCardBrandIcon:w,showNewCreditCardModal:T,goAccountCreditCardRemove:u,removeCreditCard:g}});export{ce as a,Ue as b,z as c,X as d,Be as u};
