more-desk-one 0.0.39 → 0.0.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -149,5 +149,5 @@ mutation AssistChat(
149
149
  }`,ee=10,it=()=>{const[t,n]=e.useState([]),[s,r]=e.useState(!0),[l,i]=e.useState(null),[m,h]=e.useState(!1),[d,o]=e.useState(!1),[p,S]=e.useState(!0),[A,k]=e.useState(!1),{accessToken:u,profileInfo:w}=$(),M=V("userAndTicket")?.ticket_id,L=V("userAndTicket")?.employee_id,J=e.useMemo(()=>t.find(f=>f.ticket_id!=null)?.ticket_id??null,[t]);let T=M??J??null;return e.useEffect(()=>{if(Array.isArray(t)&&t?.length>0){const f=t[t.length-1];!f?.handover&&f?.user?.user_type==="employee"?o(!0):o(!1)}},[t]),e.useEffect(()=>{if(!T||!w)return;if(L&&w?.employee_id!=L){sessionStorage.removeItem("userAndTicket");return}const f=me(lt,{ticket_id:T},C=>{const v=C;if(v?.onAssistChat?.user?.user_type==="agent"||v?.onAssistChat?.user?.user_type==="bot")if(v?.onAssistChat?.system){const _={message_id:Math.random(),text:"handover to agent",attachments:null,ticket_id:null,system:!0,handover:null,created_at:null,end:null,user:null},E={...v?.onAssistChat,system:!1};n(a=>[...a,E,_]),o(!1)}else n(_=>[..._,v.onAssistChat]),o(!1)});return()=>f()},[T,w]),e.useEffect(()=>{if(!T)return;const f=me(ct,{ticket_id:T},C=>{C?.onTicketUpdate?.status_id===3&&k(!0)});return()=>f()},[T]),e.useEffect(()=>{if(!u||!w)return;L&&w?.employee_id!==L&&(sessionStorage.removeItem("userAndTicket"),T=null);const f={...T&&{ticket_id:T},limit:ee};P(he,f,u).then(async C=>{n(C?.assistHistory??[])}).catch(C=>{i(C)}).finally(()=>{r(!1)})},[w]),{historyData:t,msgLoading:s,msgError:l,isSending:d,sendMessage:f=>{const C=t.find(E=>E.ticket_id!=null)?.ticket_id??null,v=t.find(E=>E.handover==!0)?.handover??!1,_={...C&&{ticket_id:C},message:f,handover:v,attachments:[],text:f,message_id:Math.random(),created_at:new Date().toISOString(),user:{user_name:w?.full_name,user_type:"employee"}};o(!0),n(E=>[...E,_]),K(fe,_,u).then(async E=>{const a=E;if(a.assistChat.user.user_type!=="employee"&&a.assistChat.system){const g={message_id:Math.random(),text:"handover to agent",attachments:null,ticket_id:null,system:!0,handover:null,created_at:null,end:null,user:null},y={...a.assistChat,system:!1};n(x=>[...x,y,g]),o(!1)}!V("userAndTicket")&&a.assistChat?.ticket_id&&w&&ae("userAndTicket",{ticket_id:a.assistChat?.ticket_id,employee_id:w.employee_id})}).catch(()=>{n(E=>E.slice(0,-1)),o(!1)})},getNextPageData:f=>{if(!u||m)return;const C=V("userAndTicket")?.ticket_id,v={...C&&{ticket_id:C},limit:ee,offset:f};h(!0),P(he,v,u).then(async _=>{const a=_?.assistHistory??[];n(g=>[...a,...g]),a.length<ee&&S(!1)}).catch(_=>{i(_)}).finally(()=>{h(!1)})},isLoadingMore:m,upload:async f=>{o(!0);const C={files:f.files.map(v=>`${f.ticketId}/${v.name}`),signature_type:f.signature_type};try{const v=await K(st,C,u);for(const[b,H]of f.files.entries()){const j=v.GetPresignedLink[b]?.url;j&&await fetch(j,{method:"PUT",body:H,headers:{"Content-Type":H.type}})}const _=t.find(b=>b.handover)?.handover??!1,E=f.files.map(b=>({url:URL.createObjectURL(b),filename:b.name})),a={ticket_id:f.ticketId,handover:_,attachments:E,text:"",message_id:Math.random(),created_at:new Date().toISOString(),user:{user_name:w?.full_name,user_type:"employee"}};n(b=>[...b,a]);const g={ticket_id:f.ticketId,handover:_,attachments:f.files.map(b=>`${f.ticketId}/${b.name}`),message:"",text:"",message_id:Math.random(),created_at:new Date().toISOString(),user:{user_name:w?.full_name,user_type:"employee"}},x=await K(fe,g,u);x.assistChat.user.user_type!=="employee"&&n(b=>[...b,x.assistChat]),!V("userAndTicket")&&x.assistChat?.ticket_id&&w&&ae("userAndTicket",{ticket_id:x.assistChat.ticket_id,employee_id:w.employee_id})}catch{n(_=>_.slice(0,-1))}finally{o(!1)}},hasMore:p,isChatResolved:A}},ge=({url:t,msg:n,isFirstInGroup:s,fileType:r,imageRemoveHandler:l,isPreview:i})=>{const m=async()=>{const h=n?.attachments?.[0];if(!h?.url)return;const o=await(await fetch(h.url)).blob(),p=URL.createObjectURL(o),S=document.createElement("a");S.href=p,S.download=h.filename||"download.pdf",S.click(),URL.revokeObjectURL(p)};return e.createElement(e.Fragment,null,(r==="jpg"||r==="jpeg"||r==="png")&&e.createElement("div",{className:"mhb-flex mhb-items-center mhb-gap-2"},e.createElement("div",{className:`mhb-rounded-[16px] mhb-bg-white ${n?.user?.user_type==="customer"?"mhb-ml-auto":"mhb-mr-auto"} ${s?n?.user?.user_type==="customer"?"mhb-rounded-tr-[4px]":"mhb-rounded-tl-[4px]":""}`},e.createElement("div",{className:"mhb-relative mhb-overflow-hidden mhb-rounded-[16px] mhb-bg-neutral-10 mhb-px-1 mhb-py-1"},e.createElement("div",{className:"mhb-flex mhb-w-fit mhb-space-x-1"},e.createElement("div",{className:"mhb-h-[44px] mhb-w-[44px] mhb-flex-shrink-0 mhb-rounded-[12px] mhb-bg-white mhb-relative"},e.createElement("img",{src:t,alt:"Attachment",className:"mhb-h-[42px] mhb-w-[42px] mhb-rounded-[12px] mhb-object-cover"}),i&&e.createElement("button",{type:"button",onClick:l,className:"mhb-absolute mhb-top-0 mhb-right-0 mhb-translate-x-1/2 mhb--translate-y-1/2 mhb-h-[18px] mhb-w-[18px] mhb-rounded-full mhb-bg-neutral-60 mhb-text-white mhb-flex mhb-items-center mhb-justify-center mhb-text-[10px]"},"✕")))))),r==="pdf"&&e.createElement("div",{className:"mhb-relative mhb-flex mhb-items-center mhb-gap-2"},e.createElement("button",{className:"mhb-flex mhb-w-full mhb-items-center mhb-justify-between mhb-gap-3 mhb-rounded-[20px] mhb-border mhb-border-neutral-10 mhb-bg-white p-3 focus:mhb-outline-none",onClick:m},e.createElement("div",{className:"mhb-relative mhb-flex mhb-h-[36px] mhb-w-[36px] mhb-items-center mhb-justify-center mhb-rounded-[8px] mhb-bg-neutral-20"},e.createElement("p",{className:"mhb-absolute mhb-text-white mhb-typography-para-40"},"pdf")),e.createElement("p",{className:"mhb-max-w-[50px] mhb-overflow-hidden mhb-text-ellipsis mhb-whitespace-nowrap mhb-text-neutral-110 mhb-typography-para-thick-30"},n?.attachments?.[0]?.filename||"file.pdf")),i&&e.createElement("button",{type:"button",onClick:l,className:"mhb-absolute mhb-top-0 mhb-right-0 mhb-translate-x-1/2 mhb--translate-y-1/2 mhb-h-[18px] mhb-w-[18px] mhb-rounded-full mhb-bg-neutral-60 mhb-text-white mhb-flex mhb-items-center mhb-justify-center mhb-text-[10px]"},"✕")))},ot=()=>{const[t,n]=e.useState(!1),{setIsChatScreen:s,accessToken:r}=$();return{rate:async i=>{try{n(!0),(await K(rt,i,r)).AssistRating.status==="success"&&(sessionStorage.removeItem("userAndTicket"),s(h=>!h))}catch(m){throw m}finally{n(!1)}},isProgress:t}};function mt({historyData:t}){const[n,s]=e.useState(0),{rate:r,isProgress:l}=ot(),i=e.useMemo(()=>t.find(d=>d.ticket_id!=null)?.ticket_id??null,[t]),m=d=>{s(d)},h=()=>{r({ticket_id:i,rating:n})};return e.createElement("div",{className:"mhb-flex mhb-flex-col mhb-justify-center"},e.createElement("p",{className:"mhb-self-center mhb-text-neutral-110 mhb-typography-head-50"},"how was your experience?"),e.createElement("p",{className:"mhb-self-center mhb-text-neutral-60 mhb-typography-para-30"},"Help us improve with your valuable feedback"),e.createElement("div",{className:"mhb-mx-3 mhb-mt-4 mhb-flex mhb-items-center mhb-justify-center mhb-gap-1 mhb-rounded-[12px] mhb-border mhb-border-neutral-10 mhb-py-3"},[1,2,3,4,5].map(d=>{const o=n>=d;return e.createElement("button",{key:d,disabled:l,type:"button",onClick:()=>m(d),className:"focus:mhb-outline-none"},e.createElement("svg",{className:`mhb-h-[32px] mhb-w-[32px] transition-colors ${o?"mhb-fill-orange-60":"mhb-fill-neutral-10"}`,viewBox:"0 0 22 20",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true"},e.createElement("path",{d:"M20.924 7.625a1.523 1.523 0 0 0-1.238-1.044l-5.051-.734-2.259-4.577a1.534 1.534 0 0 0-2.752 0L7.365 5.847l-5.051.734A1.535 1.535 0 0 0 1.463 9.2l3.656 3.563-.863 5.031a1.532 1.532 0 0 0 2.226 1.616L11 17.033l4.518 2.375a1.534 1.534 0 0 0 2.226-1.617l-.863-5.03L20.537 9.2a1.523 1.523 0 0 0 .387-1.575Z"})))})),n>0?e.createElement("div",{className:"mhb-flex mhb-flex-col mhb-justify-center mhb-gap-4 mhb-p-4"},e.createElement("button",{className:"mhb-flex mhb-h-[48px] mhb-items-center mhb-justify-center mhb-rounded-[9999px] mhb-bg-orange-60 mhb-text-white mhb-typography-label-thick-30 focus:mhb-outline-none",title:"Submit",onClick:h,disabled:l,type:"button"},"Submit")):null)}const ye=["image/jpeg","image/jpg","image/png"],xe=()=>{const[t,n]=e.useState(""),[s,r]=e.useState(null),l=e.useRef(null),i=e.useRef(null),m=e.useRef(null),h=e.useRef(0),d=e.useRef(0),o=e.useRef(!1),{historyData:p,sendMessage:S,getNextPageData:A,isLoadingMore:k,isSending:u,upload:w,msgLoading:M,hasMore:L,isChatResolved:J}=it();e.useLayoutEffect(()=>{const a=l.current;if(a)if(o.current){const g=h.current,y=d.current,b=a.scrollHeight-g;a.scrollTop=y+b,o.current=!1}else a.scrollTop=a.scrollHeight},[p?.length]);const T=async()=>{const a=i.current?.value?.trim()||"";L||(o.current=!1),!(!a&&!s)&&(s&&(w(s),r(null)),a&&S(a),i.current&&(i.current.value=""))},se=a=>{u||a.key==="Enter"&&(a.preventDefault(),T())},re=a=>{const g=a.currentTarget;if(g.scrollHeight>g.clientHeight&&g.scrollTop<=20&&!k){const x=p.length;h.current=g.scrollHeight,d.current=g.scrollTop,o.current=!0,A(x)}},le=a=>{const g=Array.from(a.target.files||[]),y=g.filter(H=>ye.includes(H.type));if(g.filter(H=>!ye.includes(H.type)).length>0){n("Only JPG and PNG files are allowed. Other files like videos are not supported."),setTimeout(()=>n(null),3e3),a.target.value="";return}const b=p[p?.length-1]?.ticket_id;y.length>0&&b&&r({files:y,signature_type:"upload",ticketId:b})},f=()=>{m.current?.click()},C=e.useMemo(()=>p?.some(a=>a.handover==!0),[p]),v=a=>a?a.type==="application/pdf"?"pdf":a.type.startsWith("image/")?a.type.split("/")[1]:"":"";function _(a){return a.split(`
