import{x as b,r as C,y as N,a as Q,af as E,fg as O,bJ as W,eW as $,da as j,bD as T,fh as D,fi as L,eX as U,c as V,fj as Y,fk as q,j as r,M as z,d as J,cd as F,i as B,s as m,fl as ee,fm as ae,fn as te,w as se,fo as ne,aS as oe,bc as re,aw as le,fp as ce,fq as de,fa as ie,fr as ue,fs as pe,ft as he,fu as fe,fv as me,fw as _e}from"./index-BbiZcFRx.js";const G={show:!1,agentUserProfile:null,agentPurl:null},Ne=()=>{const y=b(),[l,P]=C.useState(G),I=N(u=>u.planTypeDetail.selectedPlanType),i=N(u=>u.planTypeDetail.checkPreferredAgentModal),p=N(u=>u.userProfile.userProfile),w=N(u=>u.mainDetails.purlAgents),_=N(u=>u.mainDetails.purlAgentsLoaded),{isAuthenticated:x}=Q();return C.useEffect(()=>{if(x&&i&&p&&p.consumerId>0&&_){let u=!1;const A=I===T?D:L,g=w.find(M=>M.productType===A);let a={};const n=E(O);n&&E(W)!==n.agentPurlCode?a=n:a=E($),g&&a&&(g.agentNpn!==a.agentNpn||g.agentPurlCode!==a.agentPurlCode)&&(u=!0),P({show:u,agentUserProfile:g,agentPurl:a})}},[x,i,w,p,_]),C.useEffect(()=>{y(j(!0))},[]),{preferredAgentData:l,resetPreferredAgentData:()=>{y(j(!1)),P(G)},purlAgents:w}},Pe="data:image/svg+xml,%3csvg%20id='Graphic-User'%20xmlns='http://www.w3.org/2000/svg'%20width='96'%20height='96'%20viewBox='0%200%2096%2096'%3e%3cg%20id='Graphic-Boarder'%3e%3crect%20id='Rectangle_13715'%20data-name='Rectangle%2013715'%20width='96'%20height='96'%20fill='rgba(255,255,255,0)'/%3e%3c/g%3e%3cg%20id='Group_6184'%20data-name='Group%206184'%20transform='translate(-4%20-4)'%3e%3cg%20id='Group_5345'%20data-name='Group%205345'%20transform='translate(16%2016)'%3e%3cpath%20id='Path_20967'%20data-name='Path%2020967'%20d='M0,36A36,36,0,1,0,36,0,36,36,0,0,0,0,36'%20fill='%23e2f4fd'/%3e%3c/g%3e%3cpath%20id='Path_20968'%20data-name='Path%2020968'%20d='M55.988,243.787c0,.861,7.91,1.559,17.667,1.559s17.667-.7,17.667-1.559-7.91-1.559-17.667-1.559-17.667.7-17.667,1.559'%20transform='translate(-27.391%20-171.727)'%20fill='%23b1cdfc'/%3e%3cpath%20id='Path_20969'%20data-name='Path%2020969'%20d='M95.789,168.982a15.862,15.862,0,1,0-31.725,0v4.923H95.789Z'%20transform='translate(-33.649%20-102.668)'%20fill='%23fff'%20stroke='%23707070'%20stroke-width='1'/%3e%3cpath%20id='Path_20970'%20data-name='Path%2020970'%20d='M88.376,50.435a10.4,10.4,0,1,0,20.79,0v-3.28a10.393,10.393,0,0,0-20.785,0Z'%20transform='translate(-52.491%20-12.564)'%20fill='%23fff'%20stroke='%23707070'%20stroke-width='1'/%3e%3cpath%20id='Path_20971'%20data-name='Path%2020971'%20d='M88.376,50.435a10.4,10.4,0,1,0,20.79,0v-3.28a10.393,10.393,0,0,0-20.785,0Z'%20transform='translate(-52.491%20-12.564)'%20fill='none'%20stroke='%231f57ee'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1'/%3e%3cpath%20id='Path_20972'%20data-name='Path%2020972'%20d='M95.789,168.982a15.862,15.862,0,1,0-31.725,0v4.923H95.789Z'%20transform='translate(-33.649%20-102.668)'%20fill='none'%20stroke='%231f57ee'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1'/%3e%3cpath%20id='Path_20973'%20data-name='Path%2020973'%20d='M129.432,162.021l-6.268-6.269a2.532,2.532,0,0,0-3.58,0h0l-2.687,2.687a2.533,2.533,0,0,0,0,3.582h0l11.643,11.641a2.533,2.533,0,0,0,3.582,0h0l21.951-21.954a2.532,2.532,0,0,0,0-3.58h0l-2.686-2.683a2.533,2.533,0,0,0-3.582,0h0l-16.581,16.577a1.267,1.267,0,0,1-1.791,0'%20transform='translate(-74.02%20-96.145)'%20fill='%23b1cdfc'%20stroke='%23707070'%20stroke-width='1'/%3e%3cpath%20id='Path_20974'%20data-name='Path%2020974'%20d='M129.432,162.021l-6.268-6.269a2.532,2.532,0,0,0-3.58,0h0l-2.687,2.687a2.533,2.533,0,0,0,0,3.582h0l11.643,11.641a2.533,2.533,0,0,0,3.582,0h0l21.951-21.954a2.532,2.532,0,0,0,0-3.58h0l-2.686-2.683a2.533,2.533,0,0,0-3.582,0h0l-16.581,16.577A1.267,1.267,0,0,1,129.432,162.021Z'%20transform='translate(-74.02%20-96.145)'%20fill='none'%20stroke='%231f57ee'%20stroke-linecap='round'%20stroke-linejoin='round'%20stroke-width='1'/%3e%3c/g%3e%3c/svg%3e",ge="We noticed you have worked with another agent at one time. Please select your preferred agent from the list below and we'll update our records.",Ce="An image with a tick sign symbol",we="Save",Ae="_content_1664w_88",Te="_contentClassName_1664w_103",Ee="_footerClassName_1664w_108",ye="_closeIconClassName_1664w_114",Ie="_headerClassName_1664w_124",xe="_footerButtonClassName_1664w_129",De="_error_1664w_189",ke="_phoneValue_1664w_195",Me="_phoneText_1664w_201",ve="_agentContainer_1664w_205",Be="_agentWrapperContainer_1664w_210",Le="_agentModalBoxClassName_1664w_220",Re="_addButton_1664w_230",Se="_closeButton_1664w_236",je="_agentActionContainer_1664w_241",d={content:Ae,contentClassName:Te,footerClassName:Ee,closeIconClassName:ye,headerClassName:Ie,footerButtonClassName:xe,error:De,phoneValue:ke,phoneText:Me,agentContainer:ve,agentWrapperContainer:Be,agentModalBoxClassName:Le,addButton:Re,closeButton:Se,agentActionContainer:je},Ge=()=>{const y=b(),[l,P]=C.useState(),{clientService:I}=U(),i=N(e=>e.userProfile.userProfile),p=N(e=>e.planTypeDetail.selectedPlanType),{Post:w}=V("https://ae-api.medicarecenter.com/ae-consumer-service/api/v1.0/Consumer/Lead",!1),[_]=C.useState(E(Y)),{preferredAgentData:x,resetPreferredAgentData:k,purlAgents:u}=Ne(),A=window.location.pathname.includes(q),{show:g,agentUserProfile:a,agentPurl:n}=x,M=e=>`${(e==null?void 0:e.agentFirstName)||""} ${(e==null?void 0:e.agentMiddleName)||""} ${(e==null?void 0:e.agentLastName)||""}`,v=async e=>{if(!_&&!A)return null;le(ce);const t=E(de);t.consumerId=i.consumerId,e&&(t.purl=e.agentPurlCode,t.agentNPN=e.agentNpn);try{const s=await w(t,!0);if(s.status<200||s.status>=300)throw new Error(`Failed to register user: status code ${s.status}`);const{leadId:o}=await ie(s);return B(o),o}catch(s){return console.error(s),null}},H=async(e,t,s="")=>{const o=await v(e),h={agentId:0,agentNpnSwitchedFrom:(t==null?void 0:t.agentNpn)||"",agentNpnSwitchedTo:e==null?void 0:e.agentNpn,agentPurlSwitchedTo:e==null?void 0:e.agentPurlCode,consumerId:i==null?void 0:i.consumerId,isActive:!0,leadId:o,productType:s||(e.isMedicareAgent?D:L)};await I.agentAssociation(h);const f=await I.getConsumerByConsumerId(i.consumerId);if(f!=null&&f.consumerAgentAssociations)for(const c of(f==null?void 0:f.consumerAgentAssociations)||[])(c==null?void 0:c.productType)==="Final Expense"&&m(fe,c==null?void 0:c.agentNpnSwitchedTo),(c==null?void 0:c.productType)==="Medicare"&&m(me,c==null?void 0:c.agentNpnSwitchedTo);return f},R=async(e,t,s)=>{const o=await H(e,t,s);await Z(o)};C.useEffect(()=>{(async()=>{var t,s;if(!a&&n&&(i==null?void 0:i.consumerId)>0){const o=n.isMedicareAgent?T:n.isFinalExpenseAgent?F:null,h=n.isMedicareAgent?D:n.isFinalExpenseAgent?L:null;o&&p===o&&await R(n,null,h)}a&&n&&(_||A)&&p===T&&a.agentPurlCode===n.agentPurlCode&&((t=a==null?void 0:a.associationData)!=null&&t.leadId?B((s=a==null?void 0:a.associationData)==null?void 0:s.leadId):await v(a))})()},[a,n,i==null?void 0:i.consumerId,p,_]);const Z=async e=>{const t=e.consumerAgentAssociations||[];if(t.length>0){const s=await t.reduce(async(o,h)=>{const f=await ue(h.agentPurlSwitchedTo);let c=[];return pe(o)&&(c=await o),[...c,{...f,productType:h.productType,associationData:h}]},[]);y(he(s))}},X=e=>{m(W,e),m(O,null);var t=new URL(window.location.href);t.searchParams.set("purl",e),t.hash?window.history.replaceState(null,null,`?${t.searchParams}${t.hash}`):window.history.replaceState(null,null,`?${t.searchParams}`)},K=async()=>{var e,t,s;if((a==null?void 0:a.agentNpn)!==(l==null?void 0:l.agentNpn))await R(l,a,_e(p));else{if(_||A){const o=(e=u.find(h=>h.productType===D))==null?void 0:e.associationData;o&&!(o!=null&&o.leadId)&&((t=a==null?void 0:a.associationData)!=null&&t.leadId?B((s=a==null?void 0:a.associationData)==null?void 0:s.leadId):await v(a))}p===T&&(m(ee,l.agentPurlCode),m($,l)),p===F&&(m(ae,l.agentPurlCode),m(te,l))}X(l.agentPurlCode),k()},S=({agent:e})=>r.jsx(r.Fragment,{children:r.jsxs("div",{className:d.agentWrapperContainer,onClick:()=>P(e),children:[r.jsxs("div",{className:d.agentDetailsContainer,children:[r.jsx(se,{className:d.heading3,text:M(e)}),r.jsxs("div",{className:d.phoneText,children:[r.jsx("span",{children:"Phone: "}),ne(e==null?void 0:e.virtualNumber,!0)]})]}),r.jsx("div",{className:d.agentActionContainer,children:(e==null?void 0:e.agentNpn)===(l==null?void 0:l.agentNpn)?r.jsx(oe,{className:d.closeButton,onClick:()=>P(),size:12}):r.jsx(re,{className:d.addButton,onClick:()=>P(e)})})]})});return r.jsx("div",{className:d.modalWithHeaderFooter,children:r.jsx(z,{className:d.modal,isOpen:g,children:r.jsx(J,{closeIconClassName:d.closeIconClassName,contentClassName:d.contentClassName,footerButtonClassName:d.footerButtonClassName,footerButtonClicked:K,footerButtonDisabled:!l,footerClassName:d.footerClassName,footerLabel:we,headerClassName:d.headerClassName,headerIcon:Pe,headerIconAlt:Ce,headerText:ge,headerTitle:`Your Preferred ${p===T?"Medicare":"Final Expense"} Agent`,onClose:k,children:r.jsxs("div",{className:d.agentContainer,"data-testid":"your-preferred-agent-modal",children:[(a==null?void 0:a.agentNpn)&&r.jsx(S,{agent:a}),(n==null?void 0:n.agentNpn)&&r.jsx(S,{agent:n})]})})})})};export{Ge as P}; //# sourceMappingURL=index-B9MbtH2j.js.map