1import{u as e,j as s,C as n}from"./forms-CQIHuKgG.js";import{B as r}from"./ButtonCustom-okNO1jHW.js";import{b as t,u as o,d as a}from"./index-DlMCzIyi.js";import{F as l,a as i,b as d}from"./FormRow-D3yRVLJC.js";import{F as c}from"./FormActions-DQzPdD6o.js";import{r as u}from"./i18n-Da3IOi1c.js";import{I as m}from"./InputRadioCustom-DAiNDca8.js";import{D as p}from"./DialogCustom-DxQXA1VO.js";import{I as v}from"./InputCustom-cpSt5GNn.js";import{S as _}from"./SelectCustom-CbUWeROE.js";import{T as f}from"./ToastCustom-3YEN-L9a.js";import{u as h,d as y}from"./redux-B_RFUBXH.js";import{s as g}from"./cardSelectionSlice-DYHRf8E5.js";import{s as C}from"./digitalKeyPersonalDataSlice-DSJOE-a0.js";import{d as j,f as x}from"./mobility-cards-service-DJSX-gKy.js";import{g as N}from"./formConstants-CI2IzKYy.js";import{a as w,u as b}from"./router-CeOKvF5U.js";import"./utils-CLBY9Uzt.js";import"./query-CNvpHjp-.js";import"./ui-C0dJowBQ.js";import"./Wrapper-BDzPti5V.js";import"./ticketing-service-LjvzH5gc.js";const S=({isOpen:l,onClose:i})=>{var d,c,S,q,R,T,E,I,D,M,P,O,k,A,F,L,$;const{t:V,i18n:H}=t(),U=w(),z=b(),B=h(),{setHeaderVisibility:K}=o(),{email:Q}=a(),{type:W,category:G,isVirtual:J,consents:X,stationType:Y}=y(e=>e.cardSelection),{requisitionSteps:Z}=y(e=>e.requisitionSteps),{formData:ee}=y(e=>e.digitalKeyPersonalData),{formData:se}=y(e=>e.personalInfo),[ne,re]=u.useState([]),[te,oe]=u.useState([]),[ae,le]=u.useState(!1),[ie,de]=u.useState(!1),[ce,ue]=u.useState(""),me=e({mode:"onChange",reValidateMode:"onChange",defaultValues:{email:""}}),pe={deliveryType:(null==ee?void 0:ee.deliveryType)||void 0,station:(null==ee?void 0:ee.deliveryStation)||void 0,address:{street:(null==se?void 0:se.address)||"",number:(null==se?void 0:se.addressNumber)||"",floor:(null==se?void 0:se.floor)||"",letter:(null==se?void 0:se.letter)||"",country:(null==se?void 0:se.country)?{label:se.country,value:se.country}:void 0,postalCode:(null==se?void 0:se.postalCode)||"",locality:(null==se?void 0:se.city)||""}},ve=e({mode:"onChange",reValidateMode:"onChange",defaultValues:pe}),_e=ve.watch("deliveryType"),fe=ve.watch("station"),he=ve.watch("address"),ye=ve.watch("address.street"),ge=ve.watch("address.country"),Ce=ve.watch("address.postalCode"),je=ve.watch("address.locality");u.useEffect(()=>{const e=document.querySelector(".footer");return e&&(l?e.setAttribute("style","display: none"):e.removeAttribute("style")),()=>{const e=document.querySelector(".footer");e&&e.removeAttribute("style")}},[l]),u.useEffect(()=>{if(J||!Q)return;(async()=>{const e=(await x(Y||"",Q)).map(e=>({label:e.designation,value:e.code}));oe(e)})()},[Y,J,Q]);const xe=u.useCallback(async()=>{if(!J)try{const e=await N(!1);re(e)}catch(e){console.error("Failed to load fiscal countries:",e)}},[J]);u.useEffect(()=>{xe()},[xe]),u.useEffect(()=>{if(ne.length>0&&"address"===_e&&!(null==he?void 0:he.country)){const e=ne.find(e=>"PT"===e.value);e&&ve.setValue("address.country",e)}},[ne,_e,null==he?void 0:he.country,ve]),u.useEffect(()=>(K(!l),()=>{K(!0)}),[l,K]),u.useEffect(()=>{_e&&ve.trigger("deliveryType")},[_e,ve]),u.useEffect(()=>{"address"===_e&&(ve.setValue("station",void 0),ve.clearErrors("station"))},[_e,ve]),u.useEffect(()=>{"station"===_e&&(ve.setValue("address",{street:"",number:"",floor:"",letter:"",country:void 0,postalCode:"",locality:""}),ve.clearErrors("address"))},[_e,ve]),u.useEffect(()=>{fe&&ve.trigger("station")},[fe,ve]),u.useEffect(()=>{(null==he?void 0:he.street)&&ve.trigger("address.street")},[null==he?void 0:he.street,ve]),u.useEffect(()=>{(null==he?void 0:he.postalCode)&&ve.trigger("address.postalCode")},[null==he?void 0:he.postalCode,ve]),u.useEffect(()=>{(null==he?void 0:he.locality)&&ve.trigger("address.locality")},[null==he?void 0:he.locality,ve]),u.useEffect(()=>{(null==he?void 0:he.country)&&ve.trigger("address.country")},[null==he?void 0:he.country,ve]);const Ne=u.useMemo(()=>{const e=V("Requests.CardConfirmationModal.physical"),s=V("Requests.CardConfirmationModal.virtual");return{card:W,category:G,type:J?s:e}},[G,V,W,J]),we=u.useMemo(()=>{var e,s,n,r,t,o,a,l;if(J)return!0;
1if(!_e)return!1;if("station"===_e)return(null==fe?void 0:fe.value)&&!ve.formState.errors.station;if("address"===_e){const i=ye&&(null==ge?void 0:ge.value)&&Ce&&je,d=!((null==(s=null==(e=ve.formState.errors)?void 0:e.address)?void 0:s.street)||(null==(r=null==(n=ve.formState.errors)?void 0:n.address)?void 0:r.country)||(null==(o=null==(t=ve.formState.errors)?void 0:t.address)?void 0:o.postalCode)||(null==(l=null==(a=ve.formState.errors)?void 0:a.address)?void 0:l.locality));return i&&d}return!1},[J,_e,fe,ye,ge,Ce,je,ve.formState.errors.station,null==(c=null==(d=ve.formState.errors)?void 0:d.address)?void 0:c.street,null==(q=null==(S=ve.formState.errors)?void 0:S.address)?void 0:q.country,null==(T=null==(R=ve.formState.errors)?void 0:R.address)?void 0:T.postalCode,null==(I=null==(E=ve.formState.errors)?void 0:E.address)?void 0:I.locality]),be=u.useCallback(async()=>{var e,s,n,r,t,o,a,l;if(!we||ae)return;le(!0);const i=me.getValues(),d=ve.getValues();try{const a={...ee,email:i.email,deliveryType:d.deliveryType,deliveryStation:d.station,deliveryAddress:d.address};B(C(a));const l=z.pathname.includes("renovar")?"SECOND":"FIRST";localStorage.setItem("mobility-card-requisition-type",l);const c=null==Z?void 0:Z.find(e=>e.requisition_type===l),u=null==c?void 0:c.cards.find(e=>e.card_type_name===W);if(!u)throw new Error("Card not found in requisition steps");const m={cmd_data:{address_info:{address:(null==ee?void 0:ee.address)||null,city:(null==ee?void 0:ee.city)||null,floor_letter:(null==ee?void 0:ee.letter)||null,floor_number:(null==(e=null==ee?void 0:ee.floor)?void 0:e.toString())||null,floor_place:(null==(s=null==ee?void 0:ee.floor)?void 0:s.toString())||null,locality:(null==ee?void 0:ee.city)||null,number:(null==ee?void 0:ee.addressNumber)||null,parish_code:(null==ee?void 0:ee.parishCode)||null,street:(null==ee?void 0:ee.address)||null,zip3:(null==ee?void 0:ee.postalCode)&&ee.postalCode.split("-")[1]||null,zip4:(null==ee?void 0:ee.postalCode)&&ee.postalCode.split("-")[0]||null,zip_code:(null==ee?void 0:ee.postalCode)||null},birthday_date:(null==ee?void 0:ee.birthDate)||null,contact:(null==ee?void 0:ee.phone)||null,country:(null==ee?void 0:ee.country)||null,email:Q,gender:(null==ee?void 0:ee.gender)||null,id_card:(null==ee?void 0:ee.idCardNumber)&&(null==ee?void 0:ee.idCardExtension)?`${ee.idCardNumber}${ee.idCardExtension}`:(null==ee?void 0:ee.idCardNumber)||null,id_card_expiration:(null==ee?void 0:ee.idCardExpiration)||null,id_card_extension:(null==ee?void 0:ee.idCardExtension)||null,id_card_number:(null==ee?void 0:ee.idCardNumber)||null,name:(null==ee?void 0:ee.firstName)&&(null==ee?void 0:ee.lastName)?`${ee.firstName} ${ee.lastName}`:null,nif:(null==ee?void 0:ee.nif)||null,photo:(null==ee?void 0:ee.photo)||null},lang:H.language.includes("pt")?"PT":"EN",requisition_params:{card_type:u.card_type_id,client_category:u.client_category_name,client_type:(null==(r=null==(n=u.client_types)?void 0:n.find(e=>H.language.includes("pt")?e.pt_name===G:e.en_name===G))?void 0:r.client_type_id)||0,consents:{allow_CRM:(null==X?void 0:X.allow_CRM)||!1,allow_information:(null==X?void 0:X.allow_information)||!1,allow_marketing:(null==X?void 0:X.allow_marketing)||!1,allow_profile:(null==X?void 0:X.allow_profile)||!1,allow_survey:(null==X?void 0:X.allow_survey)||!1},current_card_number:"SECOND"===l&&(null==(t=u.current_card_details)?void 0:t.card_serial_number)||null,delivery_station:"station"===d.deliveryType&&(null==(o=d.station)?void 0:o.value)||null,delivery_type:J?"VIRTUAL":"station"===(null==d?void 0:d.deliveryType)?"STATION":"address"===(null==d?void 0:d.deliveryType)?"MAIL":"STATION",is_urgent:!1,is_virtual:J||!1,requisition_type:l,_urgent:!1,_virtual:J||!1}},p=await j(m,Q||"");localStorage.setItem("saleID",null==p?void 0:p.saleID.toString()),localStorage.setItem("clientID",null==p?void 0:p.clientData.clientID.toString()),B(g({price:p.totalAmount,isVirtual:J||!1})),U(`/${H.language}/compra-online-cartao`)}catch(c){console.error("Error creating requisition:",c);const e=(null==(l=null==(a=null==c?void 0:c.response)?void 0:a.data)?void 0:l.description)||"";if(e.includes("REQUISITION_DUPLICATED")){const s=e.match(/REQUISITION_DUPLICATED\((\d+)\)/),n=s?s[1]:"";ue(`${V("Requests.CardConfirmationModal.errorMessageRequisitionDupl
1icated",{number:n})}`),de(!0)}else ue(V("Requests.CardConfirmationModal.errorMessageGeneric")),de(!0)}finally{le(!1)}},[we,ae,me,ve,B,ee,Z,W,H.language,X,J,U,Q,V,z.pathname]);return s.jsxs(p,{isOpen:l,onClose:i,className:"card-confirmation-modal",children:[s.jsxs("div",{className:"card-confirmation-modal-content",children:[s.jsx("div",{className:"card-confirmation-modal-content__header-close",children:s.jsx(r,{variant:"ghost",onClick:i,className:"card-confirmation-modal-content__header-close-button",children:s.jsx("img",{src:"/assets/images/close.svg",alt:"","aria-hidden":"true"})})}),s.jsx("h4",{className:"card-confirmation-modal-content__header",children:V("Requests.CardConfirmationModal.title")}),s.jsxs("div",{className:"card-confirmation-modal-content__card-information",children:[s.jsxs("div",{className:"card-confirmation-modal-content__card-information-item",children:[s.jsx("h5",{children:V("Requests.CardConfirmationModal.card")}),s.jsx("p",{children:Ne.card})]}),s.jsxs("div",{className:"card-confirmation-modal-content__card-information-item",children:[s.jsx("h5",{children:V("Requests.CardConfirmationModal.category")}),s.jsx("p",{children:Ne.category})]}),s.jsxs("div",{className:"card-confirmation-modal-content__card-information-item",children:[s.jsx("h5",{children:V("Requests.CardConfirmationModal.cardType")}),s.jsx("p",{children:Ne.type})]}),s.jsx("div",{className:"card-confirmation-modal-content__card-information-item"})]}),s.jsxs("div",{className:"passenger-data-card",style:{marginBottom:J?"0px":"16px"},children:[!J&&s.jsx("p",{className:"passenger-data-card__required-text",children:V("FormContactPageInfor")}),!J&&s.jsxs(s.Fragment,{children:[s.jsx("h2",{className:"passenger-data-card__title",children:V("DeliveryOptionsTitle")}),s.jsx("p",{className:"passenger-data-card__description",children:V("DeliveryOptionsDescription")}),s.jsx("div",{className:"passenger-data-card__content",children:s.jsx("div",{className:"accordion-passager",children:s.jsxs("div",{className:"delivery-options",children:[s.jsxs("div",{className:"delivery-options__radio-group",children:[s.jsx(m,{...ve.register("deliveryType",{required:!0}),value:"station",label:V("CPStation")}),"station"===_e&&s.jsx("div",{className:"delivery-options__station-section",children:s.jsx(n,{name:"station",control:ve.control,rules:{required:"station"===_e},render:({field:e})=>{var n;return s.jsx(_,{label:V("CPStation"),onChange:e.onChange,value:null==(n=null==e?void 0:e.value)?void 0:n.value,placeholder:V("ChooseOption"),options:te,isRequired:"station"===_e,searchable:!0,maxHeight:180})}})})]}),s.jsx("div",{className:"delivery-options__separator"}),s.jsxs("div",{className:"delivery-options__radio-group",children:[s.jsx(m,{...ve.register("deliveryType",{required:!0}),value:"address",label:V("Address")}),"address"===_e&&s.jsxs("div",{className:"delivery-options__address-section",children:[s.jsx(v,{...ve.register("address.street",{required:"address"===_e}),label:V("Address"),placeholder:V("AddressPlaceholder"),isRequired:"address"===_e,error:null==(P=null==(M=null==(D=ve.formState.errors)?void 0:D.address)?void 0:M.street)?void 0:P.message}),s.jsxs("div",{className:"delivery-options__address-grid",children:[s.jsx(v,{...ve.register("address.number"),label:V("NumberLot"),placeholder:V("NumberLotPlaceholder")}),s.jsx(v,{...ve.register("address.floor"),label:V("Floor"),placeholder:V("FloorPlaceholder")}),s.jsx(v,{...ve.register("address.letter"),label:V("Letter"),placeholder:V("LetterPlaceholder")})]}),s.jsxs("div",{className:"delivery-options__address-grid",children:[s.jsx(n,{name:"address.country",control:ve.control,rules:{required:"address"===_e},render:({field:e})=>{var n;return s.jsx(_,{label:V("ResidenceCountry"),onChange:e.onChange,value:null==(n=null==e?void 0:e.value)?void 0:n.value,placeholder:V("ChooseOption"),options:ne,isRequired:"address"===_e})}}),s.jsx(v,{...ve.register("address.postalCode",{required:"address"===_e}),label:V("PostalCode"),placeholder:V("PostalCodePlaceholder"),isRequired:"address"===_e,error:null==(A=null==(k=null==(O=ve.formState.errors)?void 0:O.address)?void 0:k.postalCode)?void 0:A.message}),s.jsx(v,{...ve.register("address.locality",{required:"address"===_e}),label:V("Locality"),placeholder:V("LocalityPlaceholder"),isRequired:"address"===_e,error:null==($=null==(L=null==(F=ve.formState.errors)?void 0:F.address)?void 0:L.locality)?void 0:$.message})]})]})]})]})})})]})]}),s.jsx("div",{className:"card-confirmation-modal-content__card-cost-button",children:s.jsx(r,{variant:"primary",onClick:be,isDisabled:!we||ae,isLoading:ae,loadingText:V("Processing"),children:V("Requests.CardConfirmationModal.proceedToPayment")})})]}),ie&&s.jsx(f,{icon:"/assets/images/alert-red.svg",variant:"error",text:ce,handleClose:()=>de(!1),className:"position-fixed"})]})},q=()=>{const{t:o,i18n:a}=t(),p=w(),v=b(),_=h(),[f,C]=u.useState(!1),[j,x]=u.useState(!1),[N,q]=u.useState({}),{requisitionSteps:R}=y(e=>e.requisitionSteps),{type:T,stationType:E}=y(e=>e.cardSelection),I=u.useMemo(()=>"CARTAO_CP"===E,[E]);u.useEffect(()=>{R&&T||p(`/${a.language}/mycp/pedidos/novo-pedido?open-modal=true`)},[R,T,p,a.language]);const D=u.useMemo(()=>{const e=v.pathname.includes("renovar")?"SECOND":"FIRST",s=null==R?void 0:R.find(s=>s.requisition_type===e),n=null==s?void 0:s.cards.find(e=>e.card_type_name===T);return null==n?void 0:n.consents},[R,T,v.pathname]),M=u.useMemo(()=>
1{if(!D)return{};const e={};return Object.keys(D).forEach(s=>{e[s]=void 0}),e},[D]);u.useEffect(()=>{if(D){const e={};Object.keys(D).forEach(s=>{e[s]=void 0}),q(e)}},[D]);const{control:P}=e({defaultValues:{consents:M},values:{consents:M}}),O=u.useMemo(()=>{if(!N||!D)return!1;return Object.keys(D).every(e=>void 0!==N[e])},[N,D]),k=()=>{const e=v.pathname.includes("renovar");p(`/${a.language}/mycp/pedidos/cartoes/${e?"renovar":"novo"}/tipo`)};return s.jsxs("div",{className:"new-card-consents",children:[s.jsx(r,{variant:"ghost",className:"new-card-consents__back-button",icon:s.jsx("img",{src:"/assets/images/arrow-back-green.svg",alt:"","aria-hidden":"true"}),type:"button",onClick:k,"aria-label":o("Requests.digitalKeyPersonalData.backButton"),onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||k()}}),s.jsx("h2",{className:"new-card-consents__title",children:o("Requests.newCard.consents.title")}),I&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"new-card-consents__description",children:o("Requests.newCard.consents.cpCard.header.description1")}),s.jsx("p",{className:"new-card-consents__description",children:o("Requests.newCard.consents.cpCard.header.description2")}),s.jsx("div",{className:"new-card-consents__description-list new-card-consents__description-list-with-margin",children:s.jsxs("ul",{className:"new-card-consents__description-list-items",children:[s.jsx("li",{children:o("Requests.newCard.consents.cpCard.header.listItems.cpCardSubscription")}),s.jsx("li",{children:o("Requests.newCard.consents.cpCard.header.listItems.myCPArea")}),s.jsx("li",{children:o("Requests.newCard.consents.cpCard.header.listItems.optOutOptions")}),s.jsx("li",{dangerouslySetInnerHTML:{__html:o("Requests.newCard.consents.cpCard.header.listItems.emailContact")}})]})}),s.jsx("p",{className:"new-card-consents__description",children:o("Requests.newCard.consents.cpCard.header.description3")})]}),s.jsxs(l,{contentNoSpacing:!0,onSubmit:e=>{e.preventDefault(),(async()=>{x(!0);try{const e={};
1Object.entries(N).forEach(([s,n])=>{void 0!==n&&(e[s]=n)}),_(g({consents:e})),C(!0)}catch(e){console.error("Error saving consents:",e)}finally{x(!1)}})()},actions:s.jsx(c,{layout:"horizontal",children:s.jsx("div",{className:"new-card-consents__actions",children:s.jsx(r,{type:"submit",text:o("personalData.common.advance"),variant:"primary",isLoading:j,loadingText:o("personalData.common.submitting"),isDisabled:!O})})}),children:[s.jsx(i,{className:"consents__consents-section",children:D&&Object.entries(D).map(([e,r])=>((e,r)=>s.jsx(d,{className:"new-card-consents__consent-item consents__consent-item",children:s.jsxs("div",{className:"new-card-consents__consent-content",children:[s.jsx("p",{className:"new-card-consents__consent-label",children:r}),s.jsx("div",{className:"new-card-consents__consent-options",children:s.jsx(n,{name:`consents.${e}`,control:P,render:({field:n})=>s.jsxs("div",{className:"new-card-consents__radio-group",children:[s.jsx("div",{className:"consents__radio-option",children:s.jsx(m,{id:`${e}-yes`,checked:!0===N[e],onChange:()=>{n.onChange(!0),q(s=>({...s,[e]:!0}))},label:o("personalData.consents.options.yes"),name:`consents.${e}`})}),s.jsx("div",{className:"consents__radio-option",children:s.jsx(m,{id:`${e}-no`,checked:!1===N[e],onChange:()=>{n.onChange(!1),q(s=>({...s,[e]:!1}))},label:o("personalData.consents.options.no"),name:`consents.${e}`})})]})})})]})},`consent-${e}`))(e,"pt"===a.language?r.pt_name:r.en_name))}),I?s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"new-card-consents__description",children:o("Requests.newCard.consents.cpCard.footer.noThirdPartyShare")}),s.jsx("p",{className:"new-card-consents__description-list-title",children:o("Requests.newCard.consents.cpCard.footer.dataSubjectsRights")}),s.jsx("p",{className:"new-card-consents__description",dangerouslySetInnerHTML:{__html:o("Requests.newCard.consents.cpCard.footer.gdprRights")}}),s.jsx("p",{className:"new-card-consents__description-list-title",children:o("Requests.newCard.consents.cpCard.footer.dataRetentionTitle")}),s.jsx("p",{className:"new-card-consents__description",children:o("Requests.newCard.consents.cpCard.footer.dataRetentionText")})]}):s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"new-card-consents__description",dangerouslySetInnerHTML:{__html:o("Requests.newCard.consents.vivaCard.footer.consentWithdrawal")}}),s.jsx("p",{className:"new-card-consents__description-list-title",children:o("Requests.newCard.consents.vivaCard.footer.acceptanceTitle")}),s.jsx("p",{className:"new-card-consents__description",children:o("Requests.newCard.consents.vivaCard.footer.acceptanceText")})]})]}),s.jsx(S,{isOpen:f,onClose:()=>C(!1)})]})};export{q as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.