150
150
  `).map((y,x)=>{if(/^\s*-\s*\[\s*\]/.test(y)){const b=y.replace(/^\s*-\s*\[\s*\]\s*/,"");return e.createElement("div",{key:x,className:"mhb-flex mhb-gap-2"},e.createElement("input",{type:"checkbox",disabled:!0}),e.createElement("span",null,E(b)))}if(/^\s*[-•]/.test(y)){const b=y.replace(/^\s*[-•]\s*/,"");return e.createElement("div",{key:x,className:"mhb-flex mhb-gap-2"},e.createElement("span",null,"•"),e.createElement("span",null,E(b)))}if(/^\s*\d+[\.\)]/.test(y)){const b=y.replace(/^\s*\d+[\.\)]\s*/,"");return e.createElement("div",{key:x,className:"mhb-flex mhb-gap-2"},e.createElement("span",null,y.match(/\d+/)?.[0]),e.createElement("span",null,E(b)))}return e.createElement("div",{key:x},E(y))})}function E(a){return a.split(/(\*\*.*?\*\*)/g).map((y,x)=>y.startsWith("**")&&y.endsWith("**")?e.createElement("strong",{key:x},y.slice(2,-2)):e.createElement("span",{key:x},y))}return e.createElement("div",{className:"mhb-flex mhb-h-full mhb-flex-col mhb-overflow-hidden mhb-bg-white"},e.createElement(e.Fragment,null,M?e.createElement("div",{className:"mhb-py-3"},e.createElement(W,null)):e.createElement(e.Fragment,null,e.createElement("div",{ref:l,className:"mhb-flex-grow mhb-overflow-y-auto mhb-py-3 [&>*]:[mhb-overflow-anchor:none]",onScroll:re},e.createElement("div",{className:"mhb-flex mhb-min-h-full mhb-flex-col mhb-justify-end mhb-gap-1"},p?.map((a,g)=>{const y="user"in a&&g===0||p[g-1]?.user?.user_type!==a?.user?.user_type,x=new Date(a.created_at??""),b=g>0?new Date(p[g-1].created_at??""):null,H=!b||x.getDate()!==b.getDate()||x.getMonth()!==b.getMonth()||x.getFullYear()!==b.getFullYear(),j=b&&x.getTime()-b.getTime()>120*1e3,D=a.hasOwnProperty("user")&&(y||H||j),Ne=a?.attachments?.some(U=>{const Y=U.filename.match(/\.([a-zA-Z0-9]+)(?:\?|$)/)?.[1]?.toLowerCase();return["jpg","jpeg","png"].includes(Y||"")});return e.createElement("div",{key:a.message_id},a.system&&e.createElement("div",{className:"mhb-mb-1 mhb-mt-2 mhb-flex mhb-w-full mhb-items-center mhb-gap-1"},e.createElement("div",{className:"mhb-bg-neutral-10 mhb-h-[1px] mhb-flex-grow"}),e.createElement("p",{className:"mhb-bg-neutral-110 mhb-typography-para-40 mhb-flex mhb-h-[24px] mhb-items-center mhb-justify-center mhb-rounded-[8px] mhb-px-2 mhb-text-white"},"One of our agent will join the chat shortly."),e.createElement("div",{className:"mhb-bg-neutral-10 mhb-h-[1px] mhb-flex-grow"})),e.createElement("div",{className:`mhb-flex ${a?.user?.user_type==="bot"||a?.user?.user_type==="agent"?"mhb-justify-start":"mhb-justify-end"}`},e.createElement("div",{className:"mhb-max-w-[75%"},D&&e.createElement("div",{className:`mhb-mb-1 mhb-flex mhb-items-center ${a?.user?.user_type==="bot"||a?.user?.user_type==="agent"?"mhb-justify-start":"mhb-justify-end"}`},a?.user?.user_type==="bot"?e.createElement("div",{className:"mhb-flex mhb-gap-2 mhb-items-center"},e.createElement("div",{className:"mhb-flex mhb-items-center mhb-gap-1"},e.createElement(Ge,null),e.createElement("div",{className:"mhb-mb-1"},e.createElement(Be,null))),e.createElement("div",{className:"mhb-flex mhb-gap-1 mhb-mt-[2px] mhb-items-center"},e.createElement("div",{className:"mhb-h-[2px] mhb-w-[2px] mhb-rounded-full mhb-bg-neutral-60"}),e.createElement("p",{className:"mhb-typography-para-40 mhb-text-neutral-60"},X(a.created_at)))):a?.user?.user_type==="employee"?e.createElement("div",{className:"mhb-flex mhb-gap-2 mhb-items-center"},e.createElement("div",{className:"mhb-flex mhb-gap-1"},e.createElement("p",{className:"mhb-typography-para-40 mhb-text-neutral-60"},X(a.created_at)),e.createElement("div",{className:"mhb-h-[2px] mhb-w-[2px] mhb-rounded-full mhb-bg-neutral-60 mhb-flex mhb-self-center"}))):a?.user?.user_type==="agent"?e.createElement("div",{className:"mhb-flex mhb-gap-2 mhb-items-center"},e.createElement("div",{className:"mhb-flex mhb-gap-1 mhb-mt-1 mhb-items-center"},e.createElement("div",{className:"mhb-h-[2px] mhb-w-[2px] mhb-rounded-full mhb-bg-neutral-60"}),e.createElement("p",{className:"mhb-typography-para-40 mhb-text-neutral-60"},X(a.created_at)))):null),e.createElement("div",{className:"mhb-flex mhb-overflow-hidden mhb-min-w-0"},Array.isArray(a?.attachments)&&a?.attachments?.length>0?e.createElement("div",{className:`mhb-p-1 mhb-rounded-[16px] ${a?.user?.user_type==="bot"||a?.user?.user_type==="agent"?`mhb-bg-orange-60 ${D?"mhb-rounded-tl-[4px]":"mhb-rounded-[20px]"}`:`mhb-bg-neutral-10 ${D?"mhb-rounded-tr-[4px]":"mhb-rounded-[20px]"}`} ${Ne?"mhb-overflow-x-auto mhb-flex":"mhb-flex mhb-flex-col mhb-gap-1"}`},a.attachments.map((U,Y)=>e.createElement("div",{key:Y},e.createElement(ge,{url:U.url,msg:a,isFirstInGroup:!1,fileType:U?.filename.match(/\.([a-zA-Z0-9]+)(?:\?|$)/)?.[1]?.toLowerCase()||""})))):a?.text&&!a.system?e.createElement("div",{className:`mhb-whitespace-pre-line mhb-break-words mhb-rounded-[16px] mhb-p-3
151
151
  mhb-typography-para-30 ${a?.user?.user_type==="bot"||a?.user?.user_type==="agent"?`mhb-bg-orange-60 mhb-text-white ${D?"mhb-rounded-tl-[4px]":"mhb-rounded-[20px]"} `:`mhb-bg-neutral-10 mhb-text-neutral-110 mhb-ml-auto ${D?"mhb-rounded-tr-[4px]":"mhb-rounded-[20px]"} `}
152
- `},_(a?.text)):null))))}),u&&p?.every(a=>a.handover===!1||a.handover===null)&&e.createElement("span",{className:"mhb-loading","aria-label":"Loading"},e.createElement("span",{className:"dot"}),e.createElement("span",{className:"dot"}),e.createElement("span",{className:"dot"})))),J?e.createElement("div",{className:"mhb-p-3 mhb-flex"},e.createElement(mt,{historyData:p})):p?.some(a=>a.status_id===3||a.status_id===12)?e.createElement("div",{className:"mhb-mb-1 mhb-mt-2 mhb-flex mhb-w-full mhb-items-center mhb-gap-1 mhb-pb-3"},e.createElement("div",{className:"mhb-bg-neutral-10 mhb-h-[1px] mhb-flex-grow"}),e.createElement("p",{className:"mhb-bg-neutral-110 mhb-typography-para-40 mhb-flex mhb-h-[24px] mhb-items-center mhb-justify-center mhb-rounded-[8px] mhb-px-2 mhb-text-white"},"This chat has ended."),e.createElement("div",{className:"mhb-bg-neutral-10 mhb-h-[1px] mhb-flex-grow"})):e.createElement("div",{className:"mhb-chat-input-container mhb-sticky mhb-bottom-0 mhb-bg-white mhb-py-3 mhb-flex mhb-items-center mhb-gap-2"},e.createElement("div",{className:"mhb-bg-neutral-10 mhb-flex mhb-h-[80px] mhb-flex-1 mhb-rounded-xl mhb-p-3"},e.createElement("div",{className:"mhb-flex mhb-flex-1"},s?s?.files?.map((a,g)=>e.createElement(ge,{key:g,url:URL.createObjectURL(a),msg:{attachments:[{url:URL.createObjectURL(a),filename:a.name}],user:{user_type:"employee"}},isFirstInGroup:!1,fileType:v(a),isPreview:!0,imageRemoveHandler:()=>r(null)})):e.createElement("textarea",{ref:i,placeholder:"Type your message here...",className:"mhb-btn-reset mhb-textarea mhb-flex-grow mhb-text-neutral-70 mhb-caret-orange-70 mhb-typography-para-30 mhb-bg-transparent mhb-resize-none placeholder:mhb-text-neutral-40",onKeyDown:se})),e.createElement("div",{className:"mhb-flex mhb-gap-1 mhb-justify-end mhb-items-end"},C&&e.createElement("button",{type:"button",className:"mhb-btn-reset mhb-h-[36px] mhb-w-[36px] mhb-rounded-full mhb-bg-neutral-100 mhb-flex mhb-items-center mhb-justify-center mhb-outline-none",disabled:u,onClick:f},e.createElement(Ze,{className:"h-[16px] w-[16px] mhb-fill-current"}),e.createElement("input",{type:"file",accept:".jpg,.jpeg,.png",ref:m,onChange:le,className:"hidden",style:{display:"none"}})),e.createElement("button",{type:"button",className:"mhb-btn-reset mhb-h-[36px] mhb-rounded-[9999px] mhb-bg-orange-60 mhb-flex mhb-p-3 mhb-items-center mhb-justify-center mhb-shadow-[0_4px_12px_0_rgba(250,75,22,0.50)] mhb-outline-none",disabled:u,onClick:T},e.createElement("p",{className:"mhb-typography-label-thick-30 mhb-text-white"},"Send"))))))),t&&e.createElement(ke,{toastMsg:t}))};function ht({side:t="top",align:n="end"}){const{isChatScreen:s,setIsChatScreen:r,accessToken:l,setProfileInfo:i}=$(),m=Se();return e.useEffect(()=>{if(!l||m)return;async function h(){try{const d=await import("more-sso-sdk");if(d?.SSOAuthorization?.getProfileDetails){const o=await d.SSOAuthorization.getProfileDetails();i(o),De(o)}}catch(d){console.warn("[MoreDeskOne] Profile fetch skipped",d)}}h()},[l,m,i]),m?e.createElement("div",{className:"mhb-root mhb-flex mhb-flex-col",style:{position:"fixed",inset:0,height:"100vh",width:"100vw"}},e.createElement("div",{className:"mhb-h-full mhb-w-full mhb-flex mhb-flex-col mhb-min-h-0"},e.createElement("div",{className:"mhb-popover-children mhb-h-full mhb-flex mhb-flex-col"},e.createElement(pe,{isChatScreen:s,setIsChatScreen:r}),l?s?e.createElement(xe,null):e.createElement(de,null):e.createElement("div",null,"Please provide valid credentials")))):e.createElement("div",{className:"mhb-root"},e.createElement(Ke,{side:t,align:n},e.createElement("div",{className:"mhb-h-full mhb-w-full mhb-flex mhb-flex-col mhb-min-h-0"},e.createElement(pe,{isChatScreen:s,setIsChatScreen:r}),l?s?e.createElement(xe,null):e.createElement(de,null):e.createElement("div",null,"Please provide valid credentials"))))}function ut(t){const{apiKey:n,accessToken:s}=t;if(!n||!s)throw new Error("Missing parameters: apiKey, and accessToken are required")}let q=null,O=!1,z=[];function bt(){z.forEach(t=>t())}function Se(){return typeof window>"u"?!1:!!window.ReactNativeWebView}function dt(){return typeof window<"u"&&typeof document<"u"}async function pt(t){if(!O){if(ut(t),q=t,O=!0,dt()&&!Se())try{const n=await import("more-sso-sdk");n?.SSOAuthorization&&n.SSOAuthorization.init({env:t.env,redirectUrl:t.redirectUrl,app:t.app,idp:t.idp})}catch(n){console.warn("[MoreDeskOne] SSO skipped (not installed or not needed):",n)}Xe({apiKey:t.apiKey,apiURL:t.apiURL}),bt()}}function ft(t){const[n,s]=e.useState({initialized:O,sdkOptions:q});return e.useEffect(()=>{const r=()=>{s({initialized:O,sdkOptions:q})};return z.push(r),O&&q&&r(),()=>{z=z.filter(l=>l!==r)}},[]),!n.initialized||!n.sdkOptions?null:e.createElement(Ve,{token:n?.sdkOptions?.accessToken},e.createElement(ht,{...t}))}exports.ChatButton=ft;exports.init=pt;
152
+ `},_(a?.text)):null))))}),u&&p?.every(a=>a.handover===!1||a.handover===null)&&e.createElement("span",{className:"mhb-loading","aria-label":"Loading"},e.createElement("span",{className:"dot"}),e.createElement("span",{className:"dot"}),e.createElement("span",{className:"dot"})))),J?e.createElement("div",{className:"mhb-p-3 mhb-flex"},e.createElement(mt,{historyData:p})):p?.some(a=>a.status_id===3||a.status_id===12)?e.createElement("div",{className:"mhb-mb-1 mhb-mt-2 mhb-flex mhb-w-full mhb-items-center mhb-gap-1 mhb-pb-3"},e.createElement("div",{className:"mhb-bg-neutral-10 mhb-h-[1px] mhb-flex-grow"}),e.createElement("p",{className:"mhb-bg-neutral-110 mhb-typography-para-40 mhb-flex mhb-h-[24px] mhb-items-center mhb-justify-center mhb-rounded-[8px] mhb-px-2 mhb-text-white"},"This chat has ended."),e.createElement("div",{className:"mhb-bg-neutral-10 mhb-h-[1px] mhb-flex-grow"})):e.createElement("div",{className:"mhb-chat-input-container mhb-sticky mhb-bottom-0 mhb-bg-white mhb-py-3 mhb-flex mhb-items-center mhb-gap-2"},e.createElement("div",{className:"mhb-bg-neutral-10 mhb-flex mhb-h-[80px] mhb-flex-1 mhb-rounded-xl mhb-p-3"},e.createElement("div",{className:"mhb-flex mhb-flex-1"},s?s?.files?.map((a,g)=>e.createElement(ge,{key:g,url:URL.createObjectURL(a),msg:{attachments:[{url:URL.createObjectURL(a),filename:a.name}],user:{user_type:"employee"}},isFirstInGroup:!1,fileType:v(a),isPreview:!0,imageRemoveHandler:()=>r(null)})):e.createElement("textarea",{ref:i,placeholder:"Type your message here...",className:"mhb-btn-reset mhb-textarea mhb-flex-grow mhb-text-neutral-70 mhb-caret-orange-70 mhb-typography-para-30 mhb-bg-transparent mhb-resize-none placeholder:mhb-text-neutral-40",onKeyDown:se})),e.createElement("div",{className:"mhb-flex mhb-gap-1 mhb-justify-end mhb-items-end"},C&&e.createElement("button",{type:"button",className:"mhb-btn-reset mhb-h-[36px] mhb-w-[36px] mhb-rounded-full mhb-bg-neutral-100 mhb-flex mhb-items-center mhb-justify-center mhb-outline-none",disabled:u,onClick:f},e.createElement(Ze,{className:"h-[16px] w-[16px] mhb-fill-current"}),e.createElement("input",{type:"file",accept:".jpg,.jpeg,.png",ref:m,onChange:le,className:"hidden",style:{display:"none"}})),e.createElement("button",{type:"button",className:"mhb-btn-reset mhb-h-[36px] mhb-rounded-[9999px] mhb-bg-orange-60 mhb-flex mhb-p-3 mhb-items-center mhb-justify-center mhb-shadow-[0_4px_12px_0_rgba(250,75,22,0.50)] mhb-outline-none",disabled:u,onClick:T,style:{display:"flex",alignItems:"center",justifyContent:"center"}},e.createElement("p",{className:"mhb-typography-label-thick-30 mhb-text-white"},"Send"))))))),t&&e.createElement(ke,{toastMsg:t}))};function ht({side:t="top",align:n="end"}){const{isChatScreen:s,setIsChatScreen:r,accessToken:l,setProfileInfo:i}=$(),m=Se();return e.useEffect(()=>{if(!l||m)return;async function h(){try{const d=await import("more-sso-sdk");if(d?.SSOAuthorization?.getProfileDetails){const o=await d.SSOAuthorization.getProfileDetails();i(o),De(o)}}catch(d){console.warn("[MoreDeskOne] Profile fetch skipped",d)}}h()},[l,m,i]),m?e.createElement("div",{className:"mhb-root mhb-flex mhb-flex-col",style:{position:"fixed",inset:0,height:"100vh",width:"100vw"}},e.createElement("div",{className:"mhb-h-full mhb-w-full mhb-flex mhb-flex-col mhb-min-h-0"},e.createElement("div",{className:"mhb-popover-children mhb-h-full mhb-flex mhb-flex-col"},e.createElement(pe,{isChatScreen:s,setIsChatScreen:r}),l?s?e.createElement(xe,null):e.createElement(de,null):e.createElement("div",null,"Please provide valid credentials")))):e.createElement("div",{className:"mhb-root"},e.createElement(Ke,{side:t,align:n},e.createElement("div",{className:"mhb-h-full mhb-w-full mhb-flex mhb-flex-col mhb-min-h-0"},e.createElement(pe,{isChatScreen:s,setIsChatScreen:r}),l?s?e.createElement(xe,null):e.createElement(de,null):e.createElement("div",null,"Please provide valid credentials"))))}function ut(t){const{apiKey:n,accessToken:s}=t;if(!n||!s)throw new Error("Missing parameters: apiKey, and accessToken are required")}let q=null,O=!1,z=[];function bt(){z.forEach(t=>t())}function Se(){return typeof window>"u"?!1:!!window.ReactNativeWebView}function dt(){return typeof window<"u"&&typeof document<"u"}async function pt(t){if(!O){if(ut(t),q=t,O=!0,dt()&&!Se())try{const n=await import("more-sso-sdk");n?.SSOAuthorization&&n.SSOAuthorization.init({env:t.env,redirectUrl:t.redirectUrl,app:t.app,idp:t.idp})}catch(n){console.warn("[MoreDeskOne] SSO skipped (not installed or not needed):",n)}Xe({apiKey:t.apiKey,apiURL:t.apiURL}),bt()}}function ft(t){const[n,s]=e.useState({initialized:O,sdkOptions:q});return e.useEffect(()=>{const r=()=>{s({initialized:O,sdkOptions:q})};return z.push(r),O&&q&&r(),()=>{z=z.filter(l=>l!==r)}},[]),!n.initialized||!n.sdkOptions?null:e.createElement(Ve,{token:n?.sdkOptions?.accessToken},e.createElement(ht,{...t}))}exports.ChatButton=ft;exports.init=pt;
153
153
  //# sourceMappingURL=index.cjs.map