File: /home/kbdhpghp/atenaleaders.com.br/wp-content/plugins/woocommerce-mercadopago/build/ticket.block.js
(()=>{"use strict";const e=window.React,t=window.wc.wcBlocksRegistry,n=window.wc.wcSettings,a=window.wp.element,c=window.wp.htmlEntities,o="mercadopago_blocks_update_cart",s=({labelMessage:t,helperMessage:n,inputName:a,hiddenId:c,inputDataCheckout:o,selectId:s,selectName:r,selectDataCheckout:i,flagError:m,documents:l,validate:d})=>(0,e.createElement)("div",{className:"mp-checkout-ticket-input-document"},(0,e.createElement)("input-document",{"label-message":t,"helper-message":n,"input-name":a,"hidden-id":c,"input-data-checkout":o,"select-id":s,"select-name":r,"select-data-checkout":i,"flag-error":m,documents:l,validate:d})),r=({isVisible:t,message:n,inputId:a,id:c,dataMain:o})=>(0,e.createElement)("input-helper",{isVisible:t,message:n,"input-id":a,id:c,"data-main":o}),i=({name:t,buttonName:n,columns:a})=>(0,e.createElement)("input-table",{name:t,"button-name":n,columns:a}),m=({description:t,linkText:n,linkSrc:a,checkoutClass:c="pro"})=>(0,e.createElement)("div",{className:`mp-checkout-${c}-terms-and-conditions`},(0,e.createElement)("terms-and-conditions",{description:t,"link-text":n,"link-src":a})),l=({title:t,description:n,linkText:a,linkSrc:c})=>(0,e.createElement)("div",{className:"mp-checkout-pro-test-mode"},(0,e.createElement)("test-mode",{title:t,description:n,"link-text":a,"link-src":c})),d=(e,t,n)=>{const a={name:e,message:t,target:n,plugin:{version:wc_mercadopago_custom_checkout_params.plugin_version},platform:{name:"woocommerce",uri:window.location.href,version:wc_mercadopago_custom_checkout_params.platform_version,location:`${wc_mercadopago_custom_checkout_params.location}_${wc_mercadopago_custom_checkout_params.theme}`}};navigator.sendBeacon("https://api.mercadopago.com/v1/plugins/melidata/errors",JSON.stringify(a))};var p;const u="mp_checkout_blocks",_="woo-mercado-pago-ticket",k=(0,n.getSetting)("woo-mercado-pago-ticket_data",{}),g=(0,c.decodeEntities)(k.title)||"Checkout Ticket",h=t=>{(e=>{const{extensionCartUpdate:t}=wc.blocksCheckout,{eventRegistration:n,emitResponse:c}=e,{onPaymentSetup:s,onCheckoutSuccess:r,onCheckoutFail:i}=n;(0,a.useEffect)((()=>{((e,t)=>{e({namespace:o,data:{action:"add",gateway:t}})})(t,_);const e=s((()=>({type:c.responseTypes.SUCCESS})));return()=>(((e,t)=>{e({namespace:o,data:{action:"remove",gateway:t}})})(t,_),e())}),[s]),(0,a.useEffect)((()=>{const e=r((async e=>{const t=e.processingResponse;return d("MP_TICKET_BLOCKS_SUCCESS",t.paymentStatus,u),{type:c.responseTypes.SUCCESS}}));return()=>e()}),[r]),(0,a.useEffect)((()=>{const e=i((e=>{const t=e.processingResponse;return d("MP_TICKET_BLOCKS_ERROR",t.paymentStatus,u),{type:c.responseTypes.FAIL,messageContext:c.noticeContexts.PAYMENTS,message:t.paymentDetails.message}}));return()=>e()}),[i])})(t);const{test_mode_title:n,test_mode_description:c,test_mode_link_text:p,test_mode_link_src:g,input_document_label:h,input_document_helper:y,ticket_text_label:E,input_table_button:S,input_helper_label:f,payment_methods:w,amount:b,site_id:C,terms_and_conditions_description:v,terms_and_conditions_link_text:N,terms_and_conditions_link_src:T,test_mode:R,message_error_amount:x}=k.params;if(null==b)return(0,e.createElement)(e.Fragment,null,(0,e.createElement)("p",{className:"alert-message"},x));const M=(0,a.useRef)(null),{eventRegistration:I,emitResponse:P}=t,{onPaymentSetup:O}=I;let B={labelMessage:h,helperMessage:y,validate:"true",selectId:"docType",flagError:"mercadopago_ticket[docNumberError]",inputName:"mercadopago_ticket[docNumber]",selectName:"mercadopago_ticket[docType]",documents:function(e){switch(e){case"MLB":return'["CPF","CNPJ"]';case"MLU":return'["CI","OTRO"]';default:return null}}(C)};return(0,a.useEffect)((()=>{const e=O((async()=>{const e=document.getElementById("mp-doc-number-helper"),t=document.getElementById("mp-payment-method-helper"),n={"mercadopago_ticket[site_id]":C,"mercadopago_ticket[amount]":b.toString(),"mercadopago_ticket[doc_type]":M.current.querySelector("#docType")?.value,"mercadopago_ticket[doc_number]":M.current.querySelector("#form-checkout__identificationNumber-container > input")?.value},a=w.find((e=>{const t=`#${e.id}`,n=M.current.querySelector(t);return n&&n.checked}));function c(e,t){e&&e.style&&(e.style.display=t)}function o(e){return e&&"flex"===e.style.display}return a&&(n["mercadopago_ticket[payment_method_id]"]=M.current.querySelector(`#${a.id}`).value,t.style.display="none"),B.documents&&""===n["mercadopago_ticket[doc_number]"]&&c(e,"flex"),n["mercadopago_ticket[payment_method_id]"]||c(t,"flex"),{type:o(e)||o(t)?P.responseTypes.ERROR:P.responseTypes.SUCCESS,meta:{paymentMethodData:n}}}));return()=>e()}),[P.responseTypes.ERROR,P.responseTypes.SUCCESS,O]),(0,e.createElement)("div",{className:"mp-checkout-container"},(0,e.createElement)("div",{className:"mp-checkout-ticket-container"},(0,e.createElement)("div",{ref:M,className:"mp-checkout-ticket-content"},R?(0,e.createElement)(l,{title:n,description:c,"link-text":p,"link-src":g}):null,B.documents?(0,e.createElement)(s,{...B}):null,(0,e.createElement)("p",{className:"mp-checkout-ticket-text"},E),(0,e.createElement)(i,{name:"mercadopago_ticket[payment_method_id]",buttonName:S,columns:JSON.stringify(w)}),(0,e.createElement)(r,{isVisible:"false",message:f,inputId:"mp-payment-method-helper",id:"payment-method-helper"}),(0,e.createElement)("div",{id:"mp-box-loading"}))),(0,e.createElement)(m,{description:v,linkText:N,linkSrc:T,checkoutClass:"ticket"}))},y={name:_,label:(0,e.createElement)((t=>{const{PaymentMethodLabel:n}=t.components,a=(0,c.decodeEntities)(k?.params?.fee_title||""),o=`${g} ${a}`;return(0,e.createElement)(n,{text:o})}),null),content:(0,e.createElement)(h,null),edit:(0,e.createElement)(h,null),canMakePayment:()=>!0,ariaLabel:g,supports:{features:null!==(p=k?.supports)&&void 0!==p?p:[]}};(0,t.registerPaymentMethod)(y)})();