1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/TiptapEditorCore-CDVK5GuF.js","assets/index-hL3pcTef.js","assets/index-QR_y1HJC.css"])))=>i.map(i=>d[i]); 2import{j as e,k as ie,r as p,_ as ne,d as oe,u as ce,eD as me,a as F,I as d,ea as ue,eM as de,eN as pe,B as G,s as ge}from"./index-hL3pcTef.js";import{c as fe,b as he}from"./public.queries-BQ4rAO2p.js";import{l as xe,m as be}from"./admin.mutations-BvTTxrF1.js";import{t as je,b as Pe,s as ve}from"./agentFormData-DtnzdFEh.js";import{b as ye,e as D,c as K,d as $,f as we,g as Ne}from"./agentForm.utils-CmdwJikT.js";import{u as Ie,d as H}from"./file.service-gzlP3vSC.js";import{p as ke}from"./publicAgentWebsitePath-G6mYRwHL.js";import{F as i,C as m}from"./index-Cxf4rmVI.js";import{C as Se}from"./index-CDoQToj6.js";import{T as Ae}from"./index-BcWpjjeV.js";import{D as h}from"./index-DFK1kxIg.js";import{a as x}from"./row-B6rF7FMd.js";import{S as Fe}from"./index-C1N5wVkR.js";import{R as C}from"./index-Dc7QU0W2.js";import{C as w}from"./index-XUTl3fJi.js";import{U as Ce}from"./index-CaCM3M-d.js";import"./public.mutations-BNuhp7Yl.js";import"./joditEditor-CJw2JJBb.js";import"./useForm-CRGMdtfF.js";import"./PlusOutlined-BW1yN58X.js";import"./Dropdown-WwCtKhvr.js";import"./styleChecker-C7z56Tbj.js";import"./useBubbleLock-C2OM8qLP.js";const Ee=[{label:"Alberta",value:"Alberta"},{label:"British Columbia",value:"British Columbia"},{label:"Manitoba",value:"Manitoba"},{label:"New Brunswick",value:"New Brunswick"},{label:"Newfoundland and Labrador",value:"Newfoundland and Labrador"},{label:"Nova Scotia",value:"Nova Scotia"},{label:"Ontario",value:"Ontario"},{label:"Prince Edward Island",value:"Prince Edward Island"},{label:"Quebec",value:"Quebec"},{label:"Saskatchewan",value:"Saskatchewan"},{label:"Yukon",value:"Yukon"},{label:"Home Office",value:"Home Office"},{label:"Nunavut",value:"Nunavut"},{label:"Northwest Territories",value:"Northwest Territories"}],Le=({value:a,onChange:g})=>e.jsx(ie,{size:"large",className:"!h-[42px]",style:{width:"100%"},placeholder:"Select provinces",value:a,onChange:g,showSearch:!0,optionFilterProp:"label",options:Ee}),Ue=p.lazy(()=>ne(()=>import("./TiptapEditorCore-CDVK5GuF.js"),__vite__mapDeps([0,1,2]))),Oe=e.jsxs("div",{className:"flex w-full flex-col rounded-md border bg-white p-2",children:[e.jsx("div",{className:"mb-2 h-9 animate-pulse rounded bg-neutral-100"}),e.jsx("div",{className:"h-[100px] w-full animate-pulse rounded bg-neutral-50"})]}),Re=a=>e.jsx(p.Suspense,{fallback:Oe,children:e.jsx(Ue,{...a})}),{Title:b}=Ae,W=a=>{if(Array.isArray(a))return a;if(!a)return[];if(typeof a=="string")try{const g=JSON.parse(a);return Array.isArray(g)?g:[]}catch{return[]}return[]},N=a=>a==="female"?"female_default.png":"male_default.png",Me=a=>{if(!a||typeof a!="string"||a.includes("default"))return"";try{return new URL(a).pathname.replace(/^\/+/,"")}catch{return a}},E=a=>{typeof a=="string"&&a.startsWith("blob:")&&URL.revokeObjectURL(a)},is=({mode:a})=>{const{id:g}=oe(),[o]=i.useForm(),L=ce(),[U,P]=p.useState({}),[j,v]=p.useState("male_default.png"),[I,k]=p.useState(null),[J,O]=p.useState(!1),R=xe(),M=be(),{data:r,isLoading:Q}=fe(a==="edit"?g:void 0),{data:S=[]}=me(),{data:A=[]}=he(),T=p.useMemo(()=>ye([...Array.isArray(S)?S:[],...Array.isArray(A)?A:[]]),[S,A]),_=F("firstname",o),B=F("lastname",o),Y=F("gender",o),q=a==="create"?"Create Agent Profile":"Update Agent Profile",y=a==="edit"&&(Me(r==null?void 0:r.profilePicture)||(r==null?void 0:r.profilePicture))||"",X=a==="edit"&&(r==null?void 0:r.profilePicture)||"",Z=N(Y),V=I?null:y||Z,z=J||R.isPending||M.isPending;p.useEffect(()=>{if(a!=="create")return;const s=D(_,B);s&&o.setFieldsValue({username:s})},[_,B,o,a]),p.useEffect(()=>{if(a!=="edit"||!r)return;const s=W(r.bookNowOptions),l=W(r.socialLinks);o.setFieldsValue({firstname:r.firstName||"",lastname:r.lastName||"",username:r.username||D(r.firstName,r.lastName),gender:r.gender||null,profilePicture:y||"male_default.png",phone:r.phone||"",phoneExtension:r.phoneExtension!==void 0&&r.phoneExtension!==null?String(r.phoneExtension):"",email:r.email||"",location:r.location||"",postalCode:r.postalCode||"",isPublic:r.isPublic===!0,languages:r.languages?r.languages.split(","):[],aboutMe:r.aboutMe||"",bookNowOptions:s.map(t=>t.label),travelSpecialties:r.specialtiesNames?Array.from(new Set(r.specialtiesNames)):[],socialMedia:l.reduce((t,c)=>(t[c.platform]=c.url,t),{})});const n=s.reduce((t,c)=>(c.label&&c.linkUrl&&(t[c.label]=c.linkUrl),t),{});P(n),v(r.profilePicture||"male_default.png"),k(null)},[r,o,a,y]),p.useEffect(()=>()=>E(j),[j]);const ee=s=>{const l=s.target.value,n=N(l);E(j),v(n),k(null),o.setFieldsValue({profilePicture:n})},se=()=>{const s=j||o.getFieldValue("profilePicture")||V;return ke(s)},ae=async s=>{var n;const l=((n=s.file)==null?void 0:n.originFileObj)||s.file;if(l){E(j);const t=URL.createObjectURL(l);
2k(l),v(t),o.setFieldsValue({profilePicture:l.name})}},re=(s,l)=>{const n=o.getFieldValue("bookNowOptions")||[];let t;l?(t=[...n,s],P(c=>({...c,[s]:Ne(s,o.getFieldValue("phoneExtension"))}))):(t=n.filter(c=>c!==s),P(c=>{const u={...c};return delete u[s],u})),o.setFieldsValue({bookNowOptions:t})},le=async s=>{const l=y||N(s.gender),n=X||l;let t=V||N(s.gender),c="";try{if(O(!0),a==="create")try{K(s.username,T)}catch(f){$(o,f);return}if(I){const{key:f}=await Ie(I,"Agent/profile-picutre/",null,{},{returnResult:!0});c=f,t=f}const u=we({values:s,profileImage:t,bookNowLinks:U,mode:a});if(a==="create"?await R.mutateAsync(u):await M.mutateAsync({id:g,payload:u}),a==="edit"&&l&&l!==t)try{await H(l)}catch(f){console.error("Failed to delete previous profile image after successful save:",f)}L(-1)}catch(u){if(c&&c!==l){try{await H(c)}catch(f){console.error("Failed to clean up uploaded profile image after API failure:",f)}v(n),o.setFieldsValue({profilePicture:l})}if($(o,u))return;console.error("Agent form submission failed:",u),ge.error((u==null?void 0:u.message)||"Failed to save agent profile.")}finally{O(!1)}},te=()=>{L(-1)};return e.jsxs(Se,{className:"",children:[e.jsx("h1",{className:"mb-6 text-3xl font-semibold",children:q}),e.jsxs(i,{form:o,onFinish:le,layout:"vertical",requiredMark:!1,size:"large",initialValues:{profilePicture:"male_default.png",bookNowOptions:[],travelSpecialties:[],socialMedia:{}},children:[e.jsx(b,{level:4,children:"Basic Information"}),e.jsx(h,{}),e.jsxs(x,{gutter:24,children:[e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"First Name",name:"firstname",rules:[{required:!0,message:"Please enter first name"}],children:e.jsx(d,{placeholder:"First Name"})})}),e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Last Name",name:"lastname",rules:[{required:!0,message:"Please enter last name"}],children:e.jsx(d,{placeholder:"Last Name"})})}),e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Username",name:"username",rules:a==="create"?[{required:!0,message:"Please enter username"},{validator:async(s,l)=>{l&&K(l,T)}}]:[],children:e.jsx(d,{placeholder:"Enter username",disabled:a!=="create"})})}),a==="create"&&e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Password",name:"password",rules:[{required:!0,message:"Please enter password"},{min:8,message:"Password must be at least 8 characters"}],children:e.jsx(d.Password,{placeholder:"Password",iconRender:s=>s?e.jsx(ue,{}):e.jsx(de,{})})})}),e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Display to client",name:"isPublic",valuePropName:"checked",rules:[{required:!0,message:"Please set visibility"}],children:e.jsx(Fe,{checkedChildren:"Visible",unCheckedChildren:"Hidden"})})}),e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Gender",name:"gender",rules:[{required:!0,message:"Please select gender"}],children:e.jsxs(C.Group,{onChange:ee,children:[e.jsx(C,{value:"male",children:"Male"}),e.jsx(C,{value:"female",children:"Female"})]})})})]}),e.jsx(b,{level:4,style:{marginTop:24},children:"Contact Information"}),e.jsx(h,{}),e.jsxs(x,{gutter:24,children:[e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Email",name:"email",rules:[{required:!0,message:"Please input email!"},{type:"email",message:"Please enter a valid email!"}],children:e.jsx(d,{placeholder:"Email"})})}),e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Phone",name:"phone",rules:[{required:!0,message:"Please input phone number!"}],children:e.jsx(d,{placeholder:"Phone Number"})})}),e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Extension",name:"phoneExtension",normalize:s=>typeof s=="string"?s.replace(/\D+/g,"").slice(0,10):s,rules:[{pattern:/^\d+$/,message:"Extension can contain numbers only"},{max:10,message:"Extension must be 10 digits or less"}],children:e.jsx(d,{placeholder:"Ext",inputMode:"numeric",maxLength:10})})})]}),e.jsx(b,{level:4,style:{marginTop:24},children:"Location Information"}),e.jsx(h,{}),e.jsxs(x,{gutter:24,children:[e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Province",name:"location",rules:[{required:!0,message:"Please select province"}],children:e.jsx(Le,{})})}),e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Postal Code",name:"postalCode",rules:[{required:!0,message:"Please input postal code!"}],children:e.jsx(d,{placeholder:"Postal Code"})})}),e.jsx(m,{span:8,children:e.jsx(i.Item,{label:"Languages",name:"languages",rules:[{required:!0,message:"Please select languages"}],children:e.jsx(pe,{mode:"multiple"})})})]}),e.jsx(b,{level:4,style:{marginTop:24},children:"Travel Specialties"}),e.jsx(h,{}),e.jsx(i.Item,{name:"travelSpecialties",children:e.jsx(w.Group,{style:{width:"100%"},children:e.jsx(x,{gutter:[16,8],children:je.map(s=>e.jsx(m,{span:3,children:e.jsx(w,{value:s.value,style:{fontSize:"15px"},children:s.label})},s.value))})})}),e.jsx(b,{level:4,style:{marginTop:24},children:"Book Now Options"}),e.jsx(h,{}),e.jsx(i.Item,{name:"bookNowOptions",children:e.jsx(w.Group,{style:{width:"100%"},children:e.jsx(x,{gutter:[16],children:Pe.map(s=>{var l;return e.jsx(m,{span:8,children:e.jsxs("div",{className:"mb-4 flex items-center gap-2",children:[e.jsx(w,{value:s.value,onChange:n=>
2re(s.value,n.target.checked),style:{marginRight:8,fontSize:"15px"},children:e.jsxs("div",{className:"ml-2 flex items-center gap-2",children:[e.jsx("img",{src:`/assets/images/connectedagents/agent_book_options/${s.icon}`,alt:s.label})," ",s.label]})}),((l=o.getFieldValue("bookNowOptions"))==null?void 0:l.includes(s.value))&&e.jsx("div",{className:"ml-5 flex w-full items-center",children:e.jsx(d,{value:U[s.value]||"",onChange:n=>P(t=>({...t,[s.value]:n.target.value})),placeholder:"Enter URL",style:{width:"100%",maxWidth:400},prefix:e.jsx("img",{src:"/assets/images/admindashboard/link_black.png",alt:"link",style:{width:16,height:16}})})})]})},s.value)})})})}),e.jsx(b,{level:4,style:{marginTop:24},children:"Profile Information"}),e.jsx(h,{}),e.jsxs(x,{gutter:24,children:[e.jsx(m,{span:3,children:e.jsx(i.Item,{label:"Profile Picture",name:"profilePicture",children:e.jsx(Ce,{accept:"image/*",showUploadList:!1,beforeUpload:()=>!1,onChange:ae,children:e.jsx("div",{className:"flex flex-col items-center",children:e.jsx("img",{src:se(),alt:"Profile",className:"mb-2 max-h-[150px] !min-h-[150px] w-full cursor-pointer rounded-md object-cover"})})})})}),e.jsx(m,{span:16,children:e.jsx(i.Item,{label:"About Agent",name:"aboutMe",rules:[{required:!0,message:"Please enter about agent"}],children:e.jsx(Re,{})})})]}),e.jsx(b,{level:4,style:{marginTop:24},children:"Social Media URLs"}),e.jsx(h,{}),e.jsx(x,{gutter:24,children:ve.map(s=>e.jsx(m,{span:8,children:e.jsx(i.Item,{label:s.placeholder,name:["socialMedia",s.name],rules:[{validator:(l,n)=>{const t=typeof n=="string"?n.trim():"";if(!t)return Promise.resolve();try{return new URL(t),Promise.resolve()}catch{return Promise.reject(new Error("Please enter a valid URL"))}}}],children:e.jsx(d,{type:"url",name:`social-${s.name}-url`,autoComplete:"off",prefix:e.jsx("img",{src:s.icon,alt:s.name})})})},s.name))}),e.jsxs(i.Item,{style:{marginTop:24,textAlign:"right"},children:[e.jsx(G,{onClick:te,style:{marginRight:16},children:"Cancel"}),e.jsx(G,{type:"primary",htmlType:"submit",loading:z,disabled:Q||z,children:q})]})]})]})};export{is 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.