@paramms/chat-widget 1.0.35 β†’ 1.0.37

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/embed.js CHANGED
@@ -19,6 +19,8 @@ var RelayEmbed=function(R){"use strict";var Sn=Object.defineProperty;var Cn=(R,D
19
19
  [dir="rtl"] .ocw-input { flex-direction:row-reverse; }
20
20
  [dir="rtl"] .mine .ocw-meta { text-align:left; }
21
21
  .ocw-head { display:flex; align-items:center; gap:10px; padding:12px 14px; background:var(--ocw-card); border-bottom:1px solid var(--ocw-line); }
22
+ .ocw-back { flex:none; width:30px; height:30px; margin:-2px -2px -2px -4px; border:none; background:none; color:var(--ocw-ink); font-size:26px; line-height:1; cursor:pointer; border-radius:50%; display:flex; align-items:center; justify-content:center; }
23
+ .ocw-back:hover { background:var(--ocw-bg); }
22
24
  .ocw-avatar { width:34px; height:34px; border-radius:50%; background:#ffe9d6; display:flex; align-items:center; justify-content:center; font-size:17px; flex:none; }
23
25
  .ocw-head-main { flex:1; min-width:0; }
24
26
  .ocw-head-name { font-weight:700; font-size:15px; }
@@ -168,8 +170,8 @@ var RelayEmbed=function(R){"use strict";var Sn=Object.defineProperty;var Cn=(R,D
168
170
  .ocw-row.theirs .ocw-translate-btn { right:auto; left:-26px; }
169
171
  .ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
170
172
  .ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
171
- `;function en(){if(typeof document>"u"||document.getElementById(Ae))return;const i=document.createElement("style");i.id=Ae,i.textContent=Qt,document.head.appendChild(i)}function c(i,e,t){const n=document.createElement(i);return e&&(n.className=e),t!==void 0&&(n.textContent=t),n}function tn(i){try{return new Date(i).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function ye(i){var e;switch(i.kind){case"text":return i.text;case"system":return typeof((e=i.data)==null?void 0:e.message)=="string"?String(i.data.message):i.event;case"card":return[i.title,i.body].filter(Boolean).join(" β€” ");case"attachment":return i.name??i.url;case"form":return i.prompt;case"appointment":return`πŸ“… ${i.title} β€” ${new Date(i.startIso).toLocaleString()}`}}class nn{constructor(e,t,n,s={}){a(this,"scroll");a(this,"chips");a(this,"typing");a(this,"quick");a(this,"formHost");a(this,"csatPanel");a(this,"offlinePanel");a(this,"preChatPanel");a(this,"deflectPanel");a(this,"preChatBuilt",!1);a(this,"preChatDone",!1);a(this,"footer");a(this,"input");a(this,"subjectCard");a(this,"e2eBadge");a(this,"statusBadge");a(this,"headerName");a(this,"connStatus");a(this,"typingTimer",null);a(this,"csatSubmitted",!1);a(this,"cobrowseBtn");a(this,"cobrowseCanvas");a(this,"cobrowseToolbar");a(this,"cobrowseHint");a(this,"cobrowseActive",!1);a(this,"cobrowseColor","#f5713c");a(this,"lastAnnotationVersion",-1);a(this,"storeRef",null);a(this,"scrollCleanup",null);a(this,"translationCache",new Map);a(this,"showingTranslation",new Set);a(this,"subjectBuilt",!1);var m,y,E,I,L,M,A,U,k;this.root=e,this.me=t,this.h=n,this.cfg=s,en(),e.replaceChildren(),e.classList.add("ocw"),s.accent&&e.style.setProperty("--ocw-accent",s.accent);const o=c("div","ocw-head"),r=c("div","ocw-avatar");if((m=s.userInfo)!=null&&m.avatar){const v=document.createElement("img");v.src=s.userInfo.avatar,v.alt=s.userInfo.name??"You",v.style.cssText="width:100%;height:100%;border-radius:50%;object-fit:cover",r.append(v)}else r.textContent=(y=s.userInfo)!=null&&y.name?s.userInfo.name[0].toUpperCase():"πŸ§‘";o.append(r);const h=c("div","ocw-head-main");this.headerName=c("div","ocw-head-name",((E=s.subject)==null?void 0:E.ownerLabel)??((I=s.subject)==null?void 0:I.title)??""),h.append(this.headerName),(L=s.subject)!=null&&L.subtitle&&h.append(c("div","ocw-head-meta",s.subject.subtitle)),o.append(h),this.statusBadge=c("span","ocw-badge",((M=s.subject)==null?void 0:M.status)??""),(A=s.subject)!=null&&A.status||(this.statusBadge.style.display="none"),o.append(this.statusBadge),this.e2eBadge=c("span","ocw-e2e","πŸ”’ E2E"),this.e2eBadge.style.display="none",o.append(this.e2eBadge),this.connStatus=c("span","ocw-conn-status"),this.connStatus.style.display="none",o.append(this.connStatus),this.cobrowseBtn=c("button","ocw-menu ocw-cobrowse-btn","πŸ–"),this.cobrowseBtn.title="Shared whiteboard β€” draw to point things out together",this.cobrowseBtn.addEventListener("click",()=>{this.cobrowseActive=!this.cobrowseActive,this.updateCobrowseUI()}),o.append(this.cobrowseBtn),o.append(c("button","ocw-menu","β‹―")),this.chips=c("div","ocw-chiprow"),this.scroll=c("div","ocw-scroll"),this.subjectCard=c("div","ocw-subject"),this.typing=c("div","ocw-typing");const p=c("div","ocw-typing-bubble");p.append(c("div","ocw-typing-dot"),c("div","ocw-typing-dot"),c("div","ocw-typing-dot")),this.typing.append(c("div","ocw-dot","πŸ§‘"),p),this.quick=c("div","ocw-quick");for(const v of s.quickReplies??[]){const T=c("button",void 0,v);T.addEventListener("click",()=>{this.h.onSend(v),this.quick.style.display="none"}),this.quick.append(T)}this.formHost=c("div","ocw-form-host"),this.csatPanel=c("div","ocw-csat"),this.csatPanel.style.display="none",this.offlinePanel=c("div","ocw-offline"),this.offlinePanel.style.display="none",this.preChatPanel=c("div","ocw-prechat"),this.preChatPanel.style.display="none",this.deflectPanel=c("div","ocw-deflect"),this.deflectPanel.style.display="none",this.input=c("textarea",void 0),this.input.rows=1,this.input.placeholder="Message…";const f=c("button","ocw-sendbtn",((U=s.i18n)==null?void 0:U.send)??"➀");f.addEventListener("click",()=>this.flushSend()),this.input.addEventListener("input",()=>{var v,T;this.storeRef&&!this.storeRef.messages().some(q=>q.senderRole==="guest")?(T=(v=this.h).onDeflectQuery)==null||T.call(v,this.input.value):this.hideDeflection()}),this.input.addEventListener("keydown",v=>{v.isComposing||v.keyCode===229||(v.key==="Enter"&&!v.shiftKey?(v.preventDefault(),this.flushSend()):this.signalTyping())});const g=c("button","ocw-attach","πŸ“Ž");g.title="Attach image or file";const l=document.createElement("input");l.type="file",l.accept="image/*,.pdf,.txt,.doc,.docx",l.style.display="none",g.addEventListener("click",()=>l.click()),l.addEventListener("change",()=>{var v;(v=l.files)!=null&&v[0]&&this.h.onAttach&&this.h.onAttach(l.files[0]),l.value=""});const x=c("div","ocw-input");x.append(g,l,this.input,f);const u=c("div","ocw-footer");((k=s.i18n)==null?void 0:k.poweredBy)!==void 0?u.textContent=s.i18n.poweredBy:u.innerHTML='Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>',this.footer=u,e.append(o,this.chips,this.scroll,this.typing,this.quick,this.formHost,this.csatPanel,this.offlinePanel,this.preChatPanel,this.deflectPanel,x,this.footer),this.cobrowseCanvas=c("canvas","ocw-cobrowse-canvas"),this.cobrowseToolbar=c("div","ocw-cobrowse-toolbar");for(const v of["#f5713c","#1c1b1a","#2563eb","#16a34a","#dc2626"]){const T=c("button","ocw-cobrowse-swatch");T.style.background=v,T.type="button",v===this.cobrowseColor&&T.classList.add("sel"),T.addEventListener("click",()=>{this.cobrowseColor=v;for(const q of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch"))q.classList.remove("sel");T.classList.add("sel")}),this.cobrowseToolbar.append(T)}const S=c("button","ocw-cobrowse-clear","Clear");S.addEventListener("click",()=>{var v,T;return(T=(v=this.h).onAnnotateClear)==null?void 0:T.call(v)}),this.cobrowseToolbar.append(S),this.cobrowseHint=c("div","ocw-cobrowse-hint","πŸ– Draw to point things out β€” visible to both sides"),e.append(this.cobrowseCanvas,this.cobrowseToolbar,this.cobrowseHint),this.bindCobrowsePointerEvents()}getScrollEl(){return this.scroll}setScrollCleanup(e){var t;(t=this.scrollCleanup)==null||t.call(this),this.scrollCleanup=e}destroy(){var e;(e=this.scrollCleanup)==null||e.call(this),this.scrollCleanup=null,this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null)}flushSend(){this.hideDeflection();const e=this.input.value.trim();e&&(this.input.value="",this.h.onTyping(!1),this.h.onSend(e))}signalTyping(){const e=this.input.value.trim().slice(0,100)||void 0;this.h.onTyping(!0,e),this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout(()=>this.h.onTyping(!1),2e3)}render(e){var l,x,u,S,m;if(this.storeRef=e,this.cobrowseBtn.classList.toggle("show",!!e.subject),!e.subject&&this.cobrowseActive&&(this.cobrowseActive=!1,this.updateCobrowseUI()),this.cobrowseActive&&e.annotationVersion!==this.lastAnnotationVersion&&(this.lastAnnotationVersion=e.annotationVersion,this.resizeCobrowseCanvas(),this.redrawCobrowse()),e.accent&&this.root.style.setProperty("--ocw-accent",e.accent),this.e2eBadge.style.display=e.e2e?"inline-flex":"none",this.buildSubjectCard(e),e.subject){const y=(l=this.cfg.subject)==null?void 0:l.ownerLabel;y&&(this.headerName.textContent=y)}this.quick.style.display=e.messages().length===0?"flex":"none",this.chips.replaceChildren();const t=e.visibleActions();this.chips.style.display=t.length?"flex":"none";for(const y of t)this.chips.append(this.chipEl(y));const n=this.scroll.scrollHeight,s=this.scroll.scrollTop;if(this.scroll.replaceChildren(),this.subjectCard.childNodes.length&&this.scroll.append(this.subjectCard),e.hasMoreHistory){const y=c("div","ocw-load-more");y.textContent="↑ Loading earlier messages…",y.style.pointerEvents="none",this.scroll.append(y)}let o=0;for(const y of e.messages())this.scroll.append(this.messageEl(y,e)),y.senderId!==this.me&&y.seq>o&&(o=y.seq);s>20?this.scroll.scrollTop=this.scroll.scrollHeight-n+s:this.scroll.scrollTop=this.scroll.scrollHeight,o>0&&this.h.onReadUpTo(o);const r=[...e.typing];this.typing.classList.toggle("active",r.length>0);const h=this.typing.querySelector(".ocw-typing-bubble");h&&h.setAttribute("aria-label",r.length?"typing":""),this.footer.style.display=e.whiteLabel?"none":"block";const p=e.messages().some(y=>y.senderRole==="guest");!!((x=e.preChat)!=null&&x.enabled)&&!this.preChatDone&&!p&&(e.preChat.showWhen!=="offline"||e.offline)?(this.preChatBuilt||this.buildPreChatPanel(e.preChat),this.preChatPanel.style.display="block",this.offlinePanel.style.display="none",(u=this.root.querySelector(".ocw-input"))==null||u.style.setProperty("display","none")):(this.preChatPanel.style.display="none",e.offline?(this.offlinePanel.style.display==="none"&&this.buildOfflinePanel(e.offlineMessage),this.offlinePanel.style.display="block",(S=this.root.querySelector(".ocw-input"))==null||S.style.setProperty("display","none")):(this.offlinePanel.style.display="none",(m=this.root.querySelector(".ocw-input"))==null||m.style.removeProperty("display")));const g=["resolved","closed","sold","issued","checked_out"];this.h.onCsat&&!this.csatSubmitted&&g.includes(e.state)&&e.messages().length>0&&(this.csatPanel.style.display==="none"&&this.buildCsatPanel(),this.csatPanel.style.display="block")}setConnStatus(e,t){if(e==="open"){this.connStatus.style.display="none";return}this.connStatus.style.display="";const n=e==="error";this.connStatus.className=`ocw-conn-status${n?" err":e==="reconnecting"?" warn":""}`,this.connStatus.textContent=n?`⚠ ${t??"Chat unavailable"}`:e==="reconnecting"?t??"↻ reconnecting…":"● connecting…"}buildOfflinePanel(e){var h;this.offlinePanel.replaceChildren(),this.offlinePanel.append(c("div","ocw-offline-icon","πŸŒ™")),this.offlinePanel.append(c("div","ocw-offline-title",((h=this.cfg.i18n)==null?void 0:h.offline)??"We're offline right now")),this.offlinePanel.append(c("div","ocw-offline-msg",e||"Leave your details and we'll get back to you soon."));const t=c("div","ocw-offline-form"),n=c("input","ocw-offline-input");n.placeholder="Your name",n.type="text";const s=c("input","ocw-offline-input");s.placeholder="Your email",s.type="email";const o=c("textarea","ocw-offline-input");o.placeholder="Your message",o.rows=3;const r=c("button","ocw-offline-submit","Send message");r.addEventListener("click",()=>{!s.value.trim()||!o.value.trim()||(this.h.onSend(`[Offline form]
173
+ `;function en(){if(typeof document>"u"||document.getElementById(Ae))return;const i=document.createElement("style");i.id=Ae,i.textContent=Qt,document.head.appendChild(i)}function c(i,e,t){const n=document.createElement(i);return e&&(n.className=e),t!==void 0&&(n.textContent=t),n}function tn(i){try{return new Date(i).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function ye(i){var e;switch(i.kind){case"text":return i.text;case"system":return typeof((e=i.data)==null?void 0:e.message)=="string"?String(i.data.message):i.event;case"card":return[i.title,i.body].filter(Boolean).join(" β€” ");case"attachment":return i.name??i.url;case"form":return i.prompt;case"appointment":return`πŸ“… ${i.title} β€” ${new Date(i.startIso).toLocaleString()}`}}class nn{constructor(e,t,n,s={}){a(this,"scroll");a(this,"chips");a(this,"typing");a(this,"quick");a(this,"formHost");a(this,"csatPanel");a(this,"offlinePanel");a(this,"preChatPanel");a(this,"deflectPanel");a(this,"preChatBuilt",!1);a(this,"preChatDone",!1);a(this,"footer");a(this,"input");a(this,"subjectCard");a(this,"e2eBadge");a(this,"statusBadge");a(this,"headerName");a(this,"connStatus");a(this,"typingTimer",null);a(this,"csatSubmitted",!1);a(this,"cobrowseBtn");a(this,"cobrowseCanvas");a(this,"cobrowseToolbar");a(this,"cobrowseHint");a(this,"cobrowseActive",!1);a(this,"cobrowseColor","#f5713c");a(this,"lastAnnotationVersion",-1);a(this,"storeRef",null);a(this,"scrollCleanup",null);a(this,"translationCache",new Map);a(this,"showingTranslation",new Set);a(this,"subjectBuilt",!1);var v,y,E,I,L,M,A,U,k;this.root=e,this.me=t,this.h=n,this.cfg=s,en(),e.replaceChildren(),e.classList.add("ocw"),s.accent&&e.style.setProperty("--ocw-accent",s.accent);const o=c("div","ocw-head");if(this.h.onBack){const b=c("button","ocw-back","β€Ή");b.type="button",b.setAttribute("aria-label","Back"),b.addEventListener("click",()=>this.h.onBack()),o.append(b)}const r=c("div","ocw-avatar");if((v=s.userInfo)!=null&&v.avatar){const b=document.createElement("img");b.src=s.userInfo.avatar,b.alt=s.userInfo.name??"You",b.style.cssText="width:100%;height:100%;border-radius:50%;object-fit:cover",r.append(b)}else r.textContent=(y=s.userInfo)!=null&&y.name?s.userInfo.name[0].toUpperCase():"πŸ§‘";o.append(r);const h=c("div","ocw-head-main");this.headerName=c("div","ocw-head-name",((E=s.subject)==null?void 0:E.ownerLabel)??((I=s.subject)==null?void 0:I.title)??""),h.append(this.headerName),(L=s.subject)!=null&&L.subtitle&&h.append(c("div","ocw-head-meta",s.subject.subtitle)),o.append(h),this.statusBadge=c("span","ocw-badge",((M=s.subject)==null?void 0:M.status)??""),(A=s.subject)!=null&&A.status||(this.statusBadge.style.display="none"),o.append(this.statusBadge),this.e2eBadge=c("span","ocw-e2e","πŸ”’ E2E"),this.e2eBadge.style.display="none",o.append(this.e2eBadge),this.connStatus=c("span","ocw-conn-status"),this.connStatus.style.display="none",o.append(this.connStatus),this.cobrowseBtn=c("button","ocw-menu ocw-cobrowse-btn","πŸ–"),this.cobrowseBtn.title="Shared whiteboard β€” draw to point things out together",this.cobrowseBtn.addEventListener("click",()=>{this.cobrowseActive=!this.cobrowseActive,this.updateCobrowseUI()}),o.append(this.cobrowseBtn),o.append(c("button","ocw-menu","β‹―")),this.chips=c("div","ocw-chiprow"),this.scroll=c("div","ocw-scroll"),this.subjectCard=c("div","ocw-subject"),this.typing=c("div","ocw-typing");const p=c("div","ocw-typing-bubble");p.append(c("div","ocw-typing-dot"),c("div","ocw-typing-dot"),c("div","ocw-typing-dot")),this.typing.append(c("div","ocw-dot","πŸ§‘"),p),this.quick=c("div","ocw-quick");for(const b of s.quickReplies??[]){const T=c("button",void 0,b);T.addEventListener("click",()=>{this.h.onSend(b),this.quick.style.display="none"}),this.quick.append(T)}this.formHost=c("div","ocw-form-host"),this.csatPanel=c("div","ocw-csat"),this.csatPanel.style.display="none",this.offlinePanel=c("div","ocw-offline"),this.offlinePanel.style.display="none",this.preChatPanel=c("div","ocw-prechat"),this.preChatPanel.style.display="none",this.deflectPanel=c("div","ocw-deflect"),this.deflectPanel.style.display="none",this.input=c("textarea",void 0),this.input.rows=1,this.input.placeholder="Message…";const f=c("button","ocw-sendbtn",((U=s.i18n)==null?void 0:U.send)??"➀");f.addEventListener("click",()=>this.flushSend()),this.input.addEventListener("input",()=>{var b,T;this.storeRef&&!this.storeRef.messages().some(q=>q.senderRole==="guest")?(T=(b=this.h).onDeflectQuery)==null||T.call(b,this.input.value):this.hideDeflection()}),this.input.addEventListener("keydown",b=>{b.isComposing||b.keyCode===229||(b.key==="Enter"&&!b.shiftKey?(b.preventDefault(),this.flushSend()):this.signalTyping())});const g=c("button","ocw-attach","πŸ“Ž");g.title="Attach image or file";const l=document.createElement("input");l.type="file",l.accept="image/*,.pdf,.txt,.doc,.docx",l.style.display="none",g.addEventListener("click",()=>l.click()),l.addEventListener("change",()=>{var b;(b=l.files)!=null&&b[0]&&this.h.onAttach&&this.h.onAttach(l.files[0]),l.value=""});const x=c("div","ocw-input");x.append(g,l,this.input,f);const u=c("div","ocw-footer");((k=s.i18n)==null?void 0:k.poweredBy)!==void 0?u.textContent=s.i18n.poweredBy:u.innerHTML='Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>',this.footer=u,e.append(o,this.chips,this.scroll,this.typing,this.quick,this.formHost,this.csatPanel,this.offlinePanel,this.preChatPanel,this.deflectPanel,x,this.footer),this.cobrowseCanvas=c("canvas","ocw-cobrowse-canvas"),this.cobrowseToolbar=c("div","ocw-cobrowse-toolbar");for(const b of["#f5713c","#1c1b1a","#2563eb","#16a34a","#dc2626"]){const T=c("button","ocw-cobrowse-swatch");T.style.background=b,T.type="button",b===this.cobrowseColor&&T.classList.add("sel"),T.addEventListener("click",()=>{this.cobrowseColor=b;for(const q of this.cobrowseToolbar.querySelectorAll(".ocw-cobrowse-swatch"))q.classList.remove("sel");T.classList.add("sel")}),this.cobrowseToolbar.append(T)}const S=c("button","ocw-cobrowse-clear","Clear");S.addEventListener("click",()=>{var b,T;return(T=(b=this.h).onAnnotateClear)==null?void 0:T.call(b)}),this.cobrowseToolbar.append(S),this.cobrowseHint=c("div","ocw-cobrowse-hint","πŸ– Draw to point things out β€” visible to both sides"),e.append(this.cobrowseCanvas,this.cobrowseToolbar,this.cobrowseHint),this.bindCobrowsePointerEvents()}getScrollEl(){return this.scroll}setScrollCleanup(e){var t;(t=this.scrollCleanup)==null||t.call(this),this.scrollCleanup=e}destroy(){var e;(e=this.scrollCleanup)==null||e.call(this),this.scrollCleanup=null,this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null)}flushSend(){this.hideDeflection();const e=this.input.value.trim();e&&(this.input.value="",this.h.onTyping(!1),this.h.onSend(e))}signalTyping(){const e=this.input.value.trim().slice(0,100)||void 0;this.h.onTyping(!0,e),this.typingTimer&&clearTimeout(this.typingTimer),this.typingTimer=setTimeout(()=>this.h.onTyping(!1),2e3)}render(e){var l,x,u,S,v;if(this.storeRef=e,this.cobrowseBtn.classList.toggle("show",!!e.subject),!e.subject&&this.cobrowseActive&&(this.cobrowseActive=!1,this.updateCobrowseUI()),this.cobrowseActive&&e.annotationVersion!==this.lastAnnotationVersion&&(this.lastAnnotationVersion=e.annotationVersion,this.resizeCobrowseCanvas(),this.redrawCobrowse()),e.accent&&this.root.style.setProperty("--ocw-accent",e.accent),this.e2eBadge.style.display=e.e2e?"inline-flex":"none",this.buildSubjectCard(e),e.subject){const y=(l=this.cfg.subject)==null?void 0:l.ownerLabel;y&&(this.headerName.textContent=y)}this.quick.style.display=e.messages().length===0?"flex":"none",this.chips.replaceChildren();const t=e.visibleActions();this.chips.style.display=t.length?"flex":"none";for(const y of t)this.chips.append(this.chipEl(y));const n=this.scroll.scrollHeight,s=this.scroll.scrollTop;if(this.scroll.replaceChildren(),this.subjectCard.childNodes.length&&this.scroll.append(this.subjectCard),e.hasMoreHistory){const y=c("div","ocw-load-more");y.textContent="↑ Loading earlier messages…",y.style.pointerEvents="none",this.scroll.append(y)}let o=0;for(const y of e.messages())this.scroll.append(this.messageEl(y,e)),y.senderId!==this.me&&y.seq>o&&(o=y.seq);s>20?this.scroll.scrollTop=this.scroll.scrollHeight-n+s:this.scroll.scrollTop=this.scroll.scrollHeight,o>0&&this.h.onReadUpTo(o);const r=[...e.typing];this.typing.classList.toggle("active",r.length>0);const h=this.typing.querySelector(".ocw-typing-bubble");h&&h.setAttribute("aria-label",r.length?"typing":""),this.footer.style.display=e.whiteLabel?"none":"block";const p=e.messages().some(y=>y.senderRole==="guest");!!((x=e.preChat)!=null&&x.enabled)&&!this.preChatDone&&!p&&(e.preChat.showWhen!=="offline"||e.offline)?(this.preChatBuilt||this.buildPreChatPanel(e.preChat),this.preChatPanel.style.display="block",this.offlinePanel.style.display="none",(u=this.root.querySelector(".ocw-input"))==null||u.style.setProperty("display","none")):(this.preChatPanel.style.display="none",e.offline?(this.offlinePanel.style.display==="none"&&this.buildOfflinePanel(e.offlineMessage),this.offlinePanel.style.display="block",(S=this.root.querySelector(".ocw-input"))==null||S.style.setProperty("display","none")):(this.offlinePanel.style.display="none",(v=this.root.querySelector(".ocw-input"))==null||v.style.removeProperty("display")));const g=["resolved","closed","sold","issued","checked_out"];this.h.onCsat&&!this.csatSubmitted&&g.includes(e.state)&&e.messages().length>0&&(this.csatPanel.style.display==="none"&&this.buildCsatPanel(),this.csatPanel.style.display="block")}setConnStatus(e,t){if(e==="open"){this.connStatus.style.display="none";return}this.connStatus.style.display="";const n=e==="error";this.connStatus.className=`ocw-conn-status${n?" err":e==="reconnecting"?" warn":""}`,this.connStatus.textContent=n?`⚠ ${t??"Chat unavailable"}`:e==="reconnecting"?t??"↻ reconnecting…":"● connecting…"}buildOfflinePanel(e){var h;this.offlinePanel.replaceChildren(),this.offlinePanel.append(c("div","ocw-offline-icon","πŸŒ™")),this.offlinePanel.append(c("div","ocw-offline-title",((h=this.cfg.i18n)==null?void 0:h.offline)??"We're offline right now")),this.offlinePanel.append(c("div","ocw-offline-msg",e||"Leave your details and we'll get back to you soon."));const t=c("div","ocw-offline-form"),n=c("input","ocw-offline-input");n.placeholder="Your name",n.type="text";const s=c("input","ocw-offline-input");s.placeholder="Your email",s.type="email";const o=c("textarea","ocw-offline-input");o.placeholder="Your message",o.rows=3;const r=c("button","ocw-offline-submit","Send message");r.addEventListener("click",()=>{!s.value.trim()||!o.value.trim()||(this.h.onSend(`[Offline form]
172
174
  Name: ${n.value||"Anonymous"}
173
175
  Email: ${s.value}
174
- Message: ${o.value}`),this.offlinePanel.replaceChildren(c("div","ocw-offline-thanks","βœ“ Message sent! We'll reply to your email.")))}),t.append(n,s,o,r),this.offlinePanel.append(t)}buildPreChatPanel(e){var p;this.preChatBuilt=!0,this.preChatPanel.replaceChildren(),this.preChatPanel.append(c("div","ocw-prechat-title",e.title??"Before we start…"));const t=c("div","ocw-offline-form"),n={};for(const f of e.fields??["name","email"]){const g=c("input","ocw-offline-input");g.type=f==="email"?"email":f==="phone"?"tel":"text",g.placeholder=f==="name"?"Your name":f==="email"?"Your email":"Your phone number",n[f]=g,t.append(g)}let s=null;if((p=e.topics)!=null&&p.length){s=c("select",void 0);const f=document.createElement("option");f.value="",f.textContent="What is this about?",s.append(f);for(const g of e.topics){const l=document.createElement("option");l.value=g,l.textContent=g,s.append(l)}t.append(s)}let o=null,r=null;if(e.callbackOption){const f=c("label","ocw-prechat-cb");o=document.createElement("input"),o.type="checkbox",f.append(o,document.createTextNode("πŸ“ž Request a call back")),t.append(f),n.phone||(r=c("input","ocw-offline-input"),r.type="tel",r.placeholder="Phone number for the call",r.style.display="none",o.addEventListener("change",()=>r.style.setProperty("display",o.checked?"block":"none")),t.append(r))}const h=c("button","ocw-offline-submit","Start chat");h.addEventListener("click",()=>{var x,u,S,m,y,E,I;const f=(x=n.email)==null?void 0:x.value.trim();if(n.email&&(!f||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f))){n.email.focus();return}const g=!!(o!=null&&o.checked),l=(((u=n.phone)==null?void 0:u.value)??(r==null?void 0:r.value)??"").trim();if(g&&!l){(S=n.phone??r)==null||S.focus();return}if(s&&((m=e.topics)!=null&&m.length)&&!s.value){s.focus();return}this.completePreChat(),(I=(E=this.h).onPreChat)==null||I.call(E,{...(y=n.name)!=null&&y.value.trim()?{name:n.name.value.trim()}:{},...f?{email:f}:{},...l?{phone:l}:{},...s!=null&&s.value?{topic:s.value}:{},...g?{callback:!0}:{}})}),t.append(h),this.preChatPanel.append(t)}completePreChat(){this.preChatDone=!0,this.preChatPanel.style.display="none",this.storeRef&&this.render(this.storeRef)}showDeflection(e){if(!e.length)return this.hideDeflection();this.deflectPanel.replaceChildren(),this.deflectPanel.append(c("div","ocw-deflect-hint","Instant answers β€” tap to expand"));for(const t of e.slice(0,3)){const n=c("button","ocw-deflect-card");n.append(c("div","ocw-deflect-q",t.title),c("div","ocw-deflect-a",t.answer)),n.addEventListener("click",()=>n.classList.toggle("open")),this.deflectPanel.append(n)}this.deflectPanel.style.display="flex"}hideDeflection(){this.deflectPanel.style.display="none",this.deflectPanel.replaceChildren()}buildCsatPanel(){this.csatPanel.replaceChildren(),this.csatPanel.append(c("div","ocw-csat-title","How did we do?"));const e=c("div","ocw-csat-stars"),t=[];for(let n=1;n<=5;n++){const s=c("button","ocw-csat-star","β˜…");s.dataset.score=String(n),s.addEventListener("mouseenter",()=>t.forEach((o,r)=>o.classList.toggle("lit",r<n))),s.addEventListener("mouseleave",()=>t.forEach(o=>o.classList.remove("lit"))),s.addEventListener("click",()=>{var o,r;this.csatSubmitted=!0,this.csatPanel.replaceChildren(c("div","ocw-csat-done",`Thanks for your ${n}β˜… rating!`)),(r=(o=this.h).onCsat)==null||r.call(o,n)}),t.push(s),e.append(s)}this.csatPanel.append(e)}updateCobrowseUI(){this.cobrowseCanvas.classList.toggle("active",this.cobrowseActive),this.cobrowseToolbar.classList.toggle("active",this.cobrowseActive),this.cobrowseHint.classList.toggle("active",this.cobrowseActive),this.cobrowseBtn.classList.toggle("on",this.cobrowseActive),this.cobrowseActive&&(this.resizeCobrowseCanvas(),this.redrawCobrowse())}resizeCobrowseCanvas(){this.cobrowseCanvas.width=this.root.clientWidth||1,this.cobrowseCanvas.height=this.root.clientHeight||1}drawStroke(e){const t=this.cobrowseCanvas.getContext("2d");if(!t||e.points.length<2)return;const n=this.cobrowseCanvas.width,s=this.cobrowseCanvas.height;t.strokeStyle=e.color,t.lineWidth=Math.max(1,e.width*Math.min(n,s)),t.lineJoin="round",t.lineCap="round",t.beginPath(),t.moveTo(e.points[0].x*n,e.points[0].y*s);for(const o of e.points.slice(1))t.lineTo(o.x*n,o.y*s);t.stroke()}redrawCobrowse(){var t;const e=this.cobrowseCanvas.getContext("2d");if(e){e.clearRect(0,0,this.cobrowseCanvas.width,this.cobrowseCanvas.height);for(const n of((t=this.storeRef)==null?void 0:t.annotations)??[])this.drawStroke(n)}}bindCobrowsePointerEvents(){let e=!1,t=[];const n=r=>{const h=this.cobrowseCanvas.getBoundingClientRect(),p=h.width>0?(r.clientX-h.left)/h.width:0,f=h.height>0?(r.clientY-h.top)/h.height:0;return{x:Math.min(1,Math.max(0,p)),y:Math.min(1,Math.max(0,f))}},s=.006;this.cobrowseCanvas.addEventListener("pointerdown",r=>{this.cobrowseActive&&(e=!0,t=[n(r)],this.cobrowseCanvas.setPointerCapture(r.pointerId))}),this.cobrowseCanvas.addEventListener("pointermove",r=>{e&&(t.push(n(r)),this.redrawCobrowse(),this.drawStroke({points:t,color:this.cobrowseColor,width:s}))});const o=r=>{var h,p;if(e){e=!1,t.length>1&&((p=(h=this.h).onAnnotate)==null||p.call(h,{id:`an_${Date.now()}_${Math.random().toString(36).slice(2)}`,points:t,color:this.cobrowseColor,width:s})),t=[];try{this.cobrowseCanvas.releasePointerCapture(r.pointerId)}catch{}}};this.cobrowseCanvas.addEventListener("pointerup",o),this.cobrowseCanvas.addEventListener("pointercancel",o)}buildSubjectCard(e){if(this.subjectBuilt)return;const t=e.subject,n=this.cfg.subject,s=(t==null?void 0:t.title)??(n==null?void 0:n.title);if(!s)return;this.subjectBuilt=!0,this.subjectCard.replaceChildren(),this.subjectCard.append(c("div","ocw-subject-title",s)),n!=null&&n.subtitle&&this.subjectCard.append(c("div","ocw-subject-sub",n.subtitle));const o=c("div","ocw-tags");if(t)for(const[h,p]of Object.entries(t.fields))o.append(c("span","ocw-tag",`${h}: ${p}`));else for(const h of(n==null?void 0:n.tags)??[])o.append(c("span","ocw-tag",h));o.childNodes.length&&this.subjectCard.append(o);const r=(t==null?void 0:t.state)??(n==null?void 0:n.status);r&&(this.statusBadge.textContent=r,this.statusBadge.style.display="inline-flex")}chipEl(e){const t=c("button","ocw-chip",e.icon?`${e.icon} ${e.label}`:e.label);return t.dataset.actionId=e.id,t.addEventListener("click",async()=>{var n;e.confirm&&!await this.confirm(e.label)||((n=e.input)!=null&&n.length?this.openForm(e):this.h.onInvoke(e.id))}),t}confirm(e){return new Promise(t=>{const n=c("div","ocw-modal"),s=c("div","ocw-modal-card");s.append(c("div","ocw-modal-title",e)),s.append(c("div","ocw-modal-body",`Confirm β€œ${e}”?`));const o=c("div","ocw-modal-actions"),r=c("button","ocw-modal-cancel","Cancel"),h=c("button","ocw-modal-ok","Confirm"),p=f=>{n.remove(),t(f)};r.addEventListener("click",()=>p(!1)),h.addEventListener("click",()=>p(!0)),n.addEventListener("click",f=>{f.target===n&&p(!1)}),o.append(r,h),s.append(o),n.append(s),this.root.append(n),h.focus()})}openForm(e){var h,p;this.formHost.replaceChildren();const t=c("div","ocw-form");t.append(c("div","ocw-form-title",e.icon?`${e.icon} ${e.label}`:e.label));const n=new Map;for(const f of e.input??[]){const g=c("label","ocw-form-row");if(g.append(c("span","ocw-form-lbl",f.label)),f.type==="select"&&((h=f.options)!=null&&h.length)){const l=c("select","ocw-form-input");f.required||l.append(c("option",void 0,"β€” select β€”"));for(const x of f.options){const u=c("option");u.value=x,u.textContent=x,l.append(u)}f.required&&(l.required=!0),g.append(l),n.set(f.name,l)}else{const l=c("input","ocw-form-input");l.type=f.type==="number"?"number":f.type==="date"?"datetime-local":"text",f.required&&(l.required=!0),g.append(l),n.set(f.name,l)}t.append(g)}const s=c("div","ocw-form-actions"),o=c("button","ocw-form-cancel","Cancel"),r=c("button","ocw-form-submit","Send");o.addEventListener("click",()=>this.formHost.replaceChildren()),r.addEventListener("click",()=>{const f={};for(const[g,l]of n){if(l.required&&!l.value){l.style.borderColor="#e5484d";return}f[g]=l.type==="number"?Number(l.value):l.value}this.formHost.replaceChildren(),this.h.onInvoke(e.id,f)}),s.append(o,r),t.append(s),this.formHost.append(t),(p=n.values().next().value)==null||p.focus()}messageEl(e,t){var l;if(e.senderRole==="system"){const x=c("div","ocw-sys");return x.textContent=e.deletedAt?"message deleted":ye(e.content),x}const n=e.senderId===this.me,s=!!e.internal,o=c("div",`ocw-row ${s?"ocw-note mine":n?"mine":"theirs"} ${e.senderRole==="bot"?"ocw-bot":""}`);!n&&!s&&o.append(c("div","ocw-dot",e.senderRole==="bot"?"πŸ€–":"πŸ§‘"));const r=c("div"),h=c("div","ocw-bubble-wrap");if(e.replyToId){const x=c("div","ocw-reply-to","↩ replying to a message");x.style.cssText="font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",r.append(x)}const p=c("div","ocw-bubble");let f=null;if(e.deletedAt)p.append(c("span","ocw-deleted","message deleted"));else if(e.content.kind==="attachment"){const x=e.content;if((l=x.mime)!=null&&l.startsWith("image/")){const u=document.createElement("img");u.src=x.url,u.alt=x.name??"image",u.style.cssText="max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer",u.addEventListener("click",()=>window.open(x.url,"_blank")),p.append(u)}else{const u=document.createElement("a");u.href=x.url,u.target="_blank",u.rel="noopener",u.style.cssText="display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none",u.append(c("span",void 0,"πŸ“„"),c("span",void 0,x.name??"file")),p.append(u)}}else if(e.content.kind==="appointment"){const x=e.content,u=c("div","ocw-appt");u.append(c("div","ocw-appt-title",`πŸ“… ${x.title}`)),u.append(c("div","ocw-appt-time",new Date(x.startIso).toLocaleString()+" – "+new Date(x.endIso).toLocaleTimeString())),x.location&&u.append(c("div","ocw-appt-loc",`πŸ“ ${x.location}`)),x.description&&u.append(c("div","ocw-appt-desc",x.description));const S=c("div","ocw-appt-links"),m=document.createElement("a");m.href=x.googleUrl,m.target="_blank",m.rel="noopener",m.className="ocw-appt-btn",m.textContent="πŸ“… Add to Google Calendar";const y=document.createElement("a");y.href=x.icalUrl,y.download=`${x.title}.ics`,y.className="ocw-appt-btn ocw-appt-btn-sec",y.textContent="🍎 Apple / iCal",S.append(m,y),u.append(S),p.append(u)}else f=document.createTextNode(ye(e.content)),p.append(f),e.editedAt&&p.append(c("span","ocw-edited","(edited)"));if(h.append(p),!n&&!s&&this.h.onTranslate&&e.content.kind==="text"&&!e.deletedAt&&e.seq>0&&f){const x=e.content.text;if(x.trim()){const u=c("button","ocw-translate-btn","🌐");u.type="button",u.title="Translate",u.addEventListener("click",S=>{if(S.stopPropagation(),this.showingTranslation.has(e.id)){this.showingTranslation.delete(e.id),f.textContent=x,u.textContent="🌐",u.title="Translate";return}const m=this.translationCache.get(e.id);if(m!==void 0){this.showingTranslation.add(e.id),f.textContent=m,u.textContent="↩",u.title="Show original";return}u.textContent="⏳",this.h.onTranslate(x).then(y=>{if(y===null){u.textContent="⚠️",u.title="Translation unavailable",setTimeout(()=>{u.textContent="🌐",u.title="Translate"},1500);return}this.translationCache.set(e.id,y),this.showingTranslation.add(e.id),f.textContent=y,u.textContent="↩",u.title="Show original"})}),h.append(u)}}if(n&&!e.deletedAt&&e.seq>0&&(this.h.onEdit??this.h.onDelete)){const x=c("div","ocw-msg-menu");if(this.h.onEdit){const u=c("button",void 0,"✏️");u.title="Edit",u.addEventListener("click",S=>{S.stopPropagation();const m=ye(e.content),y=document.createElement("textarea");y.value=m,y.rows=Math.min(4,Math.ceil(m.length/40)+1),y.style.cssText="width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";const E=c("button","ocw-form-submit","Save");E.style.cssText="margin-top:6px;padding:5px 14px;font-size:13px";const I=c("button","ocw-form-cancel","Cancel");I.style.cssText="margin-top:6px;padding:5px 10px;font-size:13px";const L=c("div");L.style.cssText="display:flex;gap:6px;justify-content:flex-end",L.append(I,E);const M=c("div");M.append(y,L),p.replaceChildren(M),y.focus(),y.select();const A=()=>p.replaceChildren(f??document.createTextNode(m));I.addEventListener("click",A),E.addEventListener("click",()=>{const U=y.value.trim();U&&U!==m&&this.h.onEdit(e.id,U),A()}),y.addEventListener("keydown",U=>{U.key==="Enter"&&!U.shiftKey&&(U.preventDefault(),E.click()),U.key==="Escape"&&A()})}),x.append(u)}if(this.h.onDelete){const u=c("button","del","πŸ—‘");u.title="Delete",u.addEventListener("click",S=>{S.stopPropagation(),this.h.onDelete(e.id)}),x.append(u)}h.append(x)}if(r.append(h),this.h.onReact&&!e.deletedAt&&e.seq>0){const x=c("div","ocw-react-wrap"),u=c("div","ocw-react");if(e.reactions&&Object.keys(e.reactions).length)for(const[y,E]of Object.entries(e.reactions)){const I=c("button",`ocw-react-pill${E.includes(this.me)?" mine":""}`,`${y} ${E.length}`);I.addEventListener("click",()=>{var L,M;return(M=(L=this.h).onReact)==null?void 0:M.call(L,e.id,y,E.includes(this.me))}),u.append(I)}const S=c("button","ocw-react-btn","οΌ‹"),m=c("div","ocw-react-picker");for(const y of Zt){const E=c("button",void 0,y);E.addEventListener("click",I=>{var M,A,U,k;I.stopPropagation();const L=(A=(M=e.reactions)==null?void 0:M[y])==null?void 0:A.includes(this.me);(k=(U=this.h).onReact)==null||k.call(U,e.id,y,!!L),m.style.display="none"}),m.append(E)}m.style.display="none",S.addEventListener("click",y=>{y.stopPropagation(),m.style.display=m.style.display==="none"?"flex":"none"}),document.addEventListener("click",()=>{m.style.display="none"},{once:!0}),u.append(S),x.append(u,m),r.append(x)}else e.reactions&&Object.keys(e.reactions).length&&r.append(c("div","ocw-react",Object.entries(e.reactions).map(([x,u])=>`${x}${u.length}`).join(" ")));const g=c("div","ocw-time ocw-meta",tn(e.ts));if(n&&e.status){const x=c("span",`ocw-tick${e.status==="read"?" read":e.status==="delivered"?" delivered":""}`,sn(e.status));g.append(x)}return n&&e.seq>0&&t.lastReadByOthers>=e.seq&&g.append(c("span","ocw-seen"," Β· Seen")),r.append(g),o.append(r),o}}function sn(i){switch(i){case"read":return"βœ“βœ“";case"delivered":return"βœ“βœ“";case"sent":return"βœ“";default:return"πŸ•“"}}const on=20;function Be(i,e){var p;const t=i.trim().replace(/\/+$/,""),n=(p=t.match(/^(https|http|wss|ws):\/\//))==null?void 0:p[1],s=n?n==="https"||n==="wss":!0,o=(n?t.slice(n.length+3):t).replace(/\/ws$/,""),r=e?e.trim().replace(/\/+$/,""):`${s?"https":"http"}://${o}`;return{wsUrl:`${s?"wss":"ws"}://${o}/ws`,httpBase:r}}function rn(i){return Be(i).httpBase}function an(i,e,t,n){const s=`beforeSeq=${t}&limit=${n}`;return[`${i}/conversations/${e}/messages?${s}`,`${i}/conversations/${e}/history?${s}`]}async function Ke(i,e,t,n,s=on){for(const o of an(i,e,n,s))try{const r=await fetch(o,{headers:{authorization:`Bearer ${t}`}});if(!r.ok)continue;const h=await r.json();return{messages:h.messages??[],hasMore:h.hasMore??!1}}catch{}return null}async function cn(i,e,t,n,s,o){const r=o?o.replace(/\/+$/,""):rn(i),h=await Ke(r,t,e,Number.MAX_SAFE_INTEGER);if(!h||(h.messages.length?(n.apply({type:"sync",conversationId:t,messages:h.messages}),n.apply({type:"history",conversationId:t,messages:[],hasMore:h.hasMore}),s.render(n)):n.apply({type:"history",conversationId:t,messages:[],hasMore:!1}),!h.hasMore))return;let p=!1;const f=async()=>{if(p||!n.hasMoreHistory)return;p=!0;const u=n.messages()[0];if(!u){p=!1;return}const S=await Ke(r,t,e,u.seq);S&&(n.apply({type:"history",conversationId:t,messages:S.messages,hasMore:S.hasMore}),s.render(n)),p=!1},g=s.getScrollEl();if(!g)return;let l=!1;setTimeout(()=>{l=!0},300);const x=()=>{l&&g.scrollTop<80&&n.hasMoreHistory&&!p&&f()};g.addEventListener("scroll",x,{passive:!0}),s.setScrollCleanup(()=>g.removeEventListener("scroll",x))}const G=new WeakMap,ne=new Map;function ze(i){return`relay-launcher::${i.profileId}::${i.subjectId??""}`}function dn(i){var He,je,qe,Fe,Oe;G.has(i.el)&&(G.get(i.el).close(),G.delete(i.el)),i.launcher&&((He=ne.get(ze(i)))==null||He.close());const e=Ve();let t,n=!1;const s=i.token??i.userId??e,o=s!==e?e:void 0,{wsUrl:r,httpBase:h}=Be(i.url,i.apiUrl);let p=new Kt(s);const f=i.subjectId?`${s}::${i.subjectId}`:s,g=new Ht(f);let l,x=!1,u=null,S=null;!i.launcher&&!i.el.style.height&&i.el.clientHeight===0&&(i.el.style.width=i.el.style.width||"100%",i.el.style.height="600px");for(const d of g.load())p.addOptimistic(d.clientMsgId,d.content);let m=null,y=null,E=0,I=!i.launcher;if(i.launcher){const w=(i.position??"bottom-right").includes("right");m=document.createElement("div"),m.style.cssText=`position:fixed;${w?"right:20px":"left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${w?"flex-end":"flex-start"};gap:12px`;const b=document.createElement("div"),P=typeof window<"u"?window.matchMedia("(max-width: 479px)"):null,re=F=>{b.style.cssText=F?["position:fixed","inset:0","width:100%","height:100%","border-radius:0","overflow:hidden","box-shadow:none","display:none","flex-direction:column","background:#fff","transition:opacity .18s","opacity:0","z-index:9998"].join(";"):["width:380px","height:600px","border-radius:16px","overflow:hidden","box-shadow:0 8px 40px rgba(0,0,0,.18)","display:none","flex-direction:column","background:#fff","transform-origin:bottom "+(w?"right":"left"),"transition:opacity .18s,transform .18s","opacity:0","transform:scale(.95)"].join(";")};re((P==null?void 0:P.matches)??!1);const ae=F=>re(F.matches);P==null||P.addEventListener("change",ae),u=P,S=ae,i.el.style.cssText="width:100%;height:100%;overflow:hidden",b.append(i.el);const K=document.createElement("button");K.style.cssText=["width:56px;height:56px;border-radius:50%",`background:${i.accent??"#4F63F5"}`,"color:#fff;border:none;font-size:24px;cursor:pointer","box-shadow:0 4px 16px rgba(0,0,0,.25)","position:relative;flex:none","transition:transform .15s"].join(";"),K.textContent="πŸ’¬",K.onmouseenter=()=>{K.style.transform="scale(1.08)"},K.onmouseleave=()=>{K.style.transform="scale(1)"},y=document.createElement("span"),y.style.cssText="position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center",K.append(y),m.append(b,K),document.body.append(m);const ce=F=>{F?(b.style.display="flex",requestAnimationFrame(()=>{b.style.opacity="1",b.style.transform="scale(1)"})):(b.style.opacity="0",b.style.transform="scale(.95)",setTimeout(()=>{I||(b.style.display="none")},180))};K.addEventListener("click",()=>{I=!I,ce(I),K.textContent=I?"βœ•":"πŸ’¬",K.append(y),I&&(E=0,y&&(y.style.display="none"))}),document.addEventListener("keydown",F=>{F.key==="Escape"&&I&&(I=!1,ce(!1),K.textContent="πŸ’¬",K.append(y))})}const L=()=>{I||(E++,y&&(y.textContent=String(E),y.style.display="flex"))},M=()=>{try{const d=new AudioContext,w=d.createOscillator(),b=d.createGain();w.connect(b),b.connect(d.destination),w.frequency.setValueAtTime(880,d.currentTime),w.frequency.exponentialRampToValueAtTime(440,d.currentTime+.15),b.gain.setValueAtTime(.3,d.currentTime),b.gain.exponentialRampToValueAtTime(.001,d.currentTime+.3),w.start(),w.stop(d.currentTime+.3)}catch{}},A=[],U=d=>{for(;A.length;){const w=A.shift();g.add({clientMsgId:w.clientMsgId,content:w.content,ts:Date.now()}),k.send({type:"send",conversationId:d,clientMsgId:w.clientMsgId,content:w.content})}};let k;const v=new Jt(`ocw-e2e-${i.profileId}`);let T=!1;const q=[],se=[];let De=!1;const ge=(d,w)=>{v.sealText(w).then(b=>{l&&k.send({type:"send",conversationId:l,clientMsgId:d,content:b})})},yn=(d,w,b)=>{v.sealText(w,b).then(P=>{l&&k.send({type:"send",conversationId:l,clientMsgId:d,content:P})})},xn=()=>{for(;q.length;){const d=q.shift();ge(d.clientMsgId,d.text)}for(;se.length;){const d=se.shift();ge(d.clientMsgId,d.text)}},gn=d=>{k.send({type:"fetchPrekey",targetUserId:d})},bn=i.i18n??{},mn=["ar","he","fa","ur"],vn=typeof navigator<"u"?(navigator.language??"").slice(0,2).toLowerCase():"";mn.includes(vn)&&!i.el.dir&&(i.el.dir="rtl",i.el.style.fontFamily=i.el.style.fontFamily||"Tahoma,Arial,system-ui,sans-serif");const $e=new Lt,Re=`oc_prechat_${i.profileId}_${s.slice(-8)}`,B=new nn(i.el,s,{onSend(d){const w=`cm_${Math.random().toString(36).slice(2)}`,b={kind:"text",text:d};p.addOptimistic(w,b),B.render(p),p.e2e?v.ready?ge(w,d):De?se.push({clientMsgId:w,text:d}):(q.push({clientMsgId:w,text:d}),p.assignedAgentId&&gn(p.assignedAgentId)):l?(g.add({clientMsgId:w,content:b,ts:Date.now()}),k.send({type:"send",conversationId:l,clientMsgId:w,content:b})):A.push({clientMsgId:w,content:b})},async onAttach(d){if(!l)return;const w=`${h}/upload?name=${encodeURIComponent(d.name)}`,b=`cm_${Math.random().toString(36).slice(2)}`;p.addOptimistic(b,{kind:"text",text:`πŸ“Ž Uploading ${d.name}…`}),B.render(p);try{const P=await fetch(w,{method:"POST",headers:{"content-type":d.type,...i.token?{authorization:`Bearer ${i.token}`}:{}},body:d});if(!P.ok)throw new Error(`Upload failed: ${P.status}`);const{url:re,name:ae,mime:K,size:ce}=await P.json();k.send({type:"send",conversationId:l,clientMsgId:b,content:{kind:"attachment",url:re,name:ae,mime:K,size:ce}})}catch(P){p.addOptimistic(b,{kind:"text",text:`⚠️ Upload failed: ${P.message}`}),B.render(p)}},onInvoke(d,w){l&&k.send({type:"invoke",conversationId:l,actionId:d,clientInvokeId:`iv_${Math.random().toString(36).slice(2)}`,...w?{inputs:w}:{}})},onTyping(d,w){l&&k.send({type:"typing",conversationId:l,isTyping:d,...w?{preview:w}:{}})},onPreChat(d){try{localStorage.setItem(Re,"1")}catch{}k.send({type:"open",profileId:i.profileId,...i.subjectId?{subjectId:i.subjectId}:{},userInfo:{...d.name?{name:d.name}:{},...d.email?{email:d.email}:{},...d.phone||d.topic?{meta:{...d.phone?{phone:d.phone}:{},...d.topic?{topic:d.topic}:{}}}:{}}});const w=d.callback?`πŸ“ž Call-back requested${d.phone?`: ${d.phone}`:""}${d.topic?` β€” ${d.topic}`:""}`:d.topic?`Topic: ${d.topic}`:"";w&&l&&!p.e2e&&k.send({type:"send",conversationId:l,clientMsgId:`pc_${Math.random().toString(36).slice(2,12)}`,content:{kind:"text",text:w}})},onDeflectQuery(d){if(n)return;clearTimeout(t);const w=d.trim();if(w.length<3){B.hideDeflection();return}t=setTimeout(()=>{fetch(`${h}/kb/search?profileId=${encodeURIComponent(i.profileId)}&q=${encodeURIComponent(w.slice(0,200))}`).then(b=>b.ok?b.json():{articles:[]}).then(b=>B.showDeflection(b.articles??[])).catch(()=>B.hideDeflection())},350)},onReadUpTo(d){l&&k.send({type:"read",conversationId:l,seq:d})},onLoadMore(){if(!l||!p.e2e)return;const d=p.messages()[0];d&&k.send({type:"history",conversationId:l,beforeSeq:d.seq,limit:20})},onEdit(d,w){l&&k.send({type:"edit",conversationId:l,messageId:d,content:{kind:"text",text:w}})},onDelete(d){l&&k.send({type:"delete",conversationId:l,messageId:d})},onReact(d,w,b){l&&k.send({type:"react",conversationId:l,messageId:d,emoji:w,remove:b})},onCsat(d){l&&fetch(`${h}/conversations/${l}/csat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify({score:d})}).catch(()=>{})},onAnnotate(d){l&&k.send({type:"annotate",conversationId:l,stroke:d})},onAnnotateClear(){l&&k.send({type:"annotate_clear",conversationId:l})},...i.translateLang?{async onTranslate(d){try{const w=await fetch(`${h}/translate`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${s}`},body:JSON.stringify({text:d,targetLang:i.translateLang})});if(!w.ok)return null;const{translated:b}=await w.json();return b}catch{return null}}}:{}},{...i.subject?{subject:i.subject}:{},...i.quickReplies?{quickReplies:i.quickReplies}:{},...i.accent?{accent:i.accent}:{},...(je=i.user)!=null&&je.name||(qe=i.user)!=null&&qe.avatar?{userInfo:{...i.user.name?{name:i.user.name}:{},...i.user.avatar?{avatar:i.user.avatar}:{}}}:{},i18n:bn});try{localStorage.getItem(Re)&&B.completePreChat()}catch{}const _e=i.user&&(i.user.name||i.user.email||i.user.avatar||i.user.meta)?{...i.user.name?{name:i.user.name}:{},...i.user.email?{email:i.user.email}:{},...i.user.avatar?{avatar:i.user.avatar}:{},...i.user.meta?{meta:i.user.meta}:{}}:void 0,kn={type:"open",profileId:i.profileId,...i.kind==="direct"&&i.peerId?{kind:"direct",peerId:i.peerId}:i.subjectId?{subjectId:i.subjectId}:{},...o?{linkFrom:o}:{},..._e?{userInfo:_e}:{},...typeof location<"u"?{pageUrl:location.href}:{},...typeof document<"u"&&document.title?{pageTitle:document.title}:{},...(Fe=i.subject)!=null&&Fe.title?{subjectTitle:i.subject.title}:{},...(Oe=i.subject)!=null&&Oe.subtitle?{subjectMeta:i.subject.subtitle}:{}};k=new Mt({...i.refreshToken?{refreshToken:i.refreshToken}:{},url:r,token:s,open:kn,getCursor:()=>p.highestSeq(),onStatusChange:(d,w)=>B.setConnStatus(d,w),onFrame(d){if($e.apply(d),d.type==="opened"){if(l=d.conversation.id,!x){x=!0;for(const w of g.load())k.send({type:"send",conversationId:l,clientMsgId:w.clientMsgId,content:w.content})}cn(r,s,l,p,B,h),A.length&&U(l)}if(d.type==="ack"&&g.remove(d.clientMsgId),d.type==="prekeyBundle"){d.bundle&&(De=!0,v.x3dhSendTo(d.bundle).then(w=>{const b=[...q.splice(0),...se.splice(0)];for(const P of b)yn(P.clientMsgId,P.text,w);B.render(p)}));return}if(d.type==="message"&&p.e2e){const w=Gt(d.message.content);if(w&&!v.ready){v.x3dhReceiveFrom(w.x3dhIK,w.x3dhEK,w.x3dhSPK).then(async()=>{await v.openFrame(d),p.apply(d),B.render(p)});return}}if(d.type==="peerkey"){v.onPeerKey(d.key).then(()=>{xn(),B.render(p)});return}(async()=>{if(p.e2e&&await v.openFrame(d),p.apply(d),d.type==="message"&&d.message.senderId!==s&&!d.message.internal&&(L(),M()),p.e2e&&l&&!T){T=!0;const w=await v.initX3DH();k.send({type:"uploadPrekeys",...w});const b=await v.begin();k.send({type:"pubkey",conversationId:l,key:b})}B.render(p)})()}}),k.connect(),B.render(p);const Z=i.launcher?ze(i):null,oe={close:()=>{n=!0,clearTimeout(t),k.close(),m==null||m.remove(),B.destroy(),$e.destroy(),u&&S&&u.removeEventListener("change",S),G.delete(i.el),Z&&ne.get(Z)===oe&&ne.delete(Z)}};return G.set(i.el,oe),Z&&ne.set(Z,oe),oe}const ln="wss://api.paramms.com/ws";let j=null,$=null,W={};function hn(i,e){const t=i.profileId??i.appId;if(!t)throw new Error("Relay: `appId` is required (your chatroom id, e.g. 'p_...').");const n=i.subjectId??(i.listingId?`listing_${i.listingId}`:void 0),s=i.subjectTitle?{title:i.subjectTitle,...i.subjectMeta?{subtitle:i.subjectMeta}:{},...i.subjectPrice!=null?{tags:[`$${i.subjectPrice.toLocaleString()}`]}:{},...i.subjectStatus?{status:i.subjectStatus}:{}}:void 0,o=i.name||i.email||i.avatar?{...i.name?{name:i.name}:{},...i.email?{email:i.email}:{},...i.avatar?{avatar:i.avatar}:{}}:void 0;return{el:e,url:i.url??ln,profileId:t,...i.apiUrl?{apiUrl:i.apiUrl}:{},...n?{subjectId:n}:{},...i.token?{token:i.token}:{},...i.userId?{userId:i.userId}:{},...s?{subject:s}:{},...o?{user:o}:{},...i.accent?{accent:i.accent}:{},...i.translateLang?{translateLang:i.translateLang}:{},launcher:i.launcher??!0,position:i.position??"bottom-right"}}function pn(){return(!$||!$.isConnected)&&($=document.createElement("div"),$.id="relay-widget-root",document.body.appendChild($)),$}function Le(i){try{j==null||j.close(),j=dn(hn(i,pn()))}catch(e){console.error("[Relay]",e instanceof Error?e.message:e)}}function Me(i){W={...i},Le(W)}function un(i){W={...W,...i},Le(W)}function fn(){j==null||j.close(),j=null,$==null||$.remove(),$=null,W={}}function xe(i,e){switch(i){case"boot":Me(e??{});break;case"update":case"identify":un(e??{});break;case"shutdown":fn();break;default:console.warn("[Relay] unknown command:",i)}}function wn(){if(typeof document>"u")return null;const i=document.querySelector("script[data-relay-app]"),e=i==null?void 0:i.dataset.relayApp;if(!e)return null;const t=i.dataset,n={appId:e};t.relayUser&&(n.userId=t.relayUser),t.relayToken&&(n.token=t.relayToken),t.relayListing&&(n.listingId=t.relayListing),t.relayAccent&&(n.accent=t.relayAccent),t.relayUrl&&(n.url=t.relayUrl);const s=t.relayPosition;return(s==="bottom-left"||s==="bottom-right")&&(n.position=s),t.relayLauncher==="false"&&(n.launcher=!1),n}if(typeof window<"u"){const i=window,e=i.Relay&&i.Relay.q?i.Relay.q:[];i.Relay=xe;let t=!1;for(const n of e){const[s,o]=n;s==="boot"&&(t=!0),xe(s,o)}if(!t){const n=i.relaySettings??wn();n&&Me(n)}}return R.Relay=xe,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"}),R}({});
176
+ Message: ${o.value}`),this.offlinePanel.replaceChildren(c("div","ocw-offline-thanks","βœ“ Message sent! We'll reply to your email.")))}),t.append(n,s,o,r),this.offlinePanel.append(t)}buildPreChatPanel(e){var p;this.preChatBuilt=!0,this.preChatPanel.replaceChildren(),this.preChatPanel.append(c("div","ocw-prechat-title",e.title??"Before we start…"));const t=c("div","ocw-offline-form"),n={};for(const f of e.fields??["name","email"]){const g=c("input","ocw-offline-input");g.type=f==="email"?"email":f==="phone"?"tel":"text",g.placeholder=f==="name"?"Your name":f==="email"?"Your email":"Your phone number",n[f]=g,t.append(g)}let s=null;if((p=e.topics)!=null&&p.length){s=c("select",void 0);const f=document.createElement("option");f.value="",f.textContent="What is this about?",s.append(f);for(const g of e.topics){const l=document.createElement("option");l.value=g,l.textContent=g,s.append(l)}t.append(s)}let o=null,r=null;if(e.callbackOption){const f=c("label","ocw-prechat-cb");o=document.createElement("input"),o.type="checkbox",f.append(o,document.createTextNode("πŸ“ž Request a call back")),t.append(f),n.phone||(r=c("input","ocw-offline-input"),r.type="tel",r.placeholder="Phone number for the call",r.style.display="none",o.addEventListener("change",()=>r.style.setProperty("display",o.checked?"block":"none")),t.append(r))}const h=c("button","ocw-offline-submit","Start chat");h.addEventListener("click",()=>{var x,u,S,v,y,E,I;const f=(x=n.email)==null?void 0:x.value.trim();if(n.email&&(!f||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(f))){n.email.focus();return}const g=!!(o!=null&&o.checked),l=(((u=n.phone)==null?void 0:u.value)??(r==null?void 0:r.value)??"").trim();if(g&&!l){(S=n.phone??r)==null||S.focus();return}if(s&&((v=e.topics)!=null&&v.length)&&!s.value){s.focus();return}this.completePreChat(),(I=(E=this.h).onPreChat)==null||I.call(E,{...(y=n.name)!=null&&y.value.trim()?{name:n.name.value.trim()}:{},...f?{email:f}:{},...l?{phone:l}:{},...s!=null&&s.value?{topic:s.value}:{},...g?{callback:!0}:{}})}),t.append(h),this.preChatPanel.append(t)}completePreChat(){this.preChatDone=!0,this.preChatPanel.style.display="none",this.storeRef&&this.render(this.storeRef)}showDeflection(e){if(!e.length)return this.hideDeflection();this.deflectPanel.replaceChildren(),this.deflectPanel.append(c("div","ocw-deflect-hint","Instant answers β€” tap to expand"));for(const t of e.slice(0,3)){const n=c("button","ocw-deflect-card");n.append(c("div","ocw-deflect-q",t.title),c("div","ocw-deflect-a",t.answer)),n.addEventListener("click",()=>n.classList.toggle("open")),this.deflectPanel.append(n)}this.deflectPanel.style.display="flex"}hideDeflection(){this.deflectPanel.style.display="none",this.deflectPanel.replaceChildren()}buildCsatPanel(){this.csatPanel.replaceChildren(),this.csatPanel.append(c("div","ocw-csat-title","How did we do?"));const e=c("div","ocw-csat-stars"),t=[];for(let n=1;n<=5;n++){const s=c("button","ocw-csat-star","β˜…");s.dataset.score=String(n),s.addEventListener("mouseenter",()=>t.forEach((o,r)=>o.classList.toggle("lit",r<n))),s.addEventListener("mouseleave",()=>t.forEach(o=>o.classList.remove("lit"))),s.addEventListener("click",()=>{var o,r;this.csatSubmitted=!0,this.csatPanel.replaceChildren(c("div","ocw-csat-done",`Thanks for your ${n}β˜… rating!`)),(r=(o=this.h).onCsat)==null||r.call(o,n)}),t.push(s),e.append(s)}this.csatPanel.append(e)}updateCobrowseUI(){this.cobrowseCanvas.classList.toggle("active",this.cobrowseActive),this.cobrowseToolbar.classList.toggle("active",this.cobrowseActive),this.cobrowseHint.classList.toggle("active",this.cobrowseActive),this.cobrowseBtn.classList.toggle("on",this.cobrowseActive),this.cobrowseActive&&(this.resizeCobrowseCanvas(),this.redrawCobrowse())}resizeCobrowseCanvas(){this.cobrowseCanvas.width=this.root.clientWidth||1,this.cobrowseCanvas.height=this.root.clientHeight||1}drawStroke(e){const t=this.cobrowseCanvas.getContext("2d");if(!t||e.points.length<2)return;const n=this.cobrowseCanvas.width,s=this.cobrowseCanvas.height;t.strokeStyle=e.color,t.lineWidth=Math.max(1,e.width*Math.min(n,s)),t.lineJoin="round",t.lineCap="round",t.beginPath(),t.moveTo(e.points[0].x*n,e.points[0].y*s);for(const o of e.points.slice(1))t.lineTo(o.x*n,o.y*s);t.stroke()}redrawCobrowse(){var t;const e=this.cobrowseCanvas.getContext("2d");if(e){e.clearRect(0,0,this.cobrowseCanvas.width,this.cobrowseCanvas.height);for(const n of((t=this.storeRef)==null?void 0:t.annotations)??[])this.drawStroke(n)}}bindCobrowsePointerEvents(){let e=!1,t=[];const n=r=>{const h=this.cobrowseCanvas.getBoundingClientRect(),p=h.width>0?(r.clientX-h.left)/h.width:0,f=h.height>0?(r.clientY-h.top)/h.height:0;return{x:Math.min(1,Math.max(0,p)),y:Math.min(1,Math.max(0,f))}},s=.006;this.cobrowseCanvas.addEventListener("pointerdown",r=>{this.cobrowseActive&&(e=!0,t=[n(r)],this.cobrowseCanvas.setPointerCapture(r.pointerId))}),this.cobrowseCanvas.addEventListener("pointermove",r=>{e&&(t.push(n(r)),this.redrawCobrowse(),this.drawStroke({points:t,color:this.cobrowseColor,width:s}))});const o=r=>{var h,p;if(e){e=!1,t.length>1&&((p=(h=this.h).onAnnotate)==null||p.call(h,{id:`an_${Date.now()}_${Math.random().toString(36).slice(2)}`,points:t,color:this.cobrowseColor,width:s})),t=[];try{this.cobrowseCanvas.releasePointerCapture(r.pointerId)}catch{}}};this.cobrowseCanvas.addEventListener("pointerup",o),this.cobrowseCanvas.addEventListener("pointercancel",o)}buildSubjectCard(e){if(this.subjectBuilt)return;const t=e.subject,n=this.cfg.subject,s=(t==null?void 0:t.title)??(n==null?void 0:n.title);if(!s)return;this.subjectBuilt=!0,this.subjectCard.replaceChildren(),this.subjectCard.append(c("div","ocw-subject-title",s)),n!=null&&n.subtitle&&this.subjectCard.append(c("div","ocw-subject-sub",n.subtitle));const o=c("div","ocw-tags");if(t)for(const[h,p]of Object.entries(t.fields))o.append(c("span","ocw-tag",`${h}: ${p}`));else for(const h of(n==null?void 0:n.tags)??[])o.append(c("span","ocw-tag",h));o.childNodes.length&&this.subjectCard.append(o);const r=(t==null?void 0:t.state)??(n==null?void 0:n.status);r&&(this.statusBadge.textContent=r,this.statusBadge.style.display="inline-flex")}chipEl(e){const t=c("button","ocw-chip",e.icon?`${e.icon} ${e.label}`:e.label);return t.dataset.actionId=e.id,t.addEventListener("click",async()=>{var n;e.confirm&&!await this.confirm(e.label)||((n=e.input)!=null&&n.length?this.openForm(e):this.h.onInvoke(e.id))}),t}confirm(e){return new Promise(t=>{const n=c("div","ocw-modal"),s=c("div","ocw-modal-card");s.append(c("div","ocw-modal-title",e)),s.append(c("div","ocw-modal-body",`Confirm β€œ${e}”?`));const o=c("div","ocw-modal-actions"),r=c("button","ocw-modal-cancel","Cancel"),h=c("button","ocw-modal-ok","Confirm"),p=f=>{n.remove(),t(f)};r.addEventListener("click",()=>p(!1)),h.addEventListener("click",()=>p(!0)),n.addEventListener("click",f=>{f.target===n&&p(!1)}),o.append(r,h),s.append(o),n.append(s),this.root.append(n),h.focus()})}openForm(e){var h,p;this.formHost.replaceChildren();const t=c("div","ocw-form");t.append(c("div","ocw-form-title",e.icon?`${e.icon} ${e.label}`:e.label));const n=new Map;for(const f of e.input??[]){const g=c("label","ocw-form-row");if(g.append(c("span","ocw-form-lbl",f.label)),f.type==="select"&&((h=f.options)!=null&&h.length)){const l=c("select","ocw-form-input");f.required||l.append(c("option",void 0,"β€” select β€”"));for(const x of f.options){const u=c("option");u.value=x,u.textContent=x,l.append(u)}f.required&&(l.required=!0),g.append(l),n.set(f.name,l)}else{const l=c("input","ocw-form-input");l.type=f.type==="number"?"number":f.type==="date"?"datetime-local":"text",f.required&&(l.required=!0),g.append(l),n.set(f.name,l)}t.append(g)}const s=c("div","ocw-form-actions"),o=c("button","ocw-form-cancel","Cancel"),r=c("button","ocw-form-submit","Send");o.addEventListener("click",()=>this.formHost.replaceChildren()),r.addEventListener("click",()=>{const f={};for(const[g,l]of n){if(l.required&&!l.value){l.style.borderColor="#e5484d";return}f[g]=l.type==="number"?Number(l.value):l.value}this.formHost.replaceChildren(),this.h.onInvoke(e.id,f)}),s.append(o,r),t.append(s),this.formHost.append(t),(p=n.values().next().value)==null||p.focus()}messageEl(e,t){var l;if(e.senderRole==="system"){const x=c("div","ocw-sys");return x.textContent=e.deletedAt?"message deleted":ye(e.content),x}const n=e.senderId===this.me,s=!!e.internal,o=c("div",`ocw-row ${s?"ocw-note mine":n?"mine":"theirs"} ${e.senderRole==="bot"?"ocw-bot":""}`);!n&&!s&&o.append(c("div","ocw-dot",e.senderRole==="bot"?"πŸ€–":"πŸ§‘"));const r=c("div"),h=c("div","ocw-bubble-wrap");if(e.replyToId){const x=c("div","ocw-reply-to","↩ replying to a message");x.style.cssText="font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",r.append(x)}const p=c("div","ocw-bubble");let f=null;if(e.deletedAt)p.append(c("span","ocw-deleted","message deleted"));else if(e.content.kind==="attachment"){const x=e.content;if((l=x.mime)!=null&&l.startsWith("image/")){const u=document.createElement("img");u.src=x.url,u.alt=x.name??"image",u.style.cssText="max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer",u.addEventListener("click",()=>window.open(x.url,"_blank")),p.append(u)}else{const u=document.createElement("a");u.href=x.url,u.target="_blank",u.rel="noopener",u.style.cssText="display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none",u.append(c("span",void 0,"πŸ“„"),c("span",void 0,x.name??"file")),p.append(u)}}else if(e.content.kind==="appointment"){const x=e.content,u=c("div","ocw-appt");u.append(c("div","ocw-appt-title",`πŸ“… ${x.title}`)),u.append(c("div","ocw-appt-time",new Date(x.startIso).toLocaleString()+" – "+new Date(x.endIso).toLocaleTimeString())),x.location&&u.append(c("div","ocw-appt-loc",`πŸ“ ${x.location}`)),x.description&&u.append(c("div","ocw-appt-desc",x.description));const S=c("div","ocw-appt-links"),v=document.createElement("a");v.href=x.googleUrl,v.target="_blank",v.rel="noopener",v.className="ocw-appt-btn",v.textContent="πŸ“… Add to Google Calendar";const y=document.createElement("a");y.href=x.icalUrl,y.download=`${x.title}.ics`,y.className="ocw-appt-btn ocw-appt-btn-sec",y.textContent="🍎 Apple / iCal",S.append(v,y),u.append(S),p.append(u)}else f=document.createTextNode(ye(e.content)),p.append(f),e.editedAt&&p.append(c("span","ocw-edited","(edited)"));if(h.append(p),!n&&!s&&this.h.onTranslate&&e.content.kind==="text"&&!e.deletedAt&&e.seq>0&&f){const x=e.content.text;if(x.trim()){const u=c("button","ocw-translate-btn","🌐");u.type="button",u.title="Translate",u.addEventListener("click",S=>{if(S.stopPropagation(),this.showingTranslation.has(e.id)){this.showingTranslation.delete(e.id),f.textContent=x,u.textContent="🌐",u.title="Translate";return}const v=this.translationCache.get(e.id);if(v!==void 0){this.showingTranslation.add(e.id),f.textContent=v,u.textContent="↩",u.title="Show original";return}u.textContent="⏳",this.h.onTranslate(x).then(y=>{if(y===null){u.textContent="⚠️",u.title="Translation unavailable",setTimeout(()=>{u.textContent="🌐",u.title="Translate"},1500);return}this.translationCache.set(e.id,y),this.showingTranslation.add(e.id),f.textContent=y,u.textContent="↩",u.title="Show original"})}),h.append(u)}}if(n&&!e.deletedAt&&e.seq>0&&(this.h.onEdit??this.h.onDelete)){const x=c("div","ocw-msg-menu");if(this.h.onEdit){const u=c("button",void 0,"✏️");u.title="Edit",u.addEventListener("click",S=>{S.stopPropagation();const v=ye(e.content),y=document.createElement("textarea");y.value=v,y.rows=Math.min(4,Math.ceil(v.length/40)+1),y.style.cssText="width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:#fff;color:#1c1b1a;box-sizing:border-box";const E=c("button","ocw-form-submit","Save");E.style.cssText="margin-top:6px;padding:5px 14px;font-size:13px";const I=c("button","ocw-form-cancel","Cancel");I.style.cssText="margin-top:6px;padding:5px 10px;font-size:13px";const L=c("div");L.style.cssText="display:flex;gap:6px;justify-content:flex-end",L.append(I,E);const M=c("div");M.append(y,L),p.replaceChildren(M),y.focus(),y.select();const A=()=>p.replaceChildren(f??document.createTextNode(v));I.addEventListener("click",A),E.addEventListener("click",()=>{const U=y.value.trim();U&&U!==v&&this.h.onEdit(e.id,U),A()}),y.addEventListener("keydown",U=>{U.key==="Enter"&&!U.shiftKey&&(U.preventDefault(),E.click()),U.key==="Escape"&&A()})}),x.append(u)}if(this.h.onDelete){const u=c("button","del","πŸ—‘");u.title="Delete",u.addEventListener("click",S=>{S.stopPropagation(),this.h.onDelete(e.id)}),x.append(u)}h.append(x)}if(r.append(h),this.h.onReact&&!e.deletedAt&&e.seq>0){const x=c("div","ocw-react-wrap"),u=c("div","ocw-react");if(e.reactions&&Object.keys(e.reactions).length)for(const[y,E]of Object.entries(e.reactions)){const I=c("button",`ocw-react-pill${E.includes(this.me)?" mine":""}`,`${y} ${E.length}`);I.addEventListener("click",()=>{var L,M;return(M=(L=this.h).onReact)==null?void 0:M.call(L,e.id,y,E.includes(this.me))}),u.append(I)}const S=c("button","ocw-react-btn","οΌ‹"),v=c("div","ocw-react-picker");for(const y of Zt){const E=c("button",void 0,y);E.addEventListener("click",I=>{var M,A,U,k;I.stopPropagation();const L=(A=(M=e.reactions)==null?void 0:M[y])==null?void 0:A.includes(this.me);(k=(U=this.h).onReact)==null||k.call(U,e.id,y,!!L),v.style.display="none"}),v.append(E)}v.style.display="none",S.addEventListener("click",y=>{y.stopPropagation(),v.style.display=v.style.display==="none"?"flex":"none"}),document.addEventListener("click",()=>{v.style.display="none"},{once:!0}),u.append(S),x.append(u,v),r.append(x)}else e.reactions&&Object.keys(e.reactions).length&&r.append(c("div","ocw-react",Object.entries(e.reactions).map(([x,u])=>`${x}${u.length}`).join(" ")));const g=c("div","ocw-time ocw-meta",tn(e.ts));if(n&&e.status){const x=c("span",`ocw-tick${e.status==="read"?" read":e.status==="delivered"?" delivered":""}`,sn(e.status));g.append(x)}return n&&e.seq>0&&t.lastReadByOthers>=e.seq&&g.append(c("span","ocw-seen"," Β· Seen")),r.append(g),o.append(r),o}}function sn(i){switch(i){case"read":return"βœ“βœ“";case"delivered":return"βœ“βœ“";case"sent":return"βœ“";default:return"πŸ•“"}}const on=20;function Be(i,e){var p;const t=i.trim().replace(/\/+$/,""),n=(p=t.match(/^(https|http|wss|ws):\/\//))==null?void 0:p[1],s=n?n==="https"||n==="wss":!0,o=(n?t.slice(n.length+3):t).replace(/\/ws$/,""),r=e?e.trim().replace(/\/+$/,""):`${s?"https":"http"}://${o}`;return{wsUrl:`${s?"wss":"ws"}://${o}/ws`,httpBase:r}}function rn(i){return Be(i).httpBase}function an(i,e,t,n){const s=`beforeSeq=${t}&limit=${n}`;return[`${i}/conversations/${e}/messages?${s}`,`${i}/conversations/${e}/history?${s}`]}async function Ke(i,e,t,n,s=on){for(const o of an(i,e,n,s))try{const r=await fetch(o,{headers:{authorization:`Bearer ${t}`}});if(!r.ok)continue;const h=await r.json();return{messages:h.messages??[],hasMore:h.hasMore??!1}}catch{}return null}async function cn(i,e,t,n,s,o){const r=o?o.replace(/\/+$/,""):rn(i),h=await Ke(r,t,e,Number.MAX_SAFE_INTEGER);if(!h||(h.messages.length?(n.apply({type:"sync",conversationId:t,messages:h.messages}),n.apply({type:"history",conversationId:t,messages:[],hasMore:h.hasMore}),s.render(n)):n.apply({type:"history",conversationId:t,messages:[],hasMore:!1}),!h.hasMore))return;let p=!1;const f=async()=>{if(p||!n.hasMoreHistory)return;p=!0;const u=n.messages()[0];if(!u){p=!1;return}const S=await Ke(r,t,e,u.seq);S&&(n.apply({type:"history",conversationId:t,messages:S.messages,hasMore:S.hasMore}),s.render(n)),p=!1},g=s.getScrollEl();if(!g)return;let l=!1;setTimeout(()=>{l=!0},300);const x=()=>{l&&g.scrollTop<80&&n.hasMoreHistory&&!p&&f()};g.addEventListener("scroll",x,{passive:!0}),s.setScrollCleanup(()=>g.removeEventListener("scroll",x))}const G=new WeakMap,ne=new Map;function ze(i){return`relay-launcher::${i.profileId}::${i.subjectId??""}`}function dn(i){var He,je,qe,Fe,Oe;G.has(i.el)&&(G.get(i.el).close(),G.delete(i.el)),i.launcher&&((He=ne.get(ze(i)))==null||He.close());const e=Ve();let t,n=!1;const s=i.token??i.userId??e,o=s!==e?e:void 0,{wsUrl:r,httpBase:h}=Be(i.url,i.apiUrl);let p=new Kt(s);const f=i.subjectId?`${s}::${i.subjectId}`:s,g=new Ht(f);let l,x=!1,u=null,S=null;!i.launcher&&!i.el.style.height&&i.el.clientHeight===0&&(i.el.style.width=i.el.style.width||"100%",i.el.style.height="600px");for(const d of g.load())p.addOptimistic(d.clientMsgId,d.content);let v=null,y=null,E=0,I=!i.launcher;if(i.launcher){const w=(i.position??"bottom-right").includes("right");v=document.createElement("div"),v.style.cssText=`position:fixed;${w?"right:20px":"left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${w?"flex-end":"flex-start"};gap:12px`;const m=document.createElement("div"),P=typeof window<"u"?window.matchMedia("(max-width: 479px)"):null,re=F=>{m.style.cssText=F?["position:fixed","inset:0","width:100%","height:100%","border-radius:0","overflow:hidden","box-shadow:none","display:none","flex-direction:column","background:#fff","transition:opacity .18s","opacity:0","z-index:9998"].join(";"):["width:380px","height:600px","border-radius:16px","overflow:hidden","box-shadow:0 8px 40px rgba(0,0,0,.18)","display:none","flex-direction:column","background:#fff","transform-origin:bottom "+(w?"right":"left"),"transition:opacity .18s,transform .18s","opacity:0","transform:scale(.95)"].join(";")};re((P==null?void 0:P.matches)??!1);const ae=F=>re(F.matches);P==null||P.addEventListener("change",ae),u=P,S=ae,i.el.style.cssText="width:100%;height:100%;overflow:hidden",m.append(i.el);const K=document.createElement("button");K.style.cssText=["width:56px;height:56px;border-radius:50%",`background:${i.accent??"#4F63F5"}`,"color:#fff;border:none;font-size:24px;cursor:pointer","box-shadow:0 4px 16px rgba(0,0,0,.25)","position:relative;flex:none","transition:transform .15s"].join(";"),K.textContent="πŸ’¬",K.onmouseenter=()=>{K.style.transform="scale(1.08)"},K.onmouseleave=()=>{K.style.transform="scale(1)"},y=document.createElement("span"),y.style.cssText="position:absolute;top:-4px;right:-4px;background:#ef4444;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center",K.append(y),v.append(m,K),document.body.append(v);const ce=F=>{F?(m.style.display="flex",requestAnimationFrame(()=>{m.style.opacity="1",m.style.transform="scale(1)"})):(m.style.opacity="0",m.style.transform="scale(.95)",setTimeout(()=>{I||(m.style.display="none")},180))};K.addEventListener("click",()=>{I=!I,ce(I),K.textContent=I?"βœ•":"πŸ’¬",K.append(y),I&&(E=0,y&&(y.style.display="none"))}),document.addEventListener("keydown",F=>{F.key==="Escape"&&I&&(I=!1,ce(!1),K.textContent="πŸ’¬",K.append(y))})}const L=()=>{I||(E++,y&&(y.textContent=String(E),y.style.display="flex"))},M=()=>{try{const d=new AudioContext,w=d.createOscillator(),m=d.createGain();w.connect(m),m.connect(d.destination),w.frequency.setValueAtTime(880,d.currentTime),w.frequency.exponentialRampToValueAtTime(440,d.currentTime+.15),m.gain.setValueAtTime(.3,d.currentTime),m.gain.exponentialRampToValueAtTime(.001,d.currentTime+.3),w.start(),w.stop(d.currentTime+.3)}catch{}},A=[],U=d=>{for(;A.length;){const w=A.shift();g.add({clientMsgId:w.clientMsgId,content:w.content,ts:Date.now()}),k.send({type:"send",conversationId:d,clientMsgId:w.clientMsgId,content:w.content})}};let k;const b=new Jt(`ocw-e2e-${i.profileId}`);let T=!1;const q=[],se=[];let De=!1;const ge=(d,w)=>{b.sealText(w).then(m=>{l&&k.send({type:"send",conversationId:l,clientMsgId:d,content:m})})},yn=(d,w,m)=>{b.sealText(w,m).then(P=>{l&&k.send({type:"send",conversationId:l,clientMsgId:d,content:P})})},xn=()=>{for(;q.length;){const d=q.shift();ge(d.clientMsgId,d.text)}for(;se.length;){const d=se.shift();ge(d.clientMsgId,d.text)}},gn=d=>{k.send({type:"fetchPrekey",targetUserId:d})},bn=i.i18n??{},mn=["ar","he","fa","ur"],vn=typeof navigator<"u"?(navigator.language??"").slice(0,2).toLowerCase():"";mn.includes(vn)&&!i.el.dir&&(i.el.dir="rtl",i.el.style.fontFamily=i.el.style.fontFamily||"Tahoma,Arial,system-ui,sans-serif");const $e=new Lt,Re=`oc_prechat_${i.profileId}_${s.slice(-8)}`,B=new nn(i.el,s,{onSend(d){const w=`cm_${Math.random().toString(36).slice(2)}`,m={kind:"text",text:d};p.addOptimistic(w,m),B.render(p),p.e2e?b.ready?ge(w,d):De?se.push({clientMsgId:w,text:d}):(q.push({clientMsgId:w,text:d}),p.assignedAgentId&&gn(p.assignedAgentId)):l?(g.add({clientMsgId:w,content:m,ts:Date.now()}),k.send({type:"send",conversationId:l,clientMsgId:w,content:m})):A.push({clientMsgId:w,content:m})},async onAttach(d){if(!l)return;const w=`${h}/upload?name=${encodeURIComponent(d.name)}`,m=`cm_${Math.random().toString(36).slice(2)}`;p.addOptimistic(m,{kind:"text",text:`πŸ“Ž Uploading ${d.name}…`}),B.render(p);try{const P=await fetch(w,{method:"POST",headers:{"content-type":d.type,authorization:`Bearer ${s}`},body:d});if(!P.ok)throw new Error(`Upload failed: ${P.status}`);const{url:re,name:ae,mime:K,size:ce}=await P.json();k.send({type:"send",conversationId:l,clientMsgId:m,content:{kind:"attachment",url:re,name:ae,mime:K,size:ce}})}catch(P){p.addOptimistic(m,{kind:"text",text:`⚠️ Upload failed: ${P.message}`}),B.render(p)}},onInvoke(d,w){l&&k.send({type:"invoke",conversationId:l,actionId:d,clientInvokeId:`iv_${Math.random().toString(36).slice(2)}`,...w?{inputs:w}:{}})},onTyping(d,w){l&&k.send({type:"typing",conversationId:l,isTyping:d,...w?{preview:w}:{}})},onPreChat(d){try{localStorage.setItem(Re,"1")}catch{}k.send({type:"open",profileId:i.profileId,...i.subjectId?{subjectId:i.subjectId}:{},userInfo:{...d.name?{name:d.name}:{},...d.email?{email:d.email}:{},...d.phone||d.topic?{meta:{...d.phone?{phone:d.phone}:{},...d.topic?{topic:d.topic}:{}}}:{}}});const w=d.callback?`πŸ“ž Call-back requested${d.phone?`: ${d.phone}`:""}${d.topic?` β€” ${d.topic}`:""}`:d.topic?`Topic: ${d.topic}`:"";w&&l&&!p.e2e&&k.send({type:"send",conversationId:l,clientMsgId:`pc_${Math.random().toString(36).slice(2,12)}`,content:{kind:"text",text:w}})},onDeflectQuery(d){if(n)return;clearTimeout(t);const w=d.trim();if(w.length<3){B.hideDeflection();return}t=setTimeout(()=>{fetch(`${h}/kb/search?profileId=${encodeURIComponent(i.profileId)}&q=${encodeURIComponent(w.slice(0,200))}`).then(m=>m.ok?m.json():{articles:[]}).then(m=>B.showDeflection(m.articles??[])).catch(()=>B.hideDeflection())},350)},onReadUpTo(d){l&&k.send({type:"read",conversationId:l,seq:d})},onLoadMore(){if(!l||!p.e2e)return;const d=p.messages()[0];d&&k.send({type:"history",conversationId:l,beforeSeq:d.seq,limit:20})},onEdit(d,w){l&&k.send({type:"edit",conversationId:l,messageId:d,content:{kind:"text",text:w}})},onDelete(d){l&&k.send({type:"delete",conversationId:l,messageId:d})},onReact(d,w,m){l&&k.send({type:"react",conversationId:l,messageId:d,emoji:w,remove:m})},onCsat(d){l&&fetch(`${h}/conversations/${l}/csat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify({score:d})}).catch(()=>{})},onAnnotate(d){l&&k.send({type:"annotate",conversationId:l,stroke:d})},onAnnotateClear(){l&&k.send({type:"annotate_clear",conversationId:l})},...i.translateLang?{async onTranslate(d){try{const w=await fetch(`${h}/translate`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${s}`},body:JSON.stringify({text:d,targetLang:i.translateLang})});if(!w.ok)return null;const{translated:m}=await w.json();return m}catch{return null}}}:{},...i.onBack?{onBack:i.onBack}:{}},{...i.subject?{subject:i.subject}:{},...i.quickReplies?{quickReplies:i.quickReplies}:{},...i.accent?{accent:i.accent}:{},...(je=i.user)!=null&&je.name||(qe=i.user)!=null&&qe.avatar?{userInfo:{...i.user.name?{name:i.user.name}:{},...i.user.avatar?{avatar:i.user.avatar}:{}}}:{},i18n:bn});try{localStorage.getItem(Re)&&B.completePreChat()}catch{}const _e=i.user&&(i.user.name||i.user.email||i.user.avatar||i.user.meta)?{...i.user.name?{name:i.user.name}:{},...i.user.email?{email:i.user.email}:{},...i.user.avatar?{avatar:i.user.avatar}:{},...i.user.meta?{meta:i.user.meta}:{}}:void 0,kn={type:"open",profileId:i.profileId,...i.kind==="direct"&&i.peerId?{kind:"direct",peerId:i.peerId}:i.subjectId?{subjectId:i.subjectId}:{},...o?{linkFrom:o}:{},..._e?{userInfo:_e}:{},...typeof location<"u"?{pageUrl:location.href}:{},...typeof document<"u"&&document.title?{pageTitle:document.title}:{},...(Fe=i.subject)!=null&&Fe.title?{subjectTitle:i.subject.title}:{},...(Oe=i.subject)!=null&&Oe.subtitle?{subjectMeta:i.subject.subtitle}:{}};k=new Mt({...i.refreshToken?{refreshToken:i.refreshToken}:{},url:r,token:s,open:kn,getCursor:()=>p.highestSeq(),onStatusChange:(d,w)=>B.setConnStatus(d,w),onFrame(d){if($e.apply(d),d.type==="opened"){if(l=d.conversation.id,!x){x=!0;for(const w of g.load())k.send({type:"send",conversationId:l,clientMsgId:w.clientMsgId,content:w.content})}cn(r,s,l,p,B,h),A.length&&U(l)}if(d.type==="ack"&&g.remove(d.clientMsgId),d.type==="prekeyBundle"){d.bundle&&(De=!0,b.x3dhSendTo(d.bundle).then(w=>{const m=[...q.splice(0),...se.splice(0)];for(const P of m)yn(P.clientMsgId,P.text,w);B.render(p)}));return}if(d.type==="message"&&p.e2e){const w=Gt(d.message.content);if(w&&!b.ready){b.x3dhReceiveFrom(w.x3dhIK,w.x3dhEK,w.x3dhSPK).then(async()=>{await b.openFrame(d),p.apply(d),B.render(p)});return}}if(d.type==="peerkey"){b.onPeerKey(d.key).then(()=>{xn(),B.render(p)});return}(async()=>{if(p.e2e&&await b.openFrame(d),p.apply(d),d.type==="message"&&d.message.senderId!==s&&!d.message.internal&&(L(),M()),p.e2e&&l&&!T){T=!0;const w=await b.initX3DH();k.send({type:"uploadPrekeys",...w});const m=await b.begin();k.send({type:"pubkey",conversationId:l,key:m})}B.render(p)})()}}),k.connect(),B.render(p);const Z=i.launcher?ze(i):null,oe={close:()=>{n=!0,clearTimeout(t),k.close(),v==null||v.remove(),B.destroy(),$e.destroy(),u&&S&&u.removeEventListener("change",S),G.delete(i.el),Z&&ne.get(Z)===oe&&ne.delete(Z)}};return G.set(i.el,oe),Z&&ne.set(Z,oe),oe}const ln="wss://api.paramms.com/ws";let j=null,$=null,W={};function hn(i,e){const t=i.profileId??i.appId;if(!t)throw new Error("Relay: `appId` is required (your chatroom id, e.g. 'p_...').");const n=i.subjectId??(i.listingId?`listing_${i.listingId}`:void 0),s=i.subjectTitle?{title:i.subjectTitle,...i.subjectMeta?{subtitle:i.subjectMeta}:{},...i.subjectPrice!=null?{tags:[`$${i.subjectPrice.toLocaleString()}`]}:{},...i.subjectStatus?{status:i.subjectStatus}:{}}:void 0,o=i.name||i.email||i.avatar?{...i.name?{name:i.name}:{},...i.email?{email:i.email}:{},...i.avatar?{avatar:i.avatar}:{}}:void 0;return{el:e,url:i.url??ln,profileId:t,...i.apiUrl?{apiUrl:i.apiUrl}:{},...n?{subjectId:n}:{},...i.token?{token:i.token}:{},...i.userId?{userId:i.userId}:{},...s?{subject:s}:{},...o?{user:o}:{},...i.accent?{accent:i.accent}:{},...i.translateLang?{translateLang:i.translateLang}:{},launcher:i.launcher??!0,position:i.position??"bottom-right"}}function pn(){return(!$||!$.isConnected)&&($=document.createElement("div"),$.id="relay-widget-root",document.body.appendChild($)),$}function Le(i){try{j==null||j.close(),j=dn(hn(i,pn()))}catch(e){console.error("[Relay]",e instanceof Error?e.message:e)}}function Me(i){W={...i},Le(W)}function un(i){W={...W,...i},Le(W)}function fn(){j==null||j.close(),j=null,$==null||$.remove(),$=null,W={}}function xe(i,e){switch(i){case"boot":Me(e??{});break;case"update":case"identify":un(e??{});break;case"shutdown":fn();break;default:console.warn("[Relay] unknown command:",i)}}function wn(){if(typeof document>"u")return null;const i=document.querySelector("script[data-relay-app]"),e=i==null?void 0:i.dataset.relayApp;if(!e)return null;const t=i.dataset,n={appId:e};t.relayUser&&(n.userId=t.relayUser),t.relayToken&&(n.token=t.relayToken),t.relayListing&&(n.listingId=t.relayListing),t.relayAccent&&(n.accent=t.relayAccent),t.relayUrl&&(n.url=t.relayUrl);const s=t.relayPosition;return(s==="bottom-left"||s==="bottom-right")&&(n.position=s),t.relayLauncher==="false"&&(n.launcher=!1),n}if(typeof window<"u"){const i=window,e=i.Relay&&i.Relay.q?i.Relay.q:[];i.Relay=xe;let t=!1;for(const n of e){const[s,o]=n;s==="boot"&&(t=!0),xe(s,o)}if(!t){const n=i.relaySettings??wn();n&&Me(n)}}return R.Relay=xe,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"}),R}({});
175
177
  //# sourceMappingURL=embed.js.map