useyuva 0.0.5 → 0.0.7

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.
@@ -9,6 +9,7 @@ export interface LauncherStyle {
9
9
  color?: string;
10
10
  }
11
11
  export declare function launcherOf(inbox: components["schemas"]["ClientInbox"]): LauncherStyle;
12
+ export declare function contrastOn(color: string): string;
12
13
  export interface ChatConfig {
13
14
  channel: string | null;
14
15
  server: string;
package/dist/yuva-chat.js CHANGED
@@ -1,4 +1,4 @@
1
- var C=(t)=>typeof t==="string",yt=(t)=>typeof t==="function",H=new Map,X="en";function U(t){return[...Array.isArray(t)?t:[t],X]}function j(t,e,i){let n=U(t);if(!i)i="default";let s;if(typeof i==="string")switch(s={day:"numeric",month:"short",year:"numeric"},i){case"full":s.weekday="long";case"long":s.month="long";break;case"short":s.month="numeric";break}else s=i;return I(()=>R("date",n,i),()=>new Intl.DateTimeFormat(n,s)).format(C(e)?new Date(e):e)}function vt(t,e,i){let n;if(!i)i="default";if(typeof i==="string")switch(n={second:"numeric",minute:"numeric",hour:"numeric"},i){case"full":case"long":n.timeZoneName="short";break;case"short":delete n.second}else n=i;return j(t,e,n)}function D(t,e,i){let n=U(t);return I(()=>R("number",n,i),()=>new Intl.NumberFormat(n,i)).format(e)}function Q(t,e,i,{offset:n=0,...s}){let o=U(t),a=e?I(()=>R("plural-ordinal",o),()=>new Intl.PluralRules(o,{type:"ordinal"})):I(()=>R("plural-cardinal",o),()=>new Intl.PluralRules(o,{type:"cardinal"}));return s[i]??s[a.select(i-n)]??s.other}function I(t,e){let i=t(),n=H.get(i);if(!n)n=e(),H.set(i,n);return n}function R(t,e,i){let n=e.join("-");return`${t}-${n}-${JSON.stringify(i)}`}var V=/\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/,Z=(t)=>t.replace(/\\u([a-fA-F0-9]{4})|\\x([a-fA-F0-9]{2})/g,(e,i,n)=>{if(i){let s=parseInt(i,16);return String.fromCharCode(s)}else{let s=parseInt(n,16);return String.fromCharCode(s)}}),tt="%__lingui_octothorpe__%",bt=(t,e,i={})=>{let n=e||t,s=(a)=>{if(typeof a==="object")return a;return i[a]},o=(a,l)=>{let c=Object.keys(i).length?s("number"):void 0,h=D(n,a,c);return l.replace(new RegExp(tt,"g"),h)};return{plural:(a,l)=>{let{offset:c=0}=l,h=Q(n,!1,a,l);return o(a-c,h)},selectordinal:(a,l)=>{let{offset:c=0}=l,h=Q(n,!0,a,l);return o(a-c,h)},select:xt,number:(a,l)=>D(n,a,s(l)||{style:l}),date:(a,l)=>j(n,a,s(l)||l),time:(a,l)=>vt(n,a,s(l)||l)}},xt=(t,e)=>(Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0)??e.other;function kt(t,e,i){return(n={},s)=>{let o=bt(e,i,s),a=(c,h=!1)=>{if(!Array.isArray(c))return c;return c.reduce((p,u)=>{if(u==="#"&&h)return p+tt;if(C(u))return p+u;let[b,y,P]=u,_={};if(y==="plural"||y==="selectordinal"||y==="select")Object.entries(P).forEach(([m,k])=>{_[m]=a(k,y==="plural"||y==="selectordinal")});else _=P;let d;if(y){let m=o[y];d=m(n[b],_)}else d=n[b];if(d==null)return p;return p+d},"")},l=a(t);if(C(l)&&V.test(l))return Z(l);if(C(l))return l;return l?String(l):""}}class et{_events={};on(t,e){return this._events[t]??=new Set,this._events[t].add(e),()=>this.removeListener(t,e)}removeListener(t,e){let i=this._events[t];if(i?.delete(e),i?.size===0)delete this._events[t]}emit(t,...e){let i=this._events[t];if(!i)return;for(let n of[...i])n.apply(this,e)}}class it extends et{_locale="";_locales;_messages={};_missing;_messageCompiler;constructor(t){super();if(t.missing!=null)this._missing=t.missing;if(t.messages!=null)this.load(t.messages);if(typeof t.locale==="string"||t.locales)this.activate(t.locale??X,t.locales)}get locale(){return this._locale}get locales(){return this._locales}get messages(){return this._messages[this._locale]??{}}setMessagesCompiler(t){return this._messageCompiler=t,this}_load(t,e){let i=Object.prototype.hasOwnProperty.call(this._messages,t)?this._messages[t]:void 0;if(!i)this._messages[t]=e;else Object.assign(i,e)}load(t,e){if(typeof t=="string"&&typeof e==="object")this._load(t,e);else Object.entries(t).forEach(([i,n])=>this._load(i,n));this.emit("change")}loadAndActivate({locale:t,locales:e,messages:i}){this._locale=t,this._locales=e||void 0,this._messages[this._locale]=i,this.emit("change")}activate(t,e){this._locale=t,this._locales=e,this.emit("change")}_(t,e,i){if(!this.locale)throw Error("Lingui: Attempted to call a translation function without setting a locale.\nMake sure to call `i18n.activate(locale)` before using Lingui functions.\nThis issue may also occur due to a race condition in your initialization logic.");let n=i?.message;if(!t)t="";if(!C(t))e=t.values||e,n=t.message,t=t.id;let s=this.messages,o=Object.prototype.hasOwnProperty.call(s,t)?s[t]:void 0,a=o===void 0,l=this._missing;if(l&&a)return yt(l)?l(this._locale,t):l;if(a)this.emit("missing",{id:t,locale:this._locale});let c=o||n||t;if(C(c))if(this._messageCompiler)c=this._messageCompiler(c);else console.warn(`Uncompiled message detected! Message:
1
+ var S=(e)=>typeof e==="string",be=(e)=>typeof e==="function",Q=new Map,V="en";function j(e){return[...Array.isArray(e)?e:[e],V]}function N(e,t,i){let n=j(e);if(!i)i="default";let s;if(typeof i==="string")switch(s={day:"numeric",month:"short",year:"numeric"},i){case"full":s.weekday="long";case"long":s.month="long";break;case"short":s.month="numeric";break}else s=i;return z(()=>D("date",n,i),()=>new Intl.DateTimeFormat(n,s)).format(S(t)?new Date(t):t)}function xe(e,t,i){let n;if(!i)i="default";if(typeof i==="string")switch(n={second:"numeric",minute:"numeric",hour:"numeric"},i){case"full":case"long":n.timeZoneName="short";break;case"short":delete n.second}else n=i;return N(e,t,n)}function U(e,t,i){let n=j(e);return z(()=>D("number",n,i),()=>new Intl.NumberFormat(n,i)).format(t)}function X(e,t,i,{offset:n=0,...s}){let o=j(e),a=t?z(()=>D("plural-ordinal",o),()=>new Intl.PluralRules(o,{type:"ordinal"})):z(()=>D("plural-cardinal",o),()=>new Intl.PluralRules(o,{type:"cardinal"}));return s[i]??s[a.select(i-n)]??s.other}function z(e,t){let i=e(),n=Q.get(i);if(!n)n=t(),Q.set(i,n);return n}function D(e,t,i){let n=t.join("-");return`${e}-${n}-${JSON.stringify(i)}`}var Z=/\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/,ee=(e)=>e.replace(/\\u([a-fA-F0-9]{4})|\\x([a-fA-F0-9]{2})/g,(t,i,n)=>{if(i){let s=parseInt(i,16);return String.fromCharCode(s)}else{let s=parseInt(n,16);return String.fromCharCode(s)}}),te="%__lingui_octothorpe__%",we=(e,t,i={})=>{let n=t||e,s=(a)=>{if(typeof a==="object")return a;return i[a]},o=(a,l)=>{let c=Object.keys(i).length?s("number"):void 0,h=U(n,a,c);return l.replace(new RegExp(te,"g"),h)};return{plural:(a,l)=>{let{offset:c=0}=l,h=X(n,!1,a,l);return o(a-c,h)},selectordinal:(a,l)=>{let{offset:c=0}=l,h=X(n,!0,a,l);return o(a-c,h)},select:ke,number:(a,l)=>U(n,a,s(l)||{style:l}),date:(a,l)=>N(n,a,s(l)||l),time:(a,l)=>xe(n,a,s(l)||l)}},ke=(e,t)=>(Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0)??t.other;function Ce(e,t,i){return(n={},s)=>{let o=we(t,i,s),a=(c,h=!1)=>{if(!Array.isArray(c))return c;return c.reduce((p,u)=>{if(u==="#"&&h)return p+te;if(S(u))return p+u;let[y,g,_]=u,b={};if(g==="plural"||g==="selectordinal"||g==="select")Object.entries(_).forEach(([v,k])=>{b[v]=a(k,g==="plural"||g==="selectordinal")});else b=_;let d;if(g){let v=o[g];d=v(n[y],b)}else d=n[y];if(d==null)return p;return p+d},"")},l=a(e);if(S(l)&&Z.test(l))return ee(l);if(S(l))return l;return l?String(l):""}}class ie{_events={};on(e,t){return this._events[e]??=new Set,this._events[e].add(t),()=>this.removeListener(e,t)}removeListener(e,t){let i=this._events[e];if(i?.delete(t),i?.size===0)delete this._events[e]}emit(e,...t){let i=this._events[e];if(!i)return;for(let n of[...i])n.apply(this,t)}}class ne extends ie{_locale="";_locales;_messages={};_missing;_messageCompiler;constructor(e){super();if(e.missing!=null)this._missing=e.missing;if(e.messages!=null)this.load(e.messages);if(typeof e.locale==="string"||e.locales)this.activate(e.locale??V,e.locales)}get locale(){return this._locale}get locales(){return this._locales}get messages(){return this._messages[this._locale]??{}}setMessagesCompiler(e){return this._messageCompiler=e,this}_load(e,t){let i=Object.prototype.hasOwnProperty.call(this._messages,e)?this._messages[e]:void 0;if(!i)this._messages[e]=t;else Object.assign(i,t)}load(e,t){if(typeof e=="string"&&typeof t==="object")this._load(e,t);else Object.entries(e).forEach(([i,n])=>this._load(i,n));this.emit("change")}loadAndActivate({locale:e,locales:t,messages:i}){this._locale=e,this._locales=t||void 0,this._messages[this._locale]=i,this.emit("change")}activate(e,t){this._locale=e,this._locales=t,this.emit("change")}_(e,t,i){if(!this.locale)throw Error("Lingui: Attempted to call a translation function without setting a locale.\nMake sure to call `i18n.activate(locale)` before using Lingui functions.\nThis issue may also occur due to a race condition in your initialization logic.");let n=i?.message;if(!e)e="";if(!S(e))t=e.values||t,n=e.message,e=e.id;let s=this.messages,o=Object.prototype.hasOwnProperty.call(s,e)?s[e]:void 0,a=o===void 0,l=this._missing;if(l&&a)return be(l)?l(this._locale,e):l;if(a)this.emit("missing",{id:e,locale:this._locale});let c=o||n||e;if(S(c))if(this._messageCompiler)c=this._messageCompiler(c);else console.warn(`Uncompiled message detected! Message:
2
2
 
3
3
  > ${c}
4
4
 
@@ -6,17 +6,17 @@ That means you use raw catalog or your catalog doesn't have a translation for th
6
6
  ICU features such as interpolation and plurals will not work properly for that message.
7
7
 
8
8
  Please compile your catalog first.
9
- `);if(C(c)&&V.test(c))return Z(c);if(C(c))return c;return kt(c,this._locale,this._locales)(e,i?.formats)}t=this._.bind(this);date(t,e){return j(this._locales||this._locale,t,e)}number(t,e){return D(this._locales||this._locale,t,e)}}function B(t={}){return new it(t)}var Lt=B();var N=JSON.parse(`{"-HY5kX":["New conversation"],"-f5Tkb":["Bad"],"09Tv5j":["Reconnecting…"],"0XGLbP":["Your sign-in has expired. Reload the page and try again."],"1EICzz":["We're away right now"],"4TqZiz":["Could not send your rating. Try again."],"6Uau97":["Skip"],"6gRgw8":["Retry"],"6lGaum":["Seen"],"ASr-r0":["Show older conversations"],"Amai22":["Chat is not available right now."],"E_qvzP":["Enter a valid e-mail address."],"GQVIIl":["You seem to be offline."],"JkW3Ph":["This file type is not accepted."],"JlFcis":["Send"],"KDw4GX":["Try again"],"M62PBt":["Nobody is available right now. Leave your e-mail and we'll send the reply there too."],"N7m8E-":["Attach files"],"NBdIgR":["Comment"],"OEEQKT":["Good"],"Pwqkdw":["Loading…"],"PxYAul":["Typing…"],"RzWUUK":["Write a message…"],"S63MQu":["All conversations"],"SOk0EB":["Thanks for your feedback"],"Sad2tK":["Sending…"],"SdV5Cn":["Send us a message and we will reply here."],"UY1vmE":["Attachment"],"VggdQJ":["Usually replies in ",["duration"]],"XJURKP":["E-mail address"],"YyNOE7":["Conversation"],"ZxJcgC":["Could not save your e-mail address. Try again."],"axQ1h6":["Anything you'd like to add? (optional)"],"eOu9Px":["The file is too large."],"h69WC6":["Sent"],"iGNUZJ":["Thanks! We'll e-mail you at ",["known"]," if you're gone when we reply."],"meAa31":["No conversations yet"],"nhTADq":["We'll reply as soon as we can"],"njBr8W":["you@example.com"],"oXOSPE":["Online"],"t7TeQU":["Messages"],"tHaDPf":[["name"]," is typing…"],"tfDRzk":["Save"],"tzsBOP":["Too many attempts. Wait a moment and try again."],"uA8iBc":["How did we do?"],"upFvcp":["Not sent."],"w61W3L":["Remove ",["0"]],"xDAtGP":["Message"],"ydzYKJ":["You:"],"yz7wBu":["Close"],"zLzEI3":["Sign in to chat with us."]}`);var nt=JSON.parse('{"-HY5kX":["Yeni konuşma"],"-f5Tkb":["Kötü"],"09Tv5j":["Yeniden bağlanıyor…"],"0XGLbP":["Oturumunuzun süresi doldu. Sayfayı yenileyip tekrar deneyin."],"1EICzz":["Şu anda uzaktayız"],"4TqZiz":["Değerlendirmeniz gönderilemedi. Tekrar deneyin."],"6Uau97":["Geç"],"6gRgw8":["Tekrar dene"],"6lGaum":["Görüldü"],"ASr-r0":["Eski konuşmaları göster"],"Amai22":["Sohbet şu anda kullanılamıyor."],"E_qvzP":["Geçerli bir e-posta adresi girin."],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"JkW3Ph":["Bu dosya türü kabul edilmiyor."],"JlFcis":["Gönder"],"KDw4GX":["Tekrar dene"],"M62PBt":["Şu anda müsait kimse yok. E-posta adresinizi bırakın, yanıtı oraya da gönderelim."],"N7m8E-":["Dosya ekle"],"NBdIgR":["Yorum"],"OEEQKT":["İyi"],"Pwqkdw":["Yükleniyor…"],"PxYAul":["Yazıyor…"],"RzWUUK":["Bir mesaj yazın…"],"S63MQu":["Tüm konuşmalar"],"SOk0EB":["Geri bildiriminiz için teşekkürler"],"Sad2tK":["Gönderiliyor…"],"SdV5Cn":["Bize bir mesaj gönderin, yanıtımız burada görünecek."],"UY1vmE":["Ek"],"VggdQJ":["Genellikle ",["duration"]," içinde yanıt verir"],"XJURKP":["E-posta adresi"],"YyNOE7":["Konuşma"],"ZxJcgC":["E-posta adresiniz kaydedilemedi. Tekrar deneyin."],"axQ1h6":["Eklemek istediğiniz bir şey var mı? (isteğe bağlı)"],"eOu9Px":["Dosya çok büyük."],"h69WC6":["Gönderildi"],"iGNUZJ":["Teşekkürler! Yanıtladığımızda burada değilseniz ",["known"]," adresine e-posta göndereceğiz."],"meAa31":["Henüz konuşma yok"],"nhTADq":["En kısa sürede yanıt vereceğiz"],"njBr8W":["siz@ornek.com"],"oXOSPE":["Çevrimiçi"],"t7TeQU":["Mesajlar"],"tHaDPf":[["name"]," yazıyor…"],"tfDRzk":["Kaydet"],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"uA8iBc":["Nasıldık?"],"upFvcp":["Gönderilemedi."],"w61W3L":[["0"]," kaldır"],"xDAtGP":["Mesaj"],"ydzYKJ":["Siz:"],"yz7wBu":["Kapat"],"zLzEI3":["Bizimle sohbet etmek için giriş yapın."]}');function st(t){return{position:t.chat.launcher_position,color:t.chat.launcher_color??t.branding.color}}function rt(t){return`yuva:${t}`}function Y(t){try{let e=localStorage.getItem(rt(t));return e?JSON.parse(e):{}}catch{return{}}}function ot(t,e){try{localStorage.setItem(rt(t),JSON.stringify(e))}catch{}}class g extends Error{status;code;constructor(t,e){super(`${t} ${e}`);this.status=t;this.code=e}}async function at(t,e,i,{method:n="GET",json:s,body:o,headers:a={},token:l,blob:c}={}){if(a={...a},l)a.Authorization=`Bearer ${l}`;let h=o;if(s!==void 0)a["Content-Type"]="application/json",h=JSON.stringify(s);let p;try{p=await t(e+i,{method:n,headers:a,body:h,credentials:"omit"})}catch{throw new g(0,"network")}if(!p.ok){let u="error";try{u=(await p.json()).code??u}catch{}throw new g(p.status,u)}if(p.status===204)return;return c?await p.blob():await p.json()}class K{server;socketClass;handlers;#s=null;#p=0;#n=0;#r=null;#g=!0;constructor(t,e,i){this.server=t;this.socketClass=e;this.handlers=i}get connected(){return this.#s?.readyState===1}start(){if(this.#g=!1,!this.#s)this.#a()}stop(){if(this.#g=!0,this.#r)clearTimeout(this.#r);this.#r=null;let t=this.#s;this.#s=null,t?.close(1000)}reset(){this.#p=0}nudge(){if(this.#g||this.#s)return;if(this.#r)clearTimeout(this.#r);this.#r=null,this.#a()}#a(){let t=this.handlers.token();if(!t||this.#g)return;let e=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(e.protocol=e.protocol==="https:"?"wss:":"ws:",this.#p>0)e.searchParams.set("last_event_id",String(this.#p));let i;try{i=new this.socketClass(e,["yuva",`yuva.token.${t}`])}catch{this.#f();return}this.#s=i,i.onmessage=(n)=>{let s;try{s=JSON.parse(String(n.data))}catch{return}if(s.type==="ready")this.#n=0,this.#p=Math.max(this.#p,s.last_event_id);else if("id"in s&&typeof s.id==="number")this.#p=Math.max(this.#p,s.id);this.handlers.event(s)},i.onclose=(n)=>{if(this.#s!==i)return;if(this.#s=null,this.#g)return;if(n.code===1008){this.#p=0,this.handlers.sessionEnded();return}this.#f()}}#f(){if(this.#g||this.#r)return;let t=this.#n++;this.handlers.reconnecting(t);let e=Math.min(30000,1000*2**t)*(0.75+Math.random()*0.5);this.#r=setTimeout(()=>{this.#r=null,this.#a()},e)}}function lt(t){return`yuva:${t}`}function F(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();return Array.from(crypto.getRandomValues(new Uint8Array(16)),(t)=>t.toString(16).padStart(2,"0")).join("")}function wt(t){try{let e=(t.split(".")[1]??"").replace(/-/g,"+").replace(/_/g,"/"),i=JSON.parse(atob(e));return typeof i.sub==="string"?i.sub:null}catch{return null}}function Ct(){try{let e=globalThis.localStorage;if(e)return e}catch{}let t=new Map;return{getItem:(e)=>t.get(e)??null,setItem:(e,i)=>void t.set(e,i)}}function ct(t){let e=new URLSearchParams;for(let[n,s]of Object.entries(t))if(s!==void 0)e.set(n,String(s));let i=e.toString();return i?`?${i}`:""}function St(t){return t.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function _t(t,e,i){let n=[];for(let[s,o]of t)n.push(`--${i}\r
9
+ `);if(S(c)&&Z.test(c))return ee(c);if(S(c))return c;return Ce(c,this._locale,this._locales)(t,i?.formats)}t=this._.bind(this);date(e,t){return N(this._locales||this._locale,e,t)}number(e,t){return U(this._locales||this._locale,e,t)}}function B(e={}){return new ne(e)}var $e=B();var Y=JSON.parse(`{"-HY5kX":["New conversation"],"-f5Tkb":["Bad"],"09Tv5j":["Reconnecting…"],"0XGLbP":["Your sign-in has expired. Reload the page and try again."],"1EICzz":["We're away right now"],"4TqZiz":["Could not send your rating. Try again."],"6Uau97":["Skip"],"6gRgw8":["Retry"],"6lGaum":["Seen"],"ASr-r0":["Show older conversations"],"Amai22":["Chat is not available right now."],"E_qvzP":["Enter a valid e-mail address."],"GQVIIl":["You seem to be offline."],"JkW3Ph":["This file type is not accepted."],"JlFcis":["Send"],"KDw4GX":["Try again"],"M62PBt":["Nobody is available right now. Leave your e-mail and we'll send the reply there too."],"N7m8E-":["Attach files"],"NBdIgR":["Comment"],"OEEQKT":["Good"],"Pwqkdw":["Loading…"],"PxYAul":["Typing…"],"RzWUUK":["Write a message…"],"S63MQu":["All conversations"],"SOk0EB":["Thanks for your feedback"],"Sad2tK":["Sending…"],"SdV5Cn":["Send us a message and we will reply here."],"UY1vmE":["Attachment"],"VggdQJ":["Usually replies in ",["duration"]],"XJURKP":["E-mail address"],"YyNOE7":["Conversation"],"ZxJcgC":["Could not save your e-mail address. Try again."],"axQ1h6":["Anything you'd like to add? (optional)"],"eOu9Px":["The file is too large."],"h69WC6":["Sent"],"iGNUZJ":["Thanks! We'll e-mail you at ",["known"]," if you're gone when we reply."],"meAa31":["No conversations yet"],"nhTADq":["We'll reply as soon as we can"],"njBr8W":["you@example.com"],"oXOSPE":["Online"],"t7TeQU":["Messages"],"tHaDPf":[["name"]," is typing…"],"tfDRzk":["Save"],"tzsBOP":["Too many attempts. Wait a moment and try again."],"uA8iBc":["How did we do?"],"upFvcp":["Not sent."],"w61W3L":["Remove ",["0"]],"xDAtGP":["Message"],"ydzYKJ":["You:"],"yz7wBu":["Close"],"zLzEI3":["Sign in to chat with us."]}`);var se=JSON.parse('{"-HY5kX":["Yeni konuşma"],"-f5Tkb":["Kötü"],"09Tv5j":["Yeniden bağlanıyor…"],"0XGLbP":["Oturumunuzun süresi doldu. Sayfayı yenileyip tekrar deneyin."],"1EICzz":["Şu anda uzaktayız"],"4TqZiz":["Değerlendirmeniz gönderilemedi. Tekrar deneyin."],"6Uau97":["Geç"],"6gRgw8":["Tekrar dene"],"6lGaum":["Görüldü"],"ASr-r0":["Eski konuşmaları göster"],"Amai22":["Sohbet şu anda kullanılamıyor."],"E_qvzP":["Geçerli bir e-posta adresi girin."],"GQVIIl":["Çevrimdışı görünüyorsunuz."],"JkW3Ph":["Bu dosya türü kabul edilmiyor."],"JlFcis":["Gönder"],"KDw4GX":["Tekrar dene"],"M62PBt":["Şu anda müsait kimse yok. E-posta adresinizi bırakın, yanıtı oraya da gönderelim."],"N7m8E-":["Dosya ekle"],"NBdIgR":["Yorum"],"OEEQKT":["İyi"],"Pwqkdw":["Yükleniyor…"],"PxYAul":["Yazıyor…"],"RzWUUK":["Bir mesaj yazın…"],"S63MQu":["Tüm konuşmalar"],"SOk0EB":["Geri bildiriminiz için teşekkürler"],"Sad2tK":["Gönderiliyor…"],"SdV5Cn":["Bize bir mesaj gönderin, yanıtımız burada görünecek."],"UY1vmE":["Ek"],"VggdQJ":["Genellikle ",["duration"]," içinde yanıt verir"],"XJURKP":["E-posta adresi"],"YyNOE7":["Konuşma"],"ZxJcgC":["E-posta adresiniz kaydedilemedi. Tekrar deneyin."],"axQ1h6":["Eklemek istediğiniz bir şey var mı? (isteğe bağlı)"],"eOu9Px":["Dosya çok büyük."],"h69WC6":["Gönderildi"],"iGNUZJ":["Teşekkürler! Yanıtladığımızda burada değilseniz ",["known"]," adresine e-posta göndereceğiz."],"meAa31":["Henüz konuşma yok"],"nhTADq":["En kısa sürede yanıt vereceğiz"],"njBr8W":["siz@ornek.com"],"oXOSPE":["Çevrimiçi"],"t7TeQU":["Mesajlar"],"tHaDPf":[["name"]," yazıyor…"],"tfDRzk":["Kaydet"],"tzsBOP":["Çok fazla deneme. Biraz bekleyip tekrar deneyin."],"uA8iBc":["Nasıldık?"],"upFvcp":["Gönderilemedi."],"w61W3L":[["0"]," kaldır"],"xDAtGP":["Mesaj"],"ydzYKJ":["Siz:"],"yz7wBu":["Kapat"],"zLzEI3":["Bizimle sohbet etmek için giriş yapın."]}');function re(e){return{position:e.chat.launcher_position,color:e.chat.launcher_color??e.branding.color}}function oe(e){return`yuva:${e}`}function K(e){try{let t=localStorage.getItem(oe(e));return t?JSON.parse(t):{}}catch{return{}}}function ae(e,t){try{localStorage.setItem(oe(e),JSON.stringify(t))}catch{}}class f extends Error{status;code;constructor(e,t){super(`${e} ${t}`);this.status=e;this.code=t}}async function le(e,t,i,{method:n="GET",json:s,body:o,headers:a={},token:l,blob:c}={}){if(a={...a},l)a.Authorization=`Bearer ${l}`;let h=o;if(s!==void 0)a["Content-Type"]="application/json",h=JSON.stringify(s);let p;try{p=await e(t+i,{method:n,headers:a,body:h,credentials:"omit"})}catch{throw new f(0,"network")}if(!p.ok){let u="error";try{u=(await p.json()).code??u}catch{}throw new f(p.status,u)}if(p.status===204)return;return c?await p.blob():await p.json()}class F{server;socketClass;handlers;#s=null;#m=0;#n=0;#r=null;#y=!0;constructor(e,t,i){this.server=e;this.socketClass=t;this.handlers=i}get connected(){return this.#s?.readyState===1}start(){if(this.#y=!1,!this.#s)this.#a()}stop(){if(this.#y=!0,this.#r)clearTimeout(this.#r);this.#r=null;let e=this.#s;this.#s=null,e?.close(1000)}reset(){this.#m=0}nudge(){if(this.#y||this.#s)return;if(this.#r)clearTimeout(this.#r);this.#r=null,this.#a()}#a(){let e=this.handlers.token();if(!e||this.#y)return;let t=new URL(`${this.server}/client/v1/realtime`,globalThis.location?.href);if(t.protocol=t.protocol==="https:"?"wss:":"ws:",this.#m>0)t.searchParams.set("last_event_id",String(this.#m));let i;try{i=new this.socketClass(t,["yuva",`yuva.token.${e}`])}catch{this.#u();return}this.#s=i,i.onmessage=(n)=>{let s;try{s=JSON.parse(String(n.data))}catch{return}if(s.type==="ready")this.#n=0,this.#m=Math.max(this.#m,s.last_event_id);else if("id"in s&&typeof s.id==="number")this.#m=Math.max(this.#m,s.id);this.handlers.event(s)},i.onclose=(n)=>{if(this.#s!==i)return;if(this.#s=null,this.#y)return;if(n.code===1008){this.#m=0,this.handlers.sessionEnded();return}this.#u()}}#u(){if(this.#y||this.#r)return;let e=this.#n++;this.handlers.reconnecting(e);let t=Math.min(30000,1000*2**e)*(0.75+Math.random()*0.5);this.#r=setTimeout(()=>{this.#r=null,this.#a()},t)}}function Se(e,t,i){let n=new URL("/account/connect",e);return n.searchParams.set("channel",t),n.searchParams.set("origin",i),n.href}function _e(e){let t=e;return!!t&&typeof t.token==="string"&&t.token.startsWith("yuva_rd_")&&typeof t.expires_at==="string"&&!Number.isNaN(Date.parse(t.expires_at))&&typeof t.channel_key==="string"&&typeof t.origin==="string"&&!!t.reader&&typeof t.reader.initials==="string"}function ce(e,t,{width:i=460,height:n=640}={}){let s=new URL(e).origin,o=location.origin,a=Math.max(0,(window.screenX??0)+((window.outerWidth??i)-i)/2),l=Math.max(0,(window.screenY??0)+((window.outerHeight??n)-n)/2),c=window.open(Se(e,t,o),"yuva-reader",`popup=yes,width=${i},height=${n},left=${Math.round(a)},top=${Math.round(l)}`);if(!c)return Promise.reject(new f(0,"popup_blocked"));return new Promise((h,p)=>{let u=!1,y=()=>{u=!0,window.removeEventListener("message",g),clearInterval(_)},g=(b)=>{if(u||b.origin!==s||b.source&&b.source!==c)return;let d=b.data;if(!_e(d)||d.channel_key!==t||d.origin!==o)return;y();try{c.close()}catch{}h({token:d.token,expires_at:d.expires_at,reader:d.reader})},_=setInterval(()=>{let b=!1;try{b=c.closed}catch{}if(!b)return;clearInterval(_),setTimeout(()=>{if(u)return;y(),p(new f(0,"sign_in_cancelled"))},300)},500);window.addEventListener("message",g)})}function de(e){return`yuva:${e}`}function he(e,t){return`yuva:reader:${e} ${t}`}function I(){if(typeof crypto.randomUUID==="function")return crypto.randomUUID();return Array.from(crypto.getRandomValues(new Uint8Array(16)),(e)=>e.toString(16).padStart(2,"0")).join("")}function Pe(e){try{let t=(e.split(".")[1]??"").replace(/-/g,"+").replace(/_/g,"/"),i=JSON.parse(atob(t));return typeof i.sub==="string"?i.sub:null}catch{return null}}function Te(){try{let t=globalThis.localStorage;if(t)return t}catch{}let e=new Map;return{getItem:(t)=>e.get(t)??null,setItem:(t,i)=>void e.set(t,i)}}function J(e){let t=new URLSearchParams;for(let[n,s]of Object.entries(e))if(s!==void 0)t.set(n,String(s));let i=t.toString();return i?`?${i}`:""}function Ee(e){return e.replace(/"/g,"%22").replace(/\r/g,"%0D").replace(/\n/g,"%0A")}function Re(e,t,i){let n=[];for(let[s,o]of e)n.push(`--${i}\r
10
10
  Content-Disposition: form-data; name="${s}"\r
11
11
  \r
12
12
  ${o}\r
13
- `);for(let s of e){let o=s.name||"file";n.push(`--${i}\r
14
- Content-Disposition: form-data; name="files"; filename="${St(o)}"\r
13
+ `);for(let s of t){let o=s.name||"file";n.push(`--${i}\r
14
+ Content-Disposition: form-data; name="files"; filename="${Ee(o)}"\r
15
15
  Content-Type: ${s.type||"application/octet-stream"}\r
16
16
  \r
17
17
  `,s,`\r
18
18
  `)}return n.push(`--${i}--\r
19
- `),new Blob(n)}class dt{server;channel;#s;#p;#n;#r;#g;#a=null;#f=null;#v=null;#x=null;#e=null;#E=new Map;constructor(t){this.server=t.server.replace(/\/+$/,""),this.channel=t.channel,this.#s=t.fetch??((e,i)=>fetch(e,i)),this.#p=t.WebSocket??globalThis.WebSocket,this.#n=t.storage??Ct(),this.#r=t.identityToken??null,this.#g=t.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#f}get token(){return this.#a}get connected(){return this.#e?.connected??!1}on(t,e){let i=this.#E.get(t);if(!i)this.#E.set(t,i=new Set);return i.add(e),()=>void i.delete(e)}#l(t,e){for(let i of this.#E.get(t)??[])i(e)}stored(){try{let t=this.#n.getItem(lt(this.channel));return t?JSON.parse(t):{}}catch{return{}}}#m(t){try{this.#n.setItem(lt(this.channel),JSON.stringify(t))}catch{}}channelSettings(){return this.#i(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}setIdentityToken(t){this.#r=t,this.reset()}start(){if(this.#f)return Promise.resolve(this.#f);return this.#v??=this.#T(!1).then((t)=>(this.#l("session",{session:t,renewed:!1}),t)).finally(()=>{this.#v=null}),this.#v}async refresh(){let t=await this.#h("/client/v1/session");return this.#f={...this.#f,...t},this.#l("session",{session:this.#f,renewed:!1}),this.#f}reset(){this.#e?.stop(),this.#e?.reset(),this.#v=null,this.#x=null,this.#a=null,this.#f=null}async signOut(){let t=this.#a;this.reset();let e=this.stored();if(delete e.session,this.#m(e),t)await this.#i("/client/v1/session",{method:"DELETE",token:t}).catch(()=>{return})}async connect(){if(!this.#p)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#e??=new K(this.server,this.#p,{token:()=>this.#a,event:(t)=>{if(t.type==="ready")this.#l("connection",{state:"open",attempt:0});this.#l("event",t)},sessionEnded:()=>void this.#y().catch(()=>this.#e?.nudge()),reconnecting:(t)=>{if(this.#l("connection",{state:"reconnecting",attempt:t}),t===2)this.#h("/client/v1/session").catch(()=>{return})}}),!this.#e.connected)this.#l("connection",{state:"connecting",attempt:0});this.#e.start()}disconnect(){this.#e?.stop(),this.#l("connection",{state:"closed",attempt:0})}reconnect(){this.#e?.nudge()}listConversations(t={}){return this.#h(`/client/v1/conversations${ct({...t})}`)}getConversation(t){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}`)}startConversation(t){return this.#h("/client/v1/conversations",this.#b(t))}listMessages(t,e={}){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/messages${ct({...e})}`)}sendMessage(t,e){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/messages`,this.#b(e))}markRead(t,e){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/read`,{method:"POST",json:e?{message_id:e}:{}})}rate(t,e,i){let n={rating:e,comment:i?.trim()||void 0};return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/rating`,{method:"POST",json:n})}setTyping(t,e){return this.#h(`/client/v1/conversations/${encodeURIComponent(t)}/typing`,{method:"POST",json:{typing:e}})}setEmail(t){return this.#h("/client/v1/contact/email",{method:"PUT",json:{email:t}})}attachment(t){return this.#h(`/client/v1/attachments/${encodeURIComponent(t)}`,{blob:!0})}#b({body:t,subject:e,files:i=[],client_id:n=F()}){let s=this.#g&&/^[\x20-\x7e]{1,255}$/.test(n)?{"Idempotency-Key":n}:{};if(i.length===0)return{method:"POST",headers:s,json:{body:t,subject:e,client_id:n}};let o=[];if(e)o.push(["subject",e]);if(t)o.push(["body",t]);o.push(["client_id",n]);let a=`yuva-${n.replace(/[^\w-]/g,"").slice(0,60)}-${n.length}`;return s["Content-Type"]=`multipart/form-data; boundary=${a}`,{method:"POST",headers:s,body:_t(o,i,a)}}#i(t,e){return at(this.#s,this.server,t,e)}async#h(t,e={},i=!0){if(!this.#a)await this.start();try{return await this.#i(t,{...e,token:this.#a})}catch(n){if(!i||!(n instanceof g)||n.status!==401)throw n;return await this.#y(),this.#h(t,e,!1)}}#y(){return this.#x??=(async()=>{let t=await this.#T(!0);if(this.#e)this.#e.stop(),this.#e.reset(),this.#e.start();this.#l("session",{session:t,renewed:!0})})().finally(()=>{this.#x=null}),this.#x}async#T(t){let e=this.stored(),i=await this.#r?.()||null,n=i?wt(i):null,s=e.session;if(!t&&s&&s.sub===n&&Date.parse(s.expires_at)>Date.now()+60000)try{let c=await this.#i("/client/v1/session",{token:s.token});return this.#k(c,s.token,n)}catch(c){if(!(c instanceof g)||c.status!==401&&c.status!==403)throw c}let o=await this.#i("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:i??void 0,visitor_id:e.visitor_id}}),{token:a,...l}=o;return this.#k(l,a,n)}#k(t,e,i){this.#a=e,this.#f=t;let n=this.stored();if(n.session={token:e,expires_at:t.expires_at,sub:i},t.visitor_id)n.visitor_id=t.visitor_id;else if(t.contact.identified)delete n.visitor_id;return this.#m(n),t}}function ht(t){return new dt(t)}var ut=`
19
+ `),new Blob(n)}class ue{server;channel;#s;#m;#n;#r;#y;#a=null;#u=null;#w=null;#C=null;#t=null;#v;#p=new Map;constructor(e){this.server=e.server.replace(/\/+$/,""),this.channel=e.channel,this.#s=e.fetch??((t,i)=>fetch(t,i)),this.#m=e.WebSocket??globalThis.WebSocket,this.#n=e.storage??Te(),this.#r=e.identityToken??null,this.#y=e.idempotencyKeys??typeof globalThis.document>"u"}get session(){return this.#u}get token(){return this.#a}get connected(){return this.#t?.connected??!1}on(e,t){let i=this.#p.get(e);if(!i)this.#p.set(e,i=new Set);return i.add(t),()=>void i.delete(t)}#l(e,t){for(let i of this.#p.get(e)??[])i(t)}stored(){try{let e=this.#n.getItem(de(this.channel));return e?JSON.parse(e):{}}catch{return{}}}#k(e){try{this.#n.setItem(de(this.channel),JSON.stringify(e))}catch{}}channelSettings(){return this.#f(`/client/v1/channels/${encodeURIComponent(this.channel)}`)}ratePage(e){return this.#f(`/client/v1/channels/${encodeURIComponent(this.channel)}/page-ratings`,{method:"POST",json:e})}setIdentityToken(e){this.#r=e,this.reset()}start(){if(this.#u)return Promise.resolve(this.#u);return this.#w??=this.#I(!1).then((e)=>(this.#l("session",{session:e,renewed:!1}),e)).finally(()=>{this.#w=null}),this.#w}async refresh(){let e=await this.#c("/client/v1/session");return this.#u={...this.#u,...e},this.#l("session",{session:this.#u,renewed:!1}),this.#u}reset(){this.#t?.stop(),this.#t?.reset(),this.#w=null,this.#C=null,this.#a=null,this.#u=null}async signOut(){let e=this.#a;this.reset();let t=this.stored();if(delete t.session,this.#k(t),e)await this.#f("/client/v1/session",{method:"DELETE",token:e}).catch(()=>{return})}async connect(){if(!this.#m)throw Error("Yuva: no WebSocket in this runtime; pass options.WebSocket");if(await this.start(),this.#t??=new F(this.server,this.#m,{token:()=>this.#a,event:(e)=>{if(e.type==="ready")this.#l("connection",{state:"open",attempt:0});this.#l("event",e)},sessionEnded:()=>void this.#D().catch(()=>this.#t?.nudge()),reconnecting:(e)=>{if(this.#l("connection",{state:"reconnecting",attempt:e}),e===2)this.#c("/client/v1/session").catch(()=>{return})}}),!this.#t.connected)this.#l("connection",{state:"connecting",attempt:0});this.#t.start()}disconnect(){this.#t?.stop(),this.#l("connection",{state:"closed",attempt:0})}reconnect(){this.#t?.nudge()}listConversations(e={}){return this.#c(`/client/v1/conversations${J({...e})}`)}getConversation(e){return this.#c(`/client/v1/conversations/${encodeURIComponent(e)}`)}startConversation(e){return this.#c("/client/v1/conversations",this.#R(e))}listMessages(e,t={}){return this.#c(`/client/v1/conversations/${encodeURIComponent(e)}/messages${J({...t})}`)}sendMessage(e,t){return this.#c(`/client/v1/conversations/${encodeURIComponent(e)}/messages`,this.#R(t))}markRead(e,t){return this.#c(`/client/v1/conversations/${encodeURIComponent(e)}/read`,{method:"POST",json:t?{message_id:t}:{}})}rate(e,t,i){let n={rating:t,comment:i?.trim()||void 0};return this.#c(`/client/v1/conversations/${encodeURIComponent(e)}/rating`,{method:"POST",json:n})}setTyping(e,t){return this.#c(`/client/v1/conversations/${encodeURIComponent(e)}/typing`,{method:"POST",json:{typing:t}})}setEmail(e){return this.#c("/client/v1/contact/email",{method:"PUT",json:{email:e}})}attachment(e){return this.#c(`/client/v1/attachments/${encodeURIComponent(e)}`,{blob:!0})}sendFeedback(e){let t=e.client_id??I();return this.#c("/client/v1/feedback",{method:"POST",headers:this.#x(t),json:{...e,client_id:t}})}get reader(){if(this.#v===void 0)try{let e=this.#n.getItem(he(this.server,this.channel));this.#v=e?JSON.parse(e):null}catch{this.#v=null}if(this.#v&&Date.parse(this.#v.expires_at)<=Date.now()+30000)this.#i(null);return this.#v}#i(e){let t=this.#v?.token!==e?.token;this.#v=e;try{this.#n.setItem(he(this.server,this.channel),e?JSON.stringify(e):"")}catch{}if(t)this.#l("reader",e)}readerSignIn(e){return ce(this.server,this.channel,e).then((t)=>(this.#i(t),t))}setReader(e){this.#i(e)}async readerSignOut(){let e=this.reader?.token;if(this.#i(null),e)await this.#f("/client/v1/reader-token",{method:"DELETE",token:e}).catch(()=>{return})}listDiscussions(e,t={}){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions${J({page:e,...t})}`,{},!1)}getDiscussion(e){return this.#b(`/client/v1/channels/${encodeURIComponent(this.channel)}/discussions/${encodeURIComponent(e)}`,{},!1)}startDiscussion(e){return this.#b("/client/v1/discussions",{method:"POST",json:e})}replyToDiscussion(e,t){return this.#b(`/client/v1/discussions/${encodeURIComponent(e)}/posts`,{method:"POST",json:t})}editDiscussionPost(e,t){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"PATCH",json:t})}deleteDiscussionPost(e){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}`,{method:"DELETE"})}voteDiscussionPost(e,t=!0){return this.#b(`/client/v1/discussion-posts/${encodeURIComponent(e)}/vote`,{method:t?"PUT":"DELETE"})}followDiscussion(e,t=!0){return this.#b(`/client/v1/discussions/${encodeURIComponent(e)}/follow`,{method:t?"PUT":"DELETE"})}acceptDiscussionAnswer(e,t){let i=`/client/v1/discussions/${encodeURIComponent(e)}/answer`;return this.#b(i,t?{method:"PUT",json:{post_id:t}}:{method:"DELETE"})}async discussionWriter(){if(this.reader)return"reader";if(this.#u)return this.#u.contact.identified?"contact":null;return await this.#r?.()?"contact":null}async#b(e,t,i=!0){let n=this.reader;if(n)try{return await this.#f(e,{...t,token:n.token})}catch(o){if(!(o instanceof f)||o.status!==401||this.#v?.token!==n.token)throw o;if(this.#i(null),i)throw new f(403,"sign_in_required")}if(await this.discussionWriter()==="contact")return this.#c(e,t);if(i)throw new f(403,"sign_in_required");return this.#f(e,t)}#x(e){return this.#y&&/^[\x20-\x7e]{1,255}$/.test(e)?{"Idempotency-Key":e}:{}}#R({body:e,subject:t,files:i=[],client_id:n=I()}){let s=this.#x(n);if(i.length===0)return{method:"POST",headers:s,json:{body:e,subject:t,client_id:n}};let o=[];if(t)o.push(["subject",t]);if(e)o.push(["body",e]);o.push(["client_id",n]);let a=`yuva-${n.replace(/[^\w-]/g,"").slice(0,60)}-${n.length}`;return s["Content-Type"]=`multipart/form-data; boundary=${a}`,{method:"POST",headers:s,body:Re(o,i,a)}}#f(e,t){return le(this.#s,this.server,e,t)}async#c(e,t={},i=!0){if(!this.#a)await this.start();try{return await this.#f(e,{...t,token:this.#a})}catch(n){if(!i||!(n instanceof f)||n.status!==401)throw n;return await this.#D(),this.#c(e,t,!1)}}#D(){return this.#C??=(async()=>{let e=await this.#I(!0);if(this.#t)this.#t.stop(),this.#t.reset(),this.#t.start();this.#l("session",{session:e,renewed:!0})})().finally(()=>{this.#C=null}),this.#C}async#I(e){let t=this.stored(),i=await this.#r?.()||null,n=i?Pe(i):null,s=t.session;if(!e&&s&&s.sub===n&&Date.parse(s.expires_at)>Date.now()+60000)try{let c=await this.#f("/client/v1/session",{token:s.token});return this.#M(c,s.token,n)}catch(c){if(!(c instanceof f)||c.status!==401&&c.status!==403)throw c}let o=await this.#f("/client/v1/session",{method:"POST",json:{channel_key:this.channel,identity_token:i??void 0,visitor_id:t.visitor_id}}),{token:a,...l}=o;return this.#M(l,a,n)}#M(e,t,i){this.#a=t,this.#u=e;let n=this.stored();if(n.session={token:t,expires_at:e.expires_at,sub:i},e.visitor_id)n.visitor_id=e.visitor_id;else if(e.contact.identified)delete n.visitor_id;return this.#k(n),e}}function pe(e){return new ue(e)}var fe=`
20
20
  [hidden] { display: none !important; }
21
21
  .header {
22
22
  display: flex;
@@ -208,6 +208,6 @@ Content-Type: ${s.type||"application/octet-stream"}\r
208
208
  .banner { padding: 6px 12px; background: var(--yuva-soft); color: var(--yuva-muted); font-size: 13px; text-align: center; }
209
209
  @media (max-width: 480px) { .composer textarea, .card input, .card textarea { font-size: 16px; } }
210
210
  .sr { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
211
- `;var zt=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|((?:https?:\/\/|www\.)[^\s<>"]*[^\s<>".,:;'!?)\]])/g;function Et(t,e){let i=document.createElement("a");return i.href=t,i.textContent=e,i.target="_blank",i.rel="noopener noreferrer nofollow ugc",i}function J(t,e){let i=document.createElement(t);return i.append(...e),i}function G(t){let e=[],i=0;for(let n of t.matchAll(zt)){let s=n.index??0;if(s>i)e.push(document.createTextNode(t.slice(i,s)));let[o,a,l,c,h]=n;if(a)e.push(J("code",[document.createTextNode(a.slice(1,-1))]));else if(l)e.push(J("strong",G(l.slice(2,-2))));else if(c)e.push(J("em",G(c.slice(1,-1))));else if(h){let p=h.startsWith("www.")?`https://${h}`:h;try{let u=new URL(p);e.push(u.protocol==="http:"||u.protocol==="https:"?Et(u.href,h):document.createTextNode(h))}catch{e.push(document.createTextNode(h))}}i=s+o.length}if(i<t.length)e.push(document.createTextNode(t.slice(i)));return e}function M(t){let e=document.createDocumentFragment(),i=t.trim().replace(/\r\n?/g,`
212
- `).split(/^```[^\n]*\n([\s\S]*?)^```[ \t]*$/m);return i.forEach((n,s)=>{if(s%2===1){let a=document.createElement("pre");a.textContent=n.replace(/\n$/,""),e.append(a);return}(i.length>1?n.replace(/^\n|\n$/g,""):n).split(`
213
- `).forEach((a,l)=>{if(l>0)e.append(document.createElement("br"));e.append(...G(a))})}),e}var Tt={en:N,tr:nt},Pt=10,pt=300000,S={close:'<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',back:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 6l-6 6 6 6"/></svg>',attach:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 11.5l-8.3 8.3a5 5 0 01-7-7L13 4.5a3.3 3.3 0 014.7 4.7l-8.3 8.3a1.7 1.7 0 01-2.4-2.4L14.5 7.6"/></svg>',send:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M3.4 20.4l17.5-7.5a1 1 0 000-1.8L3.4 3.6a1 1 0 00-1.4 1.2L4.5 12l-2.5 7.2a1 1 0 001.4 1.2zM4.5 12h7"/></svg>',file:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M14 3H6v18h12V7z M14 3v4h4"/></svg>'};function r(t,e,i){let n=document.createElement(t);if(e)n.className=e;if(i!==void 0)n.textContent=i;return n}function T(t,e,i,n="icon"){let s=r("button",n);return s.type="button",s.innerHTML=t,s.setAttribute("aria-label",e),s.title=e,s.addEventListener("click",i),s}var v=(t)=>Date.parse(t),ft=(t,e)=>v(t.created_at)-v(e.created_at),It=(t,e)=>v(e.last_message_at??e.created_at)-v(t.last_message_at??t.created_at),L=(t)=>t.author.type==="contact"?"contact":`${t.author.type}:${t.author.name??""}`,Rt=(t)=>/^image\/(png|jpeg|gif|webp)$/.test(t.content_type);class gt{#s;#p;#n;#r=null;#g=null;#a="loading";#f="";#v=null;#x=null;#e=new Map;#E;#l=new Map;#m=[];#b=new Map;#i=null;#h=!1;#y=[];#T=0;#k=null;#U=new Map;#G=new Map;#W=new Map;#q=!1;#w="";#H=!1;#C=new Map;#wt=r("div","card rate");#u=r("textarea");#Q="";#rt=null;#X=r("header","header");#V=r("div","banner");#L=r("div","body");#c=r("div","scroll");#S=r("div","card");#_=r("input");#ot=r("div","composer");#Z=r("div","chips");#d=r("textarea");#z=r("input");#A;#j;#tt=r("div","sr");#B;#I=!0;constructor(t){this.#s=t;let{server:e,channel:i}=t.config();this.#n=ht({server:e,channel:i??"",identityToken:()=>t.identityToken()}),this.#n.on("event",(s)=>this.#_t(s)),this.#n.on("connection",({state:s,attempt:o})=>{if(s!=="reconnecting")return;this.#h=o>0,this.#nt()}),this.#n.on("session",({session:s,renewed:o})=>{if(this.#Y(s.inbox),this.#g=s.contact,o)this.#pt()}),this.#lt(),this.#tt.setAttribute("aria-live","polite"),this.#c.addEventListener("scroll",()=>{if(this.#I=this.#c.scrollHeight-this.#c.scrollTop-this.#c.clientHeight<48,this.#c.scrollTop<60&&this.#i?.kind==="thread"&&this.#i.id)this.#F(this.#i.id,!0)}),this.#d.rows=1,this.#d.addEventListener("keydown",(s)=>{if(s.key==="Enter"&&!s.shiftKey&&!s.isComposing)s.preventDefault(),this.#it()}),this.#d.addEventListener("input",()=>{this.#gt(),this.#D(),this.#Tt()}),this.#d.addEventListener("paste",(s)=>{let o=Array.from(s.clipboardData?.files??[]);if(o.length===0)return;s.preventDefault(),this.#ft(o)}),this.#z.type="file",this.#z.multiple=!0,this.#z.hidden=!0,this.#z.addEventListener("change",()=>{this.#ft(Array.from(this.#z.files??[])),this.#z.value=""}),this.#j=T(S.attach,"",()=>this.#z.click()),this.#A=T(S.send,"",()=>void this.#it(),"icon send");let n=r("form");n.addEventListener("submit",(s)=>{s.preventDefault(),this.#it()}),n.append(this.#j,this.#d,this.#A,this.#z),this.#ot.append(this.#Z,n),this.#_.type="email",this.#_.required=!0,this.#_.autocomplete="email",this.#u.rows=2,this.#u.maxLength=2000,this.#u.dir="auto",document.addEventListener("visibilitychange",this.#N),window.addEventListener("online",this.#N),this.#kt(),this.#O()}update(){this.#lt(),this.#kt()}opened(){if(this.#a==="error"){this.#v=null,this.#O();return}if(this.#a==="ready")this.#n.token?this.#St():this.#ct().then(()=>this.#o()).catch(()=>{return});if(this.#o(),this.#P(),this.#$(),this.#s.config().layout==="launcher")this.#d.focus({preventScroll:!0})}closed(){this.#M()}identityChanged(){this.#at(),this.#O()}async signOut(){let t=this.#n.signOut();if(this.#at(),await t,this.#s.isOpen())this.#O();else this.#o()}destroy(){this.#n.reset(),this.#M(),document.removeEventListener("visibilitychange",this.#N),window.removeEventListener("online",this.#N);for(let t of this.#U.values())URL.revokeObjectURL(t)}#at(){this.#n.reset(),this.#v=null,this.#x=null,this.#r=null,this.#g=null,this.#a="loading",this.#e.clear(),this.#l.clear(),this.#m=[],this.#C.clear(),this.#Q="",this.#i=null,this.#H=!1,this.#s.setUnread(0)}#N=()=>{if(document.visibilityState!=="visible")return;this.#n.reconnect(),this.#$(),this.#ht()};#lt(){let{locale:t}=this.#s.config();this.#p=B({locale:t,messages:{[t]:Tt[t]??N}})}#t(t){return this.#p._(t)}#O(){return this.#v??=(async()=>{this.#a="loading",this.#o();let{channel:t}=this.#s.config();if(!t)throw new g(0,"not_configured");if(await this.#s.identityToken()||Y(t).session)await this.#Ct();else if(await this.#ct(),!this.#r?.chat.allow_anonymous)throw new g(403,"anonymous_not_allowed");if(this.#a="ready",!this.#i){let e=this.#xt();if(this.#i=e.length>1?{kind:"list"}:{kind:"thread",id:e[0]?.id??null},this.#i.kind==="thread"&&this.#i.id)await this.#F(this.#i.id)}this.#o(),this.#P(),this.#$()})().catch((t)=>{if(this.#v=null,this.#ut(t))return;this.#a="error",this.#f=t instanceof g?t.code:"error",this.#o()}),this.#v}async#ct(){let t=await this.#dt();if(!this.#n.token)this.#Y(t)}#dt(){if(!this.#s.config().channel)throw new g(0,"not_configured");return this.#n.channelSettings()}#Y(t){let{channel:e}=this.#s.config();this.#r=t;let i=st(t);if(this.#s.setLauncher(i),e)ot(e,{...Y(e),launcher:i})}async#ht(){if(this.#a!=="ready")return;try{this.#Y(await this.#dt()),this.#o()}catch(t){this.#ut(t,!0)}}#ut(t,e=!this.#n.token){let i=t instanceof g&&(t.code==="origin_not_allowed"||t.status===404&&e);if(i)this.#s.refused();return i}#Ct(){return this.#x??=(async()=>{await this.#n.start(),await this.#K(),await this.#n.connect()})().finally(()=>{this.#x=null}),this.#x}async#St(){try{await this.#n.refresh(),this.#o()}catch{}}async#K(t=!1){let e=await this.#n.listConversations({limit:50,cursor:t?this.#E:void 0});if(!t)this.#e.clear();for(let i of e.items)this.#e.set(i.id,i);this.#E=e.next_cursor,this.#R()}async#pt(){await this.#K();let t=this.#i?.kind==="thread"?this.#i.id:null;for(let e of[...this.#l.keys()])if(e!==t)this.#l.delete(e);if(t)this.#l.delete(t),await this.#F(t);this.#o()}async#F(t,e=!1){let i=this.#l.get(t);if(!i)i={messages:[],complete:!1,loading:!1},this.#l.set(t,i);if(i.loading||e&&(i.complete||!i.cursor))return;i.loading=!0;let n=this.#c.scrollHeight-this.#c.scrollTop;try{let s=await this.#n.listMessages(t,{order:"desc",limit:30,cursor:e?i.cursor:void 0}),o=new Set(i.messages.map((a)=>a.id));i.messages=[...i.messages,...s.items.filter((a)=>!o.has(a.id))].sort(ft),i.cursor=s.next_cursor,i.complete=!s.next_cursor}finally{i.loading=!1}if(e)this.#o(),this.#c.scrollTop=this.#c.scrollHeight-n}#_t(t){switch(t.type){case"ready":if(this.#h=!1,this.#nt(),this.#H)this.#ht();this.#H=!0;return;case"inbox.updated":{let e=this.#r?.ask_for_rating;if(this.#Y(t.data),e!==void 0&&e!==t.data.ask_for_rating)this.#K().then(()=>this.#o()).catch(()=>{return});break}case"resync_required":this.#pt();return;case"presence":if(this.#r)this.#r={...this.#r,presence:t.data};break;case"conversation.created":if(!this.#e.has(t.data.id))this.#e.set(t.data.id,t.data);if(this.#i?.kind==="thread"&&this.#i.id===null&&this.#e.size>1)this.#i=this.#m.some((e)=>e.conversation===null)?this.#i:{kind:"list"};this.#R();break;case"conversation.updated":{let e=this.#e.get(t.data.id),{status:i,can_rate:n,rating:s}=t.data;if(e)this.#e.set(e.id,{...e,status:i,can_rate:n,rating:s});if(!n)this.#C.delete(t.data.id);break}case"message.created":case"message.updated":this.#et(t.data,t.type==="message.created");break;case"read":{let e=this.#e.get(t.data.conversation_id),i=e?.last_read_by_member_at;if(e&&(!i||v(t.data.read_at)>v(i)))this.#e.set(e.id,{...e,last_read_by_member_at:t.data.read_at});break}case"typing":{let e=t.data.conversation_id,i=this.#b.get(e);if(i)clearTimeout(i.timer);if(t.data.typing){let n=t.data.author.name??"";this.#b.set(e,{name:n,timer:setTimeout(()=>this.#b.delete(e)&&this.#o(),8000)})}else this.#b.delete(e);break}}this.#o()}#et(t,e){let i=t.conversation_id,n=this.#l.get(i);if(n){let o=n.messages.findIndex((a)=>a.id===t.id);if(o>=0)n.messages[o]=t;else n.messages=[...n.messages,t].sort(ft)}if(t.client_id)this.#m=this.#m.filter((o)=>o.client_id!==t.client_id);let s=this.#e.get(i);if(!s){this.#n.getConversation(i).then((o)=>{this.#e.set(o.id,o),this.#R(),this.#o()}).catch(()=>{return});return}if(e){let o=t.body.replace(/\s+/g," ").trim();if(this.#e.set(i,{...s,last_message:{id:t.id,author_type:t.author.type,text:o.length>140?`${o.slice(0,139)}…`:o,created_at:t.created_at},last_message_at:t.created_at,unread:s.unread||t.author.type!=="contact"}),t.author.type!=="contact"){let a=this.#b.get(i);if(a)clearTimeout(a.timer);this.#b.delete(i),this.#zt(t)}}this.#R(),this.#$()}#zt(t){this.#tt.textContent=`${t.author.name||this.#r?.name||""}: ${t.body.slice(0,200)}`}#R(){let t=0;for(let e of this.#e.values())if(e.unread)t++;this.#s.setUnread(t)}#Et(){if(!this.#s.isOpen()||document.visibilityState!=="visible")return null;return this.#i?.kind==="thread"?this.#i.id:null}#$(){let t=this.#Et(),e=t?this.#e.get(t):void 0;if(!t||!e?.unread)return;this.#e.set(t,{...e,unread:!1}),this.#R(),this.#n.markRead(t).catch(()=>{let i=this.#e.get(t);if(i)this.#e.set(t,{...i,unread:!0});this.#R()})}#ft(t){this.#y=[...this.#y,...t].slice(0,Pt),this.#J(),this.#D(),this.#d.focus()}#gt(){if(this.#d.style.blockSize="",this.#d.value==="")return;this.#d.style.blockSize="auto",this.#d.style.blockSize=`${Math.max(38,Math.min(this.#d.scrollHeight,140))}px`}#D(){this.#A.disabled=this.#d.value.trim()===""&&this.#y.length===0}#Tt(){let t=this.#i?.kind==="thread"?this.#i.id:null;if(!t||this.#d.value.trim()===""){this.#M();return}if(Date.now()-this.#T>3000)this.#T=Date.now(),this.#n.setTyping(t,!0).catch(()=>{return});if(this.#k)clearTimeout(this.#k);this.#k=setTimeout(()=>this.#M(),4000)}#M(){if(this.#k)clearTimeout(this.#k);if(this.#k=null,this.#T===0)return;this.#T=0;let t=this.#i?.kind==="thread"?this.#i.id:null;if(t)this.#n.setTyping(t,!1).catch(()=>{return})}async#it(){if(this.#a!=="ready"||this.#i?.kind!=="thread")return;let t=this.#d.value.trim(),e=this.#y;if(!t&&e.length===0)return;if(this.#i.id===null&&this.#m.some((n)=>n.conversation===null))return;this.#M(),this.#d.value="",this.#y=[],this.#gt(),this.#J(),this.#D();let i={client_id:F(),conversation:this.#i.id,body:t,files:e,state:"sending"};this.#m.push(i),this.#o(),this.#P(),await this.#mt(i)}async#mt(t){t.state="sending",this.#o();let e={body:t.body,files:t.files,client_id:t.client_id};try{if(t.conversation===null){let i=await this.#n.startConversation(e),n=i.conversation.id;if(!this.#e.has(n))this.#e.set(n,i.conversation);if(!this.#l.has(n))this.#l.set(n,{messages:[],complete:!0,loading:!1});if(this.#i?.kind==="thread"&&this.#i.id===null)this.#i={kind:"thread",id:n};this.#et(i.message,!1)}else{let i=await this.#n.sendMessage(t.conversation,e);this.#et(i,!0)}this.#m=this.#m.filter((i)=>i!==t)}catch(i){let n=i instanceof g?i.status:0;t.state=n===413||n===415?"refused":"failed",t.status=n}this.#o(),this.#P()}async rate(t,e,i){try{let n=await this.#n.rate(t,e,i);return this.#e.set(n.id,n),this.#C.delete(t),this.#o(),n}catch(n){if(n instanceof g&&n.status===409){let s=await this.#n.getConversation(t).catch(()=>null);if(s)this.#e.set(s.id,s);this.#C.delete(t),this.#o()}throw n}}#Pt(t,e){if(this.#C.get(t)?.state==="sending")return;if(this.#C.set(t,{choice:e,state:"choosing"}),this.#o(),this.#u.focus({preventScroll:!0}),this.#I)this.#P()}async#yt(t,e){let i=this.#C.get(t);if(!i||i.state==="sending")return;i.state="sending",this.#o();try{await this.rate(t,i.choice,e?this.#u.value:void 0),this.#u.value=""}catch(n){if(n instanceof g&&n.status===409)return;i.state="failed",this.#o()}}async#It(){let t=this.#_.value.trim();if(!t||!this.#_.checkValidity()){this.#w=this.#t({id:"E_qvzP"}),this.#st();return}try{this.#g=await this.#n.setEmail(t),this.#q=!0,this.#w=""}catch{this.#w=this.#t({id:"ZxJcgC"})}this.#st()}#vt(t){let e=this.#U.get(t.id);if(e)return Promise.resolve(e);let i=this.#G.get(t.id);if(!i)i=this.#n.attachment(t.id).then((n)=>{let s=URL.createObjectURL(n);return this.#U.set(t.id,s),s}),i.catch(()=>this.#G.delete(t.id)),this.#G.set(t.id,i);return i}async#bt(t){let e=await this.#vt(t),i=r("a");i.href=e,i.download=t.filename,i.rel="noopener",i.click()}#xt(){return[...this.#e.values()].sort(It)}#Rt(){let t=this.#r;if(!t)return!1;return!t.open_now||t.mode==="async"||!t.presence?.available}#P(){this.#I=!0,this.#c.scrollTop=this.#c.scrollHeight,requestAnimationFrame(()=>{if(this.#I)this.#c.scrollTop=this.#c.scrollHeight})}#kt(){this.#d.placeholder=this.#t({id:"RzWUUK"}),this.#d.setAttribute("aria-label",this.#t({id:"xDAtGP"})),this.#j.setAttribute("aria-label",this.#t({id:"N7m8E-"})),this.#j.title=this.#t({id:"N7m8E-"}),this.#A.setAttribute("aria-label",this.#t({id:"JlFcis"})),this.#A.title=this.#t({id:"JlFcis"}),this.#_.placeholder=this.#t({id:"njBr8W"}),this.#_.setAttribute("aria-label",this.#t({id:"XJURKP"})),this.#D(),this.#J(),this.#o()}#o(){let t=this.#s.panel;if(t.childElementCount===0){let e=r("style");e.textContent=ut,t.append(e,this.#X,this.#V,this.#L,this.#tt),this.#X.id="yuva-title",t.setAttribute("aria-labelledby","yuva-title")}if(this.#Lt(),this.#nt(),this.#a!=="ready"){this.#B=void 0;let e=r("div","center");if(this.#a==="loading")e.append(r("p","hint",this.#t({id:"Pwqkdw"})));else{e.append(r("p","empty",this.#Mt()));let i=r("button","primary",this.#t({id:"KDw4GX"}));i.type="button",i.addEventListener("click",()=>{this.#v=null,this.#O()}),e.append(i)}this.#L.replaceChildren(e);return}if(this.#i?.kind==="list")this.#Ot();else this.#Ut()}#Mt(){switch(this.#f){case"anonymous_not_allowed":return this.#t({id:"zLzEI3"});case"invalid_identity_token":return this.#t({id:"0XGLbP"});case"rate_limited":return this.#t({id:"tzsBOP"});case"network":return this.#t({id:"GQVIIl"});default:return this.#t({id:"Amai22"})}}#Lt(){let{layout:t}=this.#s.config(),e=this.#r,i=[],n=this.#i;if(this.#a==="ready"&&n?.kind==="thread"&&(this.#e.size>1||n.id===null&&this.#e.size>0))i.push(T(S.back,this.#t({id:"S63MQu"}),()=>{this.#M(),this.#i={kind:"list"},this.#o()}));let s=r("div","heading");if(s.append(r("h2","title",e?.name||this.#t({id:"t7TeQU"}))),e){let o=r("div","status");if(e.mode==="live"&&e.open_now&&e.presence?.available){let l=r("div","avatars");for(let c of e.presence?.members.slice(0,3)??[]){let h=r("span","avatar",c.initials||"•");h.title=c.name,l.append(h)}o.append(l,r("span","dot"),r("span","",this.#t({id:"oXOSPE"})))}else if(!e.open_now||e.mode==="live")o.append(r("span","dot away"),r("span","",this.#t({id:"1EICzz"})));else o.append(r("span","",this.#At(e.expected_reply_minutes)));s.append(o)}if(i.push(s),t==="launcher")i.push(T(S.close,this.#t({id:"yz7wBu"}),()=>this.#s.close()));this.#X.replaceChildren(...i)}#At(t){if(!t)return this.#t({id:"nhTADq"});let{locale:e}=this.#s.config(),[i,n]=t<60?[t,"minute"]:t<1440?[Math.round(t/60),"hour"]:[Math.round(t/1440),"day"],s=new Intl.NumberFormat(e,{style:"unit",unit:n,unitDisplay:"long"}).format(i);return this.#t({id:"VggdQJ",values:{duration:s}})}#nt(){this.#V.hidden=!this.#h,this.#V.textContent=this.#t({id:"09Tv5j"})}#Ot(){this.#B=void 0;let{locale:t}=this.#s.config(),e=r("ul","list"),i=new Date().toDateString();for(let s of this.#xt()){let o=r("button",s.unread?"item unread":"item");o.type="button";let a=r("div","item-main"),l=r("div","item-top");l.append(r("span","item-subject",s.subject||this.#r?.name||this.#t({id:"YyNOE7"})));let c=new Date(s.last_message_at??s.created_at);l.append(r("span","item-time",new Intl.DateTimeFormat(t,c.toDateString()===i?{timeStyle:"short"}:{month:"short",day:"numeric"}).format(c)));let h=s.last_message?`${s.last_message.author_type==="contact"?this.#t({id:"ydzYKJ"})+" ":""}${s.last_message.text||this.#t({id:"UY1vmE"})}`:"",p=r("div","item-preview",h.replace(/\*\*|`/g,""));if(p.dir="auto",a.append(l,p),o.append(a),s.unread)o.append(r("span","unread-dot"));o.addEventListener("click",()=>void this.#$t(s.id));let u=r("li");u.append(o),e.append(u)}if(this.#E){let s=r("button","link",this.#t({id:"ASr-r0"}));s.type="button",s.style.margin="8px auto",s.style.display="block",s.addEventListener("click",()=>void this.#K(!0).then(()=>this.#o())),e.append(s)}let n=r("button","primary",this.#t({id:"-HY5kX"}));n.type="button",n.addEventListener("click",()=>{this.#i={kind:"thread",id:null},this.#o(),this.#d.focus()}),this.#L.replaceChildren(e,n)}async#$t(t){if(this.#i={kind:"thread",id:t},this.#o(),!this.#l.get(t)?.complete&&!this.#l.get(t)?.messages.length)await this.#F(t).catch(()=>{return});this.#o(),this.#P(),this.#$()}#Dt(t){let e=r("span","avatar",t.initials||""),i=t.avatar_url,n=i?this.#W.get(i):!1;if(!i||n===!1)return e;let s=r("img");if(s.alt="",s.referrerPolicy="no-referrer",n)return s.src=i,e.replaceChildren(s),e;return s.addEventListener("load",()=>{if(this.#W.set(i,!0),e.isConnected)e.replaceChildren(s)}),s.addEventListener("error",()=>this.#W.set(i,!1)),s.src=i,e}#Ut(){let t=this.#i;if(t?.kind!=="thread")return;let e=t.id,i=this.#B===e,n=this.#I,s=e?this.#l.get(e):void 0,o=s?.messages??[],a=this.#m.filter((d)=>d.conversation===e),l=[],c=this.#r?.chat.greeting;if(!s||s.complete){if(c){let d=r("div","bubble greeting");d.append(M(c)),l.push(d)}else if(o.length===0&&a.length===0){let d=r("div","center");d.append(r("p","empty",this.#t({id:"meAa31"})),r("p","hint",this.#t({id:"SdV5Cn"}))),l.push(d)}}else if(s.loading)l.push(r("p","hint",this.#t({id:"Pwqkdw"})));o.forEach((d,m)=>{let k=o[m-1],x=o[m+1]??(a.length>0?null:void 0),f=d.author.type==="contact",w=!k||L(k)!==L(d)||v(d.created_at)-v(k.created_at)>pt,W=x===void 0||(x===null?!f:L(x)!==L(d)||v(x.created_at)-v(d.created_at)>pt);if(!f&&w&&d.author.name)l.push(r("div","author",d.author.name));let A=r("div",`row ${f?"mine":"theirs"}${w&&m>0?" group-gap":""}`);if(!f){let E=this.#Dt(d.author);if(!W)E.style.visibility="hidden";A.append(E)}let z=r("div","bubble");if(z.dir="auto",z.title=new Date(d.created_at).toLocaleString(this.#s.config().locale),d.body.trim())z.append(M(d.body));if(d.attachments.length>0)z.append(this.#Bt(d.attachments));if(A.append(z),l.push(A),W){let E=this.#Nt(d.created_at);if(f&&m===o.length-1&&a.length===0){let q=e?this.#e.get(e)?.last_read_by_member_at:void 0,mt=q&&v(q)>=v(d.created_at);E+=` · ${mt?this.#t({id:"6lGaum"}):this.#t({id:"h69WC6"})}`}let O=r("div","meta",E);if(!f)O.style.alignSelf="flex-start";if(!f)O.style.marginInlineStart="36px";l.push(O)}});let h=e?this.#e.get(e):void 0,p=h?this.#jt(h):null;if(p)l.push(p);a.forEach((d,m)=>{let k=r("div",`row mine${m===0&&o.length>0&&o[o.length-1]?.author.type!=="contact"?" group-gap":""}`),x=r("div","bubble");if(x.dir="auto",d.body)x.append(M(d.body));if(d.files.length>0){let f=r("div","files");for(let w of d.files)f.append(r("span","file",w.name||"image"));x.append(f)}if(k.append(x),l.push(k),d.state==="failed"){let f=r("div","meta failed",`${this.#t({id:"upFvcp"})} `),w=r("button","link",this.#t({id:"6gRgw8"}));w.type="button",w.addEventListener("click",()=>void this.#mt(d)),f.append(w),l.push(f)}else if(d.state==="refused"){let f=d.status===413?this.#t({id:"eOu9Px"}):this.#t({id:"JkW3Ph"});l.push(r("div","meta failed",`${this.#t({id:"upFvcp"})} ${f}`))}else if(m===a.length-1)l.push(r("div","meta",this.#t({id:"Sad2tK"})))});let u=e?this.#b.get(e):void 0;if(u){let d=r("div","typing");d.append(r("i"),r("i"),r("i"));let m=u.name;d.append(r("span","",m?this.#t({id:"tHaDPf",values:{name:m}}):this.#t({id:"PxYAul"}))),l.push(d)}let y=this.#c.getRootNode().activeElement===this.#u,{selectionStart:P,selectionEnd:_}=this.#u;if(this.#c.replaceChildren(...l),y&&this.#u.isConnected)this.#u.focus({preventScroll:!0}),this.#u.setSelectionRange(P,_);if(this.#st(),this.#L.firstChild!==this.#c)this.#L.replaceChildren(this.#c,this.#S,this.#ot);if(this.#B=e,!i||n)this.#P()}#jt(t){let e=t.status==="closed"?t.rating:void 0,i=t.can_rate&&this.#r?.ask_for_rating?this.#C.get(t.id):void 0;if(!e&&!(t.can_rate&&this.#r?.ask_for_rating))return null;let n=this.#wt,s=[t.id,e,i?.choice,i?.state,this.#s.config().locale].join(":");if(s===this.#Q)return n;if(this.#Q=s,this.#rt!==t.id)this.#rt=t.id,this.#u.value="";let o=this.#t({id:"uA8iBc"});n.setAttribute("role","group"),n.setAttribute("aria-label",o);let a=r("div","choices");for(let u of["good","bad"]){if(e&&e!==u)continue;let b=r("button","choice",u==="good"?"\uD83D\uDC4D":"\uD83D\uDC4E");b.type="button";let y=u==="good"?this.#t({id:"OEEQKT"}):this.#t({id:"-f5Tkb"});b.setAttribute("aria-label",y),b.title=y,b.setAttribute("aria-pressed",String((e??i?.choice)===u)),b.disabled=!!e||i?.state==="sending",b.addEventListener("click",()=>this.#Pt(t.id,u)),a.append(b)}if(e)return n.replaceChildren(a,r("p","",this.#t({id:"SOk0EB"}))),n;if(n.replaceChildren(r("p","",o),a),!i)return n;this.#u.placeholder=this.#t({id:"axQ1h6"}),this.#u.setAttribute("aria-label",this.#t({id:"NBdIgR"})),this.#u.disabled=i.state==="sending";let l=r("form");l.addEventListener("submit",(u)=>{u.preventDefault(),this.#yt(t.id,!0)});let c=r("button","link",this.#t({id:"6Uau97"}));c.type="button",c.disabled=i.state==="sending",c.addEventListener("click",()=>void this.#yt(t.id,!1));let h=r("button","",i.state==="sending"?this.#t({id:"Sad2tK"}):this.#t({id:"JlFcis"}));h.type="submit",h.disabled=i.state==="sending";let p=r("div","actions");if(p.append(c,h),l.append(this.#u,p),n.append(l),i.state==="failed")n.append(r("p","error",this.#t({id:"4TqZiz"})));return n}#Bt(t){let e=r("div","files");for(let i of t)if(Rt(i)){let n=r("img");n.alt=i.filename;let s=this.#U.get(i.id);if(s)n.src=s;else this.#vt(i).then((o)=>{n.src=o}).catch(()=>{return});n.addEventListener("load",()=>{if(this.#I)this.#c.scrollTop=this.#c.scrollHeight}),n.addEventListener("click",()=>void this.#bt(i)),e.append(n)}else{let n=r("button","file");n.type="button",n.innerHTML=S.file,n.append(r("span","",i.filename)),n.addEventListener("click",()=>void this.#bt(i)),e.append(n)}return e}#Nt(t){return new Intl.DateTimeFormat(this.#s.config().locale,{timeStyle:"short"}).format(new Date(t))}#st(){let t=this.#g,e=this.#r?.chat,n=(this.#i?.kind==="thread"?this.#i.id:null)!==null||this.#m.length>0,s=t?.email||t?.typed_email,o=!!e?.ask_email_offline&&this.#Rt()&&n&&(!s||this.#q);if(this.#S.hidden=!o,!o)return;if(s&&this.#q){this.#S.replaceChildren(r("p","",this.#t({id:"iGNUZJ",values:{known:s}})));return}if(this.#S.querySelector("form")){let c=this.#S.querySelector(".error");if(c)c.textContent=this.#w;else if(this.#w)this.#S.append(r("p","error",this.#w));return}let a=r("form");a.noValidate=!0,a.addEventListener("submit",(c)=>{c.preventDefault(),this.#It()});let l=r("button","",this.#t({id:"tfDRzk"}));if(l.type="submit",a.append(this.#_,l),this.#S.replaceChildren(r("p","",this.#t({id:"M62PBt"})),a),this.#w)this.#S.append(r("p","error",this.#w))}#J(){this.#Z.hidden=this.#y.length===0,this.#Z.replaceChildren(...this.#y.map((t,e)=>{let i=r("span","chip");return i.append(r("span","",t.name||"image"),T(S.close,this.#t({id:"w61W3L",values:{0:t.name}}),()=>{this.#y=this.#y.filter((n,s)=>s!==e),this.#J(),this.#D()})),i}))}}function Mt(t){return new gt(t)}export{Mt as mount};
211
+ `;var ze=/(`[^`\n]+`)|(\*\*[^*\n]+\*\*)|(\*[^*\s][^*\n]*\*|_[^_\s][^_\n]*_)|((?:https?:\/\/|www\.)[^\s<>"]*[^\s<>".,:;'!?)\]])/g;function De(e,t){let i=document.createElement("a");return i.href=e,i.textContent=t,i.target="_blank",i.rel="noopener noreferrer nofollow ugc",i}function W(e,t){let i=document.createElement(e);return i.append(...t),i}function G(e){let t=[],i=0;for(let n of e.matchAll(ze)){let s=n.index??0;if(s>i)t.push(document.createTextNode(e.slice(i,s)));let[o,a,l,c,h]=n;if(a)t.push(W("code",[document.createTextNode(a.slice(1,-1))]));else if(l)t.push(W("strong",G(l.slice(2,-2))));else if(c)t.push(W("em",G(c.slice(1,-1))));else if(h){let p=h.startsWith("www.")?`https://${h}`:h;try{let u=new URL(p);t.push(u.protocol==="http:"||u.protocol==="https:"?De(u.href,h):document.createTextNode(h))}catch{t.push(document.createTextNode(h))}}i=s+o.length}if(i<e.length)t.push(document.createTextNode(e.slice(i)));return t}function M(e){let t=document.createDocumentFragment(),i=e.trim().replace(/\r\n?/g,`
212
+ `).split(/^```[^\n]*\n([\s\S]*?)^```[ \t]*$/m);return i.forEach((n,s)=>{if(s%2===1){let a=document.createElement("pre");a.textContent=n.replace(/\n$/,""),t.append(a);return}(i.length>1?n.replace(/^\n|\n$/g,""):n).split(`
213
+ `).forEach((a,l)=>{if(l>0)t.append(document.createElement("br"));t.append(...G(a))})}),t}var Ie={en:Y,tr:se},Me=10,ge=300000,P={close:'<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>',back:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15 6l-6 6 6 6"/></svg>',attach:'<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 11.5l-8.3 8.3a5 5 0 01-7-7L13 4.5a3.3 3.3 0 014.7 4.7l-8.3 8.3a1.7 1.7 0 01-2.4-2.4L14.5 7.6"/></svg>',send:'<svg class="flip" width="20" height="20" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M3.4 20.4l17.5-7.5a1 1 0 000-1.8L3.4 3.6a1 1 0 00-1.4 1.2L4.5 12l-2.5 7.2a1 1 0 001.4 1.2zM4.5 12h7"/></svg>',file:'<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linejoin="round" aria-hidden="true"><path d="M14 3H6v18h12V7z M14 3v4h4"/></svg>'};function r(e,t,i){let n=document.createElement(e);if(t)n.className=t;if(i!==void 0)n.textContent=i;return n}function R(e,t,i,n="icon"){let s=r("button",n);return s.type="button",s.innerHTML=e,s.setAttribute("aria-label",t),s.title=t,s.addEventListener("click",i),s}var x=(e)=>Date.parse(e),me=(e,t)=>x(e.created_at)-x(t.created_at),Le=(e,t)=>x(t.last_message_at??t.created_at)-x(e.last_message_at??e.created_at),L=(e)=>e.author.type==="contact"?"contact":`${e.author.type}:${e.author.name??""}`,Oe=(e)=>/^image\/(png|jpeg|gif|webp)$/.test(e.content_type);class ye{#s;#m;#n;#r=null;#y=null;#a="loading";#u="";#w=null;#C=null;#t=new Map;#v;#p=new Map;#l=[];#k=new Map;#i=null;#b=!1;#x=[];#R=0;#f=null;#c=new Map;#D=new Map;#I=new Map;#M=!1;#S="";#q=!1;#_=new Map;#ke=r("div","card rate");#g=r("textarea");#Q="";#re=null;#X=r("header","header");#V=r("div","banner");#$=r("div","body");#d=r("div","scroll");#P=r("div","card");#T=r("input");#oe=r("div","composer");#Z=r("div","chips");#h=r("textarea");#E=r("input");#U;#Y;#ee=r("div","sr");#K;#L=!0;constructor(e){this.#s=e;let{server:t,channel:i}=e.config();this.#n=pe({server:t,channel:i??"",identityToken:()=>e.identityToken()}),this.#n.on("event",(s)=>this.#_e(s)),this.#n.on("connection",({state:s,attempt:o})=>{if(s!=="reconnecting")return;this.#b=o>0,this.#ne()}),this.#n.on("session",({session:s,renewed:o})=>{if(this.#J(s.inbox),this.#y=s.contact,o)this.#pe()}),this.#le(),this.#ee.setAttribute("aria-live","polite"),this.#d.addEventListener("scroll",()=>{if(this.#L=this.#d.scrollHeight-this.#d.scrollTop-this.#d.clientHeight<48,this.#d.scrollTop<60&&this.#i?.kind==="thread"&&this.#i.id)this.#G(this.#i.id,!0)}),this.#h.rows=1,this.#h.addEventListener("keydown",(s)=>{if(s.key==="Enter"&&!s.shiftKey&&!s.isComposing)s.preventDefault(),this.#ie()}),this.#h.addEventListener("input",()=>{this.#ge(),this.#B(),this.#Ee()}),this.#h.addEventListener("paste",(s)=>{let o=Array.from(s.clipboardData?.files??[]);if(o.length===0)return;s.preventDefault(),this.#fe(o)}),this.#E.type="file",this.#E.multiple=!0,this.#E.hidden=!0,this.#E.addEventListener("change",()=>{this.#fe(Array.from(this.#E.files??[])),this.#E.value=""}),this.#Y=R(P.attach,"",()=>this.#E.click()),this.#U=R(P.send,"",()=>void this.#ie(),"icon send");let n=r("form");n.addEventListener("submit",(s)=>{s.preventDefault(),this.#ie()}),n.append(this.#Y,this.#h,this.#U,this.#E),this.#oe.append(this.#Z,n),this.#T.type="email",this.#T.required=!0,this.#T.autocomplete="email",this.#g.rows=2,this.#g.maxLength=2000,this.#g.dir="auto",document.addEventListener("visibilitychange",this.#F),window.addEventListener("online",this.#F),this.#we(),this.#j()}update(){this.#le(),this.#we()}opened(){if(this.#a==="error"){this.#w=null,this.#j();return}if(this.#a==="ready")this.#n.token?this.#Se():this.#ce().then(()=>this.#o()).catch(()=>{return});if(this.#o(),this.#z(),this.#N(),this.#s.config().layout==="launcher")this.#h.focus({preventScroll:!0})}closed(){this.#A()}identityChanged(){this.#ae(),this.#j()}async signOut(){let e=this.#n.signOut();if(this.#ae(),await e,this.#s.isOpen())this.#j();else this.#o()}destroy(){this.#n.reset(),this.#A(),document.removeEventListener("visibilitychange",this.#F),window.removeEventListener("online",this.#F);for(let e of this.#c.values())URL.revokeObjectURL(e)}#ae(){this.#n.reset(),this.#w=null,this.#C=null,this.#r=null,this.#y=null,this.#a="loading",this.#t.clear(),this.#p.clear(),this.#l=[],this.#_.clear(),this.#Q="",this.#i=null,this.#q=!1,this.#s.setUnread(0)}#F=()=>{if(document.visibilityState!=="visible")return;this.#n.reconnect(),this.#N(),this.#he()};#le(){let{locale:e}=this.#s.config();this.#m=B({locale:e,messages:{[e]:Ie[e]??Y}})}#e(e){return this.#m._(e)}#j(){return this.#w??=(async()=>{this.#a="loading",this.#o();let{channel:e}=this.#s.config();if(!e)throw new f(0,"not_configured");if(await this.#s.identityToken()||K(e).session)await this.#Ce();else if(await this.#ce(),!this.#r?.chat.allow_anonymous)throw new f(403,"anonymous_not_allowed");if(this.#a="ready",!this.#i){let t=this.#xe();if(this.#i=t.length>1?{kind:"list"}:{kind:"thread",id:t[0]?.id??null},this.#i.kind==="thread"&&this.#i.id)await this.#G(this.#i.id)}this.#o(),this.#z(),this.#N()})().catch((e)=>{if(this.#w=null,this.#ue(e))return;this.#a="error",this.#u=e instanceof f?e.code:"error",this.#o()}),this.#w}async#ce(){let e=await this.#de();if(!this.#n.token)this.#J(e)}#de(){if(!this.#s.config().channel)throw new f(0,"not_configured");return this.#n.channelSettings()}#J(e){let{channel:t}=this.#s.config();this.#r=e;let i=re(e);if(this.#s.setLauncher(i),t)ae(t,{...K(t),launcher:i})}async#he(){if(this.#a!=="ready")return;try{this.#J(await this.#de()),this.#o()}catch(e){this.#ue(e,!0)}}#ue(e,t=!this.#n.token){let i=e instanceof f&&(e.code==="origin_not_allowed"||e.status===404&&t);if(i)this.#s.refused();return i}#Ce(){return this.#C??=(async()=>{await this.#n.start(),await this.#W(),await this.#n.connect()})().finally(()=>{this.#C=null}),this.#C}async#Se(){try{await this.#n.refresh(),this.#o()}catch{}}async#W(e=!1){let t=await this.#n.listConversations({limit:50,cursor:e?this.#v:void 0});if(!e)this.#t.clear();for(let i of t.items)this.#t.set(i.id,i);this.#v=t.next_cursor,this.#O()}async#pe(){await this.#W();let e=this.#i?.kind==="thread"?this.#i.id:null;for(let t of this.#p.keys())if(t!==e)this.#p.delete(t);if(e)this.#p.delete(e),await this.#G(e);this.#o()}async#G(e,t=!1){let i=this.#p.get(e);if(!i)i={messages:[],complete:!1,loading:!1},this.#p.set(e,i);if(i.loading||t&&(i.complete||!i.cursor))return;i.loading=!0;let n=this.#d.scrollHeight-this.#d.scrollTop;try{let s=await this.#n.listMessages(e,{order:"desc",limit:30,cursor:t?i.cursor:void 0}),o=new Set(i.messages.map((a)=>a.id));i.messages=[...i.messages,...s.items.filter((a)=>!o.has(a.id))].sort(me),i.cursor=s.next_cursor,i.complete=!s.next_cursor}finally{i.loading=!1}if(t)this.#o(),this.#d.scrollTop=this.#d.scrollHeight-n}#_e(e){switch(e.type){case"ready":if(this.#b=!1,this.#ne(),this.#q)this.#he();this.#q=!0;return;case"inbox.updated":{let t=this.#r?.ask_for_rating;if(this.#J(e.data),t!==void 0&&t!==e.data.ask_for_rating)this.#W().then(()=>this.#o()).catch(()=>{return});break}case"resync_required":this.#pe();return;case"presence":if(this.#r)this.#r={...this.#r,presence:e.data};break;case"conversation.created":if(!this.#t.has(e.data.id))this.#t.set(e.data.id,e.data);if(this.#i?.kind==="thread"&&this.#i.id===null&&this.#t.size>1)this.#i=this.#l.some((t)=>t.conversation===null)?this.#i:{kind:"list"};this.#O();break;case"conversation.updated":{let t=this.#t.get(e.data.id),{status:i,can_rate:n,rating:s}=e.data;if(t)this.#t.set(t.id,{...t,status:i,can_rate:n,rating:s});if(!n)this.#_.delete(e.data.id);break}case"message.created":case"message.updated":this.#te(e.data,e.type==="message.created");break;case"read":{let t=this.#t.get(e.data.conversation_id),i=t?.last_read_by_member_at;if(t&&(!i||x(e.data.read_at)>x(i)))this.#t.set(t.id,{...t,last_read_by_member_at:e.data.read_at});break}case"typing":{let t=e.data.conversation_id,i=this.#k.get(t);if(i)clearTimeout(i.timer);if(e.data.typing){let n=e.data.author.name??"";this.#k.set(t,{name:n,timer:setTimeout(()=>this.#k.delete(t)&&this.#o(),8000)})}else this.#k.delete(t);break}}this.#o()}#te(e,t){let i=e.conversation_id,n=this.#p.get(i);if(n){let o=n.messages.findIndex((a)=>a.id===e.id);if(o>=0)n.messages[o]=e;else n.messages=[...n.messages,e].sort(me)}if(e.client_id)this.#l=this.#l.filter((o)=>o.client_id!==e.client_id);let s=this.#t.get(i);if(!s){this.#n.getConversation(i).then((o)=>{this.#t.set(o.id,o),this.#O(),this.#o()}).catch(()=>{return});return}if(t){let o=e.body.replace(/\s+/g," ").trim();if(this.#t.set(i,{...s,last_message:{id:e.id,author_type:e.author.type,text:o.length>140?`${o.slice(0,139)}…`:o,created_at:e.created_at},last_message_at:e.created_at,unread:s.unread||e.author.type!=="contact"}),e.author.type!=="contact"){let a=this.#k.get(i);if(a)clearTimeout(a.timer);this.#k.delete(i),this.#Pe(e)}}this.#O(),this.#N()}#Pe(e){this.#ee.textContent=`${e.author.name||this.#r?.name||""}: ${e.body.slice(0,200)}`}#O(){let e=0;for(let t of this.#t.values())if(t.unread)e++;this.#s.setUnread(e)}#Te(){if(!this.#s.isOpen()||document.visibilityState!=="visible")return null;return this.#i?.kind==="thread"?this.#i.id:null}#N(){let e=this.#Te(),t=e?this.#t.get(e):void 0;if(!e||!t?.unread)return;this.#t.set(e,{...t,unread:!1}),this.#O(),this.#n.markRead(e).catch(()=>{let i=this.#t.get(e);if(i)this.#t.set(e,{...i,unread:!0});this.#O()})}#fe(e){this.#x=[...this.#x,...e].slice(0,Me),this.#H(),this.#B(),this.#h.focus()}#ge(){if(this.#h.style.blockSize="",this.#h.value==="")return;this.#h.style.blockSize="auto",this.#h.style.blockSize=`${Math.max(38,Math.min(this.#h.scrollHeight,140))}px`}#B(){this.#U.disabled=this.#h.value.trim()===""&&this.#x.length===0}#Ee(){let e=this.#i?.kind==="thread"?this.#i.id:null;if(!e||this.#h.value.trim()===""){this.#A();return}if(Date.now()-this.#R>3000)this.#R=Date.now(),this.#n.setTyping(e,!0).catch(()=>{return});if(this.#f)clearTimeout(this.#f);this.#f=setTimeout(()=>this.#A(),4000)}#A(){if(this.#f)clearTimeout(this.#f);if(this.#f=null,this.#R===0)return;this.#R=0;let e=this.#i?.kind==="thread"?this.#i.id:null;if(e)this.#n.setTyping(e,!1).catch(()=>{return})}async#ie(){if(this.#a!=="ready"||this.#i?.kind!=="thread")return;let e=this.#h.value.trim(),t=this.#x;if(!e&&t.length===0)return;if(this.#i.id===null&&this.#l.some((n)=>n.conversation===null))return;this.#A(),this.#h.value="",this.#x=[],this.#ge(),this.#H(),this.#B();let i={client_id:I(),conversation:this.#i.id,body:e,files:t,state:"sending"};this.#l.push(i),this.#o(),this.#z(),await this.#me(i)}async#me(e){e.state="sending",this.#o();let t={body:e.body,files:e.files,client_id:e.client_id};try{if(e.conversation===null){let i=await this.#n.startConversation(t),n=i.conversation.id;if(!this.#t.has(n))this.#t.set(n,i.conversation);if(!this.#p.has(n))this.#p.set(n,{messages:[],complete:!0,loading:!1});if(this.#i?.kind==="thread"&&this.#i.id===null)this.#i={kind:"thread",id:n};this.#te(i.message,!1)}else{let i=await this.#n.sendMessage(e.conversation,t);this.#te(i,!0)}this.#l=this.#l.filter((i)=>i!==e)}catch(i){let n=i instanceof f?i.status:0;e.state=n===413||n===415?"refused":"failed",e.status=n}this.#o(),this.#z()}async rate(e,t,i){try{let n=await this.#n.rate(e,t,i);return this.#t.set(n.id,n),this.#_.delete(e),this.#o(),n}catch(n){if(n instanceof f&&n.status===409){let s=await this.#n.getConversation(e).catch(()=>null);if(s)this.#t.set(s.id,s);this.#_.delete(e),this.#o()}throw n}}#Re(e,t){if(this.#_.get(e)?.state==="sending")return;if(this.#_.set(e,{choice:t,state:"choosing"}),this.#o(),this.#g.focus({preventScroll:!0}),this.#L)this.#z()}async#ye(e,t){let i=this.#_.get(e);if(!i||i.state==="sending")return;i.state="sending",this.#o();try{await this.rate(e,i.choice,t?this.#g.value:void 0),this.#g.value=""}catch(n){if(n instanceof f&&n.status===409)return;i.state="failed",this.#o()}}async#ze(){let e=this.#T.value.trim();if(!e||!this.#T.checkValidity()){this.#S=this.#e({id:"E_qvzP"}),this.#se();return}try{this.#y=await this.#n.setEmail(e),this.#M=!0,this.#S=""}catch{this.#S=this.#e({id:"ZxJcgC"})}this.#se()}#ve(e){let t=this.#c.get(e.id);if(t)return Promise.resolve(t);let i=this.#D.get(e.id);if(!i)i=this.#n.attachment(e.id).then((n)=>{let s=URL.createObjectURL(n);return this.#c.set(e.id,s),s}),i.catch(()=>this.#D.delete(e.id)),this.#D.set(e.id,i);return i}async#be(e){let t=await this.#ve(e),i=r("a");i.href=t,i.download=e.filename,i.rel="noopener",i.click()}#xe(){return[...this.#t.values()].sort(Le)}#De(){let e=this.#r;if(!e)return!1;return!e.open_now||e.mode==="async"||!e.presence?.available}#z(){this.#L=!0,this.#d.scrollTop=this.#d.scrollHeight,requestAnimationFrame(()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight})}#we(){this.#h.placeholder=this.#e({id:"RzWUUK"}),this.#h.setAttribute("aria-label",this.#e({id:"xDAtGP"})),this.#Y.setAttribute("aria-label",this.#e({id:"N7m8E-"})),this.#Y.title=this.#e({id:"N7m8E-"}),this.#U.setAttribute("aria-label",this.#e({id:"JlFcis"})),this.#U.title=this.#e({id:"JlFcis"}),this.#T.placeholder=this.#e({id:"njBr8W"}),this.#T.setAttribute("aria-label",this.#e({id:"XJURKP"})),this.#B(),this.#H(),this.#o()}#o(){let e=this.#s.panel;if(e.childElementCount===0){let t=r("style");t.textContent=fe,e.append(t,this.#X,this.#V,this.#$,this.#ee),this.#X.id="yuva-title",e.setAttribute("aria-labelledby","yuva-title")}if(this.#Me(),this.#ne(),this.#a!=="ready"){this.#K=void 0;let t=r("div","center");if(this.#a==="loading")t.append(r("p","hint",this.#e({id:"Pwqkdw"})));else{t.append(r("p","empty",this.#Ie()));let i=r("button","primary",this.#e({id:"KDw4GX"}));i.type="button",i.addEventListener("click",()=>{this.#w=null,this.#j()}),t.append(i)}this.#$.replaceChildren(t);return}if(this.#i?.kind==="list")this.#Oe();else this.#Ue()}#Ie(){switch(this.#u){case"anonymous_not_allowed":return this.#e({id:"zLzEI3"});case"invalid_identity_token":return this.#e({id:"0XGLbP"});case"rate_limited":return this.#e({id:"tzsBOP"});case"network":return this.#e({id:"GQVIIl"});default:return this.#e({id:"Amai22"})}}#Me(){let{layout:e}=this.#s.config(),t=this.#r,i=[],n=this.#i;if(this.#a==="ready"&&n?.kind==="thread"&&(this.#t.size>1||n.id===null&&this.#t.size>0))i.push(R(P.back,this.#e({id:"S63MQu"}),()=>{this.#A(),this.#i={kind:"list"},this.#o()}));let s=r("div","heading");if(s.append(r("h2","title",t?.name||this.#e({id:"t7TeQU"}))),t){let o=r("div","status");if(t.mode==="live"&&t.open_now&&t.presence?.available){let l=r("div","avatars");for(let c of t.presence?.members.slice(0,3)??[]){let h=r("span","avatar",c.initials||"•");h.title=c.name,l.append(h)}o.append(l,r("span","dot"),r("span","",this.#e({id:"oXOSPE"})))}else if(!t.open_now||t.mode==="live")o.append(r("span","dot away"),r("span","",this.#e({id:"1EICzz"})));else o.append(r("span","",this.#Le(t.expected_reply_minutes)));s.append(o)}if(i.push(s),e==="launcher")i.push(R(P.close,this.#e({id:"yz7wBu"}),()=>this.#s.close()));this.#X.replaceChildren(...i)}#Le(e){if(!e)return this.#e({id:"nhTADq"});let{locale:t}=this.#s.config(),[i,n]=e<60?[e,"minute"]:e<1440?[Math.round(e/60),"hour"]:[Math.round(e/1440),"day"],s=new Intl.NumberFormat(t,{style:"unit",unit:n,unitDisplay:"long"}).format(i);return this.#e({id:"VggdQJ",values:{duration:s}})}#ne(){this.#V.hidden=!this.#b,this.#V.textContent=this.#e({id:"09Tv5j"})}#Oe(){this.#K=void 0;let{locale:e}=this.#s.config(),t=r("ul","list"),i=new Date().toDateString();for(let s of this.#xe()){let o=r("button",s.unread?"item unread":"item");o.type="button";let a=r("div","item-main"),l=r("div","item-top");l.append(r("span","item-subject",s.subject||this.#r?.name||this.#e({id:"YyNOE7"})));let c=new Date(s.last_message_at??s.created_at);l.append(r("span","item-time",new Intl.DateTimeFormat(e,c.toDateString()===i?{timeStyle:"short"}:{month:"short",day:"numeric"}).format(c)));let h=s.last_message?`${s.last_message.author_type==="contact"?this.#e({id:"ydzYKJ"})+" ":""}${s.last_message.text||this.#e({id:"UY1vmE"})}`:"",p=r("div","item-preview",h.replace(/\*\*|`/g,""));if(p.dir="auto",a.append(l,p),o.append(a),s.unread)o.append(r("span","unread-dot"));o.addEventListener("click",()=>void this.#Ae(s.id));let u=r("li");u.append(o),t.append(u)}if(this.#v){let s=r("button","link",this.#e({id:"ASr-r0"}));s.type="button",s.style.margin="8px auto",s.style.display="block",s.addEventListener("click",()=>void this.#W(!0).then(()=>this.#o())),t.append(s)}let n=r("button","primary",this.#e({id:"-HY5kX"}));n.type="button",n.addEventListener("click",()=>{this.#i={kind:"thread",id:null},this.#o(),this.#h.focus()}),this.#$.replaceChildren(t,n)}async#Ae(e){if(this.#i={kind:"thread",id:e},this.#o(),!this.#p.get(e)?.complete&&!this.#p.get(e)?.messages.length)await this.#G(e).catch(()=>{return});this.#o(),this.#z(),this.#N()}#$e(e){let t=r("span","avatar",e.initials||""),i=e.avatar_url,n=i?this.#I.get(i):!1;if(!i||n===!1)return t;let s=r("img");if(s.alt="",s.referrerPolicy="no-referrer",n)return s.src=i,t.replaceChildren(s),t;return s.addEventListener("load",()=>{if(this.#I.set(i,!0),t.isConnected)t.replaceChildren(s)}),s.addEventListener("error",()=>this.#I.set(i,!1)),s.src=i,t}#Ue(){let e=this.#i;if(e?.kind!=="thread")return;let t=e.id,i=this.#K===t,n=this.#L,s=t?this.#p.get(t):void 0,o=s?.messages??[],a=this.#l.filter((d)=>d.conversation===t),l=[],c=this.#r?.chat.greeting;if(!s||s.complete){if(c){let d=r("div","bubble greeting");d.append(M(c)),l.push(d)}else if(o.length===0&&a.length===0){let d=r("div","center");d.append(r("p","empty",this.#e({id:"meAa31"})),r("p","hint",this.#e({id:"SdV5Cn"}))),l.push(d)}}else if(s.loading)l.push(r("p","hint",this.#e({id:"Pwqkdw"})));o.forEach((d,v)=>{let k=o[v-1],w=o[v+1]??(a.length>0?null:void 0),m=d.author.type==="contact",C=!k||L(k)!==L(d)||x(d.created_at)-x(k.created_at)>ge,H=w===void 0||(w===null?!m:L(w)!==L(d)||x(w.created_at)-x(d.created_at)>ge);if(!m&&C&&d.author.name)l.push(r("div","author",d.author.name));let O=r("div",`row ${m?"mine":"theirs"}${C&&v>0?" group-gap":""}`);if(!m){let E=this.#$e(d.author);if(!H)E.style.visibility="hidden";O.append(E)}let T=r("div","bubble");if(T.dir="auto",T.title=new Date(d.created_at).toLocaleString(this.#s.config().locale),d.body.trim())T.append(M(d.body));if(d.attachments.length>0)T.append(this.#Ne(d.attachments));if(O.append(T),l.push(O),H){let E=this.#Be(d.created_at);if(m&&v===o.length-1&&a.length===0){let q=t?this.#t.get(t)?.last_read_by_member_at:void 0,ve=q&&x(q)>=x(d.created_at);E+=` · ${ve?this.#e({id:"6lGaum"}):this.#e({id:"h69WC6"})}`}let A=r("div","meta",E);if(!m)A.style.alignSelf="flex-start";if(!m)A.style.marginInlineStart="36px";l.push(A)}});let h=t?this.#t.get(t):void 0,p=h?this.#je(h):null;if(p)l.push(p);a.forEach((d,v)=>{let k=r("div",`row mine${v===0&&o.length>0&&o[o.length-1]?.author.type!=="contact"?" group-gap":""}`),w=r("div","bubble");if(w.dir="auto",d.body)w.append(M(d.body));if(d.files.length>0){let m=r("div","files");for(let C of d.files)m.append(r("span","file",C.name||"image"));w.append(m)}if(k.append(w),l.push(k),d.state==="failed"){let m=r("div","meta failed",`${this.#e({id:"upFvcp"})} `),C=r("button","link",this.#e({id:"6gRgw8"}));C.type="button",C.addEventListener("click",()=>void this.#me(d)),m.append(C),l.push(m)}else if(d.state==="refused"){let m=d.status===413?this.#e({id:"eOu9Px"}):this.#e({id:"JkW3Ph"});l.push(r("div","meta failed",`${this.#e({id:"upFvcp"})} ${m}`))}else if(v===a.length-1)l.push(r("div","meta",this.#e({id:"Sad2tK"})))});let u=t?this.#k.get(t):void 0;if(u){let d=r("div","typing");d.append(r("i"),r("i"),r("i"));let v=u.name;d.append(r("span","",v?this.#e({id:"tHaDPf",values:{name:v}}):this.#e({id:"PxYAul"}))),l.push(d)}let g=this.#d.getRootNode().activeElement===this.#g,{selectionStart:_,selectionEnd:b}=this.#g;if(this.#d.replaceChildren(...l),g&&this.#g.isConnected)this.#g.focus({preventScroll:!0}),this.#g.setSelectionRange(_,b);if(this.#se(),this.#$.firstChild!==this.#d)this.#$.replaceChildren(this.#d,this.#P,this.#oe);if(this.#K=t,!i||n)this.#z()}#je(e){let t=e.status==="closed"?e.rating:void 0,i=e.can_rate&&this.#r?.ask_for_rating?this.#_.get(e.id):void 0;if(!t&&!(e.can_rate&&this.#r?.ask_for_rating))return null;let n=this.#ke,s=[e.id,t,i?.choice,i?.state,this.#s.config().locale].join(":");if(s===this.#Q)return n;if(this.#Q=s,this.#re!==e.id)this.#re=e.id,this.#g.value="";let o=this.#e({id:"uA8iBc"});n.setAttribute("role","group"),n.setAttribute("aria-label",o);let a=r("div","choices");for(let u of["good","bad"]){if(t&&t!==u)continue;let y=r("button","choice",u==="good"?"\uD83D\uDC4D":"\uD83D\uDC4E");y.type="button";let g=u==="good"?this.#e({id:"OEEQKT"}):this.#e({id:"-f5Tkb"});y.setAttribute("aria-label",g),y.title=g,y.setAttribute("aria-pressed",String((t??i?.choice)===u)),y.disabled=!!t||i?.state==="sending",y.addEventListener("click",()=>this.#Re(e.id,u)),a.append(y)}if(t)return n.replaceChildren(a,r("p","",this.#e({id:"SOk0EB"}))),n;if(n.replaceChildren(r("p","",o),a),!i)return n;this.#g.placeholder=this.#e({id:"axQ1h6"}),this.#g.setAttribute("aria-label",this.#e({id:"NBdIgR"})),this.#g.disabled=i.state==="sending";let l=r("form");l.addEventListener("submit",(u)=>{u.preventDefault(),this.#ye(e.id,!0)});let c=r("button","link",this.#e({id:"6Uau97"}));c.type="button",c.disabled=i.state==="sending",c.addEventListener("click",()=>void this.#ye(e.id,!1));let h=r("button","",i.state==="sending"?this.#e({id:"Sad2tK"}):this.#e({id:"JlFcis"}));h.type="submit",h.disabled=i.state==="sending";let p=r("div","actions");if(p.append(c,h),l.append(this.#g,p),n.append(l),i.state==="failed")n.append(r("p","error",this.#e({id:"4TqZiz"})));return n}#Ne(e){let t=r("div","files");for(let i of e)if(Oe(i)){let n=r("img");n.alt=i.filename;let s=this.#c.get(i.id);if(s)n.src=s;else this.#ve(i).then((o)=>{n.src=o}).catch(()=>{return});n.addEventListener("load",()=>{if(this.#L)this.#d.scrollTop=this.#d.scrollHeight}),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}else{let n=r("button","file");n.type="button",n.innerHTML=P.file,n.append(r("span","",i.filename)),n.addEventListener("click",()=>void this.#be(i)),t.append(n)}return t}#Be(e){return new Intl.DateTimeFormat(this.#s.config().locale,{timeStyle:"short"}).format(new Date(e))}#se(){let e=this.#y,t=this.#r?.chat,n=(this.#i?.kind==="thread"?this.#i.id:null)!==null||this.#l.length>0,s=e?.email||e?.typed_email,o=!!t?.ask_email_offline&&this.#De()&&n&&(!s||this.#M);if(this.#P.hidden=!o,!o)return;if(s&&this.#M){this.#P.replaceChildren(r("p","",this.#e({id:"iGNUZJ",values:{known:s}})));return}if(this.#P.querySelector("form")){let c=this.#P.querySelector(".error");if(c)c.textContent=this.#S;else if(this.#S)this.#P.append(r("p","error",this.#S));return}let a=r("form");a.noValidate=!0,a.addEventListener("submit",(c)=>{c.preventDefault(),this.#ze()});let l=r("button","",this.#e({id:"tfDRzk"}));if(l.type="submit",a.append(this.#T,l),this.#P.replaceChildren(r("p","",this.#e({id:"M62PBt"})),a),this.#S)this.#P.append(r("p","error",this.#S))}#H(){this.#Z.hidden=this.#x.length===0,this.#Z.replaceChildren(...this.#x.map((e,t)=>{let i=r("span","chip");return i.append(r("span","",e.name||"image"),R(P.close,this.#e({id:"w61W3L",values:{0:e.name}}),()=>{this.#x=this.#x.filter((n,s)=>s!==t),this.#H(),this.#B()})),i}))}}function Ae(e){return new ye(e)}export{Ae as mount};