@paramms/chat-widget 1.0.46 → 1.0.47
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/chatlist.js +15 -15
- package/dist/chatlist.js.map +1 -1
- package/dist/embed-lite.js +6 -6
- package/dist/embed-lite.js.map +1 -1
- package/dist/embed.d.ts +1 -1
- package/dist/embed.js +6 -6
- package/dist/embed.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/renderer.d.ts +2 -1
- package/package.json +1 -1
package/dist/embed.d.ts
CHANGED
|
@@ -98,7 +98,7 @@ export interface RelaySettings {
|
|
|
98
98
|
/** Secondary accent (guest bubble + send button). Object/attr form; follows
|
|
99
99
|
* `accent` when omitted. */
|
|
100
100
|
accent2?: string;
|
|
101
|
-
/** Colour scheme: 'auto'|'light'|'dark'. Attr: data-relay-theme. */
|
|
101
|
+
/** Colour scheme: 'auto'|'light'|'dark' (default 'light'; 'auto' follows OS). Attr: data-relay-theme. */
|
|
102
102
|
theme?: 'auto' | 'light' | 'dark';
|
|
103
103
|
/** Load brand webfonts (default true). Attr: data-relay-webfont="false". */
|
|
104
104
|
webfont?: boolean;
|
package/dist/embed.js
CHANGED
|
@@ -3,7 +3,7 @@ var RelayEmbed=function(Q){"use strict";var di=Object.defineProperty;var hi=(Q,X
|
|
|
3
3
|
position:relative;
|
|
4
4
|
display:flex; flex-direction:column; height:100%; min-height:320px; background:var(--ocw-bg);
|
|
5
5
|
font-family:var(--ocw-fb); color:var(--ocw-ink); overflow:hidden; }
|
|
6
|
-
@media (prefers-color-scheme: dark) { .ocw
|
|
6
|
+
@media (prefers-color-scheme: dark) { .ocw[data-theme="auto"] { ${Be("ocw")} } }
|
|
7
7
|
.ocw[data-theme="dark"] { ${Be("ocw")} }
|
|
8
8
|
/* ── Responsive sizing ──────────────────────────────────────────────────────
|
|
9
9
|
* Sizing is driven by the WIDGET'S OWN width (ResizeObserver toggles
|
|
@@ -110,7 +110,7 @@ var RelayEmbed=function(Q){"use strict";var di=Object.defineProperty;var hi=(Q,X
|
|
|
110
110
|
.ocw button:focus-visible, .ocw textarea:focus-visible, .ocw a:focus-visible, .ocw [tabindex]:focus-visible { outline:2px solid var(--ocw-accent); outline-offset:2px; border-radius:8px; }
|
|
111
111
|
.ocw-sendbtn:active { transform:scale(.92); }
|
|
112
112
|
.ocw-quick button:active, .ocw-chip:active { transform:scale(.97); }
|
|
113
|
-
@media (prefers-color-scheme: dark) { .ocw
|
|
113
|
+
@media (prefers-color-scheme: dark) { .ocw[data-theme="auto"] .ocw-away { background:#3a3018; border-color:#5a4a1f; color:#e8d9a8; } .ocw[data-theme="auto"] .ocw-note .ocw-bubble { background:#332b12; border-color:#7a5c17; color:#f0e2bd; } .ocw[data-theme="auto"] .ocw-note .ocw-bubble::before { color:#e0c060; } }
|
|
114
114
|
.ocw[data-theme="dark"] .ocw-away { background:#3a3018; border-color:#5a4a1f; color:#e8d9a8; }
|
|
115
115
|
.ocw[data-theme="dark"] .ocw-note .ocw-bubble { background:#332b12; border-color:#7a5c17; color:#f0e2bd; }
|
|
116
116
|
.ocw[data-theme="dark"] .ocw-note .ocw-bubble::before { color:#e0c060; }
|
|
@@ -189,11 +189,11 @@ var RelayEmbed=function(Q){"use strict";var di=Object.defineProperty;var hi=(Q,X
|
|
|
189
189
|
.ocw-row.theirs .ocw-translate-btn { right:auto; left:-26px; }
|
|
190
190
|
.ocw-bubble-wrap:hover .ocw-translate-btn { opacity:1; }
|
|
191
191
|
.ocw-translated-tag { font-size:10px; color:var(--ocw-mut); margin-top:2px; }
|
|
192
|
-
`,wt="objectchat-widget-styles",Rn=["👍","❤️","😂","😮","😢","🙏"],Dn=400,_n='<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4 20-7z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function jn(){if(typeof document>"u"||document.getElementById(wt))return;const t=document.createElement("style");t.id=wt,t.textContent=$n,document.head.appendChild(t)}const gt="ocw-webfont";function Nn(){if(typeof document>"u"||document.getElementById(gt))return;const t=document.createElement("link");t.id=gt,t.rel="stylesheet",t.href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Nunito:wght@400;500;600;700&display=swap",document.head.appendChild(t)}function c(t,e,n){const o=document.createElement(t);return e&&(o.className=e),n!==void 0&&(o.textContent=n),o}function qn(t){try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function Ve(t){var e;switch(t.kind){case"text":return t.text;case"system":return typeof((e=t.data)==null?void 0:e.message)=="string"?String(t.data.message):t.event;case"card":return[t.title,t.body].filter(Boolean).join(" — ");case"attachment":return t.name??t.url;case"form":return t.prompt;case"appointment":return`📅 ${t.title} — ${new Date(t.startIso).toLocaleString()}`}}class On{constructor(e,n,o,i={}){a(this,"scroll");a(this,"chips");a(this,"typing");a(this,"quick");a(this,"formHost");a(this,"csatPanel");a(this,"awayNotice");a(this,"headStatus");a(this,"reopenBtn");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,"sendBtn");a(this,"compactObserver",null);a(this,"storeRef",null);a(this,"cfgAccent2");a(this,"scrollCleanup",null);a(this,"translationCache",new Map);a(this,"showingTranslation",new Set);a(this,"subjectBuilt",!1);var w,U,C,x,b,_,R,j,m,P,H;this.root=e,this.me=n,this.h=o,this.cfg=i,jn(),i.webfont!==!1&&Nn(),e.replaceChildren(),e.classList.add("ocw"),i.accent&&e.style.setProperty("--ocw-accent",i.accent);const s=i.accent2??i.accent;s&&e.style.setProperty("--ocw-accent2",s),this.cfgAccent2=i.accent2,i.theme&&i.theme!=="auto"&&(e.dataset.theme=i.theme);const r=c("div","ocw-head");if(this.h.onBack){const E=c("button","ocw-back","‹");E.type="button",E.setAttribute("aria-label","Back"),E.addEventListener("click",()=>this.h.onBack()),r.append(E)}const p=c("div","ocw-avatar");if((w=i.userInfo)!=null&&w.avatar){const E=document.createElement("img");E.src=i.userInfo.avatar,E.alt=i.userInfo.name??"You",E.style.cssText="width:100%;height:100%;border-radius:50%;object-fit:cover",p.append(E)}else p.textContent=(U=i.userInfo)!=null&&U.name?i.userInfo.name[0].toUpperCase():"🧑";r.append(p);const l=c("div","ocw-head-main");this.headerName=c("div","ocw-head-name",((C=i.subject)==null?void 0:C.ownerLabel)??((x=i.subject)==null?void 0:x.title)??""),l.append(this.headerName),this.headStatus=c("div","ocw-head-status"),this.headStatus.style.display="none",l.append(this.headStatus),(b=i.subject)!=null&&b.subtitle&&l.append(c("div","ocw-head-meta",i.subject.subtitle)),r.append(l),this.statusBadge=c("span","ocw-badge",((_=i.subject)==null?void 0:_.status)??""),(R=i.subject)!=null&&R.status||(this.statusBadge.style.display="none"),r.append(this.statusBadge),this.e2eBadge=c("span","ocw-e2e","🔒 E2E"),this.e2eBadge.style.display="none",r.append(this.e2eBadge),this.connStatus=c("span","ocw-conn-status"),this.connStatus.style.display="none",r.append(this.connStatus),r.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 u=c("div","ocw-typing-bubble");u.append(c("div","ocw-typing-dot"),c("div","ocw-typing-dot"),c("div","ocw-typing-dot")),this.typing.append(c("div","ocw-dot","🧑"),u),this.quick=c("div","ocw-quick");for(const E of i.quickReplies??[]){const q=c("button",void 0,E);q.addEventListener("click",()=>{this.h.onSend(E),this.quick.style.display="none"}),this.quick.append(q)}this.formHost=c("div","ocw-form-host"),this.csatPanel=c("div","ocw-csat"),this.csatPanel.style.display="none",this.awayNotice=c("div","ocw-away"),this.awayNotice.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=((j=i.i18n)==null?void 0:j.placeholder)??"Message…";const f=c("button","ocw-sendbtn");f.type="button";const d=(m=i.i18n)==null?void 0:m.send;d?(f.textContent=d,f.classList.add("ocw-sendbtn-label"),f.setAttribute("aria-label",d)):(f.innerHTML=_n,f.setAttribute("aria-label","Send message")),f.disabled=!0,this.sendBtn=f,f.addEventListener("click",()=>this.flushSend()),this.input.addEventListener("input",()=>{var E,q;this.sendBtn.disabled=this.input.value.trim().length===0,this.autoGrowInput(),this.storeRef&&!this.storeRef.messages().some(J=>J.senderRole==="guest")?(q=(E=this.h).onDeflectQuery)==null||q.call(E,this.input.value):this.hideDeflection()}),this.input.addEventListener("keydown",E=>{E.isComposing||E.keyCode===229||(E.key==="Enter"&&!E.shiftKey?(E.preventDefault(),this.flushSend()):this.signalTyping())});const k=c("button","ocw-attach","📎");k.title="Attach image or file";const S=document.createElement("input");S.type="file",S.accept="image/*,.pdf,.txt,.doc,.docx",S.style.display="none",k.addEventListener("click",()=>S.click()),S.addEventListener("change",()=>{var E;(E=S.files)!=null&&E[0]&&this.h.onAttach&&this.h.onAttach(S.files[0]),S.value=""});const L=c("div","ocw-input");L.append(k,S,this.input,f);const z=c("div","ocw-footer");((P=i.i18n)==null?void 0:P.poweredBy)!==void 0?z.textContent=i.i18n.poweredBy:z.innerHTML='Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>',this.footer=z,this.reopenBtn=c("button","ocw-reopen",((H=this.cfg.i18n)==null?void 0:H.reopen)??"Reopen conversation"),this.reopenBtn.type="button",this.reopenBtn.addEventListener("click",()=>{this.reopenBtn.style.display="none";const E=this.root.querySelector(".ocw-input textarea");E==null||E.focus()}),e.append(r,this.chips,this.scroll,this.typing,this.quick,this.formHost,this.csatPanel,this.preChatPanel,this.deflectPanel,this.awayNotice,L,this.reopenBtn,this.footer);const g=E=>{e.classList.toggle("ocw-compact",E>0&&E<Dn)};g(e.clientWidth),typeof ResizeObserver<"u"&&(this.compactObserver=new ResizeObserver(E=>{var J;const q=((J=E[0])==null?void 0:J.contentRect.width)??e.clientWidth;g(q)}),this.compactObserver.observe(e))}getScrollEl(){return this.scroll}setScrollCleanup(e){var n;(n=this.scrollCleanup)==null||n.call(this),this.scrollCleanup=e}destroy(){var e,n;(e=this.scrollCleanup)==null||e.call(this),this.scrollCleanup=null,this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),(n=this.compactObserver)==null||n.disconnect(),this.compactObserver=null}flushSend(){this.hideDeflection();const e=this.input.value.trim();e&&(this.input.value="",this.sendBtn.disabled=!0,this.autoGrowInput(),this.h.onTyping(!1),this.h.onSend(e))}autoGrowInput(){this.input.style.height="auto";const e=this.input.scrollHeight;e>0?this.input.style.height=`${Math.min(e,120)}px`:this.input.style.removeProperty("height")}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 S,L,z,g,w,U,C,x;if(this.storeRef=e,e.accent&&(this.root.style.setProperty("--ocw-accent",e.accent),this.root.style.setProperty("--ocw-accent2",this.cfgAccent2??e.accent)),this.e2eBadge.style.display=e.e2e?"inline-flex":"none",this.buildSubjectCard(e),e.subject){const b=(S=this.cfg.subject)==null?void 0:S.ownerLabel;b&&(this.headerName.textContent=b)}this.quick.style.display=e.messages().length===0?"flex":"none",this.chips.replaceChildren();const n=e.visibleActions();this.chips.style.display=n.length?"flex":"none";for(const b of n)this.chips.append(this.chipEl(b));const o=this.scroll.scrollHeight,i=this.scroll.scrollTop;if(this.scroll.replaceChildren(),this.subjectCard.childNodes.length&&this.scroll.append(this.subjectCard),e.hasMoreHistory){const b=c("div","ocw-load-more");b.textContent="↑ Loading earlier messages…",b.style.pointerEvents="none",this.scroll.append(b)}let s=0,r=null;for(const b of e.messages()){const _=b.senderRole!=="system"&&b.senderId!==this.me&&!b.internal&&b.senderId!==r;this.scroll.append(this.messageEl(b,e,_)),b.senderRole!=="system"&&(r=b.senderId),b.senderId!==this.me&&b.seq>s&&(s=b.seq)}i>20?this.scroll.scrollTop=this.scroll.scrollHeight-o+i:this.scroll.scrollTop=this.scroll.scrollHeight,s>0&&this.h.onReadUpTo(s);const p=[...e.typing];this.typing.classList.toggle("active",p.length>0);const l=this.typing.querySelector(".ocw-typing-bubble");l&&l.setAttribute("aria-label",p.length?"typing":""),this.footer.style.display=e.whiteLabel?"none":"block";const u=e.messages().some(b=>b.senderRole==="guest");if(!!((L=e.preChat)!=null&&L.enabled)&&!this.preChatDone&&!u&&(e.preChat.showWhen!=="offline"||e.offline))this.preChatBuilt||this.buildPreChatPanel(e.preChat),this.preChatPanel.style.display="block",this.awayNotice.style.display="none",(z=this.root.querySelector(".ocw-input"))==null||z.style.setProperty("display","none");else{if(this.preChatPanel.style.display="none",e.offline){this.awayNotice.firstChild||this.awayNotice.append(c("span","ocw-away-icon","🌙"),c("span","",""));const b=this.awayNotice.lastChild;b.textContent=e.offlineMessage||((g=this.cfg.i18n)==null?void 0:g.offline)||"We're away right now — send your message and we'll reply as soon as we're back.",this.awayNotice.style.display="flex"}else this.awayNotice.style.display="none";(w=this.root.querySelector(".ocw-input"))==null||w.style.removeProperty("display")}const d=["resolved","closed","sold","issued","checked_out"];this.h.onCsat&&!this.csatSubmitted&&d.includes(e.state)&&e.messages().length>0&&(this.csatPanel.style.display==="none"&&this.buildCsatPanel(),this.csatPanel.style.display="block");const k=d.includes(e.state);if(e.offline?(this.headStatus.textContent=`● ${e.offlineMessage||((U=this.cfg.i18n)==null?void 0:U.away)||"Away"}`,this.headStatus.className="ocw-head-status away",this.headStatus.style.display=""):e.conversationId?(this.headStatus.textContent=`● ${((C=this.cfg.i18n)==null?void 0:C.online)??"Online"}`,this.headStatus.className="ocw-head-status online",this.headStatus.style.display=""):this.headStatus.style.display="none",k&&e.messages().length>0){const b=c("div","ocw-resolved-note",`— ${((x=this.cfg.i18n)==null?void 0:x.resolved)??"Marked as resolved"} —`);this.scroll.append(b),this.reopenBtn.style.display="block"}else this.reopenBtn.style.display="none"}setConnStatus(e,n){if(e==="open"){this.connStatus.style.display="none";return}this.connStatus.style.display="";const o=e==="error";this.connStatus.className=`ocw-conn-status${o?" err":e==="reconnecting"?" warn":""}`,this.connStatus.textContent=o?`⚠ ${n??"Chat unavailable"}`:e==="reconnecting"?n??"↻ reconnecting…":"● connecting…"}buildPreChatPanel(e){var l;this.preChatBuilt=!0,this.preChatPanel.replaceChildren(),this.preChatPanel.append(c("div","ocw-prechat-title",e.title??"Before we start…"));const n=c("div","ocw-offline-form"),o={};for(const u of e.fields??["name","email"]){const f=c("input","ocw-offline-input");f.type=u==="email"?"email":u==="phone"?"tel":"text",f.placeholder=u==="name"?"Your name":u==="email"?"Your email":"Your phone number",o[u]=f,n.append(f)}let i=null;if((l=e.topics)!=null&&l.length){i=c("select",void 0);const u=document.createElement("option");u.value="",u.textContent="What is this about?",i.append(u);for(const f of e.topics){const d=document.createElement("option");d.value=f,d.textContent=f,i.append(d)}n.append(i)}let s=null,r=null;if(e.callbackOption){const u=c("label","ocw-prechat-cb");s=document.createElement("input"),s.type="checkbox",u.append(s,document.createTextNode("📞 Request a call back")),n.append(u),o.phone||(r=c("input","ocw-offline-input"),r.type="tel",r.placeholder="Phone number for the call",r.style.display="none",s.addEventListener("change",()=>r.style.setProperty("display",s.checked?"block":"none")),n.append(r))}const p=c("button","ocw-offline-submit","Start chat");p.type="button",p.addEventListener("click",()=>{var k,S,L,z,g,w,U;const u=(k=o.email)==null?void 0:k.value.trim();if(o.email&&(!u||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u))){o.email.focus();return}const f=!!(s!=null&&s.checked),d=(((S=o.phone)==null?void 0:S.value)??(r==null?void 0:r.value)??"").trim();if(f&&!d){(L=o.phone??r)==null||L.focus();return}if(i&&((z=e.topics)!=null&&z.length)&&!i.value){i.focus();return}p.disabled=!0,this.completePreChat(),(U=(w=this.h).onPreChat)==null||U.call(w,{...(g=o.name)!=null&&g.value.trim()?{name:o.name.value.trim()}:{},...u?{email:u}:{},...d?{phone:d}:{},...i!=null&&i.value?{topic:i.value}:{},...f?{callback:!0}:{}})}),n.append(p),this.preChatPanel.append(n)}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 n of e.slice(0,3)){const o=c("button","ocw-deflect-card");o.append(c("div","ocw-deflect-q",n.title),c("div","ocw-deflect-a",n.answer)),o.addEventListener("click",()=>o.classList.toggle("open")),this.deflectPanel.append(o)}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"),n=[];for(let o=1;o<=5;o++){const i=c("button","ocw-csat-star","★");i.dataset.score=String(o),i.addEventListener("mouseenter",()=>n.forEach((s,r)=>s.classList.toggle("lit",r<o))),i.addEventListener("mouseleave",()=>n.forEach(s=>s.classList.remove("lit"))),i.addEventListener("click",()=>{var s,r;this.csatSubmitted=!0,this.csatPanel.replaceChildren(c("div","ocw-csat-done",`Thanks for your ${o}★ rating!`)),(r=(s=this.h).onCsat)==null||r.call(s,o)}),n.push(i),e.append(i)}this.csatPanel.append(e)}buildSubjectCard(e){if(this.subjectBuilt)return;const n=e.subject,o=this.cfg.subject,i=(n==null?void 0:n.title)??(o==null?void 0:o.title);if(!i)return;this.subjectBuilt=!0,this.subjectCard.replaceChildren(),this.subjectCard.append(c("div","ocw-subject-title",i)),o!=null&&o.subtitle&&this.subjectCard.append(c("div","ocw-subject-sub",o.subtitle));const s=c("div","ocw-tags");if(n)for(const[p,l]of Object.entries(n.fields))s.append(c("span","ocw-tag",`${p}: ${l}`));else for(const p of(o==null?void 0:o.tags)??[])s.append(c("span","ocw-tag",p));s.childNodes.length&&this.subjectCard.append(s);const r=(n==null?void 0:n.state)??(o==null?void 0:o.status);r&&(this.statusBadge.textContent=r,this.statusBadge.style.display="inline-flex")}chipEl(e){const n=c("button","ocw-chip",e.icon?`${e.icon} ${e.label}`:e.label);return n.dataset.actionId=e.id,n.addEventListener("click",async()=>{var o;e.confirm&&!await this.confirm(e.label)||((o=e.input)!=null&&o.length?this.openForm(e):this.h.onInvoke(e.id))}),n}confirm(e){return new Promise(n=>{const o=c("div","ocw-modal"),i=c("div","ocw-modal-card");i.append(c("div","ocw-modal-title",e)),i.append(c("div","ocw-modal-body",`Confirm “${e}”?`));const s=c("div","ocw-modal-actions"),r=c("button","ocw-modal-cancel","Cancel"),p=c("button","ocw-modal-ok","Confirm"),l=u=>{o.remove(),n(u)};r.addEventListener("click",()=>l(!1)),p.addEventListener("click",()=>l(!0)),o.addEventListener("click",u=>{u.target===o&&l(!1)}),s.append(r,p),i.append(s),o.append(i),this.root.append(o),p.focus()})}openForm(e){var p,l;this.formHost.replaceChildren();const n=c("div","ocw-form");n.append(c("div","ocw-form-title",e.icon?`${e.icon} ${e.label}`:e.label));const o=new Map;for(const u of e.input??[]){const f=c("label","ocw-form-row");if(f.append(c("span","ocw-form-lbl",u.label)),u.type==="select"&&((p=u.options)!=null&&p.length)){const d=c("select","ocw-form-input");u.required||d.append(c("option",void 0,"— select —"));for(const k of u.options){const S=c("option");S.value=k,S.textContent=k,d.append(S)}u.required&&(d.required=!0),f.append(d),o.set(u.name,d)}else{const d=c("input","ocw-form-input");d.type=u.type==="number"?"number":u.type==="date"?"datetime-local":"text",u.required&&(d.required=!0),f.append(d),o.set(u.name,d)}n.append(f)}const i=c("div","ocw-form-actions"),s=c("button","ocw-form-cancel","Cancel"),r=c("button","ocw-form-submit","Send");s.addEventListener("click",()=>this.formHost.replaceChildren()),r.addEventListener("click",()=>{const u={};for(const[f,d]of o){if(d.required&&!d.value){d.style.borderColor="#e5484d";return}u[f]=d.type==="number"?Number(d.value):d.value}this.formHost.replaceChildren(),this.h.onInvoke(e.id,u)}),i.append(s,r),n.append(i),this.formHost.append(n),(l=o.values().next().value)==null||l.focus()}messageEl(e,n,o=!1){var k,S,L,z;if(e.senderRole==="system"){const g=c("div","ocw-sys");return g.textContent=e.deletedAt?"message deleted":Ve(e.content),g}const i=e.senderId===this.me,s=!!e.internal,r=c("div",`ocw-row ${s?"ocw-note mine":i?"mine":"theirs"} ${e.senderRole==="bot"?"ocw-bot":""}`);!i&&!s&&r.append(c("div","ocw-dot",e.senderRole==="bot"?"🤖":"🧑"));const p=c("div");if(o){const g=e.senderRole==="bot"?((k=this.cfg.i18n)==null?void 0:k.aiAssistant)??"AI Assistant":((S=this.cfg.subject)==null?void 0:S.ownerLabel)??((L=this.cfg.subject)==null?void 0:L.title)??"Support";p.append(c("div","ocw-msg-sender",g))}const l=c("div","ocw-bubble-wrap");if(e.replyToId){const g=c("div","ocw-reply-to","↩ replying to a message");g.style.cssText="font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",p.append(g)}const u=c("div","ocw-bubble");let f=null;if(e.deletedAt)u.append(c("span","ocw-deleted","message deleted"));else if(e.content.kind==="attachment"){const g=e.content;if((z=g.mime)!=null&&z.startsWith("image/")){const w=document.createElement("img");w.src=g.url,w.alt=g.name??"image",w.style.cssText="max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer",w.addEventListener("click",()=>window.open(g.url,"_blank")),u.append(w)}else{const w=document.createElement("a");w.href=g.url,w.target="_blank",w.rel="noopener",w.style.cssText="display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none",w.append(c("span",void 0,"📄"),c("span",void 0,g.name??"file")),u.append(w)}}else if(e.content.kind==="appointment"){const g=e.content,w=c("div","ocw-appt");w.append(c("div","ocw-appt-title",`📅 ${g.title}`)),w.append(c("div","ocw-appt-time",new Date(g.startIso).toLocaleString()+" – "+new Date(g.endIso).toLocaleTimeString())),g.location&&w.append(c("div","ocw-appt-loc",`📍 ${g.location}`)),g.description&&w.append(c("div","ocw-appt-desc",g.description));const U=c("div","ocw-appt-links"),C=document.createElement("a");C.href=g.googleUrl,C.target="_blank",C.rel="noopener",C.className="ocw-appt-btn",C.textContent="📅 Add to Google Calendar";const x=document.createElement("a");x.href=g.icalUrl,x.download=`${g.title}.ics`,x.className="ocw-appt-btn ocw-appt-btn-sec",x.textContent="🍎 Apple / iCal",U.append(C,x),w.append(U),u.append(w)}else f=document.createTextNode(Ve(e.content)),u.append(f),e.editedAt&&u.append(c("span","ocw-edited","(edited)"));if(l.append(u),!i&&!s&&this.h.onTranslate&&e.content.kind==="text"&&!e.deletedAt&&e.seq>0&&f){const g=e.content.text;if(g.trim()){const w=c("button","ocw-translate-btn","🌐");w.type="button",w.title="Translate",w.addEventListener("click",U=>{if(U.stopPropagation(),this.showingTranslation.has(e.id)){this.showingTranslation.delete(e.id),f.textContent=g,w.textContent="🌐",w.title="Translate";return}const C=this.translationCache.get(e.id);if(C!==void 0){this.showingTranslation.add(e.id),f.textContent=C,w.textContent="↩",w.title="Show original";return}w.textContent="⏳",this.h.onTranslate(g).then(x=>{if(x===null){w.textContent="⚠️",w.title="Translation unavailable",setTimeout(()=>{w.textContent="🌐",w.title="Translate"},1500);return}this.translationCache.set(e.id,x),this.showingTranslation.add(e.id),f.textContent=x,w.textContent="↩",w.title="Show original"})}),l.append(w)}}if(i&&!e.deletedAt&&e.seq>0&&(this.h.onEdit??this.h.onDelete)){const g=c("div","ocw-msg-menu");if(this.h.onEdit){const w=c("button",void 0,"✏️");w.title="Edit",w.addEventListener("click",U=>{U.stopPropagation();const C=Ve(e.content),x=document.createElement("textarea");x.value=C,x.rows=Math.min(4,Math.ceil(C.length/40)+1),x.style.cssText="width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:var(--ocw-card);color:#1c1b1a;box-sizing:border-box";const b=c("button","ocw-form-submit","Save");b.style.cssText="margin-top:6px;padding:5px 14px;font-size:13px";const _=c("button","ocw-form-cancel","Cancel");_.style.cssText="margin-top:6px;padding:5px 10px;font-size:13px";const R=c("div");R.style.cssText="display:flex;gap:6px;justify-content:flex-end",R.append(_,b);const j=c("div");j.append(x,R),u.replaceChildren(j),x.focus(),x.select();const m=()=>u.replaceChildren(f??document.createTextNode(C));_.addEventListener("click",m),b.addEventListener("click",()=>{const P=x.value.trim();P&&P!==C&&this.h.onEdit(e.id,P),m()}),x.addEventListener("keydown",P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),b.click()),P.key==="Escape"&&m()})}),g.append(w)}if(this.h.onDelete){const w=c("button","del","🗑");w.title="Delete",w.addEventListener("click",U=>{U.stopPropagation(),this.h.onDelete(e.id)}),g.append(w)}l.append(g)}if(p.append(l),this.h.onReact&&!e.deletedAt&&e.seq>0){const g=c("div","ocw-react-wrap"),w=c("div","ocw-react");if(e.reactions&&Object.keys(e.reactions).length)for(const[x,b]of Object.entries(e.reactions)){const _=c("button",`ocw-react-pill${b.includes(this.me)?" mine":""}`,`${x} ${b.length}`);_.addEventListener("click",()=>{var R,j;return(j=(R=this.h).onReact)==null?void 0:j.call(R,e.id,x,b.includes(this.me))}),w.append(_)}const U=c("button","ocw-react-btn","+"),C=c("div","ocw-react-picker");for(const x of Rn){const b=c("button",void 0,x);b.addEventListener("click",_=>{var j,m,P,H;_.stopPropagation();const R=(m=(j=e.reactions)==null?void 0:j[x])==null?void 0:m.includes(this.me);(H=(P=this.h).onReact)==null||H.call(P,e.id,x,!!R),C.style.display="none"}),C.append(b)}C.style.display="none",U.addEventListener("click",x=>{x.stopPropagation();const b=C.style.display==="none";C.style.display=b?"flex":"none",b&&document.addEventListener("click",()=>{C.style.display="none"},{once:!0})}),w.append(U),g.append(w,C),p.append(g)}else e.reactions&&Object.keys(e.reactions).length&&p.append(c("div","ocw-react",Object.entries(e.reactions).map(([g,w])=>`${g}${w.length}`).join(" ")));const d=c("div","ocw-time ocw-meta",qn(e.ts));if(i&&e.status){const g=c("span",`ocw-tick${e.status==="read"?" read":e.status==="delivered"?" delivered":""}`,Hn(e.status));d.append(g)}return i&&e.seq>0&&n.lastReadByOthers>=e.seq&&d.append(c("span","ocw-seen"," · Seen")),p.append(d),r.append(p),r}}function Hn(t){switch(t){case"read":return"✓✓";case"delivered":return"✓✓";case"sent":return"✓";default:return"🕓"}}const Fn=20;function Xe(t,e){var l;const n=t.trim().replace(/\/+$/,""),o=(l=n.match(/^(https|http|wss|ws):\/\//))==null?void 0:l[1],i=o?o==="https"||o==="wss":!0,s=(o?n.slice(o.length+3):n).replace(/\/ws$/,""),r=e?e.trim().replace(/\/+$/,""):`${i?"https":"http"}://${s}`;return{wsUrl:`${i?"wss":"ws"}://${s}/ws`,httpBase:r}}function Wn(t){return Xe(t).httpBase}function Vn(t,e,n,o){const i=`beforeSeq=${n}&limit=${o}`;return[`${t}/conversations/${e}/messages?${i}`,`${t}/conversations/${e}/history?${i}`]}async function yt(t,e,n,o,i=Fn){let s,r=!1;for(const p of Vn(t,e,o,i))try{const l=await fetch(p,{headers:{authorization:`Bearer ${n}`}});if(r=!0,!l.ok)continue;const u=await l.json();return{messages:u.messages??[],hasMore:u.hasMore??!1}}catch(l){s=l}return r?console.error(`[chat-widget] history request to ${t} was rejected for conversation ${e}.`):console.error(`[chat-widget] could not load history from ${t} — the request never reached the server. This is almost always CORS: add this site's origin to the chatroom's allowed origins (dashboard → chatroom → allowed origins) or to the server's CORS_ORIGINS.`,s),null}async function Xn(t,e,n,o,i,s){const r=s?s.replace(/\/+$/,""):Wn(t),p=await yt(r,n,e,Number.MAX_SAFE_INTEGER);if(!p||(p.messages.length?(o.apply({type:"sync",conversationId:n,messages:p.messages}),o.apply({type:"history",conversationId:n,messages:[],hasMore:p.hasMore}),i.render(o)):o.apply({type:"history",conversationId:n,messages:[],hasMore:!1}),!p.hasMore))return;let l=!1;const u=async()=>{if(l||!o.hasMoreHistory)return;l=!0;const S=o.messages()[0];if(!S){l=!1;return}const L=await yt(r,n,e,S.seq);L&&(o.apply({type:"history",conversationId:n,messages:L.messages,hasMore:L.hasMore}),i.render(o)),l=!1},f=i.getScrollEl();if(!f)return;let d=!1;setTimeout(()=>{d=!0},300);const k=()=>{d&&f.scrollTop<80&&o.hasMoreHistory&&!l&&u()};f.addEventListener("scroll",k,{passive:!0}),i.setScrollCleanup(()=>f.removeEventListener("scroll",k))}const xe=new WeakMap,Ae=new Map;function xt(t){return`relay-launcher::${t.profileId}::${t.subjectId??""}`}let me=null;function Gn(){if(me&&me.state!=="closed")return me;try{return me=new AudioContext,me}catch{return null}}function mt(t){var pe,Se,Ie,kt,St,It,Ct,Et;xe.has(t.el)&&(xe.get(t.el).close(),xe.delete(t.el)),t.launcher&&((pe=Ae.get(xt(t)))==null||pe.close());const e=tt();let n,o=!1;const i=t.token??t.userId??e,s=i!==e?e:void 0,{wsUrl:r,httpBase:p}=Xe(t.url,t.apiUrl);let l=new wn(i);const u=t.subjectId?`${i}::${t.subjectId}`:i,f=new vn(u);let d,k=!1,S=null,L=null,z=null,g=null;!t.launcher&&!t.el.style.height&&t.el.clientHeight===0&&(t.el.style.width=t.el.style.width||"100%",t.el.style.height="600px");for(const h of f.load())l.addOptimistic(h.clientMsgId,h.content);let w=null,U=null,C=0,x=!t.launcher;if(t.launcher){const y=(t.position??"bottom-right").includes("right");w=document.createElement("div"),w.style.cssText=`position:fixed;${y?"right:20px":"left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${y?"flex-end":"flex-start"};gap:12px`;const T=document.createElement("div"),N=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(max-width: 479px)"):null,Ce=$=>{t.el.classList.toggle("ocw-fs",$),T.style.cssText=$?["position:fixed","inset:0","width:100%","height:100dvh","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:min(380px, calc(100vw - 40px))","height:min(600px, calc(100dvh - 108px))","border-radius:28px","overflow:hidden","box-shadow:0 12px 32px rgba(108,92,231,.14)","display:none","flex-direction:column","background:#fff","transform-origin:bottom "+(y?"right":"left"),"transition:opacity .18s,transform .18s","opacity:0","transform:scale(.95)"].join(";")};Ce((N==null?void 0:N.matches)??!1);const Ee=$=>Ce($.matches);N==null||N.addEventListener("change",Ee),S=N,L=Ee,t.el.style.cssText="width:100%;height:100%;overflow:hidden",T.append(t.el);const Ke='<svg viewBox="0 0 24 24" width="26" height="26" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',$e='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>',V=document.createElement("button");V.type="button",V.style.cssText=["width:56px;height:56px;border-radius:50%",`background:${t.accent??"#6c5ce7"}`,"color:#fff;border:none;cursor:pointer","box-shadow:0 12px 32px rgba(108,92,231,.14)","position:relative;flex:none","display:flex;align-items:center;justify-content:center","transition:transform .15s"].join(";"),V.onmouseenter=()=>{V.style.transform="scale(1.08)"},V.onmouseleave=()=>{V.style.transform="scale(1)"},U=document.createElement("span"),U.style.cssText="position:absolute;top:-4px;right:-4px;background:#4c6fff;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center";const Re=()=>{V.innerHTML=x?$e:Ke,V.setAttribute("aria-label",x?"Close chat":"Open chat"),V.setAttribute("aria-expanded",String(x)),V.append(U)};Re(),w.append(T,V),document.body.append(w);const Je=`ocw-teaser-dismissed::${t.profileId}`,De=typeof t.launcherMessage=="string"?{title:t.launcherMessage}:t.launcherMessage;let K=null;const ci=()=>{try{return sessionStorage.getItem(Je)==="1"}catch{return!1}},li='<svg viewBox="0 0 24 24" width="15" height="15" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',Tt=()=>{const $=De!=null&&De.title?De:l.launcherMessage??void 0;if(!(!!($!=null&&$.title)&&!x&&!ci())){K&&(K.remove(),K=null);return}if(K)return;K=document.createElement("div"),K.setAttribute("role","button"),K.setAttribute("tabindex","0"),K.setAttribute("aria-label",$.title),K.style.cssText=["max-width:280px","background:#fff","border-radius:16px","box-shadow:0 12px 32px rgba(108,92,231,.14)","padding:14px 40px 14px 16px","position:relative","cursor:pointer","font-family:inherit",`align-self:${y?"flex-end":"flex-start"}`,"animation:ocw-teaser-in .22s ease-out"].join(";");const Qe=document.createElement("div");if(Qe.textContent=$.title,Qe.style.cssText="font-size:15px;font-weight:600;color:#111;line-height:1.35",K.append(Qe),$.subtitle){const ne=document.createElement("div");ne.style.cssText="display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";const et=document.createElement("span");et.innerHTML=li,et.style.cssText=`color:${t.accent??"#6c5ce7"};display:inline-flex`;const Pt=document.createElement("span");Pt.textContent=$.subtitle,ne.append(et,Pt),K.append(ne)}const ue=document.createElement("button");ue.type="button",ue.setAttribute("aria-label","Dismiss"),ue.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>',ue.style.cssText="position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:#f3f4f6;color:#6b7280;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0",ue.addEventListener("click",ne=>{ne.stopPropagation();try{sessionStorage.setItem(Je,"1")}catch{}K&&(K.remove(),K=null)}),K.append(ue);const Ut=()=>{x||(x=!0,Ze(!0),Re(),C=0,U&&(U.style.display="none"),K&&(K.remove(),K=null))};K.addEventListener("click",Ut),K.addEventListener("keydown",ne=>{(ne.key==="Enter"||ne.key===" ")&&(ne.preventDefault(),Ut())}),w.insertBefore(K,V)};if(!document.getElementById("ocw-teaser-style")){const $=document.createElement("style");$.id="ocw-teaser-style",$.textContent="@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",document.head.append($)}g=Tt,Tt();const Ze=$=>{$?(T.style.display="flex",requestAnimationFrame(()=>{T.style.opacity="1",T.style.transform="scale(1)"})):(T.style.opacity="0",T.style.transform="scale(.95)",setTimeout(()=>{x||(T.style.display="none")},180))};V.addEventListener("click",()=>{if(x=!x,Ze(x),Re(),x){C=0,U&&(U.style.display="none");try{sessionStorage.setItem(Je,"1")}catch{}}g==null||g()}),z=$=>{$.key==="Escape"&&x&&(x=!1,Ze(!1),Re())},document.addEventListener("keydown",z)}const b=()=>{x||(C++,U&&(U.textContent=String(C),U.style.display="flex"))},_=()=>{try{const h=Gn();if(!h)return;h.state==="suspended"&&h.resume().catch(()=>{});const y=h.createOscillator(),T=h.createGain();y.connect(T),T.connect(h.destination),y.frequency.setValueAtTime(880,h.currentTime),y.frequency.exponentialRampToValueAtTime(440,h.currentTime+.15),T.gain.setValueAtTime(.3,h.currentTime),T.gain.exponentialRampToValueAtTime(.001,h.currentTime+.3),y.start(),y.stop(h.currentTime+.3)}catch{}},R=[],j=h=>{for(;R.length;){const y=R.shift();f.add({clientMsgId:y.clientMsgId,content:y.content,ts:Date.now()}),m.send({type:"send",conversationId:h,clientMsgId:y.clientMsgId,content:y.content})}};let m;const P=new An(`ocw-e2e-${t.profileId}`);let H=!1;const E=[],q=[];let J=!1;const he=(h,y)=>{P.sealText(y).then(T=>{d&&m.send({type:"send",conversationId:d,clientMsgId:h,content:T})})},Me=(h,y,T)=>{P.sealText(y,T).then(N=>{d&&m.send({type:"send",conversationId:d,clientMsgId:h,content:N})})},v=()=>{for(;E.length;){const h=E.shift();he(h.clientMsgId,h.text)}for(;q.length;){const h=q.shift();he(h.clientMsgId,h.text)}},M=h=>{m.send({type:"fetchPrekey",targetUserId:h})},O=t.i18n??{},G=["ar","he","fa","ur"],F=typeof navigator<"u"?(navigator.language??"").slice(0,2).toLowerCase():"";G.includes(F)&&!t.el.dir&&(t.el.dir="rtl",t.el.style.fontFamily=t.el.style.fontFamily||"Tahoma,Arial,system-ui,sans-serif");const Y=`oc_prechat_${t.profileId}_${i.slice(-8)}`,I=new On(t.el,i,{onSend(h){const y=`cm_${Math.random().toString(36).slice(2)}`,T={kind:"text",text:h};l.addOptimistic(y,T),I.render(l),l.e2e?P.ready?he(y,h):J?q.push({clientMsgId:y,text:h}):(E.push({clientMsgId:y,text:h}),l.assignedAgentId&&M(l.assignedAgentId)):d?(f.add({clientMsgId:y,content:T,ts:Date.now()}),m.send({type:"send",conversationId:d,clientMsgId:y,content:T})):R.push({clientMsgId:y,content:T})},async onAttach(h){if(!d)return;const y=`${p}/upload?name=${encodeURIComponent(h.name)}`,T=`cm_${Math.random().toString(36).slice(2)}`;l.addOptimistic(T,{kind:"text",text:`📎 Uploading ${h.name}…`}),I.render(l);try{const N=await fetch(y,{method:"POST",headers:{"content-type":h.type,authorization:`Bearer ${i}`},body:h});if(!N.ok)throw new Error(`Upload failed: ${N.status}`);const{url:Ce,name:Ee,mime:Ke,size:$e}=await N.json();l.addOptimistic(T,{kind:"attachment",url:Ce,name:Ee,mime:Ke,size:$e}),I.render(l),m.send({type:"send",conversationId:d,clientMsgId:T,content:{kind:"attachment",url:Ce,name:Ee,mime:Ke,size:$e}})}catch(N){l.addOptimistic(T,{kind:"text",text:`⚠️ Upload failed: ${N.message}`}),I.render(l)}},onInvoke(h,y){d&&m.send({type:"invoke",conversationId:d,actionId:h,clientInvokeId:`iv_${Math.random().toString(36).slice(2)}`,...y?{inputs:y}:{}})},onTyping(h,y){d&&m.send({type:"typing",conversationId:d,isTyping:h,...y?{preview:y}:{}})},onPreChat(h){try{localStorage.setItem(Y,"1")}catch{}m.send({type:"open",profileId:t.profileId,...t.subjectId?{subjectId:t.subjectId}:{},userInfo:{...h.name?{name:h.name}:{},...h.email?{email:h.email}:{},...h.phone||h.topic?{meta:{...h.phone?{phone:h.phone}:{},...h.topic?{topic:h.topic}:{}}}:{}}});const y=h.callback?`📞 Call-back requested${h.phone?`: ${h.phone}`:""}${h.topic?` — ${h.topic}`:""}`:h.topic?`Topic: ${h.topic}`:"";y&&d&&!l.e2e&&m.send({type:"send",conversationId:d,clientMsgId:`pc_${Math.random().toString(36).slice(2,12)}`,content:{kind:"text",text:y}})},...((Se=t.features)==null?void 0:Se.deflection)!==!1?{onDeflectQuery(h){if(o)return;clearTimeout(n);const y=h.trim();if(y.length<3){I.hideDeflection();return}n=setTimeout(()=>{fetch(`${p}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(y.slice(0,200))}`).then(T=>T.ok?T.json():{articles:[]}).then(T=>I.showDeflection(T.articles??[])).catch(()=>I.hideDeflection())},350)}}:{},onReadUpTo(h){d&&m.send({type:"read",conversationId:d,seq:h})},onLoadMore(){if(!d||!l.e2e)return;const h=l.messages()[0];h&&m.send({type:"history",conversationId:d,beforeSeq:h.seq,limit:20})},onEdit(h,y){d&&m.send({type:"edit",conversationId:d,messageId:h,content:{kind:"text",text:y}})},onDelete(h){d&&m.send({type:"delete",conversationId:d,messageId:h})},...((Ie=t.features)==null?void 0:Ie.reactions)!==!1?{onReact(h,y,T){d&&m.send({type:"react",conversationId:d,messageId:h,emoji:y,remove:T})}}:{},...((kt=t.features)==null?void 0:kt.csat)!==!1?{onCsat(h){d&&fetch(`${p}/conversations/${d}/csat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({score:h})}).catch(()=>{})}}:{},...t.translateLang?{async onTranslate(h){try{const y=await fetch(`${p}/translate`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${i}`},body:JSON.stringify({text:h,targetLang:t.translateLang})});if(!y.ok)return null;const{translated:T}=await y.json();return T}catch{return null}}}:{},...t.onBack?{onBack:t.onBack}:{}},{...t.subject?{subject:t.subject}:{},...t.quickReplies?{quickReplies:t.quickReplies}:{},...t.accent?{accent:t.accent}:{},...t.accent2?{accent2:t.accent2}:{},...t.theme?{theme:t.theme}:{},...t.webfont===!1?{webfont:!1}:{},...(St=t.user)!=null&&St.name||(It=t.user)!=null&&It.avatar?{userInfo:{...t.user.name?{name:t.user.name}:{},...t.user.avatar?{avatar:t.user.avatar}:{}}}:{},i18n:O});try{localStorage.getItem(Y)&&I.completePreChat()}catch{}const ae=t.user&&(t.user.name||t.user.email||t.user.avatar||t.user.meta)?{...t.user.name?{name:t.user.name}:{},...t.user.email?{email:t.user.email}:{},...t.user.avatar?{avatar:t.user.avatar}:{},...t.user.meta?{meta:t.user.meta}:{}}:void 0,ke={type:"open",profileId:t.profileId,...t.kind==="direct"&&t.peerId?{kind:"direct",peerId:t.peerId}:t.subjectId?{subjectId:t.subjectId}:{},...s?{linkFrom:s}:{},...ae?{userInfo:ae}:{},...typeof location<"u"?{pageUrl:location.href}:{},...typeof document<"u"&&document.title?{pageTitle:document.title}:{},...(Ct=t.subject)!=null&&Ct.title?{subjectTitle:t.subject.title}:{},...(Et=t.subject)!=null&&Et.subtitle?{subjectMeta:t.subject.subtitle}:{}};m=new gn({...t.refreshToken?{refreshToken:t.refreshToken}:{},url:r,token:i,open:ke,getCursor:()=>l.highestSeq(),onStatusChange:(h,y)=>I.setConnStatus(h,y),onFrame(h){if(h.type==="opened"){if(d=h.conversation.id,!k){k=!0;for(const y of f.load())m.send({type:"send",conversationId:d,clientMsgId:y.clientMsgId,content:y.content})}Xn(r,i,d,l,I,p),R.length&&j(d)}if(h.type==="ack"&&f.remove(h.clientMsgId),h.type==="prekeyBundle"){h.bundle&&(J=!0,P.x3dhSendTo(h.bundle).then(y=>{const T=[...E.splice(0),...q.splice(0)];for(const N of T)Me(N.clientMsgId,N.text,y);I.render(l)}));return}if(h.type==="message"&&l.e2e){const y=Ln(h.message.content);if(y&&!P.ready){P.x3dhReceiveFrom(y.x3dhIK,y.x3dhEK,y.x3dhSPK,y.x3dhOTP).then(async()=>{await P.openFrame(h),l.apply(h),I.render(l)});return}}if(h.type==="peerkey"){P.onPeerKey(h.key).then(()=>{v(),I.render(l)});return}(async()=>{if(l.e2e&&await P.openFrame(h),l.apply(h),h.type==="manifest"&&(g==null||g()),h.type==="message"&&h.message.senderId!==i&&!h.message.internal&&(b(),_()),l.e2e&&d&&!H){H=!0;const y=await P.initX3DH();m.send({type:"uploadPrekeys",...y});const T=await P.begin();m.send({type:"pubkey",conversationId:d,key:T})}I.render(l)})()}}),m.connect(),I.render(l);const ce=t.launcher?xt(t):null,Z={close:()=>{o=!0,clearTimeout(n),m.close(),w==null||w.remove(),I.destroy(),S&&L&&S.removeEventListener("change",L),z&&(document.removeEventListener("keydown",z),z=null),xe.delete(t.el),ce&&Ae.get(ce)===Z&&Ae.delete(ce)}};return xe.set(t.el,Z),ce&&Ae.set(ce,Z),Z}const Ge="wss://api.paramms.com/ws";function Yn(t,e){const n=t.profileId??t.appId;if(!n)throw new Error("Relay: `profileId` is required (your chatroom id, e.g. 'p_...').");const o=t.subjectId??(t.listingId?`listing_${t.listingId}`:void 0),i=t.launcher??!0,s=t.contextTitle??t.listingTitle??t.subjectTitle,r=t.contextSubtitle??t.listingMeta??t.subjectMeta,p=t.contextStatus??t.listingStatus??t.subjectStatus,l=t.listingPrice??t.subjectPrice,u=s?{title:s,...r?{subtitle:r}:{},...l!=null?{tags:[`$${l.toLocaleString()}`]}:{},...p?{status:p}:{}}:void 0,f=t.subject??u,d=t.userName??t.name,k=t.userEmail??t.email,S=t.userAvatar??t.avatar,L=d||k||S?{...d?{name:d}:{},...k?{email:k}:{},...S?{avatar:S}:{}}:void 0,z=t.user??L,g=t.launcherMessage&&typeof t.launcherMessage=="object"?t.launcherMessage:t.launcherMessage?t.launcherSubtitle?{title:t.launcherMessage,subtitle:t.launcherSubtitle}:t.launcherMessage:void 0;return{el:e,url:t.url??Ge,profileId:n,...t.apiUrl?{apiUrl:t.apiUrl}:{},...o?{subjectId:o}:{},...t.token?{token:t.token}:{},...t.refreshToken?{refreshToken:t.refreshToken}:{},...t.userId?{userId:t.userId}:{},...f?{subject:f}:{},...z?{user:z}:{},...t.quickReplies?{quickReplies:t.quickReplies}:{},...t.i18n?{i18n:t.i18n}:{},...t.features?{features:t.features}:{},...t.accent?{accent:t.accent}:{},...t.accent2?{accent2:t.accent2}:{},...t.theme?{theme:t.theme}:{},...t.webfont===!1?{webfont:!1}:{},...t.translateLang?{translateLang:t.translateLang}:{},...g?{launcherMessage:g}:{},...bt(t)&&!i?{onBack:()=>{be=!0,ve=!1,Le(re)}}:{},launcher:i,position:t.position??"bottom-right"}}let ee=null,D=null,se=!1,re={},be=!1,ve=!1;function bt(t){return!!(t.inbox||t.inboxStart)}let te=null;function Jn(t,e){const n=!e&&!!t.el;if(se&&!n&&(D.innerHTML="",D=null,se=!1),n){const o=typeof t.el=="string"?document.querySelector(t.el):t.el;o instanceof HTMLElement?(D&&D!==o&&!se&&D.remove(),D=o,se=!0):console.error(`[Relay] \`el\` ("${String(t.el)}") did not match any element — falling back to an auto-created host.`)}return(!D||!se&&!D.isConnected)&&(D=document.createElement("div"),D.id="relay-widget-root",document.body.appendChild(D),se=!1),!e&&t.height&&(D.style.height=t.height,D.style.width||(D.style.width="100%")),D}function Le(t){try{const e=t.launcher??!0;te==null||te(),te=null,ee==null||ee.close(),ee=null;const n=Jn(t,e);if(bt(t)&&!e&&be){Zn(t,n);return}ee=mt(Yn(t,n))}catch(e){console.error("[Relay]",e instanceof Error?e.message:e)}}async function Zn(t,e){const n=t.profileId??t.appId;if(!n&&!t.tenantId){console.error("[Relay] `inbox` requires `profileId` or `tenantId`.");return}e.innerHTML="";const o=document.createElement("div");o.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;background:#fff";const i=document.createElement("div");i.style.cssText="position:absolute;inset:0";const s=document.createElement("div");s.style.cssText="position:absolute;inset:0;display:none";const r=document.createElement("button");r.type="button",r.setAttribute("aria-label","Close"),r.textContent="✕",r.style.cssText="position:absolute;top:8px;right:8px;z-index:20;width:32px;height:32px;border-radius:50%;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.05);border:none;color:#1c1b1a;font-size:16px;line-height:1;cursor:pointer",r.onclick=()=>{be=!1,Le(re)},o.append(i,s);const p=!ve&&!!n;p&&o.append(r),e.appendChild(o);let l=null,u=null;te=()=>{u==null||u.close(),l==null||l.close(),e.innerHTML=""};let f;try{({mountChatList:f}=await Promise.resolve().then(()=>ai))}catch(k){console.error("[Relay] could not load the conversation list module.",k),i.isConnected&&(i.style.cssText+=";display:flex;align-items:center;justify-content:center;padding:16px;font:13px system-ui;color:#b91c1c;text-align:center",i.textContent="Could not load conversations.");return}if(!i.isConnected)return;const d=k=>{const S=k.profileId??n;if(!S){console.error("[Relay] conversation row has no chatroom; cannot open it.",k);return}r.style.display="none",u==null||u.close(),u=mt({el:s,url:t.url??Ge,...t.apiUrl?{apiUrl:t.apiUrl}:{},profileId:S,...k.kind==="direct"&&k.peerId?{kind:"direct",peerId:k.peerId}:k.subjectId?{subjectId:k.subjectId}:{},...t.token?{token:t.token}:{},...t.refreshToken?{refreshToken:t.refreshToken}:{},...t.userId?{userId:t.userId}:{},...t.userId||t.userName||t.userEmail||t.userAvatar?{user:{...t.userName?{name:t.userName}:{},...t.userEmail?{email:t.userEmail}:{},...t.userAvatar?{avatar:t.userAvatar}:{}}}:{},...k.subjectTitle?{subject:{title:k.subjectTitle,...k.subjectMeta?{subtitle:k.subjectMeta}:{}}}:{},...t.accent?{accent:t.accent}:{},launcher:!1,onBack:()=>{u==null||u.close(),u=null,s.style.display="none",i.style.display="",r.style.display="",l==null||l.refresh()}}),i.style.display="none",s.style.display=""};l=f({el:i,url:t.url??Ge,...t.apiUrl?{apiUrl:t.apiUrl}:{},...n?{profileId:n}:{},...t.tenantId?{tenantId:t.tenantId}:{},scope:t.inboxScope??"tenant",...p?{reserveCloseSpace:!0}:{},onSelect:d,onNewChat:()=>{const k=n??(l==null?void 0:l.defaultProfileId());k&&d({id:"__new__",profileId:k,state:"open",updatedAt:Date.now()})},...t.token?{token:t.token}:{},...t.userId?{userId:t.userId}:{},...t.accent?{accent:t.accent}:{}})}function vt(t){ve=!!(t.inboxStart&&!(t.launcher??!0)),be=ve,re={...t},Le(re)}function Qn(t){re={...re,...t},Le(re)}function ei(){te==null||te(),te=null,ee==null||ee.close(),ee=null,D&&!se&&D.remove(),D=null,se=!1,be=!1,ve=!1,re={}}function Ye(t,e){switch(t){case"boot":vt(e??{});break;case"update":case"identify":Qn(e??{});break;case"shutdown":ei();break;default:console.warn("[Relay] unknown command:",t)}}function ti(){if(typeof document>"u")return null;const t=document.querySelector("script[data-relay-app]")??document.querySelector("script[data-relay-profile-id]")??document.querySelector("script[data-relay-tenant-id]"),e=t==null?void 0:t.dataset,n=(e==null?void 0:e.relayApp)??(e==null?void 0:e.relayProfileId),o=e==null?void 0:e.relayTenantId;if(!n&&!o)return null;const i=n?{profileId:n}:{};o&&(i.tenantId=o),e.relayUser&&(i.userId=e.relayUser),e.relayToken&&(i.token=e.relayToken),e.relayListing&&(i.listingId=e.relayListing),e.relayAccent&&(i.accent=e.relayAccent),e.relayAccent2&&(i.accent2=e.relayAccent2),e.relayTheme&&(i.theme=e.relayTheme),e.relayWebfont==="false"&&(i.webfont=!1),e.relayUrl&&(i.url=e.relayUrl);const s=e.relayPosition;(s==="bottom-left"||s==="bottom-right")&&(i.position=s),e.relayLauncherMessage&&(i.launcherMessage=e.relayLauncherMessage),e.relayLauncherSubtitle&&(i.launcherSubtitle=e.relayLauncherSubtitle),e.relayLauncher==="false"&&(i.launcher=!1),e.relayUserName&&(i.userName=e.relayUserName),e.relayUserEmail&&(i.userEmail=e.relayUserEmail),e.relayUserAvatar&&(i.userAvatar=e.relayUserAvatar),e.relayContextTitle&&(i.contextTitle=e.relayContextTitle),e.relayContextSubtitle&&(i.contextSubtitle=e.relayContextSubtitle),e.relayContextStatus&&(i.contextStatus=e.relayContextStatus),e.relayListingTitle&&(i.listingTitle=e.relayListingTitle),e.relayListingMeta&&(i.listingMeta=e.relayListingMeta),e.relayListingPrice&&(i.listingPrice=Number(e.relayListingPrice)),e.relayListingStatus&&(i.listingStatus=e.relayListingStatus),e.relayTarget&&(i.el=e.relayTarget),e.relayHeight&&(i.height=e.relayHeight),e.relayInbox==="true"&&(i.inbox=!0),e.relayInbox==="false"&&(i.inbox=!1),e.relayInboxStart==="true"&&(i.inboxStart=!0),e.relayInboxStart==="false"&&(i.inboxStart=!1);const r=e.relayInboxScope;return(r==="tenant"||r==="profile")&&(i.inboxScope=r),e.relayTranslateLang&&(i.translateLang=e.relayTranslateLang),i}if(typeof window<"u"){const t=window,e=t.Relay&&t.Relay.q?t.Relay.q:[];t.Relay=Ye;let n=!1;for(const o of e){const[i,s]=o;i==="boot"&&(n=!0),Ye(i,s)}if(!n){const o=t.relaySettings??ti();o&&vt(o)}}const ni=`
|
|
192
|
+
`,wt="objectchat-widget-styles",Rn=["👍","❤️","😂","😮","😢","🙏"],Dn=400,_n='<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M22 2 11 13M22 2l-7 20-4-9-9-4 20-7z" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function jn(){if(typeof document>"u"||document.getElementById(wt))return;const t=document.createElement("style");t.id=wt,t.textContent=$n,document.head.appendChild(t)}const gt="ocw-webfont";function Nn(){if(typeof document>"u"||document.getElementById(gt))return;const t=document.createElement("link");t.id=gt,t.rel="stylesheet",t.href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Nunito:wght@400;500;600;700&display=swap",document.head.appendChild(t)}function c(t,e,n){const o=document.createElement(t);return e&&(o.className=e),n!==void 0&&(o.textContent=n),o}function qn(t){try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function Ve(t){var e;switch(t.kind){case"text":return t.text;case"system":return typeof((e=t.data)==null?void 0:e.message)=="string"?String(t.data.message):t.event;case"card":return[t.title,t.body].filter(Boolean).join(" — ");case"attachment":return t.name??t.url;case"form":return t.prompt;case"appointment":return`📅 ${t.title} — ${new Date(t.startIso).toLocaleString()}`}}class On{constructor(e,n,o,i={}){a(this,"scroll");a(this,"chips");a(this,"typing");a(this,"quick");a(this,"formHost");a(this,"csatPanel");a(this,"awayNotice");a(this,"headStatus");a(this,"reopenBtn");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,"sendBtn");a(this,"compactObserver",null);a(this,"storeRef",null);a(this,"cfgAccent2");a(this,"scrollCleanup",null);a(this,"translationCache",new Map);a(this,"showingTranslation",new Set);a(this,"subjectBuilt",!1);var w,U,C,x,b,_,R,j,m,P,H;this.root=e,this.me=n,this.h=o,this.cfg=i,jn(),i.webfont!==!1&&Nn(),e.replaceChildren(),e.classList.add("ocw"),i.accent&&e.style.setProperty("--ocw-accent",i.accent);const s=i.accent2??i.accent;s&&e.style.setProperty("--ocw-accent2",s),this.cfgAccent2=i.accent2,e.dataset.theme=i.theme??"light";const r=c("div","ocw-head");if(this.h.onBack){const E=c("button","ocw-back","‹");E.type="button",E.setAttribute("aria-label","Back"),E.addEventListener("click",()=>this.h.onBack()),r.append(E)}const p=c("div","ocw-avatar");if((w=i.userInfo)!=null&&w.avatar){const E=document.createElement("img");E.src=i.userInfo.avatar,E.alt=i.userInfo.name??"You",E.style.cssText="width:100%;height:100%;border-radius:50%;object-fit:cover",p.append(E)}else p.textContent=(U=i.userInfo)!=null&&U.name?i.userInfo.name[0].toUpperCase():"🧑";r.append(p);const l=c("div","ocw-head-main");this.headerName=c("div","ocw-head-name",((C=i.subject)==null?void 0:C.ownerLabel)??((x=i.subject)==null?void 0:x.title)??""),l.append(this.headerName),this.headStatus=c("div","ocw-head-status"),this.headStatus.style.display="none",l.append(this.headStatus),(b=i.subject)!=null&&b.subtitle&&l.append(c("div","ocw-head-meta",i.subject.subtitle)),r.append(l),this.statusBadge=c("span","ocw-badge",((_=i.subject)==null?void 0:_.status)??""),(R=i.subject)!=null&&R.status||(this.statusBadge.style.display="none"),r.append(this.statusBadge),this.e2eBadge=c("span","ocw-e2e","🔒 E2E"),this.e2eBadge.style.display="none",r.append(this.e2eBadge),this.connStatus=c("span","ocw-conn-status"),this.connStatus.style.display="none",r.append(this.connStatus),r.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 u=c("div","ocw-typing-bubble");u.append(c("div","ocw-typing-dot"),c("div","ocw-typing-dot"),c("div","ocw-typing-dot")),this.typing.append(c("div","ocw-dot","🧑"),u),this.quick=c("div","ocw-quick");for(const E of i.quickReplies??[]){const q=c("button",void 0,E);q.addEventListener("click",()=>{this.h.onSend(E),this.quick.style.display="none"}),this.quick.append(q)}this.formHost=c("div","ocw-form-host"),this.csatPanel=c("div","ocw-csat"),this.csatPanel.style.display="none",this.awayNotice=c("div","ocw-away"),this.awayNotice.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=((j=i.i18n)==null?void 0:j.placeholder)??"Message…";const f=c("button","ocw-sendbtn");f.type="button";const d=(m=i.i18n)==null?void 0:m.send;d?(f.textContent=d,f.classList.add("ocw-sendbtn-label"),f.setAttribute("aria-label",d)):(f.innerHTML=_n,f.setAttribute("aria-label","Send message")),f.disabled=!0,this.sendBtn=f,f.addEventListener("click",()=>this.flushSend()),this.input.addEventListener("input",()=>{var E,q;this.sendBtn.disabled=this.input.value.trim().length===0,this.autoGrowInput(),this.storeRef&&!this.storeRef.messages().some(J=>J.senderRole==="guest")?(q=(E=this.h).onDeflectQuery)==null||q.call(E,this.input.value):this.hideDeflection()}),this.input.addEventListener("keydown",E=>{E.isComposing||E.keyCode===229||(E.key==="Enter"&&!E.shiftKey?(E.preventDefault(),this.flushSend()):this.signalTyping())});const k=c("button","ocw-attach","📎");k.title="Attach image or file";const S=document.createElement("input");S.type="file",S.accept="image/*,.pdf,.txt,.doc,.docx",S.style.display="none",k.addEventListener("click",()=>S.click()),S.addEventListener("change",()=>{var E;(E=S.files)!=null&&E[0]&&this.h.onAttach&&this.h.onAttach(S.files[0]),S.value=""});const L=c("div","ocw-input");L.append(k,S,this.input,f);const z=c("div","ocw-footer");((P=i.i18n)==null?void 0:P.poweredBy)!==void 0?z.textContent=i.i18n.poweredBy:z.innerHTML='Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>',this.footer=z,this.reopenBtn=c("button","ocw-reopen",((H=this.cfg.i18n)==null?void 0:H.reopen)??"Reopen conversation"),this.reopenBtn.type="button",this.reopenBtn.addEventListener("click",()=>{this.reopenBtn.style.display="none";const E=this.root.querySelector(".ocw-input textarea");E==null||E.focus()}),e.append(r,this.chips,this.scroll,this.typing,this.quick,this.formHost,this.csatPanel,this.preChatPanel,this.deflectPanel,this.awayNotice,L,this.reopenBtn,this.footer);const g=E=>{e.classList.toggle("ocw-compact",E>0&&E<Dn)};g(e.clientWidth),typeof ResizeObserver<"u"&&(this.compactObserver=new ResizeObserver(E=>{var J;const q=((J=E[0])==null?void 0:J.contentRect.width)??e.clientWidth;g(q)}),this.compactObserver.observe(e))}getScrollEl(){return this.scroll}setScrollCleanup(e){var n;(n=this.scrollCleanup)==null||n.call(this),this.scrollCleanup=e}destroy(){var e,n;(e=this.scrollCleanup)==null||e.call(this),this.scrollCleanup=null,this.typingTimer&&(clearTimeout(this.typingTimer),this.typingTimer=null),(n=this.compactObserver)==null||n.disconnect(),this.compactObserver=null}flushSend(){this.hideDeflection();const e=this.input.value.trim();e&&(this.input.value="",this.sendBtn.disabled=!0,this.autoGrowInput(),this.h.onTyping(!1),this.h.onSend(e))}autoGrowInput(){this.input.style.height="auto";const e=this.input.scrollHeight;e>0?this.input.style.height=`${Math.min(e,120)}px`:this.input.style.removeProperty("height")}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 S,L,z,g,w,U,C,x;if(this.storeRef=e,e.accent&&(this.root.style.setProperty("--ocw-accent",e.accent),this.root.style.setProperty("--ocw-accent2",this.cfgAccent2??e.accent)),this.e2eBadge.style.display=e.e2e?"inline-flex":"none",this.buildSubjectCard(e),e.subject){const b=(S=this.cfg.subject)==null?void 0:S.ownerLabel;b&&(this.headerName.textContent=b)}this.quick.style.display=e.messages().length===0?"flex":"none",this.chips.replaceChildren();const n=e.visibleActions();this.chips.style.display=n.length?"flex":"none";for(const b of n)this.chips.append(this.chipEl(b));const o=this.scroll.scrollHeight,i=this.scroll.scrollTop;if(this.scroll.replaceChildren(),this.subjectCard.childNodes.length&&this.scroll.append(this.subjectCard),e.hasMoreHistory){const b=c("div","ocw-load-more");b.textContent="↑ Loading earlier messages…",b.style.pointerEvents="none",this.scroll.append(b)}let s=0,r=null;for(const b of e.messages()){const _=b.senderRole!=="system"&&b.senderId!==this.me&&!b.internal&&b.senderId!==r;this.scroll.append(this.messageEl(b,e,_)),b.senderRole!=="system"&&(r=b.senderId),b.senderId!==this.me&&b.seq>s&&(s=b.seq)}i>20?this.scroll.scrollTop=this.scroll.scrollHeight-o+i:this.scroll.scrollTop=this.scroll.scrollHeight,s>0&&this.h.onReadUpTo(s);const p=[...e.typing];this.typing.classList.toggle("active",p.length>0);const l=this.typing.querySelector(".ocw-typing-bubble");l&&l.setAttribute("aria-label",p.length?"typing":""),this.footer.style.display=e.whiteLabel?"none":"block";const u=e.messages().some(b=>b.senderRole==="guest");if(!!((L=e.preChat)!=null&&L.enabled)&&!this.preChatDone&&!u&&(e.preChat.showWhen!=="offline"||e.offline))this.preChatBuilt||this.buildPreChatPanel(e.preChat),this.preChatPanel.style.display="block",this.awayNotice.style.display="none",(z=this.root.querySelector(".ocw-input"))==null||z.style.setProperty("display","none");else{if(this.preChatPanel.style.display="none",e.offline){this.awayNotice.firstChild||this.awayNotice.append(c("span","ocw-away-icon","🌙"),c("span","",""));const b=this.awayNotice.lastChild;b.textContent=e.offlineMessage||((g=this.cfg.i18n)==null?void 0:g.offline)||"We're away right now — send your message and we'll reply as soon as we're back.",this.awayNotice.style.display="flex"}else this.awayNotice.style.display="none";(w=this.root.querySelector(".ocw-input"))==null||w.style.removeProperty("display")}const d=["resolved","closed","sold","issued","checked_out"];this.h.onCsat&&!this.csatSubmitted&&d.includes(e.state)&&e.messages().length>0&&(this.csatPanel.style.display==="none"&&this.buildCsatPanel(),this.csatPanel.style.display="block");const k=d.includes(e.state);if(e.offline?(this.headStatus.textContent=`● ${e.offlineMessage||((U=this.cfg.i18n)==null?void 0:U.away)||"Away"}`,this.headStatus.className="ocw-head-status away",this.headStatus.style.display=""):e.conversationId?(this.headStatus.textContent=`● ${((C=this.cfg.i18n)==null?void 0:C.online)??"Online"}`,this.headStatus.className="ocw-head-status online",this.headStatus.style.display=""):this.headStatus.style.display="none",k&&e.messages().length>0){const b=c("div","ocw-resolved-note",`— ${((x=this.cfg.i18n)==null?void 0:x.resolved)??"Marked as resolved"} —`);this.scroll.append(b),this.reopenBtn.style.display="block"}else this.reopenBtn.style.display="none"}setConnStatus(e,n){if(e==="open"){this.connStatus.style.display="none";return}this.connStatus.style.display="";const o=e==="error";this.connStatus.className=`ocw-conn-status${o?" err":e==="reconnecting"?" warn":""}`,this.connStatus.textContent=o?`⚠ ${n??"Chat unavailable"}`:e==="reconnecting"?n??"↻ reconnecting…":"● connecting…"}buildPreChatPanel(e){var l;this.preChatBuilt=!0,this.preChatPanel.replaceChildren(),this.preChatPanel.append(c("div","ocw-prechat-title",e.title??"Before we start…"));const n=c("div","ocw-offline-form"),o={};for(const u of e.fields??["name","email"]){const f=c("input","ocw-offline-input");f.type=u==="email"?"email":u==="phone"?"tel":"text",f.placeholder=u==="name"?"Your name":u==="email"?"Your email":"Your phone number",o[u]=f,n.append(f)}let i=null;if((l=e.topics)!=null&&l.length){i=c("select",void 0);const u=document.createElement("option");u.value="",u.textContent="What is this about?",i.append(u);for(const f of e.topics){const d=document.createElement("option");d.value=f,d.textContent=f,i.append(d)}n.append(i)}let s=null,r=null;if(e.callbackOption){const u=c("label","ocw-prechat-cb");s=document.createElement("input"),s.type="checkbox",u.append(s,document.createTextNode("📞 Request a call back")),n.append(u),o.phone||(r=c("input","ocw-offline-input"),r.type="tel",r.placeholder="Phone number for the call",r.style.display="none",s.addEventListener("change",()=>r.style.setProperty("display",s.checked?"block":"none")),n.append(r))}const p=c("button","ocw-offline-submit","Start chat");p.type="button",p.addEventListener("click",()=>{var k,S,L,z,g,w,U;const u=(k=o.email)==null?void 0:k.value.trim();if(o.email&&(!u||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(u))){o.email.focus();return}const f=!!(s!=null&&s.checked),d=(((S=o.phone)==null?void 0:S.value)??(r==null?void 0:r.value)??"").trim();if(f&&!d){(L=o.phone??r)==null||L.focus();return}if(i&&((z=e.topics)!=null&&z.length)&&!i.value){i.focus();return}p.disabled=!0,this.completePreChat(),(U=(w=this.h).onPreChat)==null||U.call(w,{...(g=o.name)!=null&&g.value.trim()?{name:o.name.value.trim()}:{},...u?{email:u}:{},...d?{phone:d}:{},...i!=null&&i.value?{topic:i.value}:{},...f?{callback:!0}:{}})}),n.append(p),this.preChatPanel.append(n)}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 n of e.slice(0,3)){const o=c("button","ocw-deflect-card");o.append(c("div","ocw-deflect-q",n.title),c("div","ocw-deflect-a",n.answer)),o.addEventListener("click",()=>o.classList.toggle("open")),this.deflectPanel.append(o)}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"),n=[];for(let o=1;o<=5;o++){const i=c("button","ocw-csat-star","★");i.dataset.score=String(o),i.addEventListener("mouseenter",()=>n.forEach((s,r)=>s.classList.toggle("lit",r<o))),i.addEventListener("mouseleave",()=>n.forEach(s=>s.classList.remove("lit"))),i.addEventListener("click",()=>{var s,r;this.csatSubmitted=!0,this.csatPanel.replaceChildren(c("div","ocw-csat-done",`Thanks for your ${o}★ rating!`)),(r=(s=this.h).onCsat)==null||r.call(s,o)}),n.push(i),e.append(i)}this.csatPanel.append(e)}buildSubjectCard(e){if(this.subjectBuilt)return;const n=e.subject,o=this.cfg.subject,i=(n==null?void 0:n.title)??(o==null?void 0:o.title);if(!i)return;this.subjectBuilt=!0,this.subjectCard.replaceChildren(),this.subjectCard.append(c("div","ocw-subject-title",i)),o!=null&&o.subtitle&&this.subjectCard.append(c("div","ocw-subject-sub",o.subtitle));const s=c("div","ocw-tags");if(n)for(const[p,l]of Object.entries(n.fields))s.append(c("span","ocw-tag",`${p}: ${l}`));else for(const p of(o==null?void 0:o.tags)??[])s.append(c("span","ocw-tag",p));s.childNodes.length&&this.subjectCard.append(s);const r=(n==null?void 0:n.state)??(o==null?void 0:o.status);r&&(this.statusBadge.textContent=r,this.statusBadge.style.display="inline-flex")}chipEl(e){const n=c("button","ocw-chip",e.icon?`${e.icon} ${e.label}`:e.label);return n.dataset.actionId=e.id,n.addEventListener("click",async()=>{var o;e.confirm&&!await this.confirm(e.label)||((o=e.input)!=null&&o.length?this.openForm(e):this.h.onInvoke(e.id))}),n}confirm(e){return new Promise(n=>{const o=c("div","ocw-modal"),i=c("div","ocw-modal-card");i.append(c("div","ocw-modal-title",e)),i.append(c("div","ocw-modal-body",`Confirm “${e}”?`));const s=c("div","ocw-modal-actions"),r=c("button","ocw-modal-cancel","Cancel"),p=c("button","ocw-modal-ok","Confirm"),l=u=>{o.remove(),n(u)};r.addEventListener("click",()=>l(!1)),p.addEventListener("click",()=>l(!0)),o.addEventListener("click",u=>{u.target===o&&l(!1)}),s.append(r,p),i.append(s),o.append(i),this.root.append(o),p.focus()})}openForm(e){var p,l;this.formHost.replaceChildren();const n=c("div","ocw-form");n.append(c("div","ocw-form-title",e.icon?`${e.icon} ${e.label}`:e.label));const o=new Map;for(const u of e.input??[]){const f=c("label","ocw-form-row");if(f.append(c("span","ocw-form-lbl",u.label)),u.type==="select"&&((p=u.options)!=null&&p.length)){const d=c("select","ocw-form-input");u.required||d.append(c("option",void 0,"— select —"));for(const k of u.options){const S=c("option");S.value=k,S.textContent=k,d.append(S)}u.required&&(d.required=!0),f.append(d),o.set(u.name,d)}else{const d=c("input","ocw-form-input");d.type=u.type==="number"?"number":u.type==="date"?"datetime-local":"text",u.required&&(d.required=!0),f.append(d),o.set(u.name,d)}n.append(f)}const i=c("div","ocw-form-actions"),s=c("button","ocw-form-cancel","Cancel"),r=c("button","ocw-form-submit","Send");s.addEventListener("click",()=>this.formHost.replaceChildren()),r.addEventListener("click",()=>{const u={};for(const[f,d]of o){if(d.required&&!d.value){d.style.borderColor="#e5484d";return}u[f]=d.type==="number"?Number(d.value):d.value}this.formHost.replaceChildren(),this.h.onInvoke(e.id,u)}),i.append(s,r),n.append(i),this.formHost.append(n),(l=o.values().next().value)==null||l.focus()}messageEl(e,n,o=!1){var k,S,L,z;if(e.senderRole==="system"){const g=c("div","ocw-sys");return g.textContent=e.deletedAt?"message deleted":Ve(e.content),g}const i=e.senderId===this.me,s=!!e.internal,r=c("div",`ocw-row ${s?"ocw-note mine":i?"mine":"theirs"} ${e.senderRole==="bot"?"ocw-bot":""}`);!i&&!s&&r.append(c("div","ocw-dot",e.senderRole==="bot"?"🤖":"🧑"));const p=c("div");if(o){const g=e.senderRole==="bot"?((k=this.cfg.i18n)==null?void 0:k.aiAssistant)??"AI Assistant":((S=this.cfg.subject)==null?void 0:S.ownerLabel)??((L=this.cfg.subject)==null?void 0:L.title)??"Support";p.append(c("div","ocw-msg-sender",g))}const l=c("div","ocw-bubble-wrap");if(e.replyToId){const g=c("div","ocw-reply-to","↩ replying to a message");g.style.cssText="font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",p.append(g)}const u=c("div","ocw-bubble");let f=null;if(e.deletedAt)u.append(c("span","ocw-deleted","message deleted"));else if(e.content.kind==="attachment"){const g=e.content;if((z=g.mime)!=null&&z.startsWith("image/")){const w=document.createElement("img");w.src=g.url,w.alt=g.name??"image",w.style.cssText="max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer",w.addEventListener("click",()=>window.open(g.url,"_blank")),u.append(w)}else{const w=document.createElement("a");w.href=g.url,w.target="_blank",w.rel="noopener",w.style.cssText="display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none",w.append(c("span",void 0,"📄"),c("span",void 0,g.name??"file")),u.append(w)}}else if(e.content.kind==="appointment"){const g=e.content,w=c("div","ocw-appt");w.append(c("div","ocw-appt-title",`📅 ${g.title}`)),w.append(c("div","ocw-appt-time",new Date(g.startIso).toLocaleString()+" – "+new Date(g.endIso).toLocaleTimeString())),g.location&&w.append(c("div","ocw-appt-loc",`📍 ${g.location}`)),g.description&&w.append(c("div","ocw-appt-desc",g.description));const U=c("div","ocw-appt-links"),C=document.createElement("a");C.href=g.googleUrl,C.target="_blank",C.rel="noopener",C.className="ocw-appt-btn",C.textContent="📅 Add to Google Calendar";const x=document.createElement("a");x.href=g.icalUrl,x.download=`${g.title}.ics`,x.className="ocw-appt-btn ocw-appt-btn-sec",x.textContent="🍎 Apple / iCal",U.append(C,x),w.append(U),u.append(w)}else f=document.createTextNode(Ve(e.content)),u.append(f),e.editedAt&&u.append(c("span","ocw-edited","(edited)"));if(l.append(u),!i&&!s&&this.h.onTranslate&&e.content.kind==="text"&&!e.deletedAt&&e.seq>0&&f){const g=e.content.text;if(g.trim()){const w=c("button","ocw-translate-btn","🌐");w.type="button",w.title="Translate",w.addEventListener("click",U=>{if(U.stopPropagation(),this.showingTranslation.has(e.id)){this.showingTranslation.delete(e.id),f.textContent=g,w.textContent="🌐",w.title="Translate";return}const C=this.translationCache.get(e.id);if(C!==void 0){this.showingTranslation.add(e.id),f.textContent=C,w.textContent="↩",w.title="Show original";return}w.textContent="⏳",this.h.onTranslate(g).then(x=>{if(x===null){w.textContent="⚠️",w.title="Translation unavailable",setTimeout(()=>{w.textContent="🌐",w.title="Translate"},1500);return}this.translationCache.set(e.id,x),this.showingTranslation.add(e.id),f.textContent=x,w.textContent="↩",w.title="Show original"})}),l.append(w)}}if(i&&!e.deletedAt&&e.seq>0&&(this.h.onEdit??this.h.onDelete)){const g=c("div","ocw-msg-menu");if(this.h.onEdit){const w=c("button",void 0,"✏️");w.title="Edit",w.addEventListener("click",U=>{U.stopPropagation();const C=Ve(e.content),x=document.createElement("textarea");x.value=C,x.rows=Math.min(4,Math.ceil(C.length/40)+1),x.style.cssText="width:100%;resize:vertical;border:1px solid var(--ocw-accent);border-radius:8px;padding:6px 10px;font:inherit;font-size:14px;background:var(--ocw-card);color:#1c1b1a;box-sizing:border-box";const b=c("button","ocw-form-submit","Save");b.style.cssText="margin-top:6px;padding:5px 14px;font-size:13px";const _=c("button","ocw-form-cancel","Cancel");_.style.cssText="margin-top:6px;padding:5px 10px;font-size:13px";const R=c("div");R.style.cssText="display:flex;gap:6px;justify-content:flex-end",R.append(_,b);const j=c("div");j.append(x,R),u.replaceChildren(j),x.focus(),x.select();const m=()=>u.replaceChildren(f??document.createTextNode(C));_.addEventListener("click",m),b.addEventListener("click",()=>{const P=x.value.trim();P&&P!==C&&this.h.onEdit(e.id,P),m()}),x.addEventListener("keydown",P=>{P.key==="Enter"&&!P.shiftKey&&(P.preventDefault(),b.click()),P.key==="Escape"&&m()})}),g.append(w)}if(this.h.onDelete){const w=c("button","del","🗑");w.title="Delete",w.addEventListener("click",U=>{U.stopPropagation(),this.h.onDelete(e.id)}),g.append(w)}l.append(g)}if(p.append(l),this.h.onReact&&!e.deletedAt&&e.seq>0){const g=c("div","ocw-react-wrap"),w=c("div","ocw-react");if(e.reactions&&Object.keys(e.reactions).length)for(const[x,b]of Object.entries(e.reactions)){const _=c("button",`ocw-react-pill${b.includes(this.me)?" mine":""}`,`${x} ${b.length}`);_.addEventListener("click",()=>{var R,j;return(j=(R=this.h).onReact)==null?void 0:j.call(R,e.id,x,b.includes(this.me))}),w.append(_)}const U=c("button","ocw-react-btn","+"),C=c("div","ocw-react-picker");for(const x of Rn){const b=c("button",void 0,x);b.addEventListener("click",_=>{var j,m,P,H;_.stopPropagation();const R=(m=(j=e.reactions)==null?void 0:j[x])==null?void 0:m.includes(this.me);(H=(P=this.h).onReact)==null||H.call(P,e.id,x,!!R),C.style.display="none"}),C.append(b)}C.style.display="none",U.addEventListener("click",x=>{x.stopPropagation();const b=C.style.display==="none";C.style.display=b?"flex":"none",b&&document.addEventListener("click",()=>{C.style.display="none"},{once:!0})}),w.append(U),g.append(w,C),p.append(g)}else e.reactions&&Object.keys(e.reactions).length&&p.append(c("div","ocw-react",Object.entries(e.reactions).map(([g,w])=>`${g}${w.length}`).join(" ")));const d=c("div","ocw-time ocw-meta",qn(e.ts));if(i&&e.status){const g=c("span",`ocw-tick${e.status==="read"?" read":e.status==="delivered"?" delivered":""}`,Hn(e.status));d.append(g)}return i&&e.seq>0&&n.lastReadByOthers>=e.seq&&d.append(c("span","ocw-seen"," · Seen")),p.append(d),r.append(p),r}}function Hn(t){switch(t){case"read":return"✓✓";case"delivered":return"✓✓";case"sent":return"✓";default:return"🕓"}}const Fn=20;function Xe(t,e){var l;const n=t.trim().replace(/\/+$/,""),o=(l=n.match(/^(https|http|wss|ws):\/\//))==null?void 0:l[1],i=o?o==="https"||o==="wss":!0,s=(o?n.slice(o.length+3):n).replace(/\/ws$/,""),r=e?e.trim().replace(/\/+$/,""):`${i?"https":"http"}://${s}`;return{wsUrl:`${i?"wss":"ws"}://${s}/ws`,httpBase:r}}function Wn(t){return Xe(t).httpBase}function Vn(t,e,n,o){const i=`beforeSeq=${n}&limit=${o}`;return[`${t}/conversations/${e}/messages?${i}`,`${t}/conversations/${e}/history?${i}`]}async function yt(t,e,n,o,i=Fn){let s,r=!1;for(const p of Vn(t,e,o,i))try{const l=await fetch(p,{headers:{authorization:`Bearer ${n}`}});if(r=!0,!l.ok)continue;const u=await l.json();return{messages:u.messages??[],hasMore:u.hasMore??!1}}catch(l){s=l}return r?console.error(`[chat-widget] history request to ${t} was rejected for conversation ${e}.`):console.error(`[chat-widget] could not load history from ${t} — the request never reached the server. This is almost always CORS: add this site's origin to the chatroom's allowed origins (dashboard → chatroom → allowed origins) or to the server's CORS_ORIGINS.`,s),null}async function Xn(t,e,n,o,i,s){const r=s?s.replace(/\/+$/,""):Wn(t),p=await yt(r,n,e,Number.MAX_SAFE_INTEGER);if(!p||(p.messages.length?(o.apply({type:"sync",conversationId:n,messages:p.messages}),o.apply({type:"history",conversationId:n,messages:[],hasMore:p.hasMore}),i.render(o)):o.apply({type:"history",conversationId:n,messages:[],hasMore:!1}),!p.hasMore))return;let l=!1;const u=async()=>{if(l||!o.hasMoreHistory)return;l=!0;const S=o.messages()[0];if(!S){l=!1;return}const L=await yt(r,n,e,S.seq);L&&(o.apply({type:"history",conversationId:n,messages:L.messages,hasMore:L.hasMore}),i.render(o)),l=!1},f=i.getScrollEl();if(!f)return;let d=!1;setTimeout(()=>{d=!0},300);const k=()=>{d&&f.scrollTop<80&&o.hasMoreHistory&&!l&&u()};f.addEventListener("scroll",k,{passive:!0}),i.setScrollCleanup(()=>f.removeEventListener("scroll",k))}const xe=new WeakMap,Ae=new Map;function xt(t){return`relay-launcher::${t.profileId}::${t.subjectId??""}`}let me=null;function Gn(){if(me&&me.state!=="closed")return me;try{return me=new AudioContext,me}catch{return null}}function mt(t){var pe,Se,Ie,kt,St,It,Ct,Et;xe.has(t.el)&&(xe.get(t.el).close(),xe.delete(t.el)),t.launcher&&((pe=Ae.get(xt(t)))==null||pe.close());const e=tt();let n,o=!1;const i=t.token??t.userId??e,s=i!==e?e:void 0,{wsUrl:r,httpBase:p}=Xe(t.url,t.apiUrl);let l=new wn(i);const u=t.subjectId?`${i}::${t.subjectId}`:i,f=new vn(u);let d,k=!1,S=null,L=null,z=null,g=null;!t.launcher&&!t.el.style.height&&t.el.clientHeight===0&&(t.el.style.width=t.el.style.width||"100%",t.el.style.height="600px");for(const h of f.load())l.addOptimistic(h.clientMsgId,h.content);let w=null,U=null,C=0,x=!t.launcher;if(t.launcher){const y=(t.position??"bottom-right").includes("right");w=document.createElement("div"),w.style.cssText=`position:fixed;${y?"right:20px":"left:20px"};bottom:20px;z-index:9999;display:flex;flex-direction:column;align-items:${y?"flex-end":"flex-start"};gap:12px`;const T=document.createElement("div"),N=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(max-width: 479px)"):null,Ce=$=>{t.el.classList.toggle("ocw-fs",$),T.style.cssText=$?["position:fixed","inset:0","width:100%","height:100dvh","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:min(380px, calc(100vw - 40px))","height:min(600px, calc(100dvh - 108px))","border-radius:28px","overflow:hidden","box-shadow:0 12px 32px rgba(108,92,231,.14)","display:none","flex-direction:column","background:#fff","transform-origin:bottom "+(y?"right":"left"),"transition:opacity .18s,transform .18s","opacity:0","transform:scale(.95)"].join(";")};Ce((N==null?void 0:N.matches)??!1);const Ee=$=>Ce($.matches);N==null||N.addEventListener("change",Ee),S=N,L=Ee,t.el.style.cssText="width:100%;height:100%;overflow:hidden",T.append(t.el);const Ke='<svg viewBox="0 0 24 24" width="26" height="26" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',$e='<svg viewBox="0 0 24 24" width="22" height="22" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>',V=document.createElement("button");V.type="button",V.style.cssText=["width:56px;height:56px;border-radius:50%",`background:${t.accent??"#6c5ce7"}`,"color:#fff;border:none;cursor:pointer","box-shadow:0 12px 32px rgba(108,92,231,.14)","position:relative;flex:none","display:flex;align-items:center;justify-content:center","transition:transform .15s"].join(";"),V.onmouseenter=()=>{V.style.transform="scale(1.08)"},V.onmouseleave=()=>{V.style.transform="scale(1)"},U=document.createElement("span"),U.style.cssText="position:absolute;top:-4px;right:-4px;background:#4c6fff;color:#fff;border-radius:50%;width:20px;height:20px;font-size:11px;font-weight:700;display:none;align-items:center;justify-content:center";const Re=()=>{V.innerHTML=x?$e:Ke,V.setAttribute("aria-label",x?"Close chat":"Open chat"),V.setAttribute("aria-expanded",String(x)),V.append(U)};Re(),w.append(T,V),document.body.append(w);const Je=`ocw-teaser-dismissed::${t.profileId}`,De=typeof t.launcherMessage=="string"?{title:t.launcherMessage}:t.launcherMessage;let K=null;const ci=()=>{try{return sessionStorage.getItem(Je)==="1"}catch{return!1}},li='<svg viewBox="0 0 24 24" width="15" height="15" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',Tt=()=>{const $=De!=null&&De.title?De:l.launcherMessage??void 0;if(!(!!($!=null&&$.title)&&!x&&!ci())){K&&(K.remove(),K=null);return}if(K)return;K=document.createElement("div"),K.setAttribute("role","button"),K.setAttribute("tabindex","0"),K.setAttribute("aria-label",$.title),K.style.cssText=["max-width:280px","background:#fff","border-radius:16px","box-shadow:0 12px 32px rgba(108,92,231,.14)","padding:14px 40px 14px 16px","position:relative","cursor:pointer","font-family:inherit",`align-self:${y?"flex-end":"flex-start"}`,"animation:ocw-teaser-in .22s ease-out"].join(";");const Qe=document.createElement("div");if(Qe.textContent=$.title,Qe.style.cssText="font-size:15px;font-weight:600;color:#111;line-height:1.35",K.append(Qe),$.subtitle){const ne=document.createElement("div");ne.style.cssText="display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";const et=document.createElement("span");et.innerHTML=li,et.style.cssText=`color:${t.accent??"#6c5ce7"};display:inline-flex`;const Pt=document.createElement("span");Pt.textContent=$.subtitle,ne.append(et,Pt),K.append(ne)}const ue=document.createElement("button");ue.type="button",ue.setAttribute("aria-label","Dismiss"),ue.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 6 6 18M6 6l12 12" stroke="currentColor" stroke-width="2.5" stroke-linecap="round"/></svg>',ue.style.cssText="position:absolute;top:8px;right:8px;width:24px;height:24px;border:none;border-radius:50%;background:#f3f4f6;color:#6b7280;cursor:pointer;display:flex;align-items:center;justify-content:center;padding:0",ue.addEventListener("click",ne=>{ne.stopPropagation();try{sessionStorage.setItem(Je,"1")}catch{}K&&(K.remove(),K=null)}),K.append(ue);const Ut=()=>{x||(x=!0,Ze(!0),Re(),C=0,U&&(U.style.display="none"),K&&(K.remove(),K=null))};K.addEventListener("click",Ut),K.addEventListener("keydown",ne=>{(ne.key==="Enter"||ne.key===" ")&&(ne.preventDefault(),Ut())}),w.insertBefore(K,V)};if(!document.getElementById("ocw-teaser-style")){const $=document.createElement("style");$.id="ocw-teaser-style",$.textContent="@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",document.head.append($)}g=Tt,Tt();const Ze=$=>{$?(T.style.display="flex",requestAnimationFrame(()=>{T.style.opacity="1",T.style.transform="scale(1)"})):(T.style.opacity="0",T.style.transform="scale(.95)",setTimeout(()=>{x||(T.style.display="none")},180))};V.addEventListener("click",()=>{if(x=!x,Ze(x),Re(),x){C=0,U&&(U.style.display="none");try{sessionStorage.setItem(Je,"1")}catch{}}g==null||g()}),z=$=>{$.key==="Escape"&&x&&(x=!1,Ze(!1),Re())},document.addEventListener("keydown",z)}const b=()=>{x||(C++,U&&(U.textContent=String(C),U.style.display="flex"))},_=()=>{try{const h=Gn();if(!h)return;h.state==="suspended"&&h.resume().catch(()=>{});const y=h.createOscillator(),T=h.createGain();y.connect(T),T.connect(h.destination),y.frequency.setValueAtTime(880,h.currentTime),y.frequency.exponentialRampToValueAtTime(440,h.currentTime+.15),T.gain.setValueAtTime(.3,h.currentTime),T.gain.exponentialRampToValueAtTime(.001,h.currentTime+.3),y.start(),y.stop(h.currentTime+.3)}catch{}},R=[],j=h=>{for(;R.length;){const y=R.shift();f.add({clientMsgId:y.clientMsgId,content:y.content,ts:Date.now()}),m.send({type:"send",conversationId:h,clientMsgId:y.clientMsgId,content:y.content})}};let m;const P=new An(`ocw-e2e-${t.profileId}`);let H=!1;const E=[],q=[];let J=!1;const he=(h,y)=>{P.sealText(y).then(T=>{d&&m.send({type:"send",conversationId:d,clientMsgId:h,content:T})})},Me=(h,y,T)=>{P.sealText(y,T).then(N=>{d&&m.send({type:"send",conversationId:d,clientMsgId:h,content:N})})},v=()=>{for(;E.length;){const h=E.shift();he(h.clientMsgId,h.text)}for(;q.length;){const h=q.shift();he(h.clientMsgId,h.text)}},M=h=>{m.send({type:"fetchPrekey",targetUserId:h})},O=t.i18n??{},G=["ar","he","fa","ur"],F=typeof navigator<"u"?(navigator.language??"").slice(0,2).toLowerCase():"";G.includes(F)&&!t.el.dir&&(t.el.dir="rtl",t.el.style.fontFamily=t.el.style.fontFamily||"Tahoma,Arial,system-ui,sans-serif");const Y=`oc_prechat_${t.profileId}_${i.slice(-8)}`,I=new On(t.el,i,{onSend(h){const y=`cm_${Math.random().toString(36).slice(2)}`,T={kind:"text",text:h};l.addOptimistic(y,T),I.render(l),l.e2e?P.ready?he(y,h):J?q.push({clientMsgId:y,text:h}):(E.push({clientMsgId:y,text:h}),l.assignedAgentId&&M(l.assignedAgentId)):d?(f.add({clientMsgId:y,content:T,ts:Date.now()}),m.send({type:"send",conversationId:d,clientMsgId:y,content:T})):R.push({clientMsgId:y,content:T})},async onAttach(h){if(!d)return;const y=`${p}/upload?name=${encodeURIComponent(h.name)}`,T=`cm_${Math.random().toString(36).slice(2)}`;l.addOptimistic(T,{kind:"text",text:`📎 Uploading ${h.name}…`}),I.render(l);try{const N=await fetch(y,{method:"POST",headers:{"content-type":h.type,authorization:`Bearer ${i}`},body:h});if(!N.ok)throw new Error(`Upload failed: ${N.status}`);const{url:Ce,name:Ee,mime:Ke,size:$e}=await N.json();l.addOptimistic(T,{kind:"attachment",url:Ce,name:Ee,mime:Ke,size:$e}),I.render(l),m.send({type:"send",conversationId:d,clientMsgId:T,content:{kind:"attachment",url:Ce,name:Ee,mime:Ke,size:$e}})}catch(N){l.addOptimistic(T,{kind:"text",text:`⚠️ Upload failed: ${N.message}`}),I.render(l)}},onInvoke(h,y){d&&m.send({type:"invoke",conversationId:d,actionId:h,clientInvokeId:`iv_${Math.random().toString(36).slice(2)}`,...y?{inputs:y}:{}})},onTyping(h,y){d&&m.send({type:"typing",conversationId:d,isTyping:h,...y?{preview:y}:{}})},onPreChat(h){try{localStorage.setItem(Y,"1")}catch{}m.send({type:"open",profileId:t.profileId,...t.subjectId?{subjectId:t.subjectId}:{},userInfo:{...h.name?{name:h.name}:{},...h.email?{email:h.email}:{},...h.phone||h.topic?{meta:{...h.phone?{phone:h.phone}:{},...h.topic?{topic:h.topic}:{}}}:{}}});const y=h.callback?`📞 Call-back requested${h.phone?`: ${h.phone}`:""}${h.topic?` — ${h.topic}`:""}`:h.topic?`Topic: ${h.topic}`:"";y&&d&&!l.e2e&&m.send({type:"send",conversationId:d,clientMsgId:`pc_${Math.random().toString(36).slice(2,12)}`,content:{kind:"text",text:y}})},...((Se=t.features)==null?void 0:Se.deflection)!==!1?{onDeflectQuery(h){if(o)return;clearTimeout(n);const y=h.trim();if(y.length<3){I.hideDeflection();return}n=setTimeout(()=>{fetch(`${p}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(y.slice(0,200))}`).then(T=>T.ok?T.json():{articles:[]}).then(T=>I.showDeflection(T.articles??[])).catch(()=>I.hideDeflection())},350)}}:{},onReadUpTo(h){d&&m.send({type:"read",conversationId:d,seq:h})},onLoadMore(){if(!d||!l.e2e)return;const h=l.messages()[0];h&&m.send({type:"history",conversationId:d,beforeSeq:h.seq,limit:20})},onEdit(h,y){d&&m.send({type:"edit",conversationId:d,messageId:h,content:{kind:"text",text:y}})},onDelete(h){d&&m.send({type:"delete",conversationId:d,messageId:h})},...((Ie=t.features)==null?void 0:Ie.reactions)!==!1?{onReact(h,y,T){d&&m.send({type:"react",conversationId:d,messageId:h,emoji:y,remove:T})}}:{},...((kt=t.features)==null?void 0:kt.csat)!==!1?{onCsat(h){d&&fetch(`${p}/conversations/${d}/csat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify({score:h})}).catch(()=>{})}}:{},...t.translateLang?{async onTranslate(h){try{const y=await fetch(`${p}/translate`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${i}`},body:JSON.stringify({text:h,targetLang:t.translateLang})});if(!y.ok)return null;const{translated:T}=await y.json();return T}catch{return null}}}:{},...t.onBack?{onBack:t.onBack}:{}},{...t.subject?{subject:t.subject}:{},...t.quickReplies?{quickReplies:t.quickReplies}:{},...t.accent?{accent:t.accent}:{},...t.accent2?{accent2:t.accent2}:{},...t.theme?{theme:t.theme}:{},...t.webfont===!1?{webfont:!1}:{},...(St=t.user)!=null&&St.name||(It=t.user)!=null&&It.avatar?{userInfo:{...t.user.name?{name:t.user.name}:{},...t.user.avatar?{avatar:t.user.avatar}:{}}}:{},i18n:O});try{localStorage.getItem(Y)&&I.completePreChat()}catch{}const ae=t.user&&(t.user.name||t.user.email||t.user.avatar||t.user.meta)?{...t.user.name?{name:t.user.name}:{},...t.user.email?{email:t.user.email}:{},...t.user.avatar?{avatar:t.user.avatar}:{},...t.user.meta?{meta:t.user.meta}:{}}:void 0,ke={type:"open",profileId:t.profileId,...t.kind==="direct"&&t.peerId?{kind:"direct",peerId:t.peerId}:t.subjectId?{subjectId:t.subjectId}:{},...s?{linkFrom:s}:{},...ae?{userInfo:ae}:{},...typeof location<"u"?{pageUrl:location.href}:{},...typeof document<"u"&&document.title?{pageTitle:document.title}:{},...(Ct=t.subject)!=null&&Ct.title?{subjectTitle:t.subject.title}:{},...(Et=t.subject)!=null&&Et.subtitle?{subjectMeta:t.subject.subtitle}:{}};m=new gn({...t.refreshToken?{refreshToken:t.refreshToken}:{},url:r,token:i,open:ke,getCursor:()=>l.highestSeq(),onStatusChange:(h,y)=>I.setConnStatus(h,y),onFrame(h){if(h.type==="opened"){if(d=h.conversation.id,!k){k=!0;for(const y of f.load())m.send({type:"send",conversationId:d,clientMsgId:y.clientMsgId,content:y.content})}Xn(r,i,d,l,I,p),R.length&&j(d)}if(h.type==="ack"&&f.remove(h.clientMsgId),h.type==="prekeyBundle"){h.bundle&&(J=!0,P.x3dhSendTo(h.bundle).then(y=>{const T=[...E.splice(0),...q.splice(0)];for(const N of T)Me(N.clientMsgId,N.text,y);I.render(l)}));return}if(h.type==="message"&&l.e2e){const y=Ln(h.message.content);if(y&&!P.ready){P.x3dhReceiveFrom(y.x3dhIK,y.x3dhEK,y.x3dhSPK,y.x3dhOTP).then(async()=>{await P.openFrame(h),l.apply(h),I.render(l)});return}}if(h.type==="peerkey"){P.onPeerKey(h.key).then(()=>{v(),I.render(l)});return}(async()=>{if(l.e2e&&await P.openFrame(h),l.apply(h),h.type==="manifest"&&(g==null||g()),h.type==="message"&&h.message.senderId!==i&&!h.message.internal&&(b(),_()),l.e2e&&d&&!H){H=!0;const y=await P.initX3DH();m.send({type:"uploadPrekeys",...y});const T=await P.begin();m.send({type:"pubkey",conversationId:d,key:T})}I.render(l)})()}}),m.connect(),I.render(l);const ce=t.launcher?xt(t):null,Z={close:()=>{o=!0,clearTimeout(n),m.close(),w==null||w.remove(),I.destroy(),S&&L&&S.removeEventListener("change",L),z&&(document.removeEventListener("keydown",z),z=null),xe.delete(t.el),ce&&Ae.get(ce)===Z&&Ae.delete(ce)}};return xe.set(t.el,Z),ce&&Ae.set(ce,Z),Z}const Ge="wss://api.paramms.com/ws";function Yn(t,e){const n=t.profileId??t.appId;if(!n)throw new Error("Relay: `profileId` is required (your chatroom id, e.g. 'p_...').");const o=t.subjectId??(t.listingId?`listing_${t.listingId}`:void 0),i=t.launcher??!0,s=t.contextTitle??t.listingTitle??t.subjectTitle,r=t.contextSubtitle??t.listingMeta??t.subjectMeta,p=t.contextStatus??t.listingStatus??t.subjectStatus,l=t.listingPrice??t.subjectPrice,u=s?{title:s,...r?{subtitle:r}:{},...l!=null?{tags:[`$${l.toLocaleString()}`]}:{},...p?{status:p}:{}}:void 0,f=t.subject??u,d=t.userName??t.name,k=t.userEmail??t.email,S=t.userAvatar??t.avatar,L=d||k||S?{...d?{name:d}:{},...k?{email:k}:{},...S?{avatar:S}:{}}:void 0,z=t.user??L,g=t.launcherMessage&&typeof t.launcherMessage=="object"?t.launcherMessage:t.launcherMessage?t.launcherSubtitle?{title:t.launcherMessage,subtitle:t.launcherSubtitle}:t.launcherMessage:void 0;return{el:e,url:t.url??Ge,profileId:n,...t.apiUrl?{apiUrl:t.apiUrl}:{},...o?{subjectId:o}:{},...t.token?{token:t.token}:{},...t.refreshToken?{refreshToken:t.refreshToken}:{},...t.userId?{userId:t.userId}:{},...f?{subject:f}:{},...z?{user:z}:{},...t.quickReplies?{quickReplies:t.quickReplies}:{},...t.i18n?{i18n:t.i18n}:{},...t.features?{features:t.features}:{},...t.accent?{accent:t.accent}:{},...t.accent2?{accent2:t.accent2}:{},...t.theme?{theme:t.theme}:{},...t.webfont===!1?{webfont:!1}:{},...t.translateLang?{translateLang:t.translateLang}:{},...g?{launcherMessage:g}:{},...bt(t)&&!i?{onBack:()=>{be=!0,ve=!1,Le(re)}}:{},launcher:i,position:t.position??"bottom-right"}}let ee=null,D=null,se=!1,re={},be=!1,ve=!1;function bt(t){return!!(t.inbox||t.inboxStart)}let te=null;function Jn(t,e){const n=!e&&!!t.el;if(se&&!n&&(D.innerHTML="",D=null,se=!1),n){const o=typeof t.el=="string"?document.querySelector(t.el):t.el;o instanceof HTMLElement?(D&&D!==o&&!se&&D.remove(),D=o,se=!0):console.error(`[Relay] \`el\` ("${String(t.el)}") did not match any element — falling back to an auto-created host.`)}return(!D||!se&&!D.isConnected)&&(D=document.createElement("div"),D.id="relay-widget-root",document.body.appendChild(D),se=!1),!e&&t.height&&(D.style.height=t.height,D.style.width||(D.style.width="100%")),D}function Le(t){try{const e=t.launcher??!0;te==null||te(),te=null,ee==null||ee.close(),ee=null;const n=Jn(t,e);if(bt(t)&&!e&&be){Zn(t,n);return}ee=mt(Yn(t,n))}catch(e){console.error("[Relay]",e instanceof Error?e.message:e)}}async function Zn(t,e){const n=t.profileId??t.appId;if(!n&&!t.tenantId){console.error("[Relay] `inbox` requires `profileId` or `tenantId`.");return}e.innerHTML="";const o=document.createElement("div");o.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;background:#fff";const i=document.createElement("div");i.style.cssText="position:absolute;inset:0";const s=document.createElement("div");s.style.cssText="position:absolute;inset:0;display:none";const r=document.createElement("button");r.type="button",r.setAttribute("aria-label","Close"),r.textContent="✕",r.style.cssText="position:absolute;top:8px;right:8px;z-index:20;width:32px;height:32px;border-radius:50%;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.05);border:none;color:#1c1b1a;font-size:16px;line-height:1;cursor:pointer",r.onclick=()=>{be=!1,Le(re)},o.append(i,s);const p=!ve&&!!n;p&&o.append(r),e.appendChild(o);let l=null,u=null;te=()=>{u==null||u.close(),l==null||l.close(),e.innerHTML=""};let f;try{({mountChatList:f}=await Promise.resolve().then(()=>ai))}catch(k){console.error("[Relay] could not load the conversation list module.",k),i.isConnected&&(i.style.cssText+=";display:flex;align-items:center;justify-content:center;padding:16px;font:13px system-ui;color:#b91c1c;text-align:center",i.textContent="Could not load conversations.");return}if(!i.isConnected)return;const d=k=>{const S=k.profileId??n;if(!S){console.error("[Relay] conversation row has no chatroom; cannot open it.",k);return}r.style.display="none",u==null||u.close(),u=mt({el:s,url:t.url??Ge,...t.apiUrl?{apiUrl:t.apiUrl}:{},profileId:S,...k.kind==="direct"&&k.peerId?{kind:"direct",peerId:k.peerId}:k.subjectId?{subjectId:k.subjectId}:{},...t.token?{token:t.token}:{},...t.refreshToken?{refreshToken:t.refreshToken}:{},...t.userId?{userId:t.userId}:{},...t.userId||t.userName||t.userEmail||t.userAvatar?{user:{...t.userName?{name:t.userName}:{},...t.userEmail?{email:t.userEmail}:{},...t.userAvatar?{avatar:t.userAvatar}:{}}}:{},...k.subjectTitle?{subject:{title:k.subjectTitle,...k.subjectMeta?{subtitle:k.subjectMeta}:{}}}:{},...t.accent?{accent:t.accent}:{},launcher:!1,onBack:()=>{u==null||u.close(),u=null,s.style.display="none",i.style.display="",r.style.display="",l==null||l.refresh()}}),i.style.display="none",s.style.display=""};l=f({el:i,url:t.url??Ge,...t.apiUrl?{apiUrl:t.apiUrl}:{},...n?{profileId:n}:{},...t.tenantId?{tenantId:t.tenantId}:{},scope:t.inboxScope??"tenant",...p?{reserveCloseSpace:!0}:{},onSelect:d,onNewChat:()=>{const k=n??(l==null?void 0:l.defaultProfileId());k&&d({id:"__new__",profileId:k,state:"open",updatedAt:Date.now()})},...t.token?{token:t.token}:{},...t.userId?{userId:t.userId}:{},...t.accent?{accent:t.accent}:{}})}function vt(t){ve=!!(t.inboxStart&&!(t.launcher??!0)),be=ve,re={...t},Le(re)}function Qn(t){re={...re,...t},Le(re)}function ei(){te==null||te(),te=null,ee==null||ee.close(),ee=null,D&&!se&&D.remove(),D=null,se=!1,be=!1,ve=!1,re={}}function Ye(t,e){switch(t){case"boot":vt(e??{});break;case"update":case"identify":Qn(e??{});break;case"shutdown":ei();break;default:console.warn("[Relay] unknown command:",t)}}function ti(){if(typeof document>"u")return null;const t=document.querySelector("script[data-relay-app]")??document.querySelector("script[data-relay-profile-id]")??document.querySelector("script[data-relay-tenant-id]"),e=t==null?void 0:t.dataset,n=(e==null?void 0:e.relayApp)??(e==null?void 0:e.relayProfileId),o=e==null?void 0:e.relayTenantId;if(!n&&!o)return null;const i=n?{profileId:n}:{};o&&(i.tenantId=o),e.relayUser&&(i.userId=e.relayUser),e.relayToken&&(i.token=e.relayToken),e.relayListing&&(i.listingId=e.relayListing),e.relayAccent&&(i.accent=e.relayAccent),e.relayAccent2&&(i.accent2=e.relayAccent2),e.relayTheme&&(i.theme=e.relayTheme),e.relayWebfont==="false"&&(i.webfont=!1),e.relayUrl&&(i.url=e.relayUrl);const s=e.relayPosition;(s==="bottom-left"||s==="bottom-right")&&(i.position=s),e.relayLauncherMessage&&(i.launcherMessage=e.relayLauncherMessage),e.relayLauncherSubtitle&&(i.launcherSubtitle=e.relayLauncherSubtitle),e.relayLauncher==="false"&&(i.launcher=!1),e.relayUserName&&(i.userName=e.relayUserName),e.relayUserEmail&&(i.userEmail=e.relayUserEmail),e.relayUserAvatar&&(i.userAvatar=e.relayUserAvatar),e.relayContextTitle&&(i.contextTitle=e.relayContextTitle),e.relayContextSubtitle&&(i.contextSubtitle=e.relayContextSubtitle),e.relayContextStatus&&(i.contextStatus=e.relayContextStatus),e.relayListingTitle&&(i.listingTitle=e.relayListingTitle),e.relayListingMeta&&(i.listingMeta=e.relayListingMeta),e.relayListingPrice&&(i.listingPrice=Number(e.relayListingPrice)),e.relayListingStatus&&(i.listingStatus=e.relayListingStatus),e.relayTarget&&(i.el=e.relayTarget),e.relayHeight&&(i.height=e.relayHeight),e.relayInbox==="true"&&(i.inbox=!0),e.relayInbox==="false"&&(i.inbox=!1),e.relayInboxStart==="true"&&(i.inboxStart=!0),e.relayInboxStart==="false"&&(i.inboxStart=!1);const r=e.relayInboxScope;return(r==="tenant"||r==="profile")&&(i.inboxScope=r),e.relayTranslateLang&&(i.translateLang=e.relayTranslateLang),i}if(typeof window<"u"){const t=window,e=t.Relay&&t.Relay.q?t.Relay.q:[];t.Relay=Ye;let n=!1;for(const o of e){const[i,s]=o;i==="boot"&&(n=!0),Ye(i,s)}if(!n){const o=t.relaySettings??ti();o&&vt(o)}}const ni=`
|
|
193
193
|
.ocl { ${ft("ocl")}
|
|
194
194
|
display:flex; flex-direction:column; height:100%; background:var(--ocl-bg);
|
|
195
195
|
font-family:var(--ocl-fb); color:var(--ocl-ink); overflow:hidden; }
|
|
196
|
-
@media (prefers-color-scheme: dark) { .ocl
|
|
196
|
+
@media (prefers-color-scheme: dark) { .ocl[data-theme="auto"] { ${Be("ocl")} } }
|
|
197
197
|
.ocl[data-theme="dark"] { ${Be("ocl")} }
|
|
198
198
|
.ocl-head { display:flex; align-items:center; padding:16px 16px 10px; background:var(--ocl-bg); }
|
|
199
199
|
.ocl-title { flex:1; display:flex; align-items:center; color:var(--ocl-accent); }
|
|
@@ -222,7 +222,7 @@ var RelayEmbed=function(Q){"use strict";var di=Object.defineProperty;var hi=(Q,X
|
|
|
222
222
|
.ocl-status.waiting { background:var(--ocl-tint); color:var(--ocl-accent); border:1px solid var(--ocl-accent); }
|
|
223
223
|
.ocl-status.done { background:#eee; color:#777; }
|
|
224
224
|
.ocl[data-theme="dark"] .ocl-status.done { background:#39325e; color:#b3abd6; }
|
|
225
|
-
@media (prefers-color-scheme: dark) { .ocl
|
|
225
|
+
@media (prefers-color-scheme: dark) { .ocl[data-theme="auto"] .ocl-status.done { background:#39325e; color:#b3abd6; } }
|
|
226
226
|
.ocl-spinner { padding:24px; text-align:center; color:var(--ocl-mut); font-size:13px; }
|
|
227
227
|
.ocl-compose { border:none; background:var(--ocl-accent); color:var(--ocl-onaccent); width:32px; height:32px; border-radius:50%; font-size:18px; line-height:1; cursor:pointer; box-shadow:var(--ocl-shadow); }
|
|
228
228
|
.ocl-compose:hover { filter:brightness(1.08); }
|
|
@@ -238,5 +238,5 @@ var RelayEmbed=function(Q){"use strict";var di=Object.defineProperty;var hi=(Q,X
|
|
|
238
238
|
.ocl-compact .ocl-search { font-size:16px; }
|
|
239
239
|
.ocl-compact .ocl-compose { width:36px; height:36px; }
|
|
240
240
|
.ocl-row:focus-visible, .ocl button:focus-visible, .ocl input:focus-visible { outline:2px solid var(--ocl-accent); outline-offset:2px; border-radius:12px; }
|
|
241
|
-
`;function ii(t){switch(t){case"open":return{label:"Open",cls:"open"};case"awaiting_staff":return{label:"Waiting on you",cls:"waiting"};case"resolved":return{label:"Resolved",cls:"done"};case"closed":return{label:"Closed",cls:"done"};default:return null}}function oi(t){const e=Math.floor((Date.now()-t)/1e3);if(e<60)return"just now";if(e<3600)return`${Math.floor(e/60)}m`;if(e<86400)return`${Math.floor(e/3600)}h`;const n=Math.floor(e/86400);if(n<=7)return`${n}d`;try{return new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch{return`${n}d`}}const si='<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" fill-opacity="0.12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function B(t,e,n){const o=document.createElement(t);return e&&(o.className=e),n!==void 0&&(o.textContent=n),o}function ri(t){const e=t.token??t.userId??tt(),{httpBase:n,wsUrl:o}=Xe(t.url,t.apiUrl),i=t.i18n??{},s=t.accent??"#6c5ce7";if(!document.getElementById("ocl-styles")){const v=document.createElement("style");v.id="ocl-styles",v.textContent=ni,document.head.append(v)}if(t.webfont!==!1&&typeof document<"u"&&!document.getElementById("ocw-webfont")){const v=document.createElement("link");v.id="ocw-webfont",v.rel="stylesheet",v.href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Nunito:wght@400;500;600;700&display=swap",document.head.append(v)}const r=B("div","ocl");r.style.setProperty("--ocl-accent",s),
|
|
241
|
+
`;function ii(t){switch(t){case"open":return{label:"Open",cls:"open"};case"awaiting_staff":return{label:"Waiting on you",cls:"waiting"};case"resolved":return{label:"Resolved",cls:"done"};case"closed":return{label:"Closed",cls:"done"};default:return null}}function oi(t){const e=Math.floor((Date.now()-t)/1e3);if(e<60)return"just now";if(e<3600)return`${Math.floor(e/60)}m`;if(e<86400)return`${Math.floor(e/3600)}h`;const n=Math.floor(e/86400);if(n<=7)return`${n}d`;try{return new Date(t).toLocaleDateString(void 0,{month:"short",day:"numeric"})}catch{return`${n}d`}}const si='<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z" fill="currentColor" fill-opacity="0.12" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';function B(t,e,n){const o=document.createElement(t);return e&&(o.className=e),n!==void 0&&(o.textContent=n),o}function ri(t){const e=t.token??t.userId??tt(),{httpBase:n,wsUrl:o}=Xe(t.url,t.apiUrl),i=t.i18n??{},s=t.accent??"#6c5ce7";if(!document.getElementById("ocl-styles")){const v=document.createElement("style");v.id="ocl-styles",v.textContent=ni,document.head.append(v)}if(t.webfont!==!1&&typeof document<"u"&&!document.getElementById("ocw-webfont")){const v=document.createElement("link");v.id="ocw-webfont",v.rel="stylesheet",v.href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700&family=Nunito:wght@400;500;600;700&display=swap",document.head.append(v)}const r=B("div","ocl");r.style.setProperty("--ocl-accent",s),r.dataset.theme=t.theme??"light",t.reserveCloseSpace&&r.classList.add("ocl-has-close");const p=B("div","ocl-head"),l=B("span","ocl-title");if(l.setAttribute("role","img"),l.setAttribute("aria-label",i.title??"Messages"),l.innerHTML=si,p.append(l),t.onNewChat){const v=B("button","ocl-compose","✎");v.title=i.newChat??"New conversation",v.addEventListener("click",()=>t.onNewChat()),p.append(v)}const u=B("div","ocl-search-wrap"),f=B("input","ocl-search");f.placeholder=i.search??"🔍 Search",f.type="search",u.append(f);const d=B("div","ocl-body");d.append(B("div","ocl-spinner","Loading…")),r.append(p,u,d),t.el.replaceChildren(r);const k=v=>{r.classList.toggle("ocl-compact",v>0&&v<400)};k(r.clientWidth);let S=null;if(typeof ResizeObserver<"u"&&(S=new ResizeObserver(v=>{var M;return k(((M=v[0])==null?void 0:M.contentRect.width)??r.clientWidth)}),S.observe(r)),!t.profileId&&!t.tenantId)throw new Error("[relay chatlist] provide profileId or tenantId");let L;const z=`ocl_seen_${t.profileId??`t_${t.tenantId}`}_${(t.userId??e).slice(-8)}`;let g={};try{g=JSON.parse(localStorage.getItem(z)??"{}")}catch{}const w=()=>{try{localStorage.setItem(z,JSON.stringify(g))}catch{}};let U=[],C=!1;const x=async()=>{const v=t.profileId?`profileId=${encodeURIComponent(t.profileId)}${t.scope==="tenant"?"&scope=tenant":""}`:`tenantId=${encodeURIComponent(t.tenantId)}`,M=`${n}/conversations/mine?${v}`,O={authorization:`Bearer ${e}`};let G;try{G=await fetch(M,{headers:O})}catch{G=await fetch(M,{headers:O})}if(!G.ok)return[];const F=await G.json();return F.defaultProfileId&&(L=F.defaultProfileId),(F.conversations??[]).sort((Y,I)=>I.updatedAt-Y.updatedAt)},b=(v,M)=>{if(C)return;const O=M?v.filter(I=>_(I).toLowerCase().includes(M)||(I.lastMessage??"").toLowerCase().includes(M)):v;if(d.replaceChildren(),!O.length){const I=B("div","ocl-empty",M?"No results.":i.empty??"No conversations yet.");if(!M&&t.onNewChat){I.append(B("br"));const ae=B("button","ocl-start",i.newChat??"Start a conversation");ae.addEventListener("click",()=>t.onNewChat()),I.append(ae)}d.append(I);return}const G=I=>(I.lastSeq??0)>(g[I.id]??0),F=O.filter(G),Y=O.filter(I=>!G(I));if(F.length){d.append(B("div","ocl-section",`${i.unread??"Unread"} (${F.length})`));for(const I of F)d.append(R(I,G(I)))}if(Y.length){d.append(B("div","ocl-section",F.length?i.all??"All conversations":""));for(const I of Y)d.append(R(I,!1))}},_=v=>v.subjectTitle??(v.kind==="direct"?v.peerId??"Direct message":"General enquiry"),R=(v,M)=>{var Se;const O=_(v),G=(((Se=O.match(new RegExp("\\p{L}","u")))==null?void 0:Se[0])??O.trim()[0]??"?").toUpperCase(),F=v.lastSeq??0,Y=M?Math.max(1,F-(g[v.id]??0)):0,I=B("button",`ocl-row${M?" unread":""}`),ae=B("div","ocl-av",G);I.append(ae);const ke=B("div","ocl-info");ke.append(B("div","ocl-name",O));const ce={open:"Open",awaiting_staff:"Waiting for reply…",resolved:"Resolved ✓",closed:"Closed"};ke.append(B("div","ocl-preview",v.lastMessage??ce[v.state]??v.state)),I.append(ke);const Z=B("div","ocl-right");Z.append(B("div","ocl-time",oi(v.updatedAt)));const pe=ii(v.state);return pe&&Z.append(B("div",`ocl-status ${pe.cls}`,pe.label)),Y>0&&Z.append(B("div","ocl-badge",String(Y>99?"99+":Y))),I.append(Z),I.addEventListener("click",()=>{var Ie;F>0&&(g[v.id]=F,w()),I.classList.remove("unread"),(Ie=Z.querySelector(".ocl-badge"))==null||Ie.remove(),t.onSelect(v)}),I},j=()=>{C||x().then(v=>{C||(U=v,b(v,f.value.trim().toLowerCase()))}).catch(v=>{if(C)return;console.error(`[chat-widget] failed to load conversations from ${n}/conversations/mine — check the apiUrl/CORS config.`,v);const M=B("div","ocl-empty",i.error??"Could not load conversations.");M.append(B("br"));const O=B("button","ocl-retry",i.retry??"Retry");O.addEventListener("click",()=>{d.replaceChildren(B("div","ocl-spinner","Loading…")),j()}),M.append(O),d.replaceChildren(M)})};f.addEventListener("input",()=>b(U,f.value.trim().toLowerCase())),j();let m=null,P,H,E=0,q=!1;const J=()=>{H||(H=setTimeout(()=>{H=void 0,j()},300))},he=()=>{if(!C){try{m=new WebSocket(o)}catch{Me();return}m.binaryType="arraybuffer",m.onopen=()=>{E=0,m.send(Fe({type:"auth",token:e})),m.send(Fe({type:"subscribe_inbox"})),q&&J(),q=!0},m.onmessage=v=>{const M=at(new Uint8Array(v.data));M&&M.type==="inbox_event"&&J()},m.onclose=()=>{m=null,Me()},m.onerror=()=>{try{m==null||m.close()}catch{}}}},Me=()=>{if(C||P)return;const v=Math.min(15e3,500*2**E++)+Math.random()*250;P=setTimeout(()=>{P=void 0,he()},v)};return he(),{refresh:j,close(){C=!0,P&&clearTimeout(P),H&&clearTimeout(H),S==null||S.disconnect(),S=null;try{m==null||m.close()}catch{}m=null,t.el.replaceChildren()},defaultProfileId(){return t.profileId??L}}}const ai=Object.freeze(Object.defineProperty({__proto__:null,mountChatList:ri},Symbol.toStringTag,{value:"Module"}));return Q.Relay=Ye,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"}),Q}({});
|
|
242
242
|
//# sourceMappingURL=embed.js.map
|