@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.
@@ -3,7 +3,7 @@ var RelayEmbedLite=function(J){"use strict";var $n=Object.defineProperty;var Rn=
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:not([data-theme="light"]) { ${ye("ocw")} } }
6
+ @media (prefers-color-scheme: dark) { .ocw[data-theme="auto"] { ${ye("ocw")} } }
7
7
  .ocw[data-theme="dark"] { ${ye("ocw")} }
8
8
  /* ── Responsive sizing ──────────────────────────────────────────────────────
9
9
  * Sizing is driven by the WIDGET'S OWN width (ResizeObserver toggles
@@ -110,7 +110,7 @@ var RelayEmbedLite=function(J){"use strict";var $n=Object.defineProperty;var Rn=
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:not([data-theme="light"]) .ocw-away { background:#3a3018; border-color:#5a4a1f; color:#e8d9a8; } .ocw:not([data-theme="light"]) .ocw-note .ocw-bubble { background:#332b12; border-color:#7a5c17; color:#f0e2bd; } .ocw:not([data-theme="light"]) .ocw-note .ocw-bubble::before { color:#e0c060; } }
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 RelayEmbedLite=function(J){"use strict";var $n=Object.defineProperty;var Rn=
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
- `,tt="objectchat-widget-styles",an=["👍","❤️","😂","😮","😢","🙏"],cn=400,ln='<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 dn(){if(typeof document>"u"||document.getElementById(tt))return;const t=document.createElement("style");t.id=tt,t.textContent=rn,document.head.appendChild(t)}const nt="ocw-webfont";function hn(){if(typeof document>"u"||document.getElementById(nt))return;const t=document.createElement("link");t.id=nt,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 a(t,e,n){const i=document.createElement(t);return e&&(i.className=e),n!==void 0&&(i.textContent=n),i}function pn(t){try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function Pe(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 un{constructor(e,n,i,o={}){c(this,"scroll");c(this,"chips");c(this,"typing");c(this,"quick");c(this,"formHost");c(this,"csatPanel");c(this,"awayNotice");c(this,"headStatus");c(this,"reopenBtn");c(this,"preChatPanel");c(this,"deflectPanel");c(this,"preChatBuilt",!1);c(this,"preChatDone",!1);c(this,"footer");c(this,"input");c(this,"subjectCard");c(this,"e2eBadge");c(this,"statusBadge");c(this,"headerName");c(this,"connStatus");c(this,"typingTimer",null);c(this,"csatSubmitted",!1);c(this,"sendBtn");c(this,"compactObserver",null);c(this,"storeRef",null);c(this,"cfgAccent2");c(this,"scrollCleanup",null);c(this,"translationCache",new Map);c(this,"showingTranslation",new Set);c(this,"subjectBuilt",!1);var f,T,I,m,b,q,_,j,k,M,W;this.root=e,this.me=n,this.h=i,this.cfg=o,dn(),o.webfont!==!1&&hn(),e.replaceChildren(),e.classList.add("ocw"),o.accent&&e.style.setProperty("--ocw-accent",o.accent);const s=o.accent2??o.accent;s&&e.style.setProperty("--ocw-accent2",s),this.cfgAccent2=o.accent2,o.theme&&o.theme!=="auto"&&(e.dataset.theme=o.theme);const r=a("div","ocw-head");if(this.h.onBack){const C=a("button","ocw-back","‹");C.type="button",C.setAttribute("aria-label","Back"),C.addEventListener("click",()=>this.h.onBack()),r.append(C)}const u=a("div","ocw-avatar");if((f=o.userInfo)!=null&&f.avatar){const C=document.createElement("img");C.src=o.userInfo.avatar,C.alt=o.userInfo.name??"You",C.style.cssText="width:100%;height:100%;border-radius:50%;object-fit:cover",u.append(C)}else u.textContent=(T=o.userInfo)!=null&&T.name?o.userInfo.name[0].toUpperCase():"🧑";r.append(u);const d=a("div","ocw-head-main");this.headerName=a("div","ocw-head-name",((I=o.subject)==null?void 0:I.ownerLabel)??((m=o.subject)==null?void 0:m.title)??""),d.append(this.headerName),this.headStatus=a("div","ocw-head-status"),this.headStatus.style.display="none",d.append(this.headStatus),(b=o.subject)!=null&&b.subtitle&&d.append(a("div","ocw-head-meta",o.subject.subtitle)),r.append(d),this.statusBadge=a("span","ocw-badge",((q=o.subject)==null?void 0:q.status)??""),(_=o.subject)!=null&&_.status||(this.statusBadge.style.display="none"),r.append(this.statusBadge),this.e2eBadge=a("span","ocw-e2e","🔒 E2E"),this.e2eBadge.style.display="none",r.append(this.e2eBadge),this.connStatus=a("span","ocw-conn-status"),this.connStatus.style.display="none",r.append(this.connStatus),r.append(a("button","ocw-menu","⋯")),this.chips=a("div","ocw-chiprow"),this.scroll=a("div","ocw-scroll"),this.subjectCard=a("div","ocw-subject"),this.typing=a("div","ocw-typing");const p=a("div","ocw-typing-bubble");p.append(a("div","ocw-typing-dot"),a("div","ocw-typing-dot"),a("div","ocw-typing-dot")),this.typing.append(a("div","ocw-dot","🧑"),p),this.quick=a("div","ocw-quick");for(const C of o.quickReplies??[]){const K=a("button",void 0,C);K.addEventListener("click",()=>{this.h.onSend(C),this.quick.style.display="none"}),this.quick.append(K)}this.formHost=a("div","ocw-form-host"),this.csatPanel=a("div","ocw-csat"),this.csatPanel.style.display="none",this.awayNotice=a("div","ocw-away"),this.awayNotice.style.display="none",this.preChatPanel=a("div","ocw-prechat"),this.preChatPanel.style.display="none",this.deflectPanel=a("div","ocw-deflect"),this.deflectPanel.style.display="none",this.input=a("textarea",void 0),this.input.rows=1,this.input.placeholder=((j=o.i18n)==null?void 0:j.placeholder)??"Message…";const g=a("button","ocw-sendbtn");g.type="button";const l=(k=o.i18n)==null?void 0:k.send;l?(g.textContent=l,g.classList.add("ocw-sendbtn-label"),g.setAttribute("aria-label",l)):(g.innerHTML=ln,g.setAttribute("aria-label","Send message")),g.disabled=!0,this.sendBtn=g,g.addEventListener("click",()=>this.flushSend()),this.input.addEventListener("input",()=>{var C,K;this.sendBtn.disabled=this.input.value.trim().length===0,this.autoGrowInput(),this.storeRef&&!this.storeRef.messages().some($=>$.senderRole==="guest")?(K=(C=this.h).onDeflectQuery)==null||K.call(C,this.input.value):this.hideDeflection()}),this.input.addEventListener("keydown",C=>{C.isComposing||C.keyCode===229||(C.key==="Enter"&&!C.shiftKey?(C.preventDefault(),this.flushSend()):this.signalTyping())});const v=a("button","ocw-attach","📎");v.title="Attach image or file";const S=document.createElement("input");S.type="file",S.accept="image/*,.pdf,.txt,.doc,.docx",S.style.display="none",v.addEventListener("click",()=>S.click()),S.addEventListener("change",()=>{var C;(C=S.files)!=null&&C[0]&&this.h.onAttach&&this.h.onAttach(S.files[0]),S.value=""});const A=a("div","ocw-input");A.append(v,S,this.input,g);const z=a("div","ocw-footer");((M=o.i18n)==null?void 0:M.poweredBy)!==void 0?z.textContent=o.i18n.poweredBy:z.innerHTML='Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>',this.footer=z,this.reopenBtn=a("button","ocw-reopen",((W=this.cfg.i18n)==null?void 0:W.reopen)??"Reopen conversation"),this.reopenBtn.type="button",this.reopenBtn.addEventListener("click",()=>{this.reopenBtn.style.display="none";const C=this.root.querySelector(".ocw-input textarea");C==null||C.focus()}),e.append(r,this.chips,this.scroll,this.typing,this.quick,this.formHost,this.csatPanel,this.preChatPanel,this.deflectPanel,this.awayNotice,A,this.reopenBtn,this.footer);const w=C=>{e.classList.toggle("ocw-compact",C>0&&C<cn)};w(e.clientWidth),typeof ResizeObserver<"u"&&(this.compactObserver=new ResizeObserver(C=>{var $;const K=(($=C[0])==null?void 0:$.contentRect.width)??e.clientWidth;w(K)}),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,A,z,w,f,T,I,m;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 i=this.scroll.scrollHeight,o=this.scroll.scrollTop;if(this.scroll.replaceChildren(),this.subjectCard.childNodes.length&&this.scroll.append(this.subjectCard),e.hasMoreHistory){const b=a("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 q=b.senderRole!=="system"&&b.senderId!==this.me&&!b.internal&&b.senderId!==r;this.scroll.append(this.messageEl(b,e,q)),b.senderRole!=="system"&&(r=b.senderId),b.senderId!==this.me&&b.seq>s&&(s=b.seq)}o>20?this.scroll.scrollTop=this.scroll.scrollHeight-i+o:this.scroll.scrollTop=this.scroll.scrollHeight,s>0&&this.h.onReadUpTo(s);const u=[...e.typing];this.typing.classList.toggle("active",u.length>0);const d=this.typing.querySelector(".ocw-typing-bubble");d&&d.setAttribute("aria-label",u.length?"typing":""),this.footer.style.display=e.whiteLabel?"none":"block";const p=e.messages().some(b=>b.senderRole==="guest");if(!!((A=e.preChat)!=null&&A.enabled)&&!this.preChatDone&&!p&&(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(a("span","ocw-away-icon","🌙"),a("span","",""));const b=this.awayNotice.lastChild;b.textContent=e.offlineMessage||((w=this.cfg.i18n)==null?void 0:w.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";(f=this.root.querySelector(".ocw-input"))==null||f.style.removeProperty("display")}const l=["resolved","closed","sold","issued","checked_out"];this.h.onCsat&&!this.csatSubmitted&&l.includes(e.state)&&e.messages().length>0&&(this.csatPanel.style.display==="none"&&this.buildCsatPanel(),this.csatPanel.style.display="block");const v=l.includes(e.state);if(e.offline?(this.headStatus.textContent=`● ${e.offlineMessage||((T=this.cfg.i18n)==null?void 0:T.away)||"Away"}`,this.headStatus.className="ocw-head-status away",this.headStatus.style.display=""):e.conversationId?(this.headStatus.textContent=`● ${((I=this.cfg.i18n)==null?void 0:I.online)??"Online"}`,this.headStatus.className="ocw-head-status online",this.headStatus.style.display=""):this.headStatus.style.display="none",v&&e.messages().length>0){const b=a("div","ocw-resolved-note",`— ${((m=this.cfg.i18n)==null?void 0:m.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 i=e==="error";this.connStatus.className=`ocw-conn-status${i?" err":e==="reconnecting"?" warn":""}`,this.connStatus.textContent=i?`⚠ ${n??"Chat unavailable"}`:e==="reconnecting"?n??"↻ reconnecting…":"● connecting…"}buildPreChatPanel(e){var d;this.preChatBuilt=!0,this.preChatPanel.replaceChildren(),this.preChatPanel.append(a("div","ocw-prechat-title",e.title??"Before we start…"));const n=a("div","ocw-offline-form"),i={};for(const p of e.fields??["name","email"]){const g=a("input","ocw-offline-input");g.type=p==="email"?"email":p==="phone"?"tel":"text",g.placeholder=p==="name"?"Your name":p==="email"?"Your email":"Your phone number",i[p]=g,n.append(g)}let o=null;if((d=e.topics)!=null&&d.length){o=a("select",void 0);const p=document.createElement("option");p.value="",p.textContent="What is this about?",o.append(p);for(const g of e.topics){const l=document.createElement("option");l.value=g,l.textContent=g,o.append(l)}n.append(o)}let s=null,r=null;if(e.callbackOption){const p=a("label","ocw-prechat-cb");s=document.createElement("input"),s.type="checkbox",p.append(s,document.createTextNode("📞 Request a call back")),n.append(p),i.phone||(r=a("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 u=a("button","ocw-offline-submit","Start chat");u.type="button",u.addEventListener("click",()=>{var v,S,A,z,w,f,T;const p=(v=i.email)==null?void 0:v.value.trim();if(i.email&&(!p||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p))){i.email.focus();return}const g=!!(s!=null&&s.checked),l=(((S=i.phone)==null?void 0:S.value)??(r==null?void 0:r.value)??"").trim();if(g&&!l){(A=i.phone??r)==null||A.focus();return}if(o&&((z=e.topics)!=null&&z.length)&&!o.value){o.focus();return}u.disabled=!0,this.completePreChat(),(T=(f=this.h).onPreChat)==null||T.call(f,{...(w=i.name)!=null&&w.value.trim()?{name:i.name.value.trim()}:{},...p?{email:p}:{},...l?{phone:l}:{},...o!=null&&o.value?{topic:o.value}:{},...g?{callback:!0}:{}})}),n.append(u),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(a("div","ocw-deflect-hint","Instant answers — tap to expand"));for(const n of e.slice(0,3)){const i=a("button","ocw-deflect-card");i.append(a("div","ocw-deflect-q",n.title),a("div","ocw-deflect-a",n.answer)),i.addEventListener("click",()=>i.classList.toggle("open")),this.deflectPanel.append(i)}this.deflectPanel.style.display="flex"}hideDeflection(){this.deflectPanel.style.display="none",this.deflectPanel.replaceChildren()}buildCsatPanel(){this.csatPanel.replaceChildren(),this.csatPanel.append(a("div","ocw-csat-title","How did we do?"));const e=a("div","ocw-csat-stars"),n=[];for(let i=1;i<=5;i++){const o=a("button","ocw-csat-star","★");o.dataset.score=String(i),o.addEventListener("mouseenter",()=>n.forEach((s,r)=>s.classList.toggle("lit",r<i))),o.addEventListener("mouseleave",()=>n.forEach(s=>s.classList.remove("lit"))),o.addEventListener("click",()=>{var s,r;this.csatSubmitted=!0,this.csatPanel.replaceChildren(a("div","ocw-csat-done",`Thanks for your ${i}★ rating!`)),(r=(s=this.h).onCsat)==null||r.call(s,i)}),n.push(o),e.append(o)}this.csatPanel.append(e)}buildSubjectCard(e){if(this.subjectBuilt)return;const n=e.subject,i=this.cfg.subject,o=(n==null?void 0:n.title)??(i==null?void 0:i.title);if(!o)return;this.subjectBuilt=!0,this.subjectCard.replaceChildren(),this.subjectCard.append(a("div","ocw-subject-title",o)),i!=null&&i.subtitle&&this.subjectCard.append(a("div","ocw-subject-sub",i.subtitle));const s=a("div","ocw-tags");if(n)for(const[u,d]of Object.entries(n.fields))s.append(a("span","ocw-tag",`${u}: ${d}`));else for(const u of(i==null?void 0:i.tags)??[])s.append(a("span","ocw-tag",u));s.childNodes.length&&this.subjectCard.append(s);const r=(n==null?void 0:n.state)??(i==null?void 0:i.status);r&&(this.statusBadge.textContent=r,this.statusBadge.style.display="inline-flex")}chipEl(e){const n=a("button","ocw-chip",e.icon?`${e.icon} ${e.label}`:e.label);return n.dataset.actionId=e.id,n.addEventListener("click",async()=>{var i;e.confirm&&!await this.confirm(e.label)||((i=e.input)!=null&&i.length?this.openForm(e):this.h.onInvoke(e.id))}),n}confirm(e){return new Promise(n=>{const i=a("div","ocw-modal"),o=a("div","ocw-modal-card");o.append(a("div","ocw-modal-title",e)),o.append(a("div","ocw-modal-body",`Confirm “${e}”?`));const s=a("div","ocw-modal-actions"),r=a("button","ocw-modal-cancel","Cancel"),u=a("button","ocw-modal-ok","Confirm"),d=p=>{i.remove(),n(p)};r.addEventListener("click",()=>d(!1)),u.addEventListener("click",()=>d(!0)),i.addEventListener("click",p=>{p.target===i&&d(!1)}),s.append(r,u),o.append(s),i.append(o),this.root.append(i),u.focus()})}openForm(e){var u,d;this.formHost.replaceChildren();const n=a("div","ocw-form");n.append(a("div","ocw-form-title",e.icon?`${e.icon} ${e.label}`:e.label));const i=new Map;for(const p of e.input??[]){const g=a("label","ocw-form-row");if(g.append(a("span","ocw-form-lbl",p.label)),p.type==="select"&&((u=p.options)!=null&&u.length)){const l=a("select","ocw-form-input");p.required||l.append(a("option",void 0,"— select —"));for(const v of p.options){const S=a("option");S.value=v,S.textContent=v,l.append(S)}p.required&&(l.required=!0),g.append(l),i.set(p.name,l)}else{const l=a("input","ocw-form-input");l.type=p.type==="number"?"number":p.type==="date"?"datetime-local":"text",p.required&&(l.required=!0),g.append(l),i.set(p.name,l)}n.append(g)}const o=a("div","ocw-form-actions"),s=a("button","ocw-form-cancel","Cancel"),r=a("button","ocw-form-submit","Send");s.addEventListener("click",()=>this.formHost.replaceChildren()),r.addEventListener("click",()=>{const p={};for(const[g,l]of i){if(l.required&&!l.value){l.style.borderColor="#e5484d";return}p[g]=l.type==="number"?Number(l.value):l.value}this.formHost.replaceChildren(),this.h.onInvoke(e.id,p)}),o.append(s,r),n.append(o),this.formHost.append(n),(d=i.values().next().value)==null||d.focus()}messageEl(e,n,i=!1){var v,S,A,z;if(e.senderRole==="system"){const w=a("div","ocw-sys");return w.textContent=e.deletedAt?"message deleted":Pe(e.content),w}const o=e.senderId===this.me,s=!!e.internal,r=a("div",`ocw-row ${s?"ocw-note mine":o?"mine":"theirs"} ${e.senderRole==="bot"?"ocw-bot":""}`);!o&&!s&&r.append(a("div","ocw-dot",e.senderRole==="bot"?"🤖":"🧑"));const u=a("div");if(i){const w=e.senderRole==="bot"?((v=this.cfg.i18n)==null?void 0:v.aiAssistant)??"AI Assistant":((S=this.cfg.subject)==null?void 0:S.ownerLabel)??((A=this.cfg.subject)==null?void 0:A.title)??"Support";u.append(a("div","ocw-msg-sender",w))}const d=a("div","ocw-bubble-wrap");if(e.replyToId){const w=a("div","ocw-reply-to","↩ replying to a message");w.style.cssText="font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",u.append(w)}const p=a("div","ocw-bubble");let g=null;if(e.deletedAt)p.append(a("span","ocw-deleted","message deleted"));else if(e.content.kind==="attachment"){const w=e.content;if((z=w.mime)!=null&&z.startsWith("image/")){const f=document.createElement("img");f.src=w.url,f.alt=w.name??"image",f.style.cssText="max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer",f.addEventListener("click",()=>window.open(w.url,"_blank")),p.append(f)}else{const f=document.createElement("a");f.href=w.url,f.target="_blank",f.rel="noopener",f.style.cssText="display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none",f.append(a("span",void 0,"📄"),a("span",void 0,w.name??"file")),p.append(f)}}else if(e.content.kind==="appointment"){const w=e.content,f=a("div","ocw-appt");f.append(a("div","ocw-appt-title",`📅 ${w.title}`)),f.append(a("div","ocw-appt-time",new Date(w.startIso).toLocaleString()+" – "+new Date(w.endIso).toLocaleTimeString())),w.location&&f.append(a("div","ocw-appt-loc",`📍 ${w.location}`)),w.description&&f.append(a("div","ocw-appt-desc",w.description));const T=a("div","ocw-appt-links"),I=document.createElement("a");I.href=w.googleUrl,I.target="_blank",I.rel="noopener",I.className="ocw-appt-btn",I.textContent="📅 Add to Google Calendar";const m=document.createElement("a");m.href=w.icalUrl,m.download=`${w.title}.ics`,m.className="ocw-appt-btn ocw-appt-btn-sec",m.textContent="🍎 Apple / iCal",T.append(I,m),f.append(T),p.append(f)}else g=document.createTextNode(Pe(e.content)),p.append(g),e.editedAt&&p.append(a("span","ocw-edited","(edited)"));if(d.append(p),!o&&!s&&this.h.onTranslate&&e.content.kind==="text"&&!e.deletedAt&&e.seq>0&&g){const w=e.content.text;if(w.trim()){const f=a("button","ocw-translate-btn","🌐");f.type="button",f.title="Translate",f.addEventListener("click",T=>{if(T.stopPropagation(),this.showingTranslation.has(e.id)){this.showingTranslation.delete(e.id),g.textContent=w,f.textContent="🌐",f.title="Translate";return}const I=this.translationCache.get(e.id);if(I!==void 0){this.showingTranslation.add(e.id),g.textContent=I,f.textContent="↩",f.title="Show original";return}f.textContent="⏳",this.h.onTranslate(w).then(m=>{if(m===null){f.textContent="⚠️",f.title="Translation unavailable",setTimeout(()=>{f.textContent="🌐",f.title="Translate"},1500);return}this.translationCache.set(e.id,m),this.showingTranslation.add(e.id),g.textContent=m,f.textContent="↩",f.title="Show original"})}),d.append(f)}}if(o&&!e.deletedAt&&e.seq>0&&(this.h.onEdit??this.h.onDelete)){const w=a("div","ocw-msg-menu");if(this.h.onEdit){const f=a("button",void 0,"✏️");f.title="Edit",f.addEventListener("click",T=>{T.stopPropagation();const I=Pe(e.content),m=document.createElement("textarea");m.value=I,m.rows=Math.min(4,Math.ceil(I.length/40)+1),m.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=a("button","ocw-form-submit","Save");b.style.cssText="margin-top:6px;padding:5px 14px;font-size:13px";const q=a("button","ocw-form-cancel","Cancel");q.style.cssText="margin-top:6px;padding:5px 10px;font-size:13px";const _=a("div");_.style.cssText="display:flex;gap:6px;justify-content:flex-end",_.append(q,b);const j=a("div");j.append(m,_),p.replaceChildren(j),m.focus(),m.select();const k=()=>p.replaceChildren(g??document.createTextNode(I));q.addEventListener("click",k),b.addEventListener("click",()=>{const M=m.value.trim();M&&M!==I&&this.h.onEdit(e.id,M),k()}),m.addEventListener("keydown",M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),b.click()),M.key==="Escape"&&k()})}),w.append(f)}if(this.h.onDelete){const f=a("button","del","🗑");f.title="Delete",f.addEventListener("click",T=>{T.stopPropagation(),this.h.onDelete(e.id)}),w.append(f)}d.append(w)}if(u.append(d),this.h.onReact&&!e.deletedAt&&e.seq>0){const w=a("div","ocw-react-wrap"),f=a("div","ocw-react");if(e.reactions&&Object.keys(e.reactions).length)for(const[m,b]of Object.entries(e.reactions)){const q=a("button",`ocw-react-pill${b.includes(this.me)?" mine":""}`,`${m} ${b.length}`);q.addEventListener("click",()=>{var _,j;return(j=(_=this.h).onReact)==null?void 0:j.call(_,e.id,m,b.includes(this.me))}),f.append(q)}const T=a("button","ocw-react-btn","+"),I=a("div","ocw-react-picker");for(const m of an){const b=a("button",void 0,m);b.addEventListener("click",q=>{var j,k,M,W;q.stopPropagation();const _=(k=(j=e.reactions)==null?void 0:j[m])==null?void 0:k.includes(this.me);(W=(M=this.h).onReact)==null||W.call(M,e.id,m,!!_),I.style.display="none"}),I.append(b)}I.style.display="none",T.addEventListener("click",m=>{m.stopPropagation();const b=I.style.display==="none";I.style.display=b?"flex":"none",b&&document.addEventListener("click",()=>{I.style.display="none"},{once:!0})}),f.append(T),w.append(f,I),u.append(w)}else e.reactions&&Object.keys(e.reactions).length&&u.append(a("div","ocw-react",Object.entries(e.reactions).map(([w,f])=>`${w}${f.length}`).join(" ")));const l=a("div","ocw-time ocw-meta",pn(e.ts));if(o&&e.status){const w=a("span",`ocw-tick${e.status==="read"?" read":e.status==="delivered"?" delivered":""}`,fn(e.status));l.append(w)}return o&&e.seq>0&&n.lastReadByOthers>=e.seq&&l.append(a("span","ocw-seen"," · Seen")),u.append(l),r.append(u),r}}function fn(t){switch(t){case"read":return"✓✓";case"delivered":return"✓✓";case"sent":return"✓";default:return"🕓"}}const wn=20;function _e(t,e){var d;const n=t.trim().replace(/\/+$/,""),i=(d=n.match(/^(https|http|wss|ws):\/\//))==null?void 0:d[1],o=i?i==="https"||i==="wss":!0,s=(i?n.slice(i.length+3):n).replace(/\/ws$/,""),r=e?e.trim().replace(/\/+$/,""):`${o?"https":"http"}://${s}`;return{wsUrl:`${o?"wss":"ws"}://${s}/ws`,httpBase:r}}function gn(t){return _e(t).httpBase}function xn(t,e,n,i){const o=`beforeSeq=${n}&limit=${i}`;return[`${t}/conversations/${e}/messages?${o}`,`${t}/conversations/${e}/history?${o}`]}async function ot(t,e,n,i,o=wn){let s,r=!1;for(const u of xn(t,e,i,o))try{const d=await fetch(u,{headers:{authorization:`Bearer ${n}`}});if(r=!0,!d.ok)continue;const p=await d.json();return{messages:p.messages??[],hasMore:p.hasMore??!1}}catch(d){s=d}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 mn(t,e,n,i,o,s){const r=s?s.replace(/\/+$/,""):gn(t),u=await ot(r,n,e,Number.MAX_SAFE_INTEGER);if(!u||(u.messages.length?(i.apply({type:"sync",conversationId:n,messages:u.messages}),i.apply({type:"history",conversationId:n,messages:[],hasMore:u.hasMore}),o.render(i)):i.apply({type:"history",conversationId:n,messages:[],hasMore:!1}),!u.hasMore))return;let d=!1;const p=async()=>{if(d||!i.hasMoreHistory)return;d=!0;const S=i.messages()[0];if(!S){d=!1;return}const A=await ot(r,n,e,S.seq);A&&(i.apply({type:"history",conversationId:n,messages:A.messages,hasMore:A.hasMore}),o.render(i)),d=!1},g=o.getScrollEl();if(!g)return;let l=!1;setTimeout(()=>{l=!0},300);const v=()=>{l&&g.scrollTop<80&&i.hasMoreHistory&&!d&&p()};g.addEventListener("scroll",v,{passive:!0}),o.setScrollCleanup(()=>g.removeEventListener("scroll",v))}const de=new WeakMap,be=new Map;function it(t){return`relay-launcher::${t.profileId}::${t.subjectId??""}`}let he=null;function yn(){if(he&&he.state!=="closed")return he;try{return he=new AudioContext,he}catch{return null}}function st(t){var N,V,F,X,U,oe,se,Ie;de.has(t.el)&&(de.get(t.el).close(),de.delete(t.el)),t.launcher&&((N=be.get(it(t)))==null||N.close());const e=He();let n,i=!1;const o=t.token??t.userId??e,s=o!==e?e:void 0,{wsUrl:r,httpBase:u}=_e(t.url,t.apiUrl);let d=new Yt(o);const p=t.subjectId?`${o}::${t.subjectId}`:o,g=new tn(p);let l,v=!1,S=null,A=null,z=null,w=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 g.load())d.addOptimistic(h.clientMsgId,h.content);let f=null,T=null,I=0,m=!t.launcher;if(t.launcher){const y=(t.position??"bottom-right").includes("right");f=document.createElement("div"),f.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 E=document.createElement("div"),O=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(max-width: 479px)"):null,we=P=>{t.el.classList.toggle("ocw-fs",P),E.style.cssText=P?["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(";")};we((O==null?void 0:O.matches)??!1);const ge=P=>we(P.matches);O==null||O.addEventListener("change",ge),S=O,A=ge,t.el.style.cssText="width:100%;height:100%;overflow:hidden",E.append(t.el);const Ce='<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>',Ee='<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>',G=document.createElement("button");G.type="button",G.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(";"),G.onmouseenter=()=>{G.style.transform="scale(1.08)"},G.onmouseleave=()=>{G.style.transform="scale(1)"},T=document.createElement("span"),T.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 Te=()=>{G.innerHTML=m?Ee:Ce,G.setAttribute("aria-label",m?"Close chat":"Open chat"),G.setAttribute("aria-expanded",String(m)),G.append(T)};Te(),f.append(E,G),document.body.append(f);const je=`ocw-teaser-dismissed::${t.profileId}`,Ue=typeof t.launcherMessage=="string"?{title:t.launcherMessage}:t.launcherMessage;let R=null;const zn=()=>{try{return sessionStorage.getItem(je)==="1"}catch{return!1}},Mn='<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>',ct=()=>{const P=Ue!=null&&Ue.title?Ue:d.launcherMessage??void 0;if(!(!!(P!=null&&P.title)&&!m&&!zn())){R&&(R.remove(),R=null);return}if(R)return;R=document.createElement("div"),R.setAttribute("role","button"),R.setAttribute("tabindex","0"),R.setAttribute("aria-label",P.title),R.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 Oe=document.createElement("div");if(Oe.textContent=P.title,Oe.style.cssText="font-size:15px;font-weight:600;color:#111;line-height:1.35",R.append(Oe),P.subtitle){const ee=document.createElement("div");ee.style.cssText="display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";const Fe=document.createElement("span");Fe.innerHTML=Mn,Fe.style.cssText=`color:${t.accent??"#6c5ce7"};display:inline-flex`;const dt=document.createElement("span");dt.textContent=P.subtitle,ee.append(Fe,dt),R.append(ee)}const re=document.createElement("button");re.type="button",re.setAttribute("aria-label","Dismiss"),re.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>',re.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",re.addEventListener("click",ee=>{ee.stopPropagation();try{sessionStorage.setItem(je,"1")}catch{}R&&(R.remove(),R=null)}),R.append(re);const lt=()=>{m||(m=!0,Ne(!0),Te(),I=0,T&&(T.style.display="none"),R&&(R.remove(),R=null))};R.addEventListener("click",lt),R.addEventListener("keydown",ee=>{(ee.key==="Enter"||ee.key===" ")&&(ee.preventDefault(),lt())}),f.insertBefore(R,G)};if(!document.getElementById("ocw-teaser-style")){const P=document.createElement("style");P.id="ocw-teaser-style",P.textContent="@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",document.head.append(P)}w=ct,ct();const Ne=P=>{P?(E.style.display="flex",requestAnimationFrame(()=>{E.style.opacity="1",E.style.transform="scale(1)"})):(E.style.opacity="0",E.style.transform="scale(.95)",setTimeout(()=>{m||(E.style.display="none")},180))};G.addEventListener("click",()=>{if(m=!m,Ne(m),Te(),m){I=0,T&&(T.style.display="none");try{sessionStorage.setItem(je,"1")}catch{}}w==null||w()}),z=P=>{P.key==="Escape"&&m&&(m=!1,Ne(!1),Te())},document.addEventListener("keydown",z)}const b=()=>{m||(I++,T&&(T.textContent=String(I),T.style.display="flex"))},q=()=>{try{const h=yn();if(!h)return;h.state==="suspended"&&h.resume().catch(()=>{});const y=h.createOscillator(),E=h.createGain();y.connect(E),E.connect(h.destination),y.frequency.setValueAtTime(880,h.currentTime),y.frequency.exponentialRampToValueAtTime(440,h.currentTime+.15),E.gain.setValueAtTime(.3,h.currentTime),E.gain.exponentialRampToValueAtTime(.001,h.currentTime+.3),y.start(),y.stop(h.currentTime+.3)}catch{}},_=[],j=h=>{for(;_.length;){const y=_.shift();g.add({clientMsgId:y.clientMsgId,content:y.content,ts:Date.now()}),k.send({type:"send",conversationId:h,clientMsgId:y.clientMsgId,content:y.content})}};let k;const M=t.i18n??{},W=["ar","he","fa","ur"],C=typeof navigator<"u"?(navigator.language??"").slice(0,2).toLowerCase():"";W.includes(C)&&!t.el.dir&&(t.el.dir="rtl",t.el.style.fontFamily=t.el.style.fontFamily||"Tahoma,Arial,system-ui,sans-serif");const K=`oc_prechat_${t.profileId}_${o.slice(-8)}`,$=new un(t.el,o,{onSend(h){const y=`cm_${Math.random().toString(36).slice(2)}`,E={kind:"text",text:h};if(d.addOptimistic(y,E),$.render(d),d.e2e){console.error("[relay] this chat is end-to-end encrypted — use the full widget build");return}else l?(g.add({clientMsgId:y,content:E,ts:Date.now()}),k.send({type:"send",conversationId:l,clientMsgId:y,content:E})):_.push({clientMsgId:y,content:E})},async onAttach(h){if(!l)return;const y=`${u}/upload?name=${encodeURIComponent(h.name)}`,E=`cm_${Math.random().toString(36).slice(2)}`;d.addOptimistic(E,{kind:"text",text:`📎 Uploading ${h.name}…`}),$.render(d);try{const O=await fetch(y,{method:"POST",headers:{"content-type":h.type,authorization:`Bearer ${o}`},body:h});if(!O.ok)throw new Error(`Upload failed: ${O.status}`);const{url:we,name:ge,mime:Ce,size:Ee}=await O.json();d.addOptimistic(E,{kind:"attachment",url:we,name:ge,mime:Ce,size:Ee}),$.render(d),k.send({type:"send",conversationId:l,clientMsgId:E,content:{kind:"attachment",url:we,name:ge,mime:Ce,size:Ee}})}catch(O){d.addOptimistic(E,{kind:"text",text:`⚠️ Upload failed: ${O.message}`}),$.render(d)}},onInvoke(h,y){l&&k.send({type:"invoke",conversationId:l,actionId:h,clientInvokeId:`iv_${Math.random().toString(36).slice(2)}`,...y?{inputs:y}:{}})},onTyping(h,y){l&&k.send({type:"typing",conversationId:l,isTyping:h,...y?{preview:y}:{}})},onPreChat(h){try{localStorage.setItem(K,"1")}catch{}k.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&&l&&!d.e2e&&k.send({type:"send",conversationId:l,clientMsgId:`pc_${Math.random().toString(36).slice(2,12)}`,content:{kind:"text",text:y}})},...((V=t.features)==null?void 0:V.deflection)!==!1?{onDeflectQuery(h){if(i)return;clearTimeout(n);const y=h.trim();if(y.length<3){$.hideDeflection();return}n=setTimeout(()=>{fetch(`${u}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(y.slice(0,200))}`).then(E=>E.ok?E.json():{articles:[]}).then(E=>$.showDeflection(E.articles??[])).catch(()=>$.hideDeflection())},350)}}:{},onReadUpTo(h){l&&k.send({type:"read",conversationId:l,seq:h})},onLoadMore(){if(!l||!d.e2e)return;const h=d.messages()[0];h&&k.send({type:"history",conversationId:l,beforeSeq:h.seq,limit:20})},onEdit(h,y){l&&k.send({type:"edit",conversationId:l,messageId:h,content:{kind:"text",text:y}})},onDelete(h){l&&k.send({type:"delete",conversationId:l,messageId:h})},...((F=t.features)==null?void 0:F.reactions)!==!1?{onReact(h,y,E){l&&k.send({type:"react",conversationId:l,messageId:h,emoji:y,remove:E})}}:{},...((X=t.features)==null?void 0:X.csat)!==!1?{onCsat(h){l&&fetch(`${u}/conversations/${l}/csat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify({score:h})}).catch(()=>{})}}:{},...t.translateLang?{async onTranslate(h){try{const y=await fetch(`${u}/translate`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${o}`},body:JSON.stringify({text:h,targetLang:t.translateLang})});if(!y.ok)return null;const{translated:E}=await y.json();return E}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}:{},...(U=t.user)!=null&&U.name||(oe=t.user)!=null&&oe.avatar?{userInfo:{...t.user.name?{name:t.user.name}:{},...t.user.avatar?{avatar:t.user.avatar}:{}}}:{},i18n:M});try{localStorage.getItem(K)&&$.completePreChat()}catch{}const fe=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,Se={type:"open",profileId:t.profileId,...t.kind==="direct"&&t.peerId?{kind:"direct",peerId:t.peerId}:t.subjectId?{subjectId:t.subjectId}:{},...s?{linkFrom:s}:{},...fe?{userInfo:fe}:{},...typeof location<"u"?{pageUrl:location.href}:{},...typeof document<"u"&&document.title?{pageTitle:document.title}:{},...(se=t.subject)!=null&&se.title?{subjectTitle:t.subject.title}:{},...(Ie=t.subject)!=null&&Ie.subtitle?{subjectMeta:t.subject.subtitle}:{}};k=new Xt({...t.refreshToken?{refreshToken:t.refreshToken}:{},url:r,token:o,open:Se,getCursor:()=>d.highestSeq(),onStatusChange:(h,y)=>$.setConnStatus(h,y),onFrame(h){if(h.type==="opened"){if(l=h.conversation.id,!v){v=!0;for(const y of g.load())k.send({type:"send",conversationId:l,clientMsgId:y.clientMsgId,content:y.content})}mn(r,o,l,d,$,u),_.length&&j(l)}h.type==="ack"&&g.remove(h.clientMsgId),(async()=>(d.apply(h),h.type==="manifest"&&(w==null||w()),h.type==="message"&&h.message.senderId!==o&&!h.message.internal&&(b(),q()),$.render(d)))()}}),k.connect(),$.render(d);const x=t.launcher?it(t):null,L={close:()=>{i=!0,clearTimeout(n),k.close(),f==null||f.remove(),$.destroy(),S&&A&&S.removeEventListener("change",A),z&&(document.removeEventListener("keydown",z),z=null),de.delete(t.el),x&&be.get(x)===L&&be.delete(x)}};return de.set(t.el,L),x&&be.set(x,L),L}const De="wss://api.paramms.com/ws";function bn(t,e){const n=t.profileId??t.appId;if(!n)throw new Error("Relay: `profileId` is required (your chatroom id, e.g. 'p_...').");const i=t.subjectId??(t.listingId?`listing_${t.listingId}`:void 0),o=t.launcher??!0,s=t.contextTitle??t.listingTitle??t.subjectTitle,r=t.contextSubtitle??t.listingMeta??t.subjectMeta,u=t.contextStatus??t.listingStatus??t.subjectStatus,d=t.listingPrice??t.subjectPrice,p=s?{title:s,...r?{subtitle:r}:{},...d!=null?{tags:[`$${d.toLocaleString()}`]}:{},...u?{status:u}:{}}:void 0,g=t.subject??p,l=t.userName??t.name,v=t.userEmail??t.email,S=t.userAvatar??t.avatar,A=l||v||S?{...l?{name:l}:{},...v?{email:v}:{},...S?{avatar:S}:{}}:void 0,z=t.user??A,w=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??De,profileId:n,...t.apiUrl?{apiUrl:t.apiUrl}:{},...i?{subjectId:i}:{},...t.token?{token:t.token}:{},...t.refreshToken?{refreshToken:t.refreshToken}:{},...t.userId?{userId:t.userId}:{},...g?{subject:g}:{},...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}:{},...w?{launcherMessage:w}:{},...rt(t)&&!o?{onBack:()=>{pe=!0,ue=!1,ve(ne)}}:{},launcher:o,position:t.position??"bottom-right"}}let Q=null,D=null,te=!1,ne={},pe=!1,ue=!1;function rt(t){return!!(t.inbox||t.inboxStart)}let Z=null;function vn(t,e){const n=!e&&!!t.el;if(te&&!n&&(D.innerHTML="",D=null,te=!1),n){const i=typeof t.el=="string"?document.querySelector(t.el):t.el;i instanceof HTMLElement?(D&&D!==i&&!te&&D.remove(),D=i,te=!0):console.error(`[Relay] \`el\` ("${String(t.el)}") did not match any element — falling back to an auto-created host.`)}return(!D||!te&&!D.isConnected)&&(D=document.createElement("div"),D.id="relay-widget-root",document.body.appendChild(D),te=!1),!e&&t.height&&(D.style.height=t.height,D.style.width||(D.style.width="100%")),D}function ve(t){try{const e=t.launcher??!0;Z==null||Z(),Z=null,Q==null||Q.close(),Q=null;const n=vn(t,e);if(rt(t)&&!e&&pe){kn(t,n);return}Q=st(bn(t,n))}catch(e){console.error("[Relay]",e instanceof Error?e.message:e)}}async function kn(t,e){const n=t.profileId??t.appId;if(!n&&!t.tenantId){console.error("[Relay] `inbox` requires `profileId` or `tenantId`.");return}e.innerHTML="";const i=document.createElement("div");i.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;background:#fff";const o=document.createElement("div");o.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=()=>{pe=!1,ve(ne)},i.append(o,s);const u=!ue&&!!n;u&&i.append(r),e.appendChild(i);let d=null,p=null;Z=()=>{p==null||p.close(),d==null||d.close(),e.innerHTML=""};let g;try{({mountChatList:g}=await Promise.resolve().then(()=>An))}catch(v){console.error("[Relay] could not load the conversation list module.",v),o.isConnected&&(o.style.cssText+=";display:flex;align-items:center;justify-content:center;padding:16px;font:13px system-ui;color:#b91c1c;text-align:center",o.textContent="Could not load conversations.");return}if(!o.isConnected)return;const l=v=>{const S=v.profileId??n;if(!S){console.error("[Relay] conversation row has no chatroom; cannot open it.",v);return}r.style.display="none",p==null||p.close(),p=st({el:s,url:t.url??De,...t.apiUrl?{apiUrl:t.apiUrl}:{},profileId:S,...v.kind==="direct"&&v.peerId?{kind:"direct",peerId:v.peerId}:v.subjectId?{subjectId:v.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}:{}}}:{},...v.subjectTitle?{subject:{title:v.subjectTitle,...v.subjectMeta?{subtitle:v.subjectMeta}:{}}}:{},...t.accent?{accent:t.accent}:{},launcher:!1,onBack:()=>{p==null||p.close(),p=null,s.style.display="none",o.style.display="",r.style.display="",d==null||d.refresh()}}),o.style.display="none",s.style.display=""};d=g({el:o,url:t.url??De,...t.apiUrl?{apiUrl:t.apiUrl}:{},...n?{profileId:n}:{},...t.tenantId?{tenantId:t.tenantId}:{},scope:t.inboxScope??"tenant",...u?{reserveCloseSpace:!0}:{},onSelect:l,onNewChat:()=>{const v=n??(d==null?void 0:d.defaultProfileId());v&&l({id:"__new__",profileId:v,state:"open",updatedAt:Date.now()})},...t.token?{token:t.token}:{},...t.userId?{userId:t.userId}:{},...t.accent?{accent:t.accent}:{}})}function at(t){ue=!!(t.inboxStart&&!(t.launcher??!0)),pe=ue,ne={...t},ve(ne)}function Sn(t){ne={...ne,...t},ve(ne)}function In(){Z==null||Z(),Z=null,Q==null||Q.close(),Q=null,D&&!te&&D.remove(),D=null,te=!1,pe=!1,ue=!1,ne={}}function qe(t,e){switch(t){case"boot":at(e??{});break;case"update":case"identify":Sn(e??{});break;case"shutdown":In();break;default:console.warn("[Relay] unknown command:",t)}}function Cn(){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),i=e==null?void 0:e.relayTenantId;if(!n&&!i)return null;const o=n?{profileId:n}:{};i&&(o.tenantId=i),e.relayUser&&(o.userId=e.relayUser),e.relayToken&&(o.token=e.relayToken),e.relayListing&&(o.listingId=e.relayListing),e.relayAccent&&(o.accent=e.relayAccent),e.relayAccent2&&(o.accent2=e.relayAccent2),e.relayTheme&&(o.theme=e.relayTheme),e.relayWebfont==="false"&&(o.webfont=!1),e.relayUrl&&(o.url=e.relayUrl);const s=e.relayPosition;(s==="bottom-left"||s==="bottom-right")&&(o.position=s),e.relayLauncherMessage&&(o.launcherMessage=e.relayLauncherMessage),e.relayLauncherSubtitle&&(o.launcherSubtitle=e.relayLauncherSubtitle),e.relayLauncher==="false"&&(o.launcher=!1),e.relayUserName&&(o.userName=e.relayUserName),e.relayUserEmail&&(o.userEmail=e.relayUserEmail),e.relayUserAvatar&&(o.userAvatar=e.relayUserAvatar),e.relayContextTitle&&(o.contextTitle=e.relayContextTitle),e.relayContextSubtitle&&(o.contextSubtitle=e.relayContextSubtitle),e.relayContextStatus&&(o.contextStatus=e.relayContextStatus),e.relayListingTitle&&(o.listingTitle=e.relayListingTitle),e.relayListingMeta&&(o.listingMeta=e.relayListingMeta),e.relayListingPrice&&(o.listingPrice=Number(e.relayListingPrice)),e.relayListingStatus&&(o.listingStatus=e.relayListingStatus),e.relayTarget&&(o.el=e.relayTarget),e.relayHeight&&(o.height=e.relayHeight),e.relayInbox==="true"&&(o.inbox=!0),e.relayInbox==="false"&&(o.inbox=!1),e.relayInboxStart==="true"&&(o.inboxStart=!0),e.relayInboxStart==="false"&&(o.inboxStart=!1);const r=e.relayInboxScope;return(r==="tenant"||r==="profile")&&(o.inboxScope=r),e.relayTranslateLang&&(o.translateLang=e.relayTranslateLang),o}if(typeof window<"u"){const t=window,e=t.Relay&&t.Relay.q?t.Relay.q:[];t.Relay=qe;let n=!1;for(const i of e){const[o,s]=i;o==="boot"&&(n=!0),qe(o,s)}if(!n){const i=t.relaySettings??Cn();i&&at(i)}}const En=`
192
+ `,tt="objectchat-widget-styles",an=["👍","❤️","😂","😮","😢","🙏"],cn=400,ln='<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 dn(){if(typeof document>"u"||document.getElementById(tt))return;const t=document.createElement("style");t.id=tt,t.textContent=rn,document.head.appendChild(t)}const nt="ocw-webfont";function hn(){if(typeof document>"u"||document.getElementById(nt))return;const t=document.createElement("link");t.id=nt,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 a(t,e,n){const i=document.createElement(t);return e&&(i.className=e),n!==void 0&&(i.textContent=n),i}function pn(t){try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return""}}function Pe(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 un{constructor(e,n,i,o={}){c(this,"scroll");c(this,"chips");c(this,"typing");c(this,"quick");c(this,"formHost");c(this,"csatPanel");c(this,"awayNotice");c(this,"headStatus");c(this,"reopenBtn");c(this,"preChatPanel");c(this,"deflectPanel");c(this,"preChatBuilt",!1);c(this,"preChatDone",!1);c(this,"footer");c(this,"input");c(this,"subjectCard");c(this,"e2eBadge");c(this,"statusBadge");c(this,"headerName");c(this,"connStatus");c(this,"typingTimer",null);c(this,"csatSubmitted",!1);c(this,"sendBtn");c(this,"compactObserver",null);c(this,"storeRef",null);c(this,"cfgAccent2");c(this,"scrollCleanup",null);c(this,"translationCache",new Map);c(this,"showingTranslation",new Set);c(this,"subjectBuilt",!1);var f,T,I,m,b,q,_,j,k,M,W;this.root=e,this.me=n,this.h=i,this.cfg=o,dn(),o.webfont!==!1&&hn(),e.replaceChildren(),e.classList.add("ocw"),o.accent&&e.style.setProperty("--ocw-accent",o.accent);const s=o.accent2??o.accent;s&&e.style.setProperty("--ocw-accent2",s),this.cfgAccent2=o.accent2,e.dataset.theme=o.theme??"light";const r=a("div","ocw-head");if(this.h.onBack){const C=a("button","ocw-back","‹");C.type="button",C.setAttribute("aria-label","Back"),C.addEventListener("click",()=>this.h.onBack()),r.append(C)}const u=a("div","ocw-avatar");if((f=o.userInfo)!=null&&f.avatar){const C=document.createElement("img");C.src=o.userInfo.avatar,C.alt=o.userInfo.name??"You",C.style.cssText="width:100%;height:100%;border-radius:50%;object-fit:cover",u.append(C)}else u.textContent=(T=o.userInfo)!=null&&T.name?o.userInfo.name[0].toUpperCase():"🧑";r.append(u);const d=a("div","ocw-head-main");this.headerName=a("div","ocw-head-name",((I=o.subject)==null?void 0:I.ownerLabel)??((m=o.subject)==null?void 0:m.title)??""),d.append(this.headerName),this.headStatus=a("div","ocw-head-status"),this.headStatus.style.display="none",d.append(this.headStatus),(b=o.subject)!=null&&b.subtitle&&d.append(a("div","ocw-head-meta",o.subject.subtitle)),r.append(d),this.statusBadge=a("span","ocw-badge",((q=o.subject)==null?void 0:q.status)??""),(_=o.subject)!=null&&_.status||(this.statusBadge.style.display="none"),r.append(this.statusBadge),this.e2eBadge=a("span","ocw-e2e","🔒 E2E"),this.e2eBadge.style.display="none",r.append(this.e2eBadge),this.connStatus=a("span","ocw-conn-status"),this.connStatus.style.display="none",r.append(this.connStatus),r.append(a("button","ocw-menu","⋯")),this.chips=a("div","ocw-chiprow"),this.scroll=a("div","ocw-scroll"),this.subjectCard=a("div","ocw-subject"),this.typing=a("div","ocw-typing");const p=a("div","ocw-typing-bubble");p.append(a("div","ocw-typing-dot"),a("div","ocw-typing-dot"),a("div","ocw-typing-dot")),this.typing.append(a("div","ocw-dot","🧑"),p),this.quick=a("div","ocw-quick");for(const C of o.quickReplies??[]){const K=a("button",void 0,C);K.addEventListener("click",()=>{this.h.onSend(C),this.quick.style.display="none"}),this.quick.append(K)}this.formHost=a("div","ocw-form-host"),this.csatPanel=a("div","ocw-csat"),this.csatPanel.style.display="none",this.awayNotice=a("div","ocw-away"),this.awayNotice.style.display="none",this.preChatPanel=a("div","ocw-prechat"),this.preChatPanel.style.display="none",this.deflectPanel=a("div","ocw-deflect"),this.deflectPanel.style.display="none",this.input=a("textarea",void 0),this.input.rows=1,this.input.placeholder=((j=o.i18n)==null?void 0:j.placeholder)??"Message…";const g=a("button","ocw-sendbtn");g.type="button";const l=(k=o.i18n)==null?void 0:k.send;l?(g.textContent=l,g.classList.add("ocw-sendbtn-label"),g.setAttribute("aria-label",l)):(g.innerHTML=ln,g.setAttribute("aria-label","Send message")),g.disabled=!0,this.sendBtn=g,g.addEventListener("click",()=>this.flushSend()),this.input.addEventListener("input",()=>{var C,K;this.sendBtn.disabled=this.input.value.trim().length===0,this.autoGrowInput(),this.storeRef&&!this.storeRef.messages().some($=>$.senderRole==="guest")?(K=(C=this.h).onDeflectQuery)==null||K.call(C,this.input.value):this.hideDeflection()}),this.input.addEventListener("keydown",C=>{C.isComposing||C.keyCode===229||(C.key==="Enter"&&!C.shiftKey?(C.preventDefault(),this.flushSend()):this.signalTyping())});const v=a("button","ocw-attach","📎");v.title="Attach image or file";const S=document.createElement("input");S.type="file",S.accept="image/*,.pdf,.txt,.doc,.docx",S.style.display="none",v.addEventListener("click",()=>S.click()),S.addEventListener("change",()=>{var C;(C=S.files)!=null&&C[0]&&this.h.onAttach&&this.h.onAttach(S.files[0]),S.value=""});const A=a("div","ocw-input");A.append(v,S,this.input,g);const z=a("div","ocw-footer");((M=o.i18n)==null?void 0:M.poweredBy)!==void 0?z.textContent=o.i18n.poweredBy:z.innerHTML='Powered by <a href="https://relay.paramms.com" target="_blank" rel="noopener">Relay</a>',this.footer=z,this.reopenBtn=a("button","ocw-reopen",((W=this.cfg.i18n)==null?void 0:W.reopen)??"Reopen conversation"),this.reopenBtn.type="button",this.reopenBtn.addEventListener("click",()=>{this.reopenBtn.style.display="none";const C=this.root.querySelector(".ocw-input textarea");C==null||C.focus()}),e.append(r,this.chips,this.scroll,this.typing,this.quick,this.formHost,this.csatPanel,this.preChatPanel,this.deflectPanel,this.awayNotice,A,this.reopenBtn,this.footer);const w=C=>{e.classList.toggle("ocw-compact",C>0&&C<cn)};w(e.clientWidth),typeof ResizeObserver<"u"&&(this.compactObserver=new ResizeObserver(C=>{var $;const K=(($=C[0])==null?void 0:$.contentRect.width)??e.clientWidth;w(K)}),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,A,z,w,f,T,I,m;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 i=this.scroll.scrollHeight,o=this.scroll.scrollTop;if(this.scroll.replaceChildren(),this.subjectCard.childNodes.length&&this.scroll.append(this.subjectCard),e.hasMoreHistory){const b=a("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 q=b.senderRole!=="system"&&b.senderId!==this.me&&!b.internal&&b.senderId!==r;this.scroll.append(this.messageEl(b,e,q)),b.senderRole!=="system"&&(r=b.senderId),b.senderId!==this.me&&b.seq>s&&(s=b.seq)}o>20?this.scroll.scrollTop=this.scroll.scrollHeight-i+o:this.scroll.scrollTop=this.scroll.scrollHeight,s>0&&this.h.onReadUpTo(s);const u=[...e.typing];this.typing.classList.toggle("active",u.length>0);const d=this.typing.querySelector(".ocw-typing-bubble");d&&d.setAttribute("aria-label",u.length?"typing":""),this.footer.style.display=e.whiteLabel?"none":"block";const p=e.messages().some(b=>b.senderRole==="guest");if(!!((A=e.preChat)!=null&&A.enabled)&&!this.preChatDone&&!p&&(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(a("span","ocw-away-icon","🌙"),a("span","",""));const b=this.awayNotice.lastChild;b.textContent=e.offlineMessage||((w=this.cfg.i18n)==null?void 0:w.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";(f=this.root.querySelector(".ocw-input"))==null||f.style.removeProperty("display")}const l=["resolved","closed","sold","issued","checked_out"];this.h.onCsat&&!this.csatSubmitted&&l.includes(e.state)&&e.messages().length>0&&(this.csatPanel.style.display==="none"&&this.buildCsatPanel(),this.csatPanel.style.display="block");const v=l.includes(e.state);if(e.offline?(this.headStatus.textContent=`● ${e.offlineMessage||((T=this.cfg.i18n)==null?void 0:T.away)||"Away"}`,this.headStatus.className="ocw-head-status away",this.headStatus.style.display=""):e.conversationId?(this.headStatus.textContent=`● ${((I=this.cfg.i18n)==null?void 0:I.online)??"Online"}`,this.headStatus.className="ocw-head-status online",this.headStatus.style.display=""):this.headStatus.style.display="none",v&&e.messages().length>0){const b=a("div","ocw-resolved-note",`— ${((m=this.cfg.i18n)==null?void 0:m.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 i=e==="error";this.connStatus.className=`ocw-conn-status${i?" err":e==="reconnecting"?" warn":""}`,this.connStatus.textContent=i?`⚠ ${n??"Chat unavailable"}`:e==="reconnecting"?n??"↻ reconnecting…":"● connecting…"}buildPreChatPanel(e){var d;this.preChatBuilt=!0,this.preChatPanel.replaceChildren(),this.preChatPanel.append(a("div","ocw-prechat-title",e.title??"Before we start…"));const n=a("div","ocw-offline-form"),i={};for(const p of e.fields??["name","email"]){const g=a("input","ocw-offline-input");g.type=p==="email"?"email":p==="phone"?"tel":"text",g.placeholder=p==="name"?"Your name":p==="email"?"Your email":"Your phone number",i[p]=g,n.append(g)}let o=null;if((d=e.topics)!=null&&d.length){o=a("select",void 0);const p=document.createElement("option");p.value="",p.textContent="What is this about?",o.append(p);for(const g of e.topics){const l=document.createElement("option");l.value=g,l.textContent=g,o.append(l)}n.append(o)}let s=null,r=null;if(e.callbackOption){const p=a("label","ocw-prechat-cb");s=document.createElement("input"),s.type="checkbox",p.append(s,document.createTextNode("📞 Request a call back")),n.append(p),i.phone||(r=a("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 u=a("button","ocw-offline-submit","Start chat");u.type="button",u.addEventListener("click",()=>{var v,S,A,z,w,f,T;const p=(v=i.email)==null?void 0:v.value.trim();if(i.email&&(!p||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(p))){i.email.focus();return}const g=!!(s!=null&&s.checked),l=(((S=i.phone)==null?void 0:S.value)??(r==null?void 0:r.value)??"").trim();if(g&&!l){(A=i.phone??r)==null||A.focus();return}if(o&&((z=e.topics)!=null&&z.length)&&!o.value){o.focus();return}u.disabled=!0,this.completePreChat(),(T=(f=this.h).onPreChat)==null||T.call(f,{...(w=i.name)!=null&&w.value.trim()?{name:i.name.value.trim()}:{},...p?{email:p}:{},...l?{phone:l}:{},...o!=null&&o.value?{topic:o.value}:{},...g?{callback:!0}:{}})}),n.append(u),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(a("div","ocw-deflect-hint","Instant answers — tap to expand"));for(const n of e.slice(0,3)){const i=a("button","ocw-deflect-card");i.append(a("div","ocw-deflect-q",n.title),a("div","ocw-deflect-a",n.answer)),i.addEventListener("click",()=>i.classList.toggle("open")),this.deflectPanel.append(i)}this.deflectPanel.style.display="flex"}hideDeflection(){this.deflectPanel.style.display="none",this.deflectPanel.replaceChildren()}buildCsatPanel(){this.csatPanel.replaceChildren(),this.csatPanel.append(a("div","ocw-csat-title","How did we do?"));const e=a("div","ocw-csat-stars"),n=[];for(let i=1;i<=5;i++){const o=a("button","ocw-csat-star","★");o.dataset.score=String(i),o.addEventListener("mouseenter",()=>n.forEach((s,r)=>s.classList.toggle("lit",r<i))),o.addEventListener("mouseleave",()=>n.forEach(s=>s.classList.remove("lit"))),o.addEventListener("click",()=>{var s,r;this.csatSubmitted=!0,this.csatPanel.replaceChildren(a("div","ocw-csat-done",`Thanks for your ${i}★ rating!`)),(r=(s=this.h).onCsat)==null||r.call(s,i)}),n.push(o),e.append(o)}this.csatPanel.append(e)}buildSubjectCard(e){if(this.subjectBuilt)return;const n=e.subject,i=this.cfg.subject,o=(n==null?void 0:n.title)??(i==null?void 0:i.title);if(!o)return;this.subjectBuilt=!0,this.subjectCard.replaceChildren(),this.subjectCard.append(a("div","ocw-subject-title",o)),i!=null&&i.subtitle&&this.subjectCard.append(a("div","ocw-subject-sub",i.subtitle));const s=a("div","ocw-tags");if(n)for(const[u,d]of Object.entries(n.fields))s.append(a("span","ocw-tag",`${u}: ${d}`));else for(const u of(i==null?void 0:i.tags)??[])s.append(a("span","ocw-tag",u));s.childNodes.length&&this.subjectCard.append(s);const r=(n==null?void 0:n.state)??(i==null?void 0:i.status);r&&(this.statusBadge.textContent=r,this.statusBadge.style.display="inline-flex")}chipEl(e){const n=a("button","ocw-chip",e.icon?`${e.icon} ${e.label}`:e.label);return n.dataset.actionId=e.id,n.addEventListener("click",async()=>{var i;e.confirm&&!await this.confirm(e.label)||((i=e.input)!=null&&i.length?this.openForm(e):this.h.onInvoke(e.id))}),n}confirm(e){return new Promise(n=>{const i=a("div","ocw-modal"),o=a("div","ocw-modal-card");o.append(a("div","ocw-modal-title",e)),o.append(a("div","ocw-modal-body",`Confirm “${e}”?`));const s=a("div","ocw-modal-actions"),r=a("button","ocw-modal-cancel","Cancel"),u=a("button","ocw-modal-ok","Confirm"),d=p=>{i.remove(),n(p)};r.addEventListener("click",()=>d(!1)),u.addEventListener("click",()=>d(!0)),i.addEventListener("click",p=>{p.target===i&&d(!1)}),s.append(r,u),o.append(s),i.append(o),this.root.append(i),u.focus()})}openForm(e){var u,d;this.formHost.replaceChildren();const n=a("div","ocw-form");n.append(a("div","ocw-form-title",e.icon?`${e.icon} ${e.label}`:e.label));const i=new Map;for(const p of e.input??[]){const g=a("label","ocw-form-row");if(g.append(a("span","ocw-form-lbl",p.label)),p.type==="select"&&((u=p.options)!=null&&u.length)){const l=a("select","ocw-form-input");p.required||l.append(a("option",void 0,"— select —"));for(const v of p.options){const S=a("option");S.value=v,S.textContent=v,l.append(S)}p.required&&(l.required=!0),g.append(l),i.set(p.name,l)}else{const l=a("input","ocw-form-input");l.type=p.type==="number"?"number":p.type==="date"?"datetime-local":"text",p.required&&(l.required=!0),g.append(l),i.set(p.name,l)}n.append(g)}const o=a("div","ocw-form-actions"),s=a("button","ocw-form-cancel","Cancel"),r=a("button","ocw-form-submit","Send");s.addEventListener("click",()=>this.formHost.replaceChildren()),r.addEventListener("click",()=>{const p={};for(const[g,l]of i){if(l.required&&!l.value){l.style.borderColor="#e5484d";return}p[g]=l.type==="number"?Number(l.value):l.value}this.formHost.replaceChildren(),this.h.onInvoke(e.id,p)}),o.append(s,r),n.append(o),this.formHost.append(n),(d=i.values().next().value)==null||d.focus()}messageEl(e,n,i=!1){var v,S,A,z;if(e.senderRole==="system"){const w=a("div","ocw-sys");return w.textContent=e.deletedAt?"message deleted":Pe(e.content),w}const o=e.senderId===this.me,s=!!e.internal,r=a("div",`ocw-row ${s?"ocw-note mine":o?"mine":"theirs"} ${e.senderRole==="bot"?"ocw-bot":""}`);!o&&!s&&r.append(a("div","ocw-dot",e.senderRole==="bot"?"🤖":"🧑"));const u=a("div");if(i){const w=e.senderRole==="bot"?((v=this.cfg.i18n)==null?void 0:v.aiAssistant)??"AI Assistant":((S=this.cfg.subject)==null?void 0:S.ownerLabel)??((A=this.cfg.subject)==null?void 0:A.title)??"Support";u.append(a("div","ocw-msg-sender",w))}const d=a("div","ocw-bubble-wrap");if(e.replyToId){const w=a("div","ocw-reply-to","↩ replying to a message");w.style.cssText="font-size:11px;color:var(--ocw-mut);margin-bottom:2px;font-style:italic",u.append(w)}const p=a("div","ocw-bubble");let g=null;if(e.deletedAt)p.append(a("span","ocw-deleted","message deleted"));else if(e.content.kind==="attachment"){const w=e.content;if((z=w.mime)!=null&&z.startsWith("image/")){const f=document.createElement("img");f.src=w.url,f.alt=w.name??"image",f.style.cssText="max-width:220px;max-height:160px;border-radius:10px;display:block;cursor:pointer",f.addEventListener("click",()=>window.open(w.url,"_blank")),p.append(f)}else{const f=document.createElement("a");f.href=w.url,f.target="_blank",f.rel="noopener",f.style.cssText="display:flex;align-items:center;gap:8px;color:inherit;text-decoration:none",f.append(a("span",void 0,"📄"),a("span",void 0,w.name??"file")),p.append(f)}}else if(e.content.kind==="appointment"){const w=e.content,f=a("div","ocw-appt");f.append(a("div","ocw-appt-title",`📅 ${w.title}`)),f.append(a("div","ocw-appt-time",new Date(w.startIso).toLocaleString()+" – "+new Date(w.endIso).toLocaleTimeString())),w.location&&f.append(a("div","ocw-appt-loc",`📍 ${w.location}`)),w.description&&f.append(a("div","ocw-appt-desc",w.description));const T=a("div","ocw-appt-links"),I=document.createElement("a");I.href=w.googleUrl,I.target="_blank",I.rel="noopener",I.className="ocw-appt-btn",I.textContent="📅 Add to Google Calendar";const m=document.createElement("a");m.href=w.icalUrl,m.download=`${w.title}.ics`,m.className="ocw-appt-btn ocw-appt-btn-sec",m.textContent="🍎 Apple / iCal",T.append(I,m),f.append(T),p.append(f)}else g=document.createTextNode(Pe(e.content)),p.append(g),e.editedAt&&p.append(a("span","ocw-edited","(edited)"));if(d.append(p),!o&&!s&&this.h.onTranslate&&e.content.kind==="text"&&!e.deletedAt&&e.seq>0&&g){const w=e.content.text;if(w.trim()){const f=a("button","ocw-translate-btn","🌐");f.type="button",f.title="Translate",f.addEventListener("click",T=>{if(T.stopPropagation(),this.showingTranslation.has(e.id)){this.showingTranslation.delete(e.id),g.textContent=w,f.textContent="🌐",f.title="Translate";return}const I=this.translationCache.get(e.id);if(I!==void 0){this.showingTranslation.add(e.id),g.textContent=I,f.textContent="↩",f.title="Show original";return}f.textContent="⏳",this.h.onTranslate(w).then(m=>{if(m===null){f.textContent="⚠️",f.title="Translation unavailable",setTimeout(()=>{f.textContent="🌐",f.title="Translate"},1500);return}this.translationCache.set(e.id,m),this.showingTranslation.add(e.id),g.textContent=m,f.textContent="↩",f.title="Show original"})}),d.append(f)}}if(o&&!e.deletedAt&&e.seq>0&&(this.h.onEdit??this.h.onDelete)){const w=a("div","ocw-msg-menu");if(this.h.onEdit){const f=a("button",void 0,"✏️");f.title="Edit",f.addEventListener("click",T=>{T.stopPropagation();const I=Pe(e.content),m=document.createElement("textarea");m.value=I,m.rows=Math.min(4,Math.ceil(I.length/40)+1),m.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=a("button","ocw-form-submit","Save");b.style.cssText="margin-top:6px;padding:5px 14px;font-size:13px";const q=a("button","ocw-form-cancel","Cancel");q.style.cssText="margin-top:6px;padding:5px 10px;font-size:13px";const _=a("div");_.style.cssText="display:flex;gap:6px;justify-content:flex-end",_.append(q,b);const j=a("div");j.append(m,_),p.replaceChildren(j),m.focus(),m.select();const k=()=>p.replaceChildren(g??document.createTextNode(I));q.addEventListener("click",k),b.addEventListener("click",()=>{const M=m.value.trim();M&&M!==I&&this.h.onEdit(e.id,M),k()}),m.addEventListener("keydown",M=>{M.key==="Enter"&&!M.shiftKey&&(M.preventDefault(),b.click()),M.key==="Escape"&&k()})}),w.append(f)}if(this.h.onDelete){const f=a("button","del","🗑");f.title="Delete",f.addEventListener("click",T=>{T.stopPropagation(),this.h.onDelete(e.id)}),w.append(f)}d.append(w)}if(u.append(d),this.h.onReact&&!e.deletedAt&&e.seq>0){const w=a("div","ocw-react-wrap"),f=a("div","ocw-react");if(e.reactions&&Object.keys(e.reactions).length)for(const[m,b]of Object.entries(e.reactions)){const q=a("button",`ocw-react-pill${b.includes(this.me)?" mine":""}`,`${m} ${b.length}`);q.addEventListener("click",()=>{var _,j;return(j=(_=this.h).onReact)==null?void 0:j.call(_,e.id,m,b.includes(this.me))}),f.append(q)}const T=a("button","ocw-react-btn","+"),I=a("div","ocw-react-picker");for(const m of an){const b=a("button",void 0,m);b.addEventListener("click",q=>{var j,k,M,W;q.stopPropagation();const _=(k=(j=e.reactions)==null?void 0:j[m])==null?void 0:k.includes(this.me);(W=(M=this.h).onReact)==null||W.call(M,e.id,m,!!_),I.style.display="none"}),I.append(b)}I.style.display="none",T.addEventListener("click",m=>{m.stopPropagation();const b=I.style.display==="none";I.style.display=b?"flex":"none",b&&document.addEventListener("click",()=>{I.style.display="none"},{once:!0})}),f.append(T),w.append(f,I),u.append(w)}else e.reactions&&Object.keys(e.reactions).length&&u.append(a("div","ocw-react",Object.entries(e.reactions).map(([w,f])=>`${w}${f.length}`).join(" ")));const l=a("div","ocw-time ocw-meta",pn(e.ts));if(o&&e.status){const w=a("span",`ocw-tick${e.status==="read"?" read":e.status==="delivered"?" delivered":""}`,fn(e.status));l.append(w)}return o&&e.seq>0&&n.lastReadByOthers>=e.seq&&l.append(a("span","ocw-seen"," · Seen")),u.append(l),r.append(u),r}}function fn(t){switch(t){case"read":return"✓✓";case"delivered":return"✓✓";case"sent":return"✓";default:return"🕓"}}const wn=20;function _e(t,e){var d;const n=t.trim().replace(/\/+$/,""),i=(d=n.match(/^(https|http|wss|ws):\/\//))==null?void 0:d[1],o=i?i==="https"||i==="wss":!0,s=(i?n.slice(i.length+3):n).replace(/\/ws$/,""),r=e?e.trim().replace(/\/+$/,""):`${o?"https":"http"}://${s}`;return{wsUrl:`${o?"wss":"ws"}://${s}/ws`,httpBase:r}}function gn(t){return _e(t).httpBase}function xn(t,e,n,i){const o=`beforeSeq=${n}&limit=${i}`;return[`${t}/conversations/${e}/messages?${o}`,`${t}/conversations/${e}/history?${o}`]}async function ot(t,e,n,i,o=wn){let s,r=!1;for(const u of xn(t,e,i,o))try{const d=await fetch(u,{headers:{authorization:`Bearer ${n}`}});if(r=!0,!d.ok)continue;const p=await d.json();return{messages:p.messages??[],hasMore:p.hasMore??!1}}catch(d){s=d}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 mn(t,e,n,i,o,s){const r=s?s.replace(/\/+$/,""):gn(t),u=await ot(r,n,e,Number.MAX_SAFE_INTEGER);if(!u||(u.messages.length?(i.apply({type:"sync",conversationId:n,messages:u.messages}),i.apply({type:"history",conversationId:n,messages:[],hasMore:u.hasMore}),o.render(i)):i.apply({type:"history",conversationId:n,messages:[],hasMore:!1}),!u.hasMore))return;let d=!1;const p=async()=>{if(d||!i.hasMoreHistory)return;d=!0;const S=i.messages()[0];if(!S){d=!1;return}const A=await ot(r,n,e,S.seq);A&&(i.apply({type:"history",conversationId:n,messages:A.messages,hasMore:A.hasMore}),o.render(i)),d=!1},g=o.getScrollEl();if(!g)return;let l=!1;setTimeout(()=>{l=!0},300);const v=()=>{l&&g.scrollTop<80&&i.hasMoreHistory&&!d&&p()};g.addEventListener("scroll",v,{passive:!0}),o.setScrollCleanup(()=>g.removeEventListener("scroll",v))}const de=new WeakMap,be=new Map;function it(t){return`relay-launcher::${t.profileId}::${t.subjectId??""}`}let he=null;function yn(){if(he&&he.state!=="closed")return he;try{return he=new AudioContext,he}catch{return null}}function st(t){var N,V,F,X,U,oe,se,Ie;de.has(t.el)&&(de.get(t.el).close(),de.delete(t.el)),t.launcher&&((N=be.get(it(t)))==null||N.close());const e=He();let n,i=!1;const o=t.token??t.userId??e,s=o!==e?e:void 0,{wsUrl:r,httpBase:u}=_e(t.url,t.apiUrl);let d=new Yt(o);const p=t.subjectId?`${o}::${t.subjectId}`:o,g=new tn(p);let l,v=!1,S=null,A=null,z=null,w=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 g.load())d.addOptimistic(h.clientMsgId,h.content);let f=null,T=null,I=0,m=!t.launcher;if(t.launcher){const y=(t.position??"bottom-right").includes("right");f=document.createElement("div"),f.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 E=document.createElement("div"),O=typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia("(max-width: 479px)"):null,we=P=>{t.el.classList.toggle("ocw-fs",P),E.style.cssText=P?["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(";")};we((O==null?void 0:O.matches)??!1);const ge=P=>we(P.matches);O==null||O.addEventListener("change",ge),S=O,A=ge,t.el.style.cssText="width:100%;height:100%;overflow:hidden",E.append(t.el);const Ce='<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>',Ee='<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>',G=document.createElement("button");G.type="button",G.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(";"),G.onmouseenter=()=>{G.style.transform="scale(1.08)"},G.onmouseleave=()=>{G.style.transform="scale(1)"},T=document.createElement("span"),T.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 Te=()=>{G.innerHTML=m?Ee:Ce,G.setAttribute("aria-label",m?"Close chat":"Open chat"),G.setAttribute("aria-expanded",String(m)),G.append(T)};Te(),f.append(E,G),document.body.append(f);const je=`ocw-teaser-dismissed::${t.profileId}`,Ue=typeof t.launcherMessage=="string"?{title:t.launcherMessage}:t.launcherMessage;let R=null;const zn=()=>{try{return sessionStorage.getItem(je)==="1"}catch{return!1}},Mn='<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>',ct=()=>{const P=Ue!=null&&Ue.title?Ue:d.launcherMessage??void 0;if(!(!!(P!=null&&P.title)&&!m&&!zn())){R&&(R.remove(),R=null);return}if(R)return;R=document.createElement("div"),R.setAttribute("role","button"),R.setAttribute("tabindex","0"),R.setAttribute("aria-label",P.title),R.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 Oe=document.createElement("div");if(Oe.textContent=P.title,Oe.style.cssText="font-size:15px;font-weight:600;color:#111;line-height:1.35",R.append(Oe),P.subtitle){const ee=document.createElement("div");ee.style.cssText="display:flex;align-items:center;gap:6px;margin-top:6px;font-size:13px;color:#6b7280";const Fe=document.createElement("span");Fe.innerHTML=Mn,Fe.style.cssText=`color:${t.accent??"#6c5ce7"};display:inline-flex`;const dt=document.createElement("span");dt.textContent=P.subtitle,ee.append(Fe,dt),R.append(ee)}const re=document.createElement("button");re.type="button",re.setAttribute("aria-label","Dismiss"),re.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>',re.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",re.addEventListener("click",ee=>{ee.stopPropagation();try{sessionStorage.setItem(je,"1")}catch{}R&&(R.remove(),R=null)}),R.append(re);const lt=()=>{m||(m=!0,Ne(!0),Te(),I=0,T&&(T.style.display="none"),R&&(R.remove(),R=null))};R.addEventListener("click",lt),R.addEventListener("keydown",ee=>{(ee.key==="Enter"||ee.key===" ")&&(ee.preventDefault(),lt())}),f.insertBefore(R,G)};if(!document.getElementById("ocw-teaser-style")){const P=document.createElement("style");P.id="ocw-teaser-style",P.textContent="@keyframes ocw-teaser-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:translateY(0)}}",document.head.append(P)}w=ct,ct();const Ne=P=>{P?(E.style.display="flex",requestAnimationFrame(()=>{E.style.opacity="1",E.style.transform="scale(1)"})):(E.style.opacity="0",E.style.transform="scale(.95)",setTimeout(()=>{m||(E.style.display="none")},180))};G.addEventListener("click",()=>{if(m=!m,Ne(m),Te(),m){I=0,T&&(T.style.display="none");try{sessionStorage.setItem(je,"1")}catch{}}w==null||w()}),z=P=>{P.key==="Escape"&&m&&(m=!1,Ne(!1),Te())},document.addEventListener("keydown",z)}const b=()=>{m||(I++,T&&(T.textContent=String(I),T.style.display="flex"))},q=()=>{try{const h=yn();if(!h)return;h.state==="suspended"&&h.resume().catch(()=>{});const y=h.createOscillator(),E=h.createGain();y.connect(E),E.connect(h.destination),y.frequency.setValueAtTime(880,h.currentTime),y.frequency.exponentialRampToValueAtTime(440,h.currentTime+.15),E.gain.setValueAtTime(.3,h.currentTime),E.gain.exponentialRampToValueAtTime(.001,h.currentTime+.3),y.start(),y.stop(h.currentTime+.3)}catch{}},_=[],j=h=>{for(;_.length;){const y=_.shift();g.add({clientMsgId:y.clientMsgId,content:y.content,ts:Date.now()}),k.send({type:"send",conversationId:h,clientMsgId:y.clientMsgId,content:y.content})}};let k;const M=t.i18n??{},W=["ar","he","fa","ur"],C=typeof navigator<"u"?(navigator.language??"").slice(0,2).toLowerCase():"";W.includes(C)&&!t.el.dir&&(t.el.dir="rtl",t.el.style.fontFamily=t.el.style.fontFamily||"Tahoma,Arial,system-ui,sans-serif");const K=`oc_prechat_${t.profileId}_${o.slice(-8)}`,$=new un(t.el,o,{onSend(h){const y=`cm_${Math.random().toString(36).slice(2)}`,E={kind:"text",text:h};if(d.addOptimistic(y,E),$.render(d),d.e2e){console.error("[relay] this chat is end-to-end encrypted — use the full widget build");return}else l?(g.add({clientMsgId:y,content:E,ts:Date.now()}),k.send({type:"send",conversationId:l,clientMsgId:y,content:E})):_.push({clientMsgId:y,content:E})},async onAttach(h){if(!l)return;const y=`${u}/upload?name=${encodeURIComponent(h.name)}`,E=`cm_${Math.random().toString(36).slice(2)}`;d.addOptimistic(E,{kind:"text",text:`📎 Uploading ${h.name}…`}),$.render(d);try{const O=await fetch(y,{method:"POST",headers:{"content-type":h.type,authorization:`Bearer ${o}`},body:h});if(!O.ok)throw new Error(`Upload failed: ${O.status}`);const{url:we,name:ge,mime:Ce,size:Ee}=await O.json();d.addOptimistic(E,{kind:"attachment",url:we,name:ge,mime:Ce,size:Ee}),$.render(d),k.send({type:"send",conversationId:l,clientMsgId:E,content:{kind:"attachment",url:we,name:ge,mime:Ce,size:Ee}})}catch(O){d.addOptimistic(E,{kind:"text",text:`⚠️ Upload failed: ${O.message}`}),$.render(d)}},onInvoke(h,y){l&&k.send({type:"invoke",conversationId:l,actionId:h,clientInvokeId:`iv_${Math.random().toString(36).slice(2)}`,...y?{inputs:y}:{}})},onTyping(h,y){l&&k.send({type:"typing",conversationId:l,isTyping:h,...y?{preview:y}:{}})},onPreChat(h){try{localStorage.setItem(K,"1")}catch{}k.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&&l&&!d.e2e&&k.send({type:"send",conversationId:l,clientMsgId:`pc_${Math.random().toString(36).slice(2,12)}`,content:{kind:"text",text:y}})},...((V=t.features)==null?void 0:V.deflection)!==!1?{onDeflectQuery(h){if(i)return;clearTimeout(n);const y=h.trim();if(y.length<3){$.hideDeflection();return}n=setTimeout(()=>{fetch(`${u}/kb/search?profileId=${encodeURIComponent(t.profileId)}&q=${encodeURIComponent(y.slice(0,200))}`).then(E=>E.ok?E.json():{articles:[]}).then(E=>$.showDeflection(E.articles??[])).catch(()=>$.hideDeflection())},350)}}:{},onReadUpTo(h){l&&k.send({type:"read",conversationId:l,seq:h})},onLoadMore(){if(!l||!d.e2e)return;const h=d.messages()[0];h&&k.send({type:"history",conversationId:l,beforeSeq:h.seq,limit:20})},onEdit(h,y){l&&k.send({type:"edit",conversationId:l,messageId:h,content:{kind:"text",text:y}})},onDelete(h){l&&k.send({type:"delete",conversationId:l,messageId:h})},...((F=t.features)==null?void 0:F.reactions)!==!1?{onReact(h,y,E){l&&k.send({type:"react",conversationId:l,messageId:h,emoji:y,remove:E})}}:{},...((X=t.features)==null?void 0:X.csat)!==!1?{onCsat(h){l&&fetch(`${u}/conversations/${l}/csat`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify({score:h})}).catch(()=>{})}}:{},...t.translateLang?{async onTranslate(h){try{const y=await fetch(`${u}/translate`,{method:"POST",headers:{"content-type":"application/json",authorization:`Bearer ${o}`},body:JSON.stringify({text:h,targetLang:t.translateLang})});if(!y.ok)return null;const{translated:E}=await y.json();return E}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}:{},...(U=t.user)!=null&&U.name||(oe=t.user)!=null&&oe.avatar?{userInfo:{...t.user.name?{name:t.user.name}:{},...t.user.avatar?{avatar:t.user.avatar}:{}}}:{},i18n:M});try{localStorage.getItem(K)&&$.completePreChat()}catch{}const fe=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,Se={type:"open",profileId:t.profileId,...t.kind==="direct"&&t.peerId?{kind:"direct",peerId:t.peerId}:t.subjectId?{subjectId:t.subjectId}:{},...s?{linkFrom:s}:{},...fe?{userInfo:fe}:{},...typeof location<"u"?{pageUrl:location.href}:{},...typeof document<"u"&&document.title?{pageTitle:document.title}:{},...(se=t.subject)!=null&&se.title?{subjectTitle:t.subject.title}:{},...(Ie=t.subject)!=null&&Ie.subtitle?{subjectMeta:t.subject.subtitle}:{}};k=new Xt({...t.refreshToken?{refreshToken:t.refreshToken}:{},url:r,token:o,open:Se,getCursor:()=>d.highestSeq(),onStatusChange:(h,y)=>$.setConnStatus(h,y),onFrame(h){if(h.type==="opened"){if(l=h.conversation.id,!v){v=!0;for(const y of g.load())k.send({type:"send",conversationId:l,clientMsgId:y.clientMsgId,content:y.content})}mn(r,o,l,d,$,u),_.length&&j(l)}h.type==="ack"&&g.remove(h.clientMsgId),(async()=>(d.apply(h),h.type==="manifest"&&(w==null||w()),h.type==="message"&&h.message.senderId!==o&&!h.message.internal&&(b(),q()),$.render(d)))()}}),k.connect(),$.render(d);const x=t.launcher?it(t):null,L={close:()=>{i=!0,clearTimeout(n),k.close(),f==null||f.remove(),$.destroy(),S&&A&&S.removeEventListener("change",A),z&&(document.removeEventListener("keydown",z),z=null),de.delete(t.el),x&&be.get(x)===L&&be.delete(x)}};return de.set(t.el,L),x&&be.set(x,L),L}const De="wss://api.paramms.com/ws";function bn(t,e){const n=t.profileId??t.appId;if(!n)throw new Error("Relay: `profileId` is required (your chatroom id, e.g. 'p_...').");const i=t.subjectId??(t.listingId?`listing_${t.listingId}`:void 0),o=t.launcher??!0,s=t.contextTitle??t.listingTitle??t.subjectTitle,r=t.contextSubtitle??t.listingMeta??t.subjectMeta,u=t.contextStatus??t.listingStatus??t.subjectStatus,d=t.listingPrice??t.subjectPrice,p=s?{title:s,...r?{subtitle:r}:{},...d!=null?{tags:[`$${d.toLocaleString()}`]}:{},...u?{status:u}:{}}:void 0,g=t.subject??p,l=t.userName??t.name,v=t.userEmail??t.email,S=t.userAvatar??t.avatar,A=l||v||S?{...l?{name:l}:{},...v?{email:v}:{},...S?{avatar:S}:{}}:void 0,z=t.user??A,w=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??De,profileId:n,...t.apiUrl?{apiUrl:t.apiUrl}:{},...i?{subjectId:i}:{},...t.token?{token:t.token}:{},...t.refreshToken?{refreshToken:t.refreshToken}:{},...t.userId?{userId:t.userId}:{},...g?{subject:g}:{},...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}:{},...w?{launcherMessage:w}:{},...rt(t)&&!o?{onBack:()=>{pe=!0,ue=!1,ve(ne)}}:{},launcher:o,position:t.position??"bottom-right"}}let Q=null,D=null,te=!1,ne={},pe=!1,ue=!1;function rt(t){return!!(t.inbox||t.inboxStart)}let Z=null;function vn(t,e){const n=!e&&!!t.el;if(te&&!n&&(D.innerHTML="",D=null,te=!1),n){const i=typeof t.el=="string"?document.querySelector(t.el):t.el;i instanceof HTMLElement?(D&&D!==i&&!te&&D.remove(),D=i,te=!0):console.error(`[Relay] \`el\` ("${String(t.el)}") did not match any element — falling back to an auto-created host.`)}return(!D||!te&&!D.isConnected)&&(D=document.createElement("div"),D.id="relay-widget-root",document.body.appendChild(D),te=!1),!e&&t.height&&(D.style.height=t.height,D.style.width||(D.style.width="100%")),D}function ve(t){try{const e=t.launcher??!0;Z==null||Z(),Z=null,Q==null||Q.close(),Q=null;const n=vn(t,e);if(rt(t)&&!e&&pe){kn(t,n);return}Q=st(bn(t,n))}catch(e){console.error("[Relay]",e instanceof Error?e.message:e)}}async function kn(t,e){const n=t.profileId??t.appId;if(!n&&!t.tenantId){console.error("[Relay] `inbox` requires `profileId` or `tenantId`.");return}e.innerHTML="";const i=document.createElement("div");i.style.cssText="position:relative;width:100%;height:100%;overflow:hidden;background:#fff";const o=document.createElement("div");o.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=()=>{pe=!1,ve(ne)},i.append(o,s);const u=!ue&&!!n;u&&i.append(r),e.appendChild(i);let d=null,p=null;Z=()=>{p==null||p.close(),d==null||d.close(),e.innerHTML=""};let g;try{({mountChatList:g}=await Promise.resolve().then(()=>An))}catch(v){console.error("[Relay] could not load the conversation list module.",v),o.isConnected&&(o.style.cssText+=";display:flex;align-items:center;justify-content:center;padding:16px;font:13px system-ui;color:#b91c1c;text-align:center",o.textContent="Could not load conversations.");return}if(!o.isConnected)return;const l=v=>{const S=v.profileId??n;if(!S){console.error("[Relay] conversation row has no chatroom; cannot open it.",v);return}r.style.display="none",p==null||p.close(),p=st({el:s,url:t.url??De,...t.apiUrl?{apiUrl:t.apiUrl}:{},profileId:S,...v.kind==="direct"&&v.peerId?{kind:"direct",peerId:v.peerId}:v.subjectId?{subjectId:v.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}:{}}}:{},...v.subjectTitle?{subject:{title:v.subjectTitle,...v.subjectMeta?{subtitle:v.subjectMeta}:{}}}:{},...t.accent?{accent:t.accent}:{},launcher:!1,onBack:()=>{p==null||p.close(),p=null,s.style.display="none",o.style.display="",r.style.display="",d==null||d.refresh()}}),o.style.display="none",s.style.display=""};d=g({el:o,url:t.url??De,...t.apiUrl?{apiUrl:t.apiUrl}:{},...n?{profileId:n}:{},...t.tenantId?{tenantId:t.tenantId}:{},scope:t.inboxScope??"tenant",...u?{reserveCloseSpace:!0}:{},onSelect:l,onNewChat:()=>{const v=n??(d==null?void 0:d.defaultProfileId());v&&l({id:"__new__",profileId:v,state:"open",updatedAt:Date.now()})},...t.token?{token:t.token}:{},...t.userId?{userId:t.userId}:{},...t.accent?{accent:t.accent}:{}})}function at(t){ue=!!(t.inboxStart&&!(t.launcher??!0)),pe=ue,ne={...t},ve(ne)}function Sn(t){ne={...ne,...t},ve(ne)}function In(){Z==null||Z(),Z=null,Q==null||Q.close(),Q=null,D&&!te&&D.remove(),D=null,te=!1,pe=!1,ue=!1,ne={}}function qe(t,e){switch(t){case"boot":at(e??{});break;case"update":case"identify":Sn(e??{});break;case"shutdown":In();break;default:console.warn("[Relay] unknown command:",t)}}function Cn(){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),i=e==null?void 0:e.relayTenantId;if(!n&&!i)return null;const o=n?{profileId:n}:{};i&&(o.tenantId=i),e.relayUser&&(o.userId=e.relayUser),e.relayToken&&(o.token=e.relayToken),e.relayListing&&(o.listingId=e.relayListing),e.relayAccent&&(o.accent=e.relayAccent),e.relayAccent2&&(o.accent2=e.relayAccent2),e.relayTheme&&(o.theme=e.relayTheme),e.relayWebfont==="false"&&(o.webfont=!1),e.relayUrl&&(o.url=e.relayUrl);const s=e.relayPosition;(s==="bottom-left"||s==="bottom-right")&&(o.position=s),e.relayLauncherMessage&&(o.launcherMessage=e.relayLauncherMessage),e.relayLauncherSubtitle&&(o.launcherSubtitle=e.relayLauncherSubtitle),e.relayLauncher==="false"&&(o.launcher=!1),e.relayUserName&&(o.userName=e.relayUserName),e.relayUserEmail&&(o.userEmail=e.relayUserEmail),e.relayUserAvatar&&(o.userAvatar=e.relayUserAvatar),e.relayContextTitle&&(o.contextTitle=e.relayContextTitle),e.relayContextSubtitle&&(o.contextSubtitle=e.relayContextSubtitle),e.relayContextStatus&&(o.contextStatus=e.relayContextStatus),e.relayListingTitle&&(o.listingTitle=e.relayListingTitle),e.relayListingMeta&&(o.listingMeta=e.relayListingMeta),e.relayListingPrice&&(o.listingPrice=Number(e.relayListingPrice)),e.relayListingStatus&&(o.listingStatus=e.relayListingStatus),e.relayTarget&&(o.el=e.relayTarget),e.relayHeight&&(o.height=e.relayHeight),e.relayInbox==="true"&&(o.inbox=!0),e.relayInbox==="false"&&(o.inbox=!1),e.relayInboxStart==="true"&&(o.inboxStart=!0),e.relayInboxStart==="false"&&(o.inboxStart=!1);const r=e.relayInboxScope;return(r==="tenant"||r==="profile")&&(o.inboxScope=r),e.relayTranslateLang&&(o.translateLang=e.relayTranslateLang),o}if(typeof window<"u"){const t=window,e=t.Relay&&t.Relay.q?t.Relay.q:[];t.Relay=qe;let n=!1;for(const i of e){const[o,s]=i;o==="boot"&&(n=!0),qe(o,s)}if(!n){const i=t.relaySettings??Cn();i&&at(i)}}const En=`
193
193
  .ocl { ${et("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:not([data-theme="light"]) { ${ye("ocl")} } }
196
+ @media (prefers-color-scheme: dark) { .ocl[data-theme="auto"] { ${ye("ocl")} } }
197
197
  .ocl[data-theme="dark"] { ${ye("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 RelayEmbedLite=function(J){"use strict";var $n=Object.defineProperty;var Rn=
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:not([data-theme="light"]) .ocl-status.done { background:#39325e; color:#b3abd6; } }
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 RelayEmbedLite=function(J){"use strict";var $n=Object.defineProperty;var Rn=
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 Tn(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 Un(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 Bn='<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 i=document.createElement(t);return e&&(i.className=e),n!==void 0&&(i.textContent=n),i}function Ln(t){const e=t.token??t.userId??He(),{httpBase:n,wsUrl:i}=_e(t.url,t.apiUrl),o=t.i18n??{},s=t.accent??"#6c5ce7";if(!document.getElementById("ocl-styles")){const x=document.createElement("style");x.id="ocl-styles",x.textContent=En,document.head.append(x)}if(t.webfont!==!1&&typeof document<"u"&&!document.getElementById("ocw-webfont")){const x=document.createElement("link");x.id="ocw-webfont",x.rel="stylesheet",x.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(x)}const r=B("div","ocl");r.style.setProperty("--ocl-accent",s),t.theme&&t.theme!=="auto"&&(r.dataset.theme=t.theme),t.reserveCloseSpace&&r.classList.add("ocl-has-close");const u=B("div","ocl-head"),d=B("span","ocl-title");if(d.setAttribute("role","img"),d.setAttribute("aria-label",o.title??"Messages"),d.innerHTML=Bn,u.append(d),t.onNewChat){const x=B("button","ocl-compose","✎");x.title=o.newChat??"New conversation",x.addEventListener("click",()=>t.onNewChat()),u.append(x)}const p=B("div","ocl-search-wrap"),g=B("input","ocl-search");g.placeholder=o.search??"🔍 Search",g.type="search",p.append(g);const l=B("div","ocl-body");l.append(B("div","ocl-spinner","Loading…")),r.append(u,p,l),t.el.replaceChildren(r);const v=x=>{r.classList.toggle("ocl-compact",x>0&&x<400)};v(r.clientWidth);let S=null;if(typeof ResizeObserver<"u"&&(S=new ResizeObserver(x=>{var L;return v(((L=x[0])==null?void 0:L.contentRect.width)??r.clientWidth)}),S.observe(r)),!t.profileId&&!t.tenantId)throw new Error("[relay chatlist] provide profileId or tenantId");let A;const z=`ocl_seen_${t.profileId??`t_${t.tenantId}`}_${(t.userId??e).slice(-8)}`;let w={};try{w=JSON.parse(localStorage.getItem(z)??"{}")}catch{}const f=()=>{try{localStorage.setItem(z,JSON.stringify(w))}catch{}};let T=[],I=!1;const m=async()=>{const x=t.profileId?`profileId=${encodeURIComponent(t.profileId)}${t.scope==="tenant"?"&scope=tenant":""}`:`tenantId=${encodeURIComponent(t.tenantId)}`,L=`${n}/conversations/mine?${x}`,N={authorization:`Bearer ${e}`};let V;try{V=await fetch(L,{headers:N})}catch{V=await fetch(L,{headers:N})}if(!V.ok)return[];const F=await V.json();return F.defaultProfileId&&(A=F.defaultProfileId),(F.conversations??[]).sort((X,U)=>U.updatedAt-X.updatedAt)},b=(x,L)=>{if(I)return;const N=L?x.filter(U=>q(U).toLowerCase().includes(L)||(U.lastMessage??"").toLowerCase().includes(L)):x;if(l.replaceChildren(),!N.length){const U=B("div","ocl-empty",L?"No results.":o.empty??"No conversations yet.");if(!L&&t.onNewChat){U.append(B("br"));const oe=B("button","ocl-start",o.newChat??"Start a conversation");oe.addEventListener("click",()=>t.onNewChat()),U.append(oe)}l.append(U);return}const V=U=>(U.lastSeq??0)>(w[U.id]??0),F=N.filter(V),X=N.filter(U=>!V(U));if(F.length){l.append(B("div","ocl-section",`${o.unread??"Unread"} (${F.length})`));for(const U of F)l.append(_(U,V(U)))}if(X.length){l.append(B("div","ocl-section",F.length?o.all??"All conversations":""));for(const U of X)l.append(_(U,!1))}},q=x=>x.subjectTitle??(x.kind==="direct"?x.peerId??"Direct message":"General enquiry"),_=(x,L)=>{var E;const N=q(x),V=(((E=N.match(new RegExp("\\p{L}","u")))==null?void 0:E[0])??N.trim()[0]??"?").toUpperCase(),F=x.lastSeq??0,X=L?Math.max(1,F-(w[x.id]??0)):0,U=B("button",`ocl-row${L?" unread":""}`),oe=B("div","ocl-av",V);U.append(oe);const se=B("div","ocl-info");se.append(B("div","ocl-name",N));const Ie={open:"Open",awaiting_staff:"Waiting for reply…",resolved:"Resolved ✓",closed:"Closed"};se.append(B("div","ocl-preview",x.lastMessage??Ie[x.state]??x.state)),U.append(se);const h=B("div","ocl-right");h.append(B("div","ocl-time",Un(x.updatedAt)));const y=Tn(x.state);return y&&h.append(B("div",`ocl-status ${y.cls}`,y.label)),X>0&&h.append(B("div","ocl-badge",String(X>99?"99+":X))),U.append(h),U.addEventListener("click",()=>{var O;F>0&&(w[x.id]=F,f()),U.classList.remove("unread"),(O=h.querySelector(".ocl-badge"))==null||O.remove(),t.onSelect(x)}),U},j=()=>{I||m().then(x=>{I||(T=x,b(x,g.value.trim().toLowerCase()))}).catch(x=>{if(I)return;console.error(`[chat-widget] failed to load conversations from ${n}/conversations/mine — check the apiUrl/CORS config.`,x);const L=B("div","ocl-empty",o.error??"Could not load conversations.");L.append(B("br"));const N=B("button","ocl-retry",o.retry??"Retry");N.addEventListener("click",()=>{l.replaceChildren(B("div","ocl-spinner","Loading…")),j()}),L.append(N),l.replaceChildren(L)})};g.addEventListener("input",()=>b(T,g.value.trim().toLowerCase())),j();let k=null,M,W,C=0,K=!1;const $=()=>{W||(W=setTimeout(()=>{W=void 0,j()},300))},fe=()=>{if(!I){try{k=new WebSocket(i)}catch{Se();return}k.binaryType="arraybuffer",k.onopen=()=>{C=0,k.send(Re({type:"auth",token:e})),k.send(Re({type:"subscribe_inbox"})),K&&$(),K=!0},k.onmessage=x=>{const L=Xe(new Uint8Array(x.data));L&&L.type==="inbox_event"&&$()},k.onclose=()=>{k=null,Se()},k.onerror=()=>{try{k==null||k.close()}catch{}}}},Se=()=>{if(I||M)return;const x=Math.min(15e3,500*2**C++)+Math.random()*250;M=setTimeout(()=>{M=void 0,fe()},x)};return fe(),{refresh:j,close(){I=!0,M&&clearTimeout(M),W&&clearTimeout(W),S==null||S.disconnect(),S=null;try{k==null||k.close()}catch{}k=null,t.el.replaceChildren()},defaultProfileId(){return t.profileId??A}}}const An=Object.freeze(Object.defineProperty({__proto__:null,mountChatList:Ln},Symbol.toStringTag,{value:"Module"}));return J.Relay=qe,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"}),J}({});
241
+ `;function Tn(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 Un(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 Bn='<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 i=document.createElement(t);return e&&(i.className=e),n!==void 0&&(i.textContent=n),i}function Ln(t){const e=t.token??t.userId??He(),{httpBase:n,wsUrl:i}=_e(t.url,t.apiUrl),o=t.i18n??{},s=t.accent??"#6c5ce7";if(!document.getElementById("ocl-styles")){const x=document.createElement("style");x.id="ocl-styles",x.textContent=En,document.head.append(x)}if(t.webfont!==!1&&typeof document<"u"&&!document.getElementById("ocw-webfont")){const x=document.createElement("link");x.id="ocw-webfont",x.rel="stylesheet",x.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(x)}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 u=B("div","ocl-head"),d=B("span","ocl-title");if(d.setAttribute("role","img"),d.setAttribute("aria-label",o.title??"Messages"),d.innerHTML=Bn,u.append(d),t.onNewChat){const x=B("button","ocl-compose","✎");x.title=o.newChat??"New conversation",x.addEventListener("click",()=>t.onNewChat()),u.append(x)}const p=B("div","ocl-search-wrap"),g=B("input","ocl-search");g.placeholder=o.search??"🔍 Search",g.type="search",p.append(g);const l=B("div","ocl-body");l.append(B("div","ocl-spinner","Loading…")),r.append(u,p,l),t.el.replaceChildren(r);const v=x=>{r.classList.toggle("ocl-compact",x>0&&x<400)};v(r.clientWidth);let S=null;if(typeof ResizeObserver<"u"&&(S=new ResizeObserver(x=>{var L;return v(((L=x[0])==null?void 0:L.contentRect.width)??r.clientWidth)}),S.observe(r)),!t.profileId&&!t.tenantId)throw new Error("[relay chatlist] provide profileId or tenantId");let A;const z=`ocl_seen_${t.profileId??`t_${t.tenantId}`}_${(t.userId??e).slice(-8)}`;let w={};try{w=JSON.parse(localStorage.getItem(z)??"{}")}catch{}const f=()=>{try{localStorage.setItem(z,JSON.stringify(w))}catch{}};let T=[],I=!1;const m=async()=>{const x=t.profileId?`profileId=${encodeURIComponent(t.profileId)}${t.scope==="tenant"?"&scope=tenant":""}`:`tenantId=${encodeURIComponent(t.tenantId)}`,L=`${n}/conversations/mine?${x}`,N={authorization:`Bearer ${e}`};let V;try{V=await fetch(L,{headers:N})}catch{V=await fetch(L,{headers:N})}if(!V.ok)return[];const F=await V.json();return F.defaultProfileId&&(A=F.defaultProfileId),(F.conversations??[]).sort((X,U)=>U.updatedAt-X.updatedAt)},b=(x,L)=>{if(I)return;const N=L?x.filter(U=>q(U).toLowerCase().includes(L)||(U.lastMessage??"").toLowerCase().includes(L)):x;if(l.replaceChildren(),!N.length){const U=B("div","ocl-empty",L?"No results.":o.empty??"No conversations yet.");if(!L&&t.onNewChat){U.append(B("br"));const oe=B("button","ocl-start",o.newChat??"Start a conversation");oe.addEventListener("click",()=>t.onNewChat()),U.append(oe)}l.append(U);return}const V=U=>(U.lastSeq??0)>(w[U.id]??0),F=N.filter(V),X=N.filter(U=>!V(U));if(F.length){l.append(B("div","ocl-section",`${o.unread??"Unread"} (${F.length})`));for(const U of F)l.append(_(U,V(U)))}if(X.length){l.append(B("div","ocl-section",F.length?o.all??"All conversations":""));for(const U of X)l.append(_(U,!1))}},q=x=>x.subjectTitle??(x.kind==="direct"?x.peerId??"Direct message":"General enquiry"),_=(x,L)=>{var E;const N=q(x),V=(((E=N.match(new RegExp("\\p{L}","u")))==null?void 0:E[0])??N.trim()[0]??"?").toUpperCase(),F=x.lastSeq??0,X=L?Math.max(1,F-(w[x.id]??0)):0,U=B("button",`ocl-row${L?" unread":""}`),oe=B("div","ocl-av",V);U.append(oe);const se=B("div","ocl-info");se.append(B("div","ocl-name",N));const Ie={open:"Open",awaiting_staff:"Waiting for reply…",resolved:"Resolved ✓",closed:"Closed"};se.append(B("div","ocl-preview",x.lastMessage??Ie[x.state]??x.state)),U.append(se);const h=B("div","ocl-right");h.append(B("div","ocl-time",Un(x.updatedAt)));const y=Tn(x.state);return y&&h.append(B("div",`ocl-status ${y.cls}`,y.label)),X>0&&h.append(B("div","ocl-badge",String(X>99?"99+":X))),U.append(h),U.addEventListener("click",()=>{var O;F>0&&(w[x.id]=F,f()),U.classList.remove("unread"),(O=h.querySelector(".ocl-badge"))==null||O.remove(),t.onSelect(x)}),U},j=()=>{I||m().then(x=>{I||(T=x,b(x,g.value.trim().toLowerCase()))}).catch(x=>{if(I)return;console.error(`[chat-widget] failed to load conversations from ${n}/conversations/mine — check the apiUrl/CORS config.`,x);const L=B("div","ocl-empty",o.error??"Could not load conversations.");L.append(B("br"));const N=B("button","ocl-retry",o.retry??"Retry");N.addEventListener("click",()=>{l.replaceChildren(B("div","ocl-spinner","Loading…")),j()}),L.append(N),l.replaceChildren(L)})};g.addEventListener("input",()=>b(T,g.value.trim().toLowerCase())),j();let k=null,M,W,C=0,K=!1;const $=()=>{W||(W=setTimeout(()=>{W=void 0,j()},300))},fe=()=>{if(!I){try{k=new WebSocket(i)}catch{Se();return}k.binaryType="arraybuffer",k.onopen=()=>{C=0,k.send(Re({type:"auth",token:e})),k.send(Re({type:"subscribe_inbox"})),K&&$(),K=!0},k.onmessage=x=>{const L=Xe(new Uint8Array(x.data));L&&L.type==="inbox_event"&&$()},k.onclose=()=>{k=null,Se()},k.onerror=()=>{try{k==null||k.close()}catch{}}}},Se=()=>{if(I||M)return;const x=Math.min(15e3,500*2**C++)+Math.random()*250;M=setTimeout(()=>{M=void 0,fe()},x)};return fe(),{refresh:j,close(){I=!0,M&&clearTimeout(M),W&&clearTimeout(W),S==null||S.disconnect(),S=null;try{k==null||k.close()}catch{}k=null,t.el.replaceChildren()},defaultProfileId(){return t.profileId??A}}}const An=Object.freeze(Object.defineProperty({__proto__:null,mountChatList:Ln},Symbol.toStringTag,{value:"Module"}));return J.Relay=qe,Object.defineProperty(J,Symbol.toStringTag,{value:"Module"}),J}({});
242
242
  //# sourceMappingURL=embed-lite.js.map