1var $i=Object.defineProperty,vi=Object.defineProperties;var qi=Object.getOwnPropertyDescriptors;var he=Object.getOwnPropertySymbols;var ni=Object.prototype.hasOwnProperty,oi=Object.prototype.propertyIsEnumerable;var ii=(e,o,t)=>o in e?$i(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,H=(e,o)=>{for(var t in o||(o={}))ni.call(o,t)&&ii(e,t,o[t]);if(he)for(var t of he(o))oi.call(o,t)&&ii(e,t,o[t]);return e},C=(e,o)=>vi(e,qi(o));var ri=(e,o)=>{var t={};for(var a in e)ni.call(e,a)&&o.indexOf(a)<0&&(t[a]=e[a]);if(e!=null&&he)for(var a of he(e))o.indexOf(a)<0&&oi.call(e,a)&&(t[a]=e[a]);return t};var D=(e,o,t)=>new Promise((a,c)=>{var l=s=>{try{r(t.next(s))}catch(d){c(d)}},i=s=>{try{r(t.throw(s))}catch(d){c(d)}},r=s=>s.done?a(s.value):Promise.resolve(s.value).then(l,i);r((t=t.apply(e,o)).next())});import{d as p,c as n,r as P,F as di,u as ai,h as mi,x as fi,y as Re,z as Ve,A as ke,D as X,X as Ri,W as Vi}from"./B6b-bfBC.js";import{u as Me,a as Ne,b as Fe,c as ki}from"./R_M227Qa.js";import{c as Q,T as _,fs as Wi,H as le,bA as ee,B as g,m as we,ft as Bi,n as Pe,q as k,bu as se,fu as Gi,t as de,fv as ti,fw as Ui,cj as _e,d as ce,N as Ki,G as ui,fx as Hi,ax as hi,d1 as pi,fy as Ae,fz as Se,fA as Te,fB as yi,fC as bi,dl as Ee,cL as We,fD as Ni,fE as Ai,fF as Si,fG as Ti,fH as Qi,fI as zi,bb as Oe,fJ as ji,e1 as Ei,e5 as Yi,dW as Ci,fK as Xi,fL as Zi,fM as Ji,fN as gi,W as Di,ci,b$ as en,fO as nn,fP as on,fQ as rn,fR as tn,fS as cn,fT as sn,ai as ln,eZ as dn,fU as an,bt as mn,fV as fn,b6 as un,bq as hn,fW as pe,bv as pn,bz as yn,az as ye,aE as bn,fr as Nn,fh as An,D as Sn,F as Tn,bF as En,fX as On}from"./CZnjgNll.js";import{R as xn}from"./HBhvABKI.js";import{u as z,t as be,T as In}from"./DkKYNZmr.js";import{u as ae,B as Z,S as G,G as W,L as xe,c as Ie,a4 as Mn}from"./BWNFmVLl.js";import{g as si,a as li,u as wn}from"./BvjeGm1x.js";import"./D9vrHrkH.js";import"./BOTCFGu1.js";import"./CCRAbWtf.js";const Pn=({fullName:e,careOf:o,street:t,postalCode:a,city:c,country:l,isCompany:i})=>{const{t:r}=z(),{palette:s}=ae();return p(Z,{borderRadius:1,border:`1px solid ${s.grey[920]}`,padding:1.5,children:[n(Q,{mb:1,display:"block",children:e}),o&&n(_,{color:s.grey[600],mb:.5,children:`C/O: ${o}`}),n(_,{color:s.grey[600],mb:.5,children:t}),n(_,{color:s.grey[600],mb:.5,children:`${Wi(a)} ${c}`}),n(_,{color:s.grey[600],mb:.5,children:l}),!i&&n("i",{children:n(_,{color:s.grey[600],children:r("commonv2.profile.addressFetchedFromPopulationRegister")})})]})},Ln=({currentEngagement:e,contactPersons:o,isModalOpen:t,setIsModalOpen:a})=>{const{t:c}=z(),l=Me(),[i,r]=P.useState(!1),s=[...o.alternativeBeneficialOwners,...o.beneficialOwners],d=()=>{i&&l.invalidateQueries({queryKey:[k.SAVINGS_PROFILE,e==null?void 0:e.id]}),r(!1),a(!1)};return n(Pe,{size:"medium",onClose:d,open:t,status:i?"success":void 0,children:i?p(G,{height:"100%",justifyContent:"space-between",children:[p(Z,{children:[n(le,{children:c("commonv2.profile.contactPersons.addSuccessTitle",{defaultValue:"Du har lagt till verklig huvudman"})}),n(ee,{children:n(_,{children:c("commonv2.profile.contactPersons.addSuccessDescription",{defaultValue:"Du har lagt till verklig huvudman."})})})]}),n(Z,{mt:{xs:0,sm:5},children:n(g,{stretch:!0,variant:"primary",onClick:d,children:c("forms.actions.close")})})]}):p(di,{children:[n(we,{children:n(le,{children:c("forms.title.addBeneficial")})}),n(Bi,{currentEngagement:e,onClose:d,onSuccess:()=>r(!0),existingOwners:s})]})})},ve=e=>`profileV2_phone_${e}`,qe=e=>`profileV2_email_${e}`,Fn=(e,o,t,a)=>{localStorage.setItem(ve(o),t),localStorage.setItem(qe(o),a),e.setQueryData(["profileV2_phone",o],t),e.setQueryData(["profileV2_email",o],a)},_n=(e,o,t)=>{var r,s,d,h;const a=(r=t==null?void 0:t.phoneNumber)!=null?r:"",c=(s=t==null?void 0:t.email)!=null?s:"",l=((d=e.getQueryData(["profileV2_phone",o]))!=null?d:localStorage.getItem(ve(o)))||void 0,i=((h=e.getQueryData(["profileV2_email",o]))!=null?h:localStorage.getItem(qe(o)))||void 0;return l&&l===a&&localStorage.removeItem(ve(o)),i&&i===c&&localStorage.removeItem(qe(o)),{phoneNumber:l&&l!==a?l:a,email:i&&i!==c?i:c}},$n=(e,o,t,a,c,l,i)=>{const r={phoneNumber:(i==null?void 0:i.contactInformation.mobileNumber)||"",email:(i==null?void 0:i.contactInformation.emailAddress)||"",firstName:(i==null?void 0:i.firstName)||"",lastName:(i==null?void 0:i.lastName)||""},s={phoneNumber:(c==null?void 0:c.mobileNumber)||"",email:(c==null?void 0:c.email)||"",firstName:(c==null?void 0:c.firstName)||"",lastName:(c==null?void 0:c.lastName)||""},d={phoneNumber:(l==null?void 0:l.mobilePhone)||"",email:(l==null?void 0:l.email)||"",firstName:(l==null?void 0:l.firstName)||"",lastName:(l==null?void 0:l.lastName)||""},h=u=>!!(u.phoneNumber||u.email||u.firstName||u.lastName);if(e){if((!o||(i==null?void 0:i.customerType)===se.COMPANY)&&h(r))return r;if(t&&o&&h(d))return d}if(t&&h(d))return d;const m={phoneNumber:r.phoneNumber||s.phoneNumber||d.phoneNumber,email:r.email||s.email||d.email,firstName:r.firstName||s.firstName||d.firstName,lastName:r.lastName||s.lastName||d.lastName};if(h(m))return m;if(e){if(t&&o&&(i==null?void 0:i.customerType)!==se.COMPANY)return d;if(!o||(i==null?void 0:i.customerType)===se.COMPANY)return r}if(t)return d;if(!t){if(i!=null&&i.domesticAddress)return r;if(c!=null&&c.address)return s}return null},vn=(e,o,t,a,c,l,i)=>{var h,m,u,A,f,S,$,v,O,x,N,T,I,F,L;const r={street:(c==null?void 0:c.address.street)||((h=c==null?void 0:c.foreignAddress)==null?void 0:h.address1)||"",careOf:(c==null?void 0:c.address.careOf)||((m=c==null?void 0:c.foreignAddress)==null?void 0:m.coAddress)||"",postalCode:(c==null?void 0:c.address.postalCode)||((u=c==null?void 0:c.foreignAddress)==null?void 0:u.postalCode)||"",city:(c==null?void 0:c.address.city)||((A=c==null?void 0:c.foreignAddress)==null?void 0:A.city)||"",country:(c==null?void 0:c.address.country)||((f=c==null?void 0:c.foreignAddress)==null?void 0:f.country)||""},s={street:(l==null?void 0:l.address1)||"",careOf:(l==null?void 0:l.coAddress)||"",postalCode:(l==null?void 0:l.postalCode)||"",city:(l==null?void 0:l.city)||"",country:"SE"},d={street:((S=i==null?void 0:i.domesticAddress)==null?void 0:S.streetAddress)||(($=i==null?void 0:i.foreignAddress)==null?void 0:$.address1)||"",careOf:((v=i==null?void 0:i.domesticAddress)==null?void 0:v.careOf)||((O=i==null?void 0:i.foreignAddress)==null?void 0:O.address3)||"",postalCode:((x=i==null?void 0:i.domesticAddress)==null?void 0:x.postalCode)||((N=i==null?void 0:i.foreignAddress)==null?void 0:N.address4)||"",city:((T=i==null?void 0:i.domesticAddress)==null?void 0:T.city)||((I=i==null?void 0:i.foreignAddress)==null?void 0:I.address5)||"",country:((F=i==null?void 0:i.domesticAddress)==null?void 0:F.country)||((L=i==null?void 0:i.foreignAddress)==null?void 0:L.country)||""};
1if(e)return t&&o&&!a?s:d;if(t)return s;if(!t){if(i!=null&&i.domesticAddress)return d;if(c!=null&&c.address)return r}return null},qn=(e,o,t)=>[e,o,t].filter(Boolean).length>1,Rn=(e,o,t)=>new Set([e,o,t]).size===3,Vn=(e,o,t)=>new Set([e,o,t]).size===3,kn=(e,o,t,a)=>{if(a)return!1;if(e){if(o)return de(ti),!0;if(t)return de(ti),!0}return!1},$e=e=>{if(Gi.some(a=>e.startsWith(a.value)))return e;const t=e.startsWith("0")?e.slice(1):e;return t?`+46${t}`:""},Wn=(e,o)=>new Intl.DisplayNames([e!=null?e:Ui.language],{type:"region"}).of(o),Bn=(e,o,t)=>t==="FI"?[{countryCode:"FI",number:o}]:t==="NO"?[{countryCode:"NO",number:o}]:t==="SE"?[{countryCode:"SE",number:o}]:e,Gn=e=>{const o={};return[...(e==null?void 0:e.accountAdministrators)||[],...(e==null?void 0:e.beneficialOwners)||[],...(e==null?void 0:e.alternativeBeneficialOwners)||[],...(e==null?void 0:e.signatories)||[]].forEach(c=>{const r=c,{customerNumber:l}=r,i=ri(r,["customerNumber"]);o[l]||(o[l]=C(H({},i),{customerNumber:l,roles:[]})),e!=null&&e.accountAdministrators.some(s=>s.customerNumber===l)&&o[l].roles.push(be("commonv2.profile.contactPersons.accountAdmin")),e!=null&&e.alternativeBeneficialOwners.some(s=>s.customerNumber===l)&&o[l].roles.push(be("commonv2.profile.contactPersons.altBeneficialOwner")),e!=null&&e.beneficialOwners.some(s=>s.customerNumber===l)&&o[l].roles.push(be("commonv2.beneficialOwner")),e!=null&&e.signatories.some(s=>s.customerNumber===l)&&o[l].roles.push(be("commonv2.profile.contactPersons.signatory"))}),Object.values(o)},Un=e=>{const o=new Set;return e.filter(t=>o.has(t)?!1:(o.add(t),!0))},Kn=({userDetails:e,currentEngagement:o})=>{const{t}=z(),a=ai(),c=mi(),{palette:l}=ae(),[i,r]=P.useState(!1),s=Gn(e==null?void 0:e.contactPersons);return p(Z,{children:[i&&o&&(e!=null&&e.contactPersons)?n(Ln,{currentEngagement:o,contactPersons:e.contactPersons,isModalOpen:i,setIsModalOpen:r}):null,n(Z,{mt:5,children:n(_,{children:n(In,{i18nKey:"commonv2.profile.changeAdminInfo",components:{link1:n(_e,{onClick:()=>c("/documents/savings",{state:H({},a.state)})}),a:n(_e,{}),link2:n(_e,{onClick:()=>c("/contact",{state:H({},a.state)})})}})})}),p(G,{mt:5,spacing:1.5,children:[n(Q,{mb:.5,children:t("commonv2.profile.contactPersons.adminsForCompany",{companyName:e==null?void 0:e.customerName})}),s.map(d=>{var h;return n(ui,{border:"full",children:p(Z,{p:1.5,children:[n(Q,{children:`${d.firstName} ${d.lastName}`}),n(ce,{pt:1,children:d.customerNumber}),Un(d.roles).map(m=>n(ce,{pt:.5,children:m},m)),d.phoneNumber?n(ce,{pt:.5,children:d.phoneNumber}):null,d.emailAddress?n(ce,{pt:.5,children:d.emailAddress}):null,(h=d.roles)!=null&&h.find(m=>m===t("commonv2.beneficialOwner"))&&d.needsManualValidation?p(G,{flexDirection:"row",alignItems:"center",children:[n(ce,{color:l.info.main,mr:.5,children:t("commonv2.profile.contactPersons.toolTipTitle")}),n(Ki,{text:n(_,{children:t("commonv2.profile.contactPersons.toolTipDesc")}),tooltipPlacement:"top"})]}):null]})},d.id)}),n(g,{startIcon:n(Hi,{color:l.primary.main}),variant:"ghost",onClick:()=>r(!0),children:t("savingsv2.contactPersons.addBeneficialOwner")})]})]})},Hn=({phoneNumber:e,email:o,canEdit:t,onEditClick:a})=>{const{t:c}=z(),{palette:l}=ae();return n(Z,{borderRadius:1,border:`1px solid ${l.grey[920]}`,padding:1.5,children:p(W,{display:"flex",flexDirection:"row",alignItems:"flex-start",justifyContent:"space-between",children:[p(W,{item:!0,children:[n(Q,{mb:1,display:"block",children:c("forms.labels.contactInformation")}),n(_,{color:l.grey[600],mb:.5,children:`${c("forms.labels.phoneNumber")}: ${e}`}),n(_,{color:l.grey[600],children:`${c("forms.labels.email")}: ${o}`})]}),t&&n(W,{item:!0,alignSelf:"center",mr:1,children:n(hi,{noUnderline:!0,color:l.primary.light,icon:n(pi,{color:l.primary.light}),onClick:a,children:c("forms.actions.change")})})]})})},Qn=Si.filter(e=>["+46","+47","+358"].includes(e.value)),zn=ke({countryCode:X(),mobileNumber:X().required("forms.errors.phoneNumberWithoutCountryCode").when("countryCode",([e],o)=>Ai(e,o)).matches(/^[0-9]+$/,"forms.errors.phoneNumberWithoutCountryCode"),emailAddress:X().required("forms.errors.required").email("forms.errors.email").test("invalid-email","forms.errors.email",e=>!!e&&Ni.test(e))}),jn=({isOpen:e,isLoading:o,currentPhoneNumber:t,currentEmail:a,onSubmit:c,onClose:l})=>{const{t:i}=z(),r=Ae(t,Se),s=fi({defaultValues:{countryCode:r.countryNumber,mobileNumber:Te(r.phoneNumberWithoutCountryCode),emailAddress:a},mode:"onBlur",resolver:Re(zn),shouldFocusError:!0}),{reset:d}=s;P.useEffect(()=>{const m=Ae(t,Se);d({countryCode:m.countryNumber,mobileNumber:Te(m.phoneNumberWithoutCountryCode),emailAddress:a})},[t,a,d]);const h=m=>{var A;const u=Ti((A=m.countryCode)!=null?A:"",m.mobileNumber);c(C(H({},m),{mobileNumber:u}))};return n(Ve,C(H({}
1,s),{children:n("form",{onSubmit:s.handleSubmit(h),children:p(Pe,{open:e,onClose:l,size:"medium",children:[n(we,{children:n(le,{children:i("loansv2.application.confirm.accurateInformation")})}),p(G,{height:"100%",justifyContent:"space-between",children:[n(G,{children:p(ee,{children:[n(_,{children:i("commonv2.profile.importantContactInfoMsg")}),n(Q,{mb:1.5,mt:3,display:"block",children:i("forms.common.contactDetails")}),p(W,{container:!0,direction:"row",spacing:1.5,mb:1.5,children:[n(W,{item:!0,sm:4,xs:5,children:p(yi,{label:i("forms.labels.countryCode"),name:"countryCode",children:[n(xe,{children:i("commonv2.regular")}),Qn.map(m=>n(Ie,{value:m.value,children:`${m.label} ${m.value}`},m.value)),n(xe,{children:i("commonv2.other")}),bi.map(m=>n(Ie,{value:m.value,children:`${m.label} ${m.value}`},m.value))]})}),n(W,{item:!0,sm:8,xs:7,children:n(Ee,{label:i("forms.labels.phoneNumber"),type:"tel",name:"mobileNumber",id:"confirmMobileNumber"})})]}),n(Ee,{label:i("forms.labels.email"),name:"emailAddress",id:"confirmEmailAddress",inputProps:{inputMode:"email"}})]})}),n(We,{children:n(g,{type:"submit",onClick:s.handleSubmit(h),disabled:!s.formState.isValid,isLoading:o,children:i("commonv2.profile.saveDetails")})})]})]})})}))},Yn=Si.filter(e=>["+46","+47","+358"].includes(e.value)),Cn=ke({countryCode:X(),mobileNumber:X().required("forms.errors.phoneNumberWithoutCountryCode").when("countryCode",([e],o)=>Ai(e,o)).matches(/^[0-9]+$/,"forms.errors.phoneNumberWithoutCountryCode"),emailAddress:X().required("forms.errors.required").email("forms.errors.email").test("invalid-email","forms.errors.email",e=>!!e&&Ni.test(e))}),Xn=({isOpen:e,isLoading:o,currentPhoneNumber:t,currentEmail:a,onSubmit:c,onClose:l,isSuccess:i})=>{const{t:r}=z(),s=Ae(t,Se),d=fi({defaultValues:{countryCode:s.countryNumber,mobileNumber:Te(s.phoneNumberWithoutCountryCode),emailAddress:a},mode:"onBlur",resolver:Re(Cn),shouldFocusError:!0}),{reset:h,formState:{isValid:m,isDirty:u}}=d;P.useEffect(()=>{const f=Ae(t,Se);h({countryCode:f.countryNumber,mobileNumber:Te(f.phoneNumberWithoutCountryCode),emailAddress:a})},[t,a,h]);const A=f=>{var $;const S=Ti(($=f.countryCode)!=null?$:"",f.mobileNumber);c(C(H({},f),{mobileNumber:S}))};return n(Ve,C(H({},d),{children:n("form",{onSubmit:d.handleSubmit(A),children:p(Pe,{open:e,onClose:l,size:"medium",status:i?"success":void 0,children:[i?null:n(we,{children:n(le,{children:r("commonv2.profile.editContactInfo")})}),p(G,{height:"100%",justifyContent:"space-between",children:[p(G,{children:[n(Q,{children:r(i?"commonv2.profile.updateSuccess":"forms.labels.contactInformation")}),i?n(ee,{children:n(_,{children:r("forms.info.contactInfoUpdated")})}):p(ee,{children:[p(W,{container:!0,direction:"row",spacing:1.5,mb:1.5,children:[n(W,{item:!0,sm:4,xs:5,children:p(yi,{label:r("forms.labels.countryCode"),name:"countryCode",children:[n(xe,{children:r("commonv2.regular")}),Yn.map(f=>n(Ie,{value:f.value,children:`${f.label} ${f.value}`},f.value)),n(xe,{children:r("commonv2.other")}),bi.map(f=>n(Ie,{value:f.value,children:`${f.label} ${f.value}`},f.value))]})}),n(W,{item:!0,sm:8,xs:7,children:n(Ee,{label:r("forms.labels.phoneNumber"),type:"tel",name:"mobileNumber",id:"editMobileNumber"})})]}),n(Ee,{label:r("forms.labels.email"),name:"emailAddress",id:"editEmailAddress",inputProps:{inputMode:"email"}})]})]}),n(We,{children:i?n(g,{onClick:()=>l(),children:r("forms.actions.close")}):n(g,{type:"button",onClick:d.handleSubmit(A),disabled:!m||!u,isLoading:o,children:r("forms.actions.saveChanges")})})]})]})})}))},Zn=ke({taxCountry:X().required().nullable(),taxIdentificationNumbers:Vi(),paysPreliminaryTax:X().required()}),Jn=({isOpen:e,engagementId:o,customerNumber:t,onClose:a})=>{var L,q,y;const{t:c}=z(),l=Me(),[i,r]=P.useState(!1),{data:s}=Ne({queryKey:[k.SAVINGS_PROFILE,o],queryFn:()=>Ei(o),enabled:!!o}),[d,h]=P.useState((L=s==null?void 0:s.taxIdentificationNumbers)!=null?L:[]),m=Qi({defaultValues:{tin:li((q=s==null?void 0:s.taxIdentificationNumbers)!=null?q:[]),taxCountry:si((y=s==null?void 0:s.taxIdentificationNumbers)!=null?y:[]),paysPreliminaryTax:s!=null&&s.paysPreliminaryTax?"yes":"no"},mode:"all",resolver:Re(Zn),shouldUnregister:!1});P.useEffect(()=>{var b,M,w;!e||!s||(r(!1),h((b=s.taxIdentificationNumbers)!=null?b:[]),m.reset({t
1in:li((M=s.taxIdentificationNumbers)!=null?M:[]),taxCountry:si((w=s.taxIdentificationNumbers)!=null?w:[]),paysPreliminaryTax:s.paysPreliminaryTax?"yes":"no"}))},[e,o]);const{mutateAsync:u,isPending:A}=wn({onSuccess:()=>{r(!0)}}),f=m.watch("taxCountry"),S=Ri({control:m.control,name:"paysPreliminaryTax"}),$=f===null||f==="SE"||f==="NO"||f==="FI"||f==="OTHER"&&d.length>0,v=(()=>{var M;const b=(M=s==null?void 0:s.taxIdentificationNumbers)!=null?M:[];return d.length!==b.length?!1:d.every((w,R)=>w.countryCode===b[R].countryCode&&w.number===b[R].number)})(),O=s!=null&&s.paysPreliminaryTax?"yes":"no",x=v&&S===O,N=m.handleSubmit(b=>F(b)),T=A||!$||x||i,I=()=>{i&&l.invalidateQueries({queryKey:[k.SAVINGS_PROFILE,o]}),r(!1),a()},F=b=>D(null,null,function*(){var R,B,U,K,V;de(zi);const M=b.tin||t,w=Bn(d,M!=null?M:"",(R=b.taxCountry)!=null?R:"");yield u({profileModel:{firstName:(B=s==null?void 0:s.firstName)!=null?B:"",lastName:(U=s==null?void 0:s.lastName)!=null?U:"",contactInformation:{emailAddress:(K=s==null?void 0:s.contactInformation.emailAddress)!=null?K:"",mobileNumber:(V=s==null?void 0:s.contactInformation.mobileNumber)!=null?V:""},taxIdentificationNumbers:w!=null?w:[],paysPreliminaryTax:Oe?b.paysPreliminaryTax==="yes":!1},engagementId:o})});return n(Ve,C(H({},m),{children:n("form",{onSubmit:m.handleSubmit(b=>F(b)),children:p(Pe,{open:e,onClose:I,size:"medium",status:i?"success":void 0,children:[i?null:n(we,{children:n(le,{children:c("commonv2.profile.editTaxInfo")})}),p(G,{height:"100%",justifyContent:"space-between",children:[p(G,{children:[n(Q,{children:i?c("commonv2.profile.updateSuccess"):null}),i?n(ee,{children:n(_,{children:c("commonv2.profile.taxInfoUpdated")})}):n(ee,{children:n(ji,{labels:{selector:c("savingsv2.company.isYouTaxliableInAnotherCountry"),taxCountry:c("savingsv2.company.addMyTaxCountryInfo")},tins:d,onChange:b=>h(b),customerNumber:t,preliminaryTax:Oe})})]}),n(We,{children:i?n(g,{onClick:I,children:c("forms.actions.close")}):n(g,{type:"submit",onClick:N,disabled:T,isPending:A,children:c("forms.actions.saveChanges")})})]})]})})}))},gn=({paysPreliminaryTax:e,taxIdentificationNumbers:o,onEditClick:t})=>{const{t:a,i18n:c}=z(),{palette:l}=ae();let i="SE";Yi&&(i="NO"),Ci&&(i="FI");const r=(o!=null?o:[]).some(m=>m.countryCode!==i),d=Array.from(new Set((o!=null?o:[]).map(m=>m.countryCode).filter(m=>!!m&&m!==i))).map(m=>{var u;return(u=Wn(c.language,m))!=null?u:m}),h=r?[a("commonv2.yes"),...d].join(", "):a("commonv2.no");return n(Z,{borderRadius:1,border:`1px solid ${l.grey[920]}`,padding:1.5,children:p(W,{display:"flex",flexDirection:"row",alignItems:"flex-start",justifyContent:"space-between",children:[p(W,{item:!0,children:[n(Q,{mb:1,display:"block",children:a("commonv2.profile.taxInformation")}),Oe&&n(_,{color:l.grey[600],mb:.5,children:`${a("forms.labels.payPreliminaryTaxInSweden")}: ${a(e?"commonv2.yes":"commonv2.no")}`}),n(_,{color:l.grey[600],children:`${a("commonv2.profile.preliminaryTaxInOtherCountry")}: ${h}`})]}),n(W,{item:!0,alignSelf:"center",mr:1,children:n(hi,{noUnderline:!0,color:l.primary.light,icon:n(pi,{color:l.primary.light}),onClick:t,children:a("forms.actions.change")})})]})})},Dn=({engagementId:e,customerFirstName:o,customerLastName:t,hasActiveSavingsEngagement:a,hasActiveLoanEngagement:c,hasActiveCardEngagement:l,activeCreditAccountIds:i,isCompany:r,isSavingsLoggedIn:s})=>{const d=Me(),[h,m]=P.useState(!1),u=Fe({mutationKey:[k.SAVINGS_PROFILE],mutationFn:O=>Xi(e,O)}),A=Fe({mutationKey:[k.LOAN_APPLICATION],mutationFn:O=>Zi(O)}),f=Fe({mutationFn:({creditAccountId:O,model:x})=>Ji(O,x)}),S=u.isPending||A.isPending||f.isPending;return{submit:O=>D(null,null,function*(){const{mobileNumber:x,emailAddress:N}=O;de(gi),Fn(d,e,x,N),m(!1);const T={emailAddress:N,email:N,phoneNumber:x.replace(/\s+/g,""),mobileNumber:x.replace(/\s+/g,""),mobilePhone:x.replace(/\s+/g,"")},I={firstName:o,lastName:t,contactInformation:T},F={phoneNumber:x,email:N,performedBy:"SecureWeb"},L=[];a&&L.push(u.mutateAsync(I)),s&&c&&!r&&L.push(A.mutateAsync(T)),s&&l&&!r&&i.forEach(q=>{L.push(f.mutateAsync({creditAccountId:q,model:F}))}),yield Promise.allSettled(L),m(!0)}),isPending:S,isSuccess:h,setIsSuccess:m,invalidateUpdatedContactInfo:()=>{a&&d.invalidateQueries({queryKey:[k.SAVINGS_PROFILE]}),s&&c&&!r&&d.invalidateQueries({queryKey:[k.CUSTOMER_INFO]}),s&&l&&!r&&d.invalidateQueries({queryKey:[k.CARD_CONTACT_INFO]})}}},eo=(e=!0)=>{var O,x,N,T,I,F,L,q;const{data:o,isInitialLoading:t,isError:a,isFetching:c,refetch:l}=Ne({queryKey:[k.CREDIT_ACCOUNTS],queryFn:()=>ln(),enabled:Oe&&e}),{creditAccountId:i}=Di(),r=(x=(O=o==null?void 0:o.data)==null?void 0:O.creditAccounts)==null?void 0:x.filter(y=>y.status===ci.Active),s=(T=(N=o==null?void 0:o.data)==null?void 0:N.creditAccounts)==null?void 0:T.filter(y=>y.status!==ci.Active),d=ki({queries:(I=r==null?void 0:r.map(y=>({queryKey:[k.INCREASE_CREDIT_LIMIT_APPLICATION_ALLOWED,y.creditAccountId],queryFn:()=>D(null,null,function*(){var V,J,j,Y,ie,ne,me,fe,oe,ue,re;const b=yield en(y.creditAccountId||""),M=yield nn(y.creditAccountId||""),w=yield on(y.creditAccountId||""),R=(V=M.data)!=null&&V.activeApplicationId?yield rn((J=M.data)==null?void 0:J.activeApplicationId):null,B=(j=b==null?void 0:b.data)!=null&&j.activeApplicationId?yield tn((Y=b.data)==null?void 0:Y.activeApplicationId):null,U=(ie=w.data)!=null&&ie.activeApplicationId?yield cn((ne=w.data)==null?void 0:ne.activeApplicationId):null;return C(H({},y),{canIncreaseCreditLimit:(me=M.data)==null?void 0:me.allowed,canOrderExtraCard:(fe=M.data)==null?void 0:fe.allowed,canOrderNewCard:(oe=w.data)==null?void 0:oe.allowed,activeIncreaseCreditApplication:(ue=B==null?void 0:B.data)!=null?ue:null,maxCreditLimit:(re=b==null?void 0:b.data)==null?void 0:re.maxCreditLimit,activeExtraCardApplication:(R==null?void 0:R.data)||null,activeNewCardApplication:(U==null?void 0:U.data)||null})})})))!=null?I:[]}),h=d.some(y=>y.isLoading),m=d.map(y=>y.data).filter(y=>y!==void 0),u=(F=m==null?void 0:m.find(y=>(y==null?void 0:y.creditAccountId)===i))!=null?F:null,{data:A,isLoading:f}=sn(e,(u==null?void 0:u.creditAccountId)||((L=r==null?void 0:r[0])==null?void 0:L.creditAccountId)),S=r&&(r==null?void 0:r.length)>0,$=f||h,v=d.some(y=>y.isLoading);return{isLoading:$,isInitialLoading:t,isError:a,isFetching:c,contactInfo:A,hasActiveCardEngagement:S,activeCreditAccounts:m,inactiveCreditAccounts:s,creditAccounts:(q=o==null?void 0:o.data)==null?void 0:q.creditAccounts,currentCreditAccount:u,isActiveCreditAccountsInitialLoading:v,refetch:l}},io=()=>{const e=dn(),{data:o,isLoading:t}=an(),a=e.hasActiveEngagement;return{isLoanLoading:t,loansEngagements:e,loanCustomerData:o,hasActiveLoanEngagement:a}},no=(e,o)=>{var u,A,f,S;const t=((u=e==null?void 0:e.currentEngagement)==null?void 0:u.id)||"",a=mn(),c=Ne({queryKey:[k.SAVINGS_PROFILE,t],queryFn:()=>Ei(t),enabled:!!t&&a.hasActiveEngagement===!0||!1}),l=a.hasActiveEngagement,i=a.engagements&&((A=a.engagements)==null?void 0:A.length)>1,r=Ne({queryKey:[k.SAVINGS_PERMISSIONS,t],queryFn:()=>fn(t),enabled:!!t}),s=a.isLoading||c.isFetching,d=r.data,h=c.data,m=((f=e==null?void 0:e.currentEngagement)==null?void 0:f.customerNumber)||(a==null?void 0:a.engagements)&&((S=a.engagements[0])==null?void 0:S.customerNumber)||"";return{isSavingsLoading:s,hasMultipleSavingsEngagements:i,hasActiveSavingsEngagement:l,savingsEngagements:a,savingsProfile:h,customerNumber:m,permissions:d}},oo=(e,o,t)=>{var K,V,J,j;const{isSavingsLoading:a,hasMultipleSavingsEngagements:c,hasActiveSavingsEngagement:l,savingsEngagements:i,savingsProfile:r,customerNumber:s,permissions:d}=no(e),{isLoanLoading:h,hasActiveLoanEngagement:m,loanCustomerData:u,loansEngagements:A}=io(),{hasActiveCardEngagement:f,contactInfo:S,activeCreditAccounts:$}=eo(t),{data:v}=un(),O=!l&&!f&&!m,x=(r==null?void 0:r.customerType)===se.COMPANY,N=((K=e==null?void 0:e.currentEngagement)==null?void 0:K.customerNumber.replace("-",""))===(v==null?void 0:v.replace("-","").toString()),T=P.useMemo(()=>$n(l,N,!!f,!!c,u,S,r),[l,N,f,c,u,S,r]),I=P.useMemo(()=>vn(l,N,!!f,x,u,S,r),[l,N,f,x,u,S,r]),F=$e((S==null?void 0:S.mobilePhone)||""),L=$e((u==null?void 0:u.mobileNumber)||""),q=$e((r==null?void 0:r.contactInformation.mobileNumber)||""),y=Rn(f?F:void 0,L,N?q:void 0),b=Vn(u==null?void 0:u.email.toLowerCase(),N?r==null?void 0:r.contactInformation.emailAddress.toLowerCase():void 0,f?(V=S.email)==null?void 0:V.toLowerCase():void 0),M=qn(m,l,f),w=a||h,R=kn(M,y,b,w),B=(J=e==null?void 0:e.allEngagements)==null?void 0:J.some(Y=>Y.customerNumber.replace("-","")===(u==null?void 0:u.personNumber)),U=(j=e==null?void 0:e.allEngagements)==null?void 0:j.find(Y=>Y.customerNumber.replace("-","")===(u==null?void 0:u.personNumber));return{isLoading:w,hasActiveCardEngagement:f,hasActiveLoanEngagement:m,hasActiveSavingsEngagement:l,customerInfo:T,customerAdress:I,showModalIfContactInfoDiffers:R,noEngagements:O,loanCustomerData:u,loansEngagements:A,hasMultipleSavingsEngagements:c,savingsEngagements:i,savingsProfile:r,customerNumber:s,isCompany:x,permissions:d,isLoggedInEngagement:N,activeCreditAccounts:$,isLoanAndSavingCustomer:B,loanAndSavingsEngagement:U}},yo=()=>{var Ge,Ue,Ke,He,Qe,ze,je,Ye,Ce,Xe,Ze,Je,ge,De;const{t:e}=z(),{palette:o}=ae(),t=ai(),a=mi(),c=Me(),{state:l,dispatch:i}=hn(),{currentEngagement:r}=l.engagement,{isLoading:s,customerInfo:d,customerAdress:h,showModalIfContactInfoDiffers:m,isCompany:u,isLoggedInEngagement:A,savingsProfile:f,hasActiveSavingsEngagement:S,hasActiveLoanEngagement:$,hasActiveCardEngagement:v,activeCreditAccounts:O,noEngagements:x,permissions:N,savingsEngagements:T,hasMultipleSavingsEngagements:I}=oo(l.engagement),F=T==null?void 0:T.hasActiveEngagement,L=(Ue=(Ge=T==null?void 0:T.engagements)==null?void 0:Ge[0])!=null?Ue:null;P.useEffect(()=>{var te,ei;if(s||I)return;const E=(ei=(te=t.state)==null?void 0:te.currentEngagement)!=null?ei:F?L:null;E&&E.id!==(r==null?void 0:r.id)&&i({type:pe.SET_ENGAGEMENT,payload:E})},[I,s,t.state,F,L,r==null?void 0:r.id,i]),P.useEffect(()=>{var te;if(!I)return;const E=(te=t.state)==null?void 0:te.currentEngagement;E&&E.id!==(r==null?void 0:r.id)&&i({type:pe.SET_ENGAGEMENT,payload:E})},[I,t.state,r==null?void 0:r.id,i]);const q=(Ke=r==null?void 0:r.id)!=null?Ke:"",y=!f||A,b=(He=O==null?void 0:O.map(E=>E.creditAccountId).filter(E=>!!E))!=null?He:[],{submit:M,isPending:w,isSuccess:R,setIsSuccess:B,invalidateUpdatedContactInfo:U}=Dn({engagementId:q,customerFirstName:(Qe=d==null?void 0:d.firstName)!=null?Qe:"",customerLastName:(ze=d==null?void 0:d.lastName)!=null?ze:"",hasActiveSavingsEngagement:S,hasActiveLoanEngagement:$,hasActiveCardEngagement:v,activeCreditAccountIds:b,isCompany:u,isSavingsLoggedIn:y});P.useEffect(()=>{if(t.pathname.endsWith("profile")&&I)return i({type:pe.CLEAR_CURRENT_ENGAGEMENT})},[t.pathname]);const{phoneNumber:K,email:V}=_n(c,q,d),[J,j]=P.useState(!1),[Y,ie]=P.useState(!1),[ne,me]=P.useState("about-company"),[fe,oe]=P.useState(!1),ue=m&&!fe&&!En,re=!!f&&(N==null?void 0:N.updateProfileInformation)&&!u,Oi=u?!0:(N==null?void 0:N.updateProfileInformation)!==!1,Le=u&&!!f,xi=P.useMemo(()=>[{title:"Om företaget",value:"about-company"},{title:"Nyckelpersoner",value:"contact-persons"}],[]),Ii=(Ye=(je=r==null?void 0:r.name)==null?void 0:je.trim())!=null?Ye:"",Mi=u?(Ce=f==null?void 0:f.customerName)!=null?Ce:"":`${(Xe=d==null?void 0:d.firstName)!=null?Xe:""} ${(Ze=d==null?void 0:d.lastName)!=null?Ze:""}`.trim(),wi=Ii||Mi,Be=A?"":(Je=r==null?void 0:r.name)!=null?Je:"";P.useEffect(()=>{i({type:pn.SET_HEADER_CAPTION,payload:{caption:Be,setBy:"page"}})},[i,Be]);const Pi=E=>D(null,null,function*(){yield M(E)}),Li=()=>{B(!1),j(!0)},Fi=()=>{j(!1),B(!1),U()},_i=E=>D(null,null,function*(){de(On),yield M(E),oe(!0)});return s?n(ye,{children:n(yn,{})}):I&&!r?n(ye,{children:n(ui,{border:"between",size:"neutral",children:(ge=T==null?void 0:T.engagements)==null?void 0:ge.map(E=>n(bn,{elevate:!1,onClick:()=>{i({type:pe.SET_ENGAGEMENT,payload:E}),a(t.pathname,{state:{currentEngagement:E,captionName:E.name},replace:!0})},children:p(G,{flexDirection:"row",alignItems:"center",py:1,children:[n(Mn,{sx:{backgroundColor:o.lavender[500],mr:1.5},children:E.customerType===se.COMPANY?n(Nn,{color:o.lavender[400]}):n(An,{color:o.lavender[400]})}),n(Q,{children:E.name})]})},E.id))})}):x?n(ye,{children:n(Sn,{noIcon:!0,children:n(Tn,{children:e("commonv2.profile.noProducts")})})}):h?p(di,{children:[p(ye,{children:[Le&&n(xn,{options:xi,onChange:me,defaultValue:ne}),ne==="contact-persons"&&Le?n(Kn,{userDetails:f,currentEngagement:r}):p(G,{spacing:3,mt:Le?5:0,children:[n(Pn,{fullName:wi,careOf:h.careOf,street:h.street,postalCode:h.postalCode,city:h.city,country:h.country,isCompany:u}),n(Hn,{phoneNumber:K,email:V,canEdit:Oi,onEditClick:Li}),re&&f&&n(gn,{paysPreliminaryTax:f.paysPreliminaryTax,taxIdentificationNumbers:f.taxIdentificationNumbers,onEditClick:()=>ie(!0)})]})]}),n(Xn,{isOpen:J,isLoading:w,currentPhoneNumber:K,currentEmail:V,onSubmit:Pi,onClose:Fi,isSuccess:R}),ue&&n(jn,{isOpen:!0,isLoading:w,currentPhoneNumber:K,currentEmail:V,onSubmit:_i,onClose:()=>oe(!0)}),re&&Y&&n(Jn,{isOpen:!0,engagementId:q,customerNumber:(De=r==null?void 0:r.customerNumber)!=null?De:"",onClose:()=>ie(!1)})]}):null};export{yo 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.