@sphoro/bugcatch-web-sdk 0.20.0 → 0.21.0

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.
@@ -1,4 +1,4 @@
1
- (function(K,F){typeof exports=="object"&&typeof module<"u"?module.exports=F():typeof define=="function"&&define.amd?define(F):(K=typeof globalThis<"u"?globalThis:K||self,K.BugCatch=F())})(this,function(){"use strict";var Bn=K=>{throw TypeError(K)};var Or=(K,F,ie)=>F.has(K)||Bn("Cannot "+ie);var Rn=(K,F,ie)=>F.has(K)?Bn("Cannot add the same private member more than once"):F instanceof WeakSet?F.add(K):F.set(K,ie);var q=(K,F,ie)=>(Or(K,F,"access private method"),ie);var B,Pe,jn,re,On,pt,Ke,_e,ht,zn,qn,Dn,Ve,Qn;const K="[REDACTED]",F=new Set(["auth","bearer","session","sid","phpsessid","otp","pass","passwd","pwd","sig","codeverifier"]),ie=["token","secret","password","passwd","apikey","signature","credential","sessionid","privatekey","accesskey","authorization"],Hn=new Set(["key","code","state","nonce","salt","hash"]),ft=[/eyJ[\w-]{8,}\.[\w-]{8,}\.[\w-]+/g,/(?:AKIA|ASIA|AROA|AIDA|AGPA|ANPA|ANVA|APKA)[0-9A-Z]{16}/g,/AIza[\w-]{35}/g,/gh[pousr]_[A-Za-z0-9]{36,}/g,/github_pat_\w{22,}/g,/[sprk]k_(?:live|test)_[0-9A-Za-z]{10,}/g,/xox[abposr]-[A-Za-z0-9-]{10,}/g,/sk-ant-[\w-]{20,}/g,/sk-[\w-]{20,}/g,/glpat-[\w-]{20,}/g,/shp(?:at|ss|ca|pa)_[A-Za-z0-9]{32}/g],Nn=/\bBearer\s+[\w.~+/=-]{8,}/gi,Un=/^([A-Za-z][A-Za-z0-9+.-]*:\/\/)([^/?#@]+)@/;function gt(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return e}}function Pn(e){return gt(e).toLowerCase().replace(/[^a-z0-9]/g,"")}function Kn(e){return e.length>=20?!0:ft.some(t=>(t.lastIndex=0,t.test(e)))}function _n(e,t){const n=Pn(e);if(!n)return!1;if(F.has(n))return!0;for(const o of ie)if(n.includes(o))return!0;return Hn.has(n)?Kn(gt(t)):!1}function Fe(e){return e.split("&").map(t=>{const n=t.indexOf("=");if(n===-1)return t;const o=t.slice(0,n),a=t.slice(n+1);return a&&_n(o,a)?`${o}=${K}`:t}).join("&")}function bt(e){let t=e;for(const n of ft)n.lastIndex=0,t=t.replace(n,K);return t}function mt(e){if(e==null)return e;let t=String(e);if(!t)return t;t=t.replace(Un,`$1${K}@`);const n=t.indexOf("#");let o=n===-1?t:t.slice(0,n),a=n===-1?"":t.slice(n);const r=o.indexOf("?");if(r!==-1&&(o=o.slice(0,r+1)+Fe(o.slice(r+1))),a.length>1){const i=a.slice(1),s=i.indexOf("?");s!==-1?a=`#${i.slice(0,s+1)}${Fe(i.slice(s+1))}`:i.includes("=")&&(a=`#${Fe(i)}`)}return bt(o+a)}function Vn(e){if(e==null)return e;let t=String(e);return t&&(t=t.replace(/[A-Za-z][A-Za-z0-9+.-]{0,30}:\/\/[^\s"'<>)\]]+/g,n=>mt(n)),t=t.replace(Nn,`Bearer ${K}`),bt(t))}function $e(e){const t=[];return{push(n){t.push(n),t.length>e&&t.splice(0,t.length-e)},all:()=>t.slice(),clear:()=>{t.length=0},get size(){return t.length}}}const yt=["log","info","warn","error","debug"];function Fn(e,{levels:t=["warn","error","log","info"]}={}){const n={};for(const o of yt)n[o]=console[o],t.includes(o)&&(console[o]=(...a)=>{try{e.push({level:o,text:a.map(xt).join(" ").slice(0,2e3),at:new Date().toISOString()})}catch{}n[o].apply(console,a)});return()=>{for(const o of yt)console[o]=n[o]}}function Wn(e,{slowMs:t=2e3}={}){const n=window.fetch,o=XMLHttpRequest.prototype.open,a=XMLHttpRequest.prototype.send;return n&&(window.fetch=async function(...i){var p,f,u;const s=performance.now(),d=typeof i[0]=="string"?i[0]:(p=i[0])==null?void 0:p.url,c=((f=i[1])==null?void 0:f.method)||(typeof i[0]=="object"?(u=i[0])==null?void 0:u.method:"GET")||"GET";try{const h=await n.apply(this,i);return We(e,{url:d,method:c,status:h.status,ms:Math.round(performance.now()-s),slowMs:t}),h}catch(h){throw We(e,{url:d,method:c,status:0,error:String((h==null?void 0:h.message)||h),ms:Math.round(performance.now()-s),slowMs:t}),h}}),XMLHttpRequest.prototype.open=function(i,s,...d){return this.__bc={method:i,url:s,started:0},o.call(this,i,s,...d)},XMLHttpRequest.prototype.send=function(...i){return this.__bc&&(this.__bc.started=performance.now(),this.addEventListener("loadend",()=>{We(e,{url:this.__bc.url,method:this.__bc.method,status:this.status,ms:Math.round(performance.now()-this.__bc.started),slowMs:t})})),a.apply(this,i)},()=>{n&&(window.fetch=n),XMLHttpRequest.prototype.open=o,XMLHttpRequest.prototype.send=a}}function We(e,{url:t,method:n,status:o,ms:a,error:r,slowMs:i}){try{e.push({url:mt(String(t)).slice(0,500),method:n,status:o,ms:a,error:r===void 0?void 0:Vn(r),failed:o===0||o>=400,slow:a>=i,at:new Date().toISOString()})}catch{}}function Yn(e){const t=o=>{const a=String(o.message||"Error"),r=o.filename?` (${o.filename}:${o.lineno}:${o.colno})`:"";e.push({level:"error",text:(/^uncaught/i.test(a)?a:`Uncaught ${a}`)+r,at:new Date().toISOString()})},n=o=>{e.push({level:"error",text:`Unhandled rejection: ${xt(o.reason)}`,at:new Date().toISOString()})};return window.addEventListener("error",t),window.addEventListener("unhandledrejection",n),()=>{window.removeEventListener("error",t),window.removeEventListener("unhandledrejection",n)}}async function wt(){const e=vt();try{if(navigator.getBattery){const t=await navigator.getBattery();e.battery=Math.round(t.level*100),e.charging=t.charging}}catch{}return e}function vt(){var t,n,o,a,r,i,s,d,c;const e=window.navigator||{};return{userAgent:e.userAgent,platform:e.platform,language:e.language,languages:e.languages?[...e.languages]:null,online:e.onLine,cookieEnabled:e.cookieEnabled,maxTouchPoints:e.maxTouchPoints??null,viewport:{width:window.innerWidth,height:window.innerHeight},screen:{width:(t=window.screen)==null?void 0:t.width,height:(n=window.screen)==null?void 0:n.height,availWidth:(o=window.screen)==null?void 0:o.availWidth,availHeight:(a=window.screen)==null?void 0:a.availHeight,colorDepth:(r=window.screen)==null?void 0:r.colorDepth,orientation:((s=(i=window.screen)==null?void 0:i.orientation)==null?void 0:s.type)||null},devicePixelRatio:window.devicePixelRatio,referrer:document.referrer||null,title:document.title,capturedAt:new Date().toISOString(),timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,timezoneOffsetMinutes:new Date().getTimezoneOffset(),browserMode:e.webdriver?"Automated":"Normal",doNotTrack:e.doNotTrack||null,hardwareConcurrency:e.hardwareConcurrency??null,deviceMemory:e.deviceMemory??null,connection:e.connection?{effectiveType:e.connection.effectiveType,downlink:e.connection.downlink,rtt:e.connection.rtt,saveData:e.connection.saveData}:null,prefersColorScheme:(d=window.matchMedia)!=null&&d.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light",prefersReducedMotion:((c=window.matchMedia)==null?void 0:c.call(window,"(prefers-reduced-motion: reduce)").matches)||!1}}function xt(e){if(typeof e=="string")return e;if(e instanceof Error)return`${e.name}: ${e.message}`;try{return JSON.stringify(e)}catch{return String(e)}}const Xn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M4 11.5a7.5 7 0 0 1 7.5-7h1a7.5 7 0 0 1 0 14H9l-4.2 2.6a.5.5 0 0 1-.76-.5l.5-3.1A7 7 0 0 1 4 11.5z"/><path d="M8.5 11.5h.01M12 11.5h.01M15.5 11.5h.01" stroke-width="2.6"/></svg>',Jn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9.5l6 6 6-6"/></svg>',kt='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4.2"/><path d="M12 2.6v2.2M12 19.2v2.2M2.6 12h2.2M19.2 12h2.2M5.4 5.4l1.6 1.6M17 17l1.6 1.6M18.6 5.4L17 7M7 17l-1.6 1.6"/></svg>',St='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M20 13.4A8.2 8.2 0 1 1 10.6 4a6.6 6.6 0 0 0 9.4 9.4z"/></svg>',$t='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><rect x="2.8" y="4.4" width="18.4" height="12.6" rx="2.2"/><path d="M8.6 20.2h6.8"/><path d="M12 4.4v12.6"/><path d="M12 7.2a3.6 3.6 0 0 1 0 7.2z" fill="currentColor" stroke="none"/></svg>',se='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 7.5v5.2M12 16.3h.01"/></svg>',ge='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>',oe='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.8l4.6 4.4L19 7"/></svg>',Ct='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 11v5.5M12 7.7h.01"/></svg>',Zn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.3 4.2a2 2 0 0 1 3.4 0l7.6 13.1a2 2 0 0 1-1.7 3H4.4a2 2 0 0 1-1.7-3z"/><path d="M12 9.5v4.2M12 17h.01"/></svg>';function Tt(e,t){console.warn(`[BugCatch] ${e}`,...t?[t]:[]);const n=new Error("[BugCatch] part of the widget could not be loaded — check the connection and try again.");return t&&(n.cause=t),n}function Et(e){let t=null;return(...n)=>(t||(t=e(...n).catch(o=>{throw t=null,o})),t)}const It=Et(()=>Promise.resolve().then(()=>gr).catch(e=>{throw Tt("the report panel could not be loaded.",e)})),Ce=Et(()=>Promise.resolve().then(()=>Mr).catch(e=>{throw Tt("the calling code could not be loaded.",e)})),Gn={info:Ct,success:oe,warning:Zn,critical:se};function Lt(e,{where:t,onDismiss:n}){const o=document.createElement("div");o.className=`notice tone-${e.tone} at-${t}`,o.setAttribute("role","status");const a=document.createElement("span");a.className="notice-ico",a.setAttribute("aria-hidden","true"),a.innerHTML=Gn[e.tone]||Ct;const r=document.createElement("div");r.className="notice-text";const i=document.createElement("strong");if(i.textContent=e.title,r.append(i),e.body){const s=document.createElement("p");s.textContent=e.body,r.append(s)}if(e.ctaHref&&e.ctaLabel){const s=document.createElement("a");s.className="notice-cta",s.href=e.ctaHref,s.textContent=e.ctaLabel,/^https?:/i.test(e.ctaHref)&&(s.target="_blank",s.rel="noopener noreferrer"),r.append(s)}if(o.append(a,r),e.dismissible&&n){const s=document.createElement("button");s.type="button",s.className="notice-x",s.setAttribute("aria-label","Dismiss this notice"),s.innerHTML=ge,s.addEventListener("click",()=>n(e)),o.append(s)}return o}const Ye="#0e0e10",Te="#ffffff";function Xe(e){const t=eo(e);if(!t)return Te;const[n,o,a]=t.map(i=>{const s=i/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4});return .2126*n+.7152*o+.0722*a>.179?Ye:Te}function eo(e){const t=String(e||"").trim();let n=/^#([0-9a-f]{3})$/i.exec(t);return n?[...n[1]].map(o=>parseInt(o+o,16)):(n=/^#([0-9a-f]{6})$/i.exec(t),n?[0,2,4].map(o=>parseInt(n[1].slice(o,o+2),16)):(n=/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/i.exec(t),n?[n[1],n[2],n[3]].map(Number):null))}const At={"bottom-right":"bottom:20px;right:20px;","bottom-left":"bottom:20px;left:20px;","top-right":"top:20px;right:20px;","top-left":"top:20px;left:20px;"},be=[{value:"light",label:"Light",icon:kt},{value:"dark",label:"Dark",icon:St},{value:"auto",label:"System default",icon:$t}],Mt="bugcatch:theme";function to(){try{const e=localStorage.getItem(Mt);return be.some(t=>t.value===e)?e:null}catch{return null}}function no(e){try{localStorage.setItem(Mt,e)}catch{}}const Bt=`
1
+ (function(V,W){typeof exports=="object"&&typeof module<"u"?module.exports=W():typeof define=="function"&&define.amd?define(W):(V=typeof globalThis<"u"?globalThis:V||self,V.BugCatch=W())})(this,function(){"use strict";var qn=V=>{throw TypeError(V)};var Gr=(V,W,se)=>W.has(V)||qn("Cannot "+se);var Dn=(V,W,se)=>W.has(V)?qn("Cannot add the same private member more than once"):W instanceof WeakSet?W.add(V):W.set(V,se);var D=(V,W,se)=>(Gr(V,W,"access private method"),se);var R,_e,Hn,ie,Qn,mt,$e,Ve,Fe,Nn,Kn,Pn,We,Un;const V="[REDACTED]",W=new Set(["auth","bearer","session","sid","phpsessid","otp","pass","passwd","pwd","sig","codeverifier"]),se=["token","secret","password","passwd","apikey","signature","credential","sessionid","privatekey","accesskey","authorization"],_n=new Set(["key","code","state","nonce","salt","hash"]),yt=[/eyJ[\w-]{8,}\.[\w-]{8,}\.[\w-]+/g,/(?:AKIA|ASIA|AROA|AIDA|AGPA|ANPA|ANVA|APKA)[0-9A-Z]{16}/g,/AIza[\w-]{35}/g,/gh[pousr]_[A-Za-z0-9]{36,}/g,/github_pat_\w{22,}/g,/[sprk]k_(?:live|test)_[0-9A-Za-z]{10,}/g,/xox[abposr]-[A-Za-z0-9-]{10,}/g,/sk-ant-[\w-]{20,}/g,/sk-[\w-]{20,}/g,/glpat-[\w-]{20,}/g,/shp(?:at|ss|ca|pa)_[A-Za-z0-9]{32}/g],Vn=/\bBearer\s+[\w.~+/=-]{8,}/gi,Fn=/^([A-Za-z][A-Za-z0-9+.-]*:\/\/)([^/?#@]+)@/;function wt(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return e}}function Wn(e){return wt(e).toLowerCase().replace(/[^a-z0-9]/g,"")}function Yn(e){return e.length>=20?!0:yt.some(t=>(t.lastIndex=0,t.test(e)))}function Xn(e,t){const n=Wn(e);if(!n)return!1;if(W.has(n))return!0;for(const o of se)if(n.includes(o))return!0;return _n.has(n)?Yn(wt(t)):!1}function Ye(e){return e.split("&").map(t=>{const n=t.indexOf("=");if(n===-1)return t;const o=t.slice(0,n),a=t.slice(n+1);return a&&Xn(o,a)?`${o}=${V}`:t}).join("&")}function vt(e){let t=e;for(const n of yt)n.lastIndex=0,t=t.replace(n,V);return t}function xt(e){if(e==null)return e;let t=String(e);if(!t)return t;t=t.replace(Fn,`$1${V}@`);const n=t.indexOf("#");let o=n===-1?t:t.slice(0,n),a=n===-1?"":t.slice(n);const r=o.indexOf("?");if(r!==-1&&(o=o.slice(0,r+1)+Ye(o.slice(r+1))),a.length>1){const i=a.slice(1),s=i.indexOf("?");s!==-1?a=`#${i.slice(0,s+1)}${Ye(i.slice(s+1))}`:i.includes("=")&&(a=`#${Ye(i)}`)}return vt(o+a)}function Jn(e){if(e==null)return e;let t=String(e);return t&&(t=t.replace(/[A-Za-z][A-Za-z0-9+.-]{0,30}:\/\/[^\s"'<>)\]]+/g,n=>xt(n)),t=t.replace(Vn,`Bearer ${V}`),vt(t))}function Ce(e){const t=[];return{push(n){t.push(n),t.length>e&&t.splice(0,t.length-e)},all:()=>t.slice(),clear:()=>{t.length=0},get size(){return t.length}}}const kt=["log","info","warn","error","debug"];function Zn(e,{levels:t=["warn","error","log","info"]}={}){const n={};for(const o of kt)n[o]=console[o],t.includes(o)&&(console[o]=(...a)=>{try{e.push({level:o,text:a.map($t).join(" ").slice(0,2e3),at:new Date().toISOString()})}catch{}n[o].apply(console,a)});return()=>{for(const o of kt)console[o]=n[o]}}function Gn(e,{slowMs:t=2e3}={}){const n=window.fetch,o=XMLHttpRequest.prototype.open,a=XMLHttpRequest.prototype.send;return n&&(window.fetch=async function(...i){var h,f,d;const s=performance.now(),l=typeof i[0]=="string"?i[0]:(h=i[0])==null?void 0:h.url,c=((f=i[1])==null?void 0:f.method)||(typeof i[0]=="object"?(d=i[0])==null?void 0:d.method:"GET")||"GET";try{const p=await n.apply(this,i);return Xe(e,{url:l,method:c,status:p.status,ms:Math.round(performance.now()-s),slowMs:t}),p}catch(p){throw Xe(e,{url:l,method:c,status:0,error:String((p==null?void 0:p.message)||p),ms:Math.round(performance.now()-s),slowMs:t}),p}}),XMLHttpRequest.prototype.open=function(i,s,...l){return this.__bc={method:i,url:s,started:0},o.call(this,i,s,...l)},XMLHttpRequest.prototype.send=function(...i){return this.__bc&&(this.__bc.started=performance.now(),this.addEventListener("loadend",()=>{Xe(e,{url:this.__bc.url,method:this.__bc.method,status:this.status,ms:Math.round(performance.now()-this.__bc.started),slowMs:t})})),a.apply(this,i)},()=>{n&&(window.fetch=n),XMLHttpRequest.prototype.open=o,XMLHttpRequest.prototype.send=a}}function Xe(e,{url:t,method:n,status:o,ms:a,error:r,slowMs:i}){try{e.push({url:xt(String(t)).slice(0,500),method:n,status:o,ms:a,error:r===void 0?void 0:Jn(r),failed:o===0||o>=400,slow:a>=i,at:new Date().toISOString()})}catch{}}function eo(e){const t=o=>{const a=String(o.message||"Error"),r=o.filename?` (${o.filename}:${o.lineno}:${o.colno})`:"";e.push({level:"error",text:(/^uncaught/i.test(a)?a:`Uncaught ${a}`)+r,at:new Date().toISOString()})},n=o=>{e.push({level:"error",text:`Unhandled rejection: ${$t(o.reason)}`,at:new Date().toISOString()})};return window.addEventListener("error",t),window.addEventListener("unhandledrejection",n),()=>{window.removeEventListener("error",t),window.removeEventListener("unhandledrejection",n)}}async function Je(){const e=St();try{if(navigator.getBattery){const t=await navigator.getBattery();e.battery=Math.round(t.level*100),e.charging=t.charging}}catch{}return e}function St(){var t,n,o,a,r,i,s,l,c;const e=window.navigator||{};return{userAgent:e.userAgent,platform:e.platform,language:e.language,languages:e.languages?[...e.languages]:null,online:e.onLine,cookieEnabled:e.cookieEnabled,maxTouchPoints:e.maxTouchPoints??null,viewport:{width:window.innerWidth,height:window.innerHeight},screen:{width:(t=window.screen)==null?void 0:t.width,height:(n=window.screen)==null?void 0:n.height,availWidth:(o=window.screen)==null?void 0:o.availWidth,availHeight:(a=window.screen)==null?void 0:a.availHeight,colorDepth:(r=window.screen)==null?void 0:r.colorDepth,orientation:((s=(i=window.screen)==null?void 0:i.orientation)==null?void 0:s.type)||null},devicePixelRatio:window.devicePixelRatio,referrer:document.referrer||null,title:document.title,capturedAt:new Date().toISOString(),timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,timezoneOffsetMinutes:new Date().getTimezoneOffset(),browserMode:e.webdriver?"Automated":"Normal",doNotTrack:e.doNotTrack||null,hardwareConcurrency:e.hardwareConcurrency??null,deviceMemory:e.deviceMemory??null,connection:e.connection?{effectiveType:e.connection.effectiveType,downlink:e.connection.downlink,rtt:e.connection.rtt,saveData:e.connection.saveData}:null,prefersColorScheme:(l=window.matchMedia)!=null&&l.call(window,"(prefers-color-scheme: dark)").matches?"dark":"light",prefersReducedMotion:((c=window.matchMedia)==null?void 0:c.call(window,"(prefers-reduced-motion: reduce)").matches)||!1}}function $t(e){if(typeof e=="string")return e;if(e instanceof Error)return`${e.name}: ${e.message}`;try{return JSON.stringify(e)}catch{return String(e)}}const to='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M4 11.5a7.5 7 0 0 1 7.5-7h1a7.5 7 0 0 1 0 14H9l-4.2 2.6a.5.5 0 0 1-.76-.5l.5-3.1A7 7 0 0 1 4 11.5z"/><path d="M8.5 11.5h.01M12 11.5h.01M15.5 11.5h.01" stroke-width="2.6"/></svg>',no='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9.5l6 6 6-6"/></svg>',Ct='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4.2"/><path d="M12 2.6v2.2M12 19.2v2.2M2.6 12h2.2M19.2 12h2.2M5.4 5.4l1.6 1.6M17 17l1.6 1.6M18.6 5.4L17 7M7 17l-1.6 1.6"/></svg>',Tt='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M20 13.4A8.2 8.2 0 1 1 10.6 4a6.6 6.6 0 0 0 9.4 9.4z"/></svg>',Et='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><rect x="2.8" y="4.4" width="18.4" height="12.6" rx="2.2"/><path d="M8.6 20.2h6.8"/><path d="M12 4.4v12.6"/><path d="M12 7.2a3.6 3.6 0 0 1 0 7.2z" fill="currentColor" stroke="none"/></svg>',re='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 7.5v5.2M12 16.3h.01"/></svg>',be='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6L6 18"/></svg>',ee='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12.8l4.6 4.4L19 7"/></svg>',It='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M12 11v5.5M12 7.7h.01"/></svg>',oo='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10.3 4.2a2 2 0 0 1 3.4 0l7.6 13.1a2 2 0 0 1-1.7 3H4.4a2 2 0 0 1-1.7-3z"/><path d="M12 9.5v4.2M12 17h.01"/></svg>';function Lt(e,t){console.warn(`[BugCatch] ${e}`,...t?[t]:[]);const n=new Error("[BugCatch] part of the widget could not be loaded — check the connection and try again.");return t&&(n.cause=t),n}function At(e){let t=null;return(...n)=>(t||(t=e(...n).catch(o=>{throw t=null,o})),t)}const Mt=At(()=>Promise.resolve().then(()=>Rr).catch(e=>{throw Lt("the report panel could not be loaded.",e)})),Te=At(()=>Promise.resolve().then(()=>Yr).catch(e=>{throw Lt("the calling code could not be loaded.",e)})),ao={info:It,success:ee,warning:oo,critical:re};function Bt(e,{where:t,onDismiss:n}){const o=document.createElement("div");o.className=`notice tone-${e.tone} at-${t}`,o.setAttribute("role","status");const a=document.createElement("span");a.className="notice-ico",a.setAttribute("aria-hidden","true"),a.innerHTML=ao[e.tone]||It;const r=document.createElement("div");r.className="notice-text";const i=document.createElement("strong");if(i.textContent=e.title,r.append(i),e.body){const s=document.createElement("p");s.textContent=e.body,r.append(s)}if(e.ctaHref&&e.ctaLabel){const s=document.createElement("a");s.className="notice-cta",s.href=e.ctaHref,s.textContent=e.ctaLabel,/^https?:/i.test(e.ctaHref)&&(s.target="_blank",s.rel="noopener noreferrer"),r.append(s)}if(o.append(a,r),e.dismissible&&n){const s=document.createElement("button");s.type="button",s.className="notice-x",s.setAttribute("aria-label","Dismiss this notice"),s.innerHTML=be,s.addEventListener("click",()=>n(e)),o.append(s)}return o}const Ze="#0e0e10",Ee="#ffffff";function Ge(e){const t=ro(e);if(!t)return Ee;const[n,o,a]=t.map(i=>{const s=i/255;return s<=.03928?s/12.92:((s+.055)/1.055)**2.4});return .2126*n+.7152*o+.0722*a>.179?Ze:Ee}function ro(e){const t=String(e||"").trim();let n=/^#([0-9a-f]{3})$/i.exec(t);return n?[...n[1]].map(o=>parseInt(o+o,16)):(n=/^#([0-9a-f]{6})$/i.exec(t),n?[0,2,4].map(o=>parseInt(n[1].slice(o,o+2),16)):(n=/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/i.exec(t),n?[n[1],n[2],n[3]].map(Number):null))}const Rt={"bottom-right":"bottom:20px;right:20px;","bottom-left":"bottom:20px;left:20px;","top-right":"top:20px;right:20px;","top-left":"top:20px;left:20px;"},me=[{value:"light",label:"Light",icon:Ct},{value:"dark",label:"Dark",icon:Tt},{value:"auto",label:"System default",icon:Et}],jt="bugcatch:theme";function io(){try{const e=localStorage.getItem(jt);return me.some(t=>t.value===e)?e:null}catch{return null}}function so(e){try{localStorage.setItem(jt,e)}catch{}}const Ot=`
2
2
  --bc-bg: #151517;
3
3
  --bc-elevated: #1c1c1f;
4
4
  --bc-fg: #f3f2ef;
@@ -16,11 +16,11 @@
16
16
  --bc-brand-mark: #a59cff;
17
17
  --bc-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 30px 70px -20px rgba(0,0,0,.8), 0 8px 20px -8px rgba(0,0,0,.5);
18
18
  --bc-shadow-sm: 0 0 0 1px rgba(255,255,255,.07), 0 1px 2px rgba(0,0,0,.4);
19
- --bc-accent-soft: color-mix(in srgb, var(--bc-accent) 14%, var(--bc-bg));`,oo=e=>`
19
+ --bc-accent-soft: color-mix(in srgb, var(--bc-accent) 14%, var(--bc-bg));`,co=e=>`
20
20
  :host { all: initial; }
21
21
  :host {
22
22
  --bc-accent: ${e||"var(--bc-fg)"};
23
- --bc-on-accent: ${e?Xe(e):"var(--bc-bg)"};
23
+ --bc-on-accent: ${e?Ge(e):"var(--bc-bg)"};
24
24
  /* The assistant's orb: BugCatch's own three colours, or the host's accent
25
25
  with two lighter cuts of it, so the orb on their site is in their colour. */
26
26
  --bc-o1: ${e?`color-mix(in srgb, ${e} 32%, #fff)`:"#ffb3c9"};
@@ -68,10 +68,10 @@
68
68
  --bc-fs-lg: 15px;
69
69
  --bc-pad: 18px;
70
70
  }
71
- :host(.bc-dark) {${Bt}
71
+ :host(.bc-dark) {${Ot}
72
72
  }
73
73
  @media (prefers-color-scheme: dark) {
74
- :host(.bc-auto) {${Bt}
74
+ :host(.bc-auto) {${Ot}
75
75
  }
76
76
  }
77
77
 
@@ -300,13 +300,13 @@ button:focus-visible, a:focus-visible, select:focus-visible, [tabindex]:focus-vi
300
300
  }
301
301
  .loadfail button[data-act="retry"] { text-decoration: underline; text-underline-offset: 2px; }
302
302
  .loadfail button svg { font-size: 13px; margin: 0; }
303
- `;function ao(e){const t=document.createElement("div");t.setAttribute("data-bugcatch","widget");let n=to()||ro(e.config.theme);t.className=Rt(n);const o=t.attachShadow({mode:"open"}),a=document.createElement("style");a.textContent=oo(e.config.accent||null),o.appendChild(a);const r=At[e.config.widgetPosition]?e.config.widgetPosition:"bottom-right",i=document.createElement("div");i.className=`dock ${r.includes("right")?"at-right":"at-left"}`+(r.startsWith("top")?" at-top":""),i.style.cssText=At[r];const s={current:()=>n,label:()=>be.find(y=>y.value===n).label,cycle(){const y=be[(be.findIndex(x=>x.value===n)+1)%be.length];return n=y.value,t.className=Rt(n),no(n),y}},d=document.createElement("button");d.className="launcher",d.type="button",d.innerHTML=`<span class="ico" aria-hidden="true"><span class="when-closed"><span class="orb"></span></span><span class="when-open">${Jn}</span></span><span>Report a bug</span>`,d.setAttribute("aria-haspopup","dialog"),d.setAttribute("aria-expanded","false");let c=null;d.addEventListener("click",()=>{if(c){c.close();return}c=p()});function p(){w(),l();let y=null,x=!1;const v=()=>{x=!0,d.removeAttribute("aria-busy"),c=null},k={close:()=>y?y.close():v(),destroy:()=>y?y.destroy():v()};return d.setAttribute("aria-busy","true"),It(e.config.chunkBase).then(({openPanel:T})=>{x||(d.removeAttribute("aria-busy"),i.classList.add("over"),d.setAttribute("aria-expanded","true"),y=T({root:o,host:t,dock:i,client:e,preloadCall:h,themeControls:s,onClose:()=>{c=null,i.classList.remove("over"),d.setAttribute("aria-expanded","false")}}))},()=>{x||(v(),C())}),k}const f=()=>{It(e.config.chunkBase).catch(()=>{})};for(const y of["pointerenter","touchstart","focus"])d.addEventListener(y,f,{once:!0,passive:!0});const u=jt(f);function h(){Ce(e.config.chunkBase).catch(()=>{})}let m=null;function C(){w(),m=document.createElement("div"),m.className="msg err loadfail",m.setAttribute("role","alert"),m.innerHTML=`${se}<span>The report form didn't load. Check your connection and try again.</span><button type="button" data-act="retry">Try again</button><button type="button" data-act="dismiss" aria-label="Dismiss">${ge}</button>`,m.querySelector('[data-act="retry"]').addEventListener("click",()=>{d.focus(),c||(c=p())}),m.querySelector('[data-act="dismiss"]').addEventListener("click",()=>{d.focus(),w()}),i.prepend(m)}function w(){m==null||m.remove(),m=null}let g=null;function b(y){l(),g=Lt(y,{where:"launcher",onDismiss:x=>{e.dismissAnnouncement(x),d.focus(),l()}}),m?m.after(g):i.prepend(g)}function l(){g==null||g.remove(),g=null}const S=e.config.announcements===!1?()=>{}:jt(()=>{e.announcements().then(y=>{const x=y.find(v=>v.placement==="launcher");x&&!c&&t.isConnected&&b(x)}).catch(()=>{})});return i.append(d),o.appendChild(i),document.body.appendChild(t),e.widgetControls={open:()=>{c||d.click()},close:()=>{c==null||c.close()},isOpen:()=>!!c},()=>{u(),S(),c==null||c.destroy(),t.remove(),e.widgetControls=null}}function ro(e){return e==="dark"||e==="light"?e:"auto"}function Rt(e){return e==="dark"?"bc-dark":e==="light"?"bc-light":"bc-auto"}function jt(e){let t=()=>{};const n=()=>{if(typeof requestIdleCallback=="function"){const o=requestIdleCallback(e,{timeout:5e3});t=()=>cancelIdleCallback(o)}else{const o=setTimeout(e,1500);t=()=>clearTimeout(o)}};return document.readyState==="complete"?n():(window.addEventListener("load",n,{once:!0}),t=()=>window.removeEventListener("load",n)),()=>t()}const io="Too many requests are being sent from here at the moment. Please try again in a minute.";function pe(e){return e||io}const so=typeof window<"u"&&window.fetch?window.fetch.bind(window):null,co=typeof XMLHttpRequest<"u"?XMLHttpRequest.prototype.open:null,lo=typeof XMLHttpRequest<"u"?XMLHttpRequest.prototype.send:null,Ot=["image/png","image/jpeg","image/webp","image/gif","video/webm","video/mp4","audio/webm","audio/ogg","audio/mpeg","audio/mp4","audio/wav","application/pdf","text/plain","text/csv","application/json","application/zip","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],Ee=["image/png","image/jpeg","image/webp","video/webm","video/mp4"],uo=()=>{var e;return!!((e=navigator==null?void 0:navigator.mediaDevices)!=null&&e.getUserMedia&&typeof MediaRecorder<"u")},po=()=>{var e;return!!((e=navigator==null?void 0:navigator.mediaDevices)!=null&&e.getDisplayMedia&&typeof MediaRecorder<"u")},ho=()=>{var e;return!!((e=navigator==null?void 0:navigator.mediaDevices)!=null&&e.getDisplayMedia)};function Ie(e,t=Ot){const n=String(e||"").split(";")[0].trim().toLowerCase();return t.includes(n)?n:null}async function fo(){const e=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:1},audio:!1});try{const t=e.getVideoTracks()[0],n=document.createElement("video");n.srcObject=e,n.muted=!0,n.playsInline=!0,await n.play(),await new Promise(s=>requestAnimationFrame(()=>requestAnimationFrame(s)));const{width:o,height:a}=t.getSettings(),r=document.createElement("canvas");r.width=o||n.videoWidth,r.height=a||n.videoHeight,r.getContext("2d").drawImage(n,0,0,r.width,r.height);const i=await new Promise(s=>r.toBlob(s,"image/png"));if(!i)throw new Error("The browser returned an empty screenshot.");return{blob:i,mime:"image/png",kind:"SCREENSHOT"}}finally{e.getTracks().forEach(t=>t.stop())}}async function go({maxMs:e=12e4,onTick:t,onAutoStop:n}={}){const o=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:15},audio:!1}),a=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"].find(h=>MediaRecorder.isTypeSupported(h))||"video/webm",r=new MediaRecorder(o,{mimeType:a,videoBitsPerSecond:25e5}),i=[];r.ondataavailable=h=>{h.data.size&&i.push(h.data)},r.start(1e3);const s=Date.now(),d=setInterval(()=>t==null?void 0:t(Math.floor((Date.now()-s)/1e3)),500),c=()=>{clearInterval(d),clearTimeout(u),o.getTracks().forEach(h=>h.stop())},p=new Promise(h=>{r.onstop=()=>{c(),h(new Blob(i,{type:a}))}}),f=()=>{r.state!=="inactive"&&r.stop(),n==null||n()};o.getVideoTracks()[0].addEventListener("ended",f);const u=setTimeout(f,e);return{mime:a,maxMs:e,async stop(){return clearTimeout(u),r.state!=="inactive"&&r.stop(),{blob:await p,mime:a,kind:"VIDEO"}},cancel(){c(),r.state!=="inactive"&&r.stop()}}}async function bo({maxMs:e=12e4,onTick:t,onAutoStop:n}={}){const o=await navigator.mediaDevices.getUserMedia({audio:!0}),a=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg"].find(h=>MediaRecorder.isTypeSupported(h))||"",r=new MediaRecorder(o,a?{mimeType:a}:void 0),i=[];r.ondataavailable=h=>{h.data.size&&i.push(h.data)},r.start(1e3);const s=Date.now(),d=setInterval(()=>t==null?void 0:t(Math.floor((Date.now()-s)/1e3)),500),c=()=>{clearInterval(d),clearTimeout(u),o.getTracks().forEach(h=>h.stop())},p=new Promise(h=>{r.onstop=()=>{c(),h(new Blob(i,{type:r.mimeType||a}))}}),u=setTimeout(()=>{r.state!=="inactive"&&r.stop(),n==null||n()},e);return{mime:r.mimeType||a,maxMs:e,async stop(){clearTimeout(u),r.state!=="inactive"&&r.stop();const h=await p;return{blob:h,mime:h.type||r.mimeType||a,kind:"AUDIO"}},cancel(){c(),r.state!=="inactive"&&r.stop()}}}async function mo({apiBase:e,apiKey:t,blob:n,mime:o,onProgress:a}){var c;const r=Ie(o||n.type);if(!r)throw new Error(`[BugCatch] ${o||n.type||"that file"} can't be attached.`);const i=await so(`${e}/ingest/presign`,{method:"POST",headers:{"Content-Type":"application/json","X-BugCatch-Key":t},body:JSON.stringify({mime:r})});if(i.status===429){let p="";try{p=((c=await i.json())==null?void 0:c.message)||""}catch{}throw new Error(`[BugCatch] ${pe(typeof p=="string"?p:"")}`)}if(!i.ok)throw new Error(`[BugCatch] could not start the upload (HTTP ${i.status}).`);const{key:s,uploadUrl:d}=await i.json();return await yo(d,n,r,a),{storageKey:s,mime:r}}function yo(e,t,n,o){return new Promise((a,r)=>{const i=new XMLHttpRequest;co.call(i,"PUT",e,!0),i.setRequestHeader("Content-Type",n),i.upload.onprogress=s=>{s.lengthComputable&&(o==null||o(s.loaded/s.total))},i.onload=()=>{i.status>=200&&i.status<300?a():r(new Error(`[BugCatch] upload failed (HTTP ${i.status}).`))},i.onerror=()=>r(new Error("[BugCatch] the browser blocked the upload to storage. If this is a new environment, the media bucket is probably missing its CORS policy.")),i.onabort=()=>r(new Error("[BugCatch] upload cancelled.")),lo.call(i,t)})}function he(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Le(e){const t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,"0")}`}const Ae="bugcatch.watch",zt=[2e3,5e3,15e3,3e4,6e4],wo=5e3;let me=null;function vo(e){me=e||null}const Je=()=>me?`${Ae}:${me}`:Ae;function Me(){return me?`?projectId=${encodeURIComponent(me)}`:""}function V(){try{const e=window.localStorage;return(e==null?void 0:e.getItem(Je()))||(e==null?void 0:e.getItem(Ae))||null}catch{return null}}function Ze(e){var t;if(e)try{(t=window.localStorage)==null||t.setItem(Je(),e)}catch{}}function ce(){var e,t;try{(e=window.localStorage)==null||e.removeItem(Je()),(t=window.localStorage)==null||t.removeItem(Ae)}catch{}qt()}const Be="bugcatch.unread";function xo(e){return[(e==null?void 0:e.bugId)||"report",(e==null?void 0:e.kind)||"status",(e==null?void 0:e.at)||""].join("|")}function ye(){var e;try{const t=(e=window.localStorage)==null?void 0:e.getItem(Be),n=t?JSON.parse(t):[];return Array.isArray(n)?n.filter(o=>o&&typeof o.id=="string"):[]}catch{return[]}}function Re(e){var t,n;try{e.length?(t=window.localStorage)==null||t.setItem(Be,JSON.stringify(e)):(n=window.localStorage)==null||n.removeItem(Be)}catch{}}function ko(e){const t={...e,id:xo(e)},n=ye().filter(o=>o.id!==t.id);return n.push(t),Re(n.slice(-20)),t}function So(e){const t=ye().filter(n=>n.id!==e);return Re(t),t}function $o(e){const t=ye().filter(n=>n.bugId!==e);return Re(t),t}function qt(){return Re([]),[]}function Co(e,t){let n=e,o=n.indexOf(`
303
+ `;function lo(e){const t=document.createElement("div");t.setAttribute("data-bugcatch","widget");let n=io()||uo(e.config.theme);t.className=zt(n);const o=t.attachShadow({mode:"open"}),a=document.createElement("style");a.textContent=co(e.config.accent||null),o.appendChild(a);const r=Rt[e.config.widgetPosition]?e.config.widgetPosition:"bottom-right",i=document.createElement("div");i.className=`dock ${r.includes("right")?"at-right":"at-left"}`+(r.startsWith("top")?" at-top":""),i.style.cssText=Rt[r];const s={current:()=>n,label:()=>me.find(x=>x.value===n).label,cycle(){const x=me[(me.findIndex(w=>w.value===n)+1)%me.length];return n=x.value,t.className=zt(n),so(n),x}},l=document.createElement("button");l.className="launcher",l.type="button",l.innerHTML=`<span class="ico" aria-hidden="true"><span class="when-closed"><span class="orb"></span></span><span class="when-open">${no}</span></span><span>Report a bug</span>`,l.setAttribute("aria-haspopup","dialog"),l.setAttribute("aria-expanded","false");let c=null;l.addEventListener("click",()=>{if(c){c.close();return}c=f()});let h="report";function f(){let x=h;h="report",b(),$();let w=null,S=!1;const v=()=>{S=!0,l.removeAttribute("aria-busy"),c=null},M={close:()=>w?w.close():v(),destroy:()=>w?w.destroy():v(),setMode:I=>{var O;w?(O=w.setMode)==null||O.call(w,I):x=I}};return l.setAttribute("aria-busy","true"),Mt(e.config.chunkBase).then(({openPanel:I})=>{S||(l.removeAttribute("aria-busy"),i.classList.add("over"),l.setAttribute("aria-expanded","true"),w=I({root:o,host:t,dock:i,client:e,preloadCall:y,themeControls:s,mode:x,onClose:()=>{c=null,i.classList.remove("over"),l.setAttribute("aria-expanded","false")}}))},()=>{S||(v(),g())}),M}const d=()=>{Mt(e.config.chunkBase).catch(()=>{})};for(const x of["pointerenter","touchstart","focus"])l.addEventListener(x,d,{once:!0,passive:!0});const p=qt(d);function y(){Te(e.config.chunkBase).catch(()=>{})}let k=null;function g(){b(),k=document.createElement("div"),k.className="msg err loadfail",k.setAttribute("role","alert"),k.innerHTML=`${re}<span>The report form didn't load. Check your connection and try again.</span><button type="button" data-act="retry">Try again</button><button type="button" data-act="dismiss" aria-label="Dismiss">${be}</button>`,k.querySelector('[data-act="retry"]').addEventListener("click",()=>{l.focus(),c||(c=f())}),k.querySelector('[data-act="dismiss"]').addEventListener("click",()=>{l.focus(),b()}),i.prepend(k)}function b(){k==null||k.remove(),k=null}let m=null;function u(x){$(),m=Bt(x,{where:"launcher",onDismiss:w=>{e.dismissAnnouncement(w),l.focus(),$()}}),k?k.after(m):i.prepend(m)}function $(){m==null||m.remove(),m=null}const C=e.config.announcements===!1?()=>{}:qt(()=>{e.announcements().then(x=>{const w=x.find(S=>S.placement==="launcher");w&&!c&&t.isConnected&&u(w)}).catch(()=>{})});return i.append(l),o.appendChild(i),document.body.appendChild(t),e.widgetControls={open:x=>{if(c){x&&c.setMode(x);return}h=x||"report",l.click()},close:()=>{c==null||c.close()},isOpen:()=>!!c},()=>{p(),C(),c==null||c.destroy(),t.remove(),e.widgetControls=null}}function uo(e){return e==="dark"||e==="light"?e:"auto"}function zt(e){return e==="dark"?"bc-dark":e==="light"?"bc-light":"bc-auto"}function qt(e){let t=()=>{};const n=()=>{if(typeof requestIdleCallback=="function"){const o=requestIdleCallback(e,{timeout:5e3});t=()=>cancelIdleCallback(o)}else{const o=setTimeout(e,1500);t=()=>clearTimeout(o)}};return document.readyState==="complete"?n():(window.addEventListener("load",n,{once:!0}),t=()=>window.removeEventListener("load",n)),()=>t()}const po="Too many requests are being sent from here at the moment. Please try again in a minute.";function ce(e){return e||po}const ho=typeof window<"u"&&window.fetch?window.fetch.bind(window):null,fo=typeof XMLHttpRequest<"u"?XMLHttpRequest.prototype.open:null,go=typeof XMLHttpRequest<"u"?XMLHttpRequest.prototype.send:null,Dt=["image/png","image/jpeg","image/webp","image/gif","video/webm","video/mp4","audio/webm","audio/ogg","audio/mpeg","audio/mp4","audio/wav","application/pdf","text/plain","text/csv","application/json","application/zip","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],Ie=["image/png","image/jpeg","image/webp","video/webm","video/mp4"],bo=()=>{var e;return!!((e=navigator==null?void 0:navigator.mediaDevices)!=null&&e.getUserMedia&&typeof MediaRecorder<"u")},mo=()=>{var e;return!!((e=navigator==null?void 0:navigator.mediaDevices)!=null&&e.getDisplayMedia&&typeof MediaRecorder<"u")},yo=()=>{var e;return!!((e=navigator==null?void 0:navigator.mediaDevices)!=null&&e.getDisplayMedia)};function Le(e,t=Dt){const n=String(e||"").split(";")[0].trim().toLowerCase();return t.includes(n)?n:null}async function wo(){const e=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:1},audio:!1});try{const t=e.getVideoTracks()[0],n=document.createElement("video");n.srcObject=e,n.muted=!0,n.playsInline=!0,await n.play(),await new Promise(s=>requestAnimationFrame(()=>requestAnimationFrame(s)));const{width:o,height:a}=t.getSettings(),r=document.createElement("canvas");r.width=o||n.videoWidth,r.height=a||n.videoHeight,r.getContext("2d").drawImage(n,0,0,r.width,r.height);const i=await new Promise(s=>r.toBlob(s,"image/png"));if(!i)throw new Error("The browser returned an empty screenshot.");return{blob:i,mime:"image/png",kind:"SCREENSHOT"}}finally{e.getTracks().forEach(t=>t.stop())}}async function vo({maxMs:e=12e4,onTick:t,onAutoStop:n}={}){const o=await navigator.mediaDevices.getDisplayMedia({video:{frameRate:15},audio:!1}),a=["video/webm;codecs=vp9","video/webm;codecs=vp8","video/webm"].find(p=>MediaRecorder.isTypeSupported(p))||"video/webm",r=new MediaRecorder(o,{mimeType:a,videoBitsPerSecond:25e5}),i=[];r.ondataavailable=p=>{p.data.size&&i.push(p.data)},r.start(1e3);const s=Date.now(),l=setInterval(()=>t==null?void 0:t(Math.floor((Date.now()-s)/1e3)),500),c=()=>{clearInterval(l),clearTimeout(d),o.getTracks().forEach(p=>p.stop())},h=new Promise(p=>{r.onstop=()=>{c(),p(new Blob(i,{type:a}))}}),f=()=>{r.state!=="inactive"&&r.stop(),n==null||n()};o.getVideoTracks()[0].addEventListener("ended",f);const d=setTimeout(f,e);return{mime:a,maxMs:e,async stop(){return clearTimeout(d),r.state!=="inactive"&&r.stop(),{blob:await h,mime:a,kind:"VIDEO"}},cancel(){c(),r.state!=="inactive"&&r.stop()}}}async function xo({maxMs:e=12e4,onTick:t,onAutoStop:n}={}){const o=await navigator.mediaDevices.getUserMedia({audio:!0}),a=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg"].find(p=>MediaRecorder.isTypeSupported(p))||"",r=new MediaRecorder(o,a?{mimeType:a}:void 0),i=[];r.ondataavailable=p=>{p.data.size&&i.push(p.data)},r.start(1e3);const s=Date.now(),l=setInterval(()=>t==null?void 0:t(Math.floor((Date.now()-s)/1e3)),500),c=()=>{clearInterval(l),clearTimeout(d),o.getTracks().forEach(p=>p.stop())},h=new Promise(p=>{r.onstop=()=>{c(),p(new Blob(i,{type:r.mimeType||a}))}}),d=setTimeout(()=>{r.state!=="inactive"&&r.stop(),n==null||n()},e);return{mime:r.mimeType||a,maxMs:e,async stop(){clearTimeout(d),r.state!=="inactive"&&r.stop();const p=await h;return{blob:p,mime:p.type||r.mimeType||a,kind:"AUDIO"}},cancel(){c(),r.state!=="inactive"&&r.stop()}}}async function ko({apiBase:e,apiKey:t,blob:n,mime:o,onProgress:a}){var c;const r=Le(o||n.type);if(!r)throw new Error(`[BugCatch] ${o||n.type||"that file"} can't be attached.`);const i=await ho(`${e}/ingest/presign`,{method:"POST",headers:{"Content-Type":"application/json","X-BugCatch-Key":t},body:JSON.stringify({mime:r})});if(i.status===429){let h="";try{h=((c=await i.json())==null?void 0:c.message)||""}catch{}throw new Error(`[BugCatch] ${ce(typeof h=="string"?h:"")}`)}if(!i.ok)throw new Error(`[BugCatch] could not start the upload (HTTP ${i.status}).`);const{key:s,uploadUrl:l}=await i.json();return await So(l,n,r,a),{storageKey:s,mime:r}}function So(e,t,n,o){return new Promise((a,r)=>{const i=new XMLHttpRequest;fo.call(i,"PUT",e,!0),i.setRequestHeader("Content-Type",n),i.upload.onprogress=s=>{s.lengthComputable&&(o==null||o(s.loaded/s.total))},i.onload=()=>{i.status>=200&&i.status<300?a():r(new Error(`[BugCatch] upload failed (HTTP ${i.status}).`))},i.onerror=()=>r(new Error("[BugCatch] the browser blocked the upload to storage. If this is a new environment, the media bucket is probably missing its CORS policy.")),i.onabort=()=>r(new Error("[BugCatch] upload cancelled.")),go.call(i,t)})}function he(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(0)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Ae(e){const t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,"0")}`}const Me="bugcatch.watch",Ht=[2e3,5e3,15e3,3e4,6e4],$o=5e3;let ye=null;function Co(e){ye=e||null}const et=()=>ye?`${Me}:${ye}`:Me;function Be(){return ye?`?projectId=${encodeURIComponent(ye)}`:""}function F(){try{const e=window.localStorage;return(e==null?void 0:e.getItem(et()))||(e==null?void 0:e.getItem(Me))||null}catch{return null}}function tt(e){var t;if(e)try{(t=window.localStorage)==null||t.setItem(et(),e)}catch{}}function le(){var e,t;try{(e=window.localStorage)==null||e.removeItem(et()),(t=window.localStorage)==null||t.removeItem(Me)}catch{}Qt()}const Re="bugcatch.unread";function To(e){return[(e==null?void 0:e.bugId)||"report",(e==null?void 0:e.kind)||"status",(e==null?void 0:e.at)||""].join("|")}function we(){var e;try{const t=(e=window.localStorage)==null?void 0:e.getItem(Re),n=t?JSON.parse(t):[];return Array.isArray(n)?n.filter(o=>o&&typeof o.id=="string"):[]}catch{return[]}}function je(e){var t,n;try{e.length?(t=window.localStorage)==null||t.setItem(Re,JSON.stringify(e)):(n=window.localStorage)==null||n.removeItem(Re)}catch{}}function Eo(e){const t={...e,id:To(e)},n=we().filter(o=>o.id!==t.id);return n.push(t),je(n.slice(-20)),t}function Io(e){const t=we().filter(n=>n.id!==e);return je(t),t}function Lo(e){const t=we().filter(n=>n.bugId!==e);return je(t),t}function Qt(){return je([]),[]}function Ao(e,t){let n=e,o=n.indexOf(`
304
304
 
305
305
  `);for(;o!==-1;){const a=n.slice(0,o);n=n.slice(o+2);const r=a.split(`
306
306
  `).filter(i=>i.startsWith("data:")).map(i=>i.slice(5).trim()).join(`
307
307
  `);if(r)try{t(JSON.parse(r))}catch{}o=n.indexOf(`
308
308
 
309
- `)}return n}async function To({apiBase:e}){const t=V();if(!t)return{reporter:null,reports:[]};const n=await fetch(`${e}/ingest/watch/reports${Me()}`,{headers:{Authorization:`Bearer ${t}`}});if(n.status===401)return ce(),{reporter:null,reports:[]};if(!n.ok)throw new Error(`[BugCatch] could not load your reports (HTTP ${n.status})`);return n.json()}async function Eo({apiBase:e,bugId:t}){const n=V();if(!n)return null;const o=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}${Me()}`,{headers:{Authorization:`Bearer ${n}`}});if(o.status===401)return ce(),null;if(o.status===404)return null;if(!o.ok)throw new Error(`[BugCatch] could not load that report (HTTP ${o.status})`);return o.json()}async function Io({apiBase:e,bugId:t,body:n,attachments:o}){const a=V();if(!a)throw new Error("[BugCatch] nothing filed from this browser yet.");const r=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/messages`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({...n?{body:n}:{},...o!=null&&o.length?{attachments:o}:{}})});if(r.status===401)throw ce(),new Error("[BugCatch] this browser can no longer prove it filed that report.");if(!r.ok){let i="";try{const s=await r.json();i=Array.isArray(s.message)?s.message.join(", "):s.message||""}catch{}throw r.status===429?new Error(pe(i)):new Error(i||`[BugCatch] could not send that (HTTP ${r.status}).`)}return r.json()}async function Lo({apiBase:e,apiKey:t,projectId:n}){const o={agent:!1,live:!1};try{const a=await fetch(`${e}/ingest/calls?projectId=${encodeURIComponent(n)}`,{headers:{"X-BugCatch-Key":t}});if(!a.ok)return o;const r=await a.json();return r!=null&&r.available?r.kinds&&typeof r.kinds=="object"?{agent:!1,live:!!r.kinds.live}:{agent:!1,live:r.kind==="live"}:o}catch{return o}}async function Ao({apiBase:e,apiKey:t,token:n,payload:o,watchToken:a}){const r=await fetch(`${e}/ingest/calls`,{method:"POST",headers:{"Content-Type":"application/json","X-BugCatch-Key":t,...n?{"X-BugCatch-Session":n}:{}},body:JSON.stringify(a?{...o,watchToken:a}:o)});if(!r.ok){let i="";try{const d=await r.json();i=Array.isArray(d.message)?d.message.join(", "):d.message||""}catch{}const s=new Error(r.status===429?pe(i):i||`[BugCatch] the call could not be started (HTTP ${r.status}).`);throw s.status=r.status,s}return r.json()}async function Dt({apiBase:e,bugId:t}){const n=V();if(!n)return!1;try{const o=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call`,{headers:{Authorization:`Bearer ${n}`}});if(!o.ok)return!1;const a=await o.json();return!!(a!=null&&a.offered)}catch{return!1}}async function Mo({apiBase:e,bugId:t}){const n=V();if(!n)throw new Error("[BugCatch] nothing filed from this browser yet.");const o=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call`,{method:"POST",headers:{Authorization:`Bearer ${n}`}});if(o.status===401)throw ce(),new Error("[BugCatch] this browser can no longer prove it filed that report.");if(!o.ok){let a="";try{const r=await o.json();a=Array.isArray(r.message)?r.message.join(", "):r.message||""}catch{}throw new Error(a||`[BugCatch] the call could not be started (HTTP ${o.status}).`)}return o.json()}async function Bo({apiBase:e,bugId:t,callId:n}){const o=V();if(o)try{await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call/${encodeURIComponent(n)}/give-up`,{method:"POST",headers:{Authorization:`Bearer ${o}`}})}catch{}}async function Ro({apiBase:e,bugId:t,callId:n}){const o=V();if(!o)throw new Error("[BugCatch] nothing filed from this browser yet.");const a=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call/${encodeURIComponent(n)}/answer`,{method:"POST",headers:{Authorization:`Bearer ${o}`}});if(a.status===401)throw ce(),new Error("[BugCatch] this browser can no longer prove it filed that report.");if(a.status===409)throw new Error("[BugCatch] that call is no longer ringing.");if(!a.ok){let r="";try{const i=await a.json();r=Array.isArray(i.message)?i.message.join(", "):i.message||""}catch{}throw new Error(r||`[BugCatch] the call could not be answered (HTTP ${a.status}).`)}return a.json()}async function Qt({apiBase:e,bugId:t,callId:n}){const o=V();if(o)try{await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call/${encodeURIComponent(n)}/decline`,{method:"POST",headers:{Authorization:`Bearer ${o}`}})}catch{}}function jo({apiBase:e,onUpdate:t}){let n=!0,o=0,a=null;async function r(){const i=V();if(!i)throw new Error("nothing filed from this browser yet");a=new AbortController;const s=await fetch(`${e}/ingest/watch/stream${Me()}`,{headers:{Authorization:`Bearer ${i}`,Accept:"text/event-stream"},signal:a.signal});if(s.status===401)throw n=!1,ce(),new Error("subscription no longer valid");if(!s.ok||!s.body)throw new Error(`stream failed (${s.status})`);const d=Date.now(),c=s.body.getReader(),p=new TextDecoder;let f="";try{for(;;){const{value:u,done:h}=await c.read();if(h)break;f+=p.decode(u,{stream:!0}),f=Co(f,m=>{if(m.type!=="ping")try{t(m)}catch{}})}}finally{Date.now()-d>=wo&&(o=0)}}return(async()=>{for(;n;){try{await r()}catch(s){if((s==null?void 0:s.name)==="AbortError")return}if(!n)return;const i=zt[Math.min(o,zt.length-1)];o+=1,await new Promise(s=>setTimeout(s,i))}})(),()=>{n=!1,a==null||a.abort(),a=null}}const Oo={OPEN:"is open",IN_PROGRESS:"is being worked on",RESOLVED:"has been fixed",CLOSED:"has been closed"},zo={status:null,severity:"#f2a54a",assignment:"#79a8ff",reply:"#4fd19a"},X={bg:"#111113",fg:"#f3f2ef",muted:"#b3b0aa",faint:"#8f8c86",ring:"rgba(255,255,255,.09)",brand:"#a59cff"};function Ht(e){return e!=null&&e.summary?e.summary:`Your report ${Oo[e==null?void 0:e.status]||"was updated"}`}function qo(e){var t;return(e==null?void 0:e.kind)==="reply"&&((t=e.reply)!=null&&t.body)?`${e.reply.author?`${e.reply.author}: `:""}${e.reply.body}`:(e==null?void 0:e.title)||""}function Do(e){const t=Date.parse(e||"");if(!Number.isFinite(t))return"";const n=Math.round((Date.now()-t)/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const o=Math.round(n/60);if(o<24)return`${o}h ago`;const a=Math.round(o/24);return a===1?"yesterday":`${a}d ago`}function Qo(){var e;try{const t=document.querySelector('[data-bugcatch="widget"]'),n=(e=t==null?void 0:t.shadowRoot)==null?void 0:e.querySelector(".dock"),o=(n==null?void 0:n.getBoundingClientRect().height)||0;return o?Math.round(o)+12:0}catch{return 0}}function Ho({accent:e=null,position:t="bottom-right",onRead:n=null,onReadAll:o=null,onCall:a=null}={}){const[r,i]=String(t).split("-"),s=r==="top",d=i==="left",c=new Map;let p=null,f=null;function u(){return p!=null&&p.isConnected||(p=document.createElement("div"),p.setAttribute("data-bugcatch","updates"),p.style.cssText=["position:fixed",`${s?"top":"bottom"}:${20+Qo()}px`,`${d?"left":"right"}:20px`,"z-index:2147482998","display:flex","flex-direction:column","gap:10px",`align-items:${d?"flex-start":"flex-end"}`,"width:min(320px,calc(100vw - 40px))","pointer-events:none"].join(";"),document.body.appendChild(p)),p}function h(l){if(!l._bcShown){l.remove();return}l.style.opacity="0",l.style.transform=`translateY(${s?-8:8}px)`,setTimeout(()=>l.remove(),250)}const m=e||Te,C=e?Xe(e):Ye;function w(l,S){const y=document.createElement("button");return y.type="button",y.textContent=l,y.style.cssText=["padding:6px 12px","border:0",`box-shadow:${S?"none":`inset 0 0 0 1px ${X.ring}`}`,"border-radius:999px",`background:${S?m:"rgba(255,255,255,.06)"}`,`color:${S?C:X.fg}`,"font:560 12px/1.4 inherit","cursor:pointer","white-space:nowrap"].join(";"),y}function g(l){var _;const S=document.createElement("div");S.setAttribute("role","status"),S.style.cssText=["box-sizing:border-box","width:100%","padding:13px 14px","border-radius:14px",`background:${X.bg}`,`color:${X.fg}`,'font:13px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif',`box-shadow:0 0 0 1px ${X.ring},0 20px 44px -12px rgba(0,0,0,.55),0 4px 12px rgba(0,0,0,.25)`,"opacity:0",`transform:translateY(${s?-8:8}px)`,"transition:opacity .2s ease,transform .2s ease","pointer-events:auto"].join(";");const y=document.createElement("div");y.style.cssText="display:flex;align-items:baseline;gap:8px;font-weight:600;margin-bottom:2px";const x=document.createElement("span");x.setAttribute("aria-hidden","true"),x.style.cssText=`flex:none;width:7px;height:7px;border-radius:50%;transform:translateY(-1px);background:${zo[l==null?void 0:l.kind]||e||X.brand}`;const v=document.createElement("span");v.textContent=Ht(l),y.append(x,v);const k=document.createElement("div");k.style.cssText=(l==null?void 0:l.kind)==="reply"?`color:${X.muted};padding-left:15px;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden`:`color:${X.muted};padding-left:15px`,k.textContent=qo(l);const T=document.createElement("div");T.style.cssText="display:flex;align-items:center;gap:8px;margin-top:10px;padding-left:15px;flex-wrap:wrap";const j=document.createElement("span");j.style.cssText=`color:${X.faint};font-size:11px;margin-right:auto`,j.textContent=Do(l==null?void 0:l.at);const O=w("Mark as read",!1);if(O.setAttribute("aria-label",`Mark as read: ${Ht(l)}`),O.addEventListener("click",()=>n==null?void 0:n(l.id)),T.append(j,O),(_=l==null?void 0:l.call)!=null&&_.offered&&typeof a=="function"){const Y=w("Talk it through",!0);Y.addEventListener("click",()=>a(l)),T.insertBefore(Y,O)}return S.append(y,k,T),S}function b(l){const S=document.createElement("div");S.style.cssText=["box-sizing:border-box","width:100%","display:flex","align-items:center","gap:8px","padding:8px 10px 8px 14px","border-radius:999px",`background:${X.bg}`,`color:${X.muted}`,'font:12px/1.4 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif',`box-shadow:0 0 0 1px ${X.ring},0 12px 30px -10px rgba(0,0,0,.5)`,"pointer-events:auto"].join(";");const y=document.createElement("span");y.style.cssText="margin-right:auto",y.textContent=`${l} more update${l===1?"":"s"}`;const x=w("Mark all as read",!1);return x.style.cssText+=";padding:4px 9px",x.addEventListener("click",()=>o==null?void 0:o()),S.append(y,x),S}return{render(l){const S=Array.isArray(l)?l:[];if(!S.length){for(const O of c.values())h(O);c.clear(),f==null||f.remove(),f=null,p==null||p.remove(),p=null;return}const y=S.slice(-3),x=new Set(y.map(O=>O.id)),v=u();for(const[O,_]of c)x.has(O)||(h(_),c.delete(O));const k=[];for(const O of y){if(c.has(O.id))continue;const _=g(O);c.set(O.id,_),k.push(_)}const T=s?[...y].reverse():y;for(const O of T)v.appendChild(c.get(O.id));const j=S.length-y.length;j>0?(f==null||f.remove(),f=b(j),s?v.appendChild(f):v.insertBefore(f,v.firstChild)):(f==null||f.remove(),f=null),requestAnimationFrame(()=>{for(const O of k)O.isConnected&&(O._bcShown=!0,O.style.opacity="1",O.style.transform="translateY(0)")})},destroy(){c.clear(),f=null,p==null||p.remove(),p=null}}}async function No({apiBase:e,apiKey:t,projectId:n,sessionToken:o}){try{const a=await fetch(`${e}/ingest/known-issues?projectId=${encodeURIComponent(n)}`,{headers:Ge(t,o)});if(!a.ok)return[];const r=await a.json();return Array.isArray(r==null?void 0:r.issues)?r.issues:[]}catch{return[]}}async function Uo({apiBase:e,apiKey:t,projectId:n,q:o,sessionToken:a,signal:r}){try{const i=`${e}/ingest/known-issues/match?projectId=${encodeURIComponent(n)}&q=${encodeURIComponent(o)}`,s=await fetch(i,{headers:Ge(t,a),signal:r});if(!s.ok)return[];const d=await s.json();return Array.isArray(d==null?void 0:d.issues)?d.issues:[]}catch{return[]}}async function Po({apiBase:e,apiKey:t,projectId:n,bugId:o,reporterEmail:a,reporterName:r,metadata:i,logs:s,sessionToken:d}){const c=V(),p=await fetch(`${e}/ingest/known-issues/${encodeURIComponent(o)}/join`,{method:"POST",headers:Ge(t,d),body:JSON.stringify({projectId:n,reporterEmail:a,reporterName:r,metadata:i,logs:s,...c?{watchToken:c}:{}})});if(!p.ok)throw new Error(await Ko(p));const f=await p.json();return f!=null&&f.watchToken&&Ze(f.watchToken),f}function Ge(e,t){return{"Content-Type":"application/json","X-BugCatch-Key":e,...t?{"X-BugCatch-Session":t}:{}}}async function Ko(e){let t="";try{const n=await e.json();t=Array.isArray(n.message)?n.message.join(", "):n.message||""}catch{}return e.status===429?pe(t):t||`Could not add you to this issue (HTTP ${e.status})`}async function _o({apiBase:e,bugId:t,score:n,comment:o}){const a=V();if(!a)throw new Error("This browser cannot access that report.");const r=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/rating${Me()}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({score:n,...o?{comment:o}:{}})}),i=await r.json().catch(()=>({}));if(!r.ok){const s=Array.isArray(i.message)?i.message.join(", "):i.message;throw new Error(s||"Could not send your rating. Please try again.")}return i}async function Vo({apiBase:e,bugId:t,...n}){const o=V();if(!o)throw new Error("This browser cannot access that report.");const a=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/verification`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(n)}),r=await a.json().catch(()=>({}));if(!a.ok)throw new Error(r.message||"Could not record feedback. Please refresh and try again.");return r}const Fo="bugcatch.session.",et=e=>`${Fo}${e}`,tt=new Map;function ae(e){var t;if(!e)return null;try{const n=(t=window.localStorage)==null?void 0:t.getItem(et(e));if(n){const o=JSON.parse(n);if(o!=null&&o.token)return o}}catch{}return tt.get(e)||null}function Wo(e,t){var o;if(!e||!(t!=null&&t.token))return;const n={token:t.token,email:t.email||null,name:t.name||null};tt.set(e,n);try{(o=window.localStorage)==null||o.setItem(et(e),JSON.stringify(n))}catch{}}function nt(e){var t;if(e){tt.delete(e);try{(t=window.localStorage)==null||t.removeItem(et(e))}catch{}}}function je({apiKey:e,token:t}){return{"Content-Type":"application/json","X-BugCatch-Key":e,...t?{"X-BugCatch-Session":t}:{}}}async function Nt(e){let t="";try{const n=await e.json();t=Array.isArray(n.message)?n.message.join(", "):n.message||""}catch{}return e.status===429?pe(t):t||`Request failed (HTTP ${e.status})`}async function Yo({apiBase:e,apiKey:t,projectId:n,token:o}){const a={mode:"off",signedIn:null,signedOutReason:null};try{const r=await fetch(`${e}/ingest/login?projectId=${encodeURIComponent(n)}`,{headers:je({apiKey:t,token:o})});if(!r.ok)return a;const i=await r.json();return{mode:i.mode==="optional"||i.mode==="required"?i.mode:"off",signedIn:i.signedIn||null,signedOutReason:i.signedOutReason||null}}catch{return a}}async function Xo({apiBase:e,apiKey:t,projectId:n,email:o,name:a}){const r=await fetch(`${e}/ingest/login/start`,{method:"POST",headers:je({apiKey:t}),body:JSON.stringify({projectId:n,email:o,...a?{name:a}:{}})});if(!r.ok)throw new Error(await Nt(r));return r.json()}async function Jo({apiBase:e,apiKey:t,projectId:n,email:o,code:a}){const r=await fetch(`${e}/ingest/login`,{method:"POST",headers:je({apiKey:t}),body:JSON.stringify({projectId:n,email:o,code:a})});if(!r.ok)throw new Error(await Nt(r));const i=await r.json(),s={token:i.sessionToken,email:i.email,name:i.name};return Wo(n,s),s}async function Zo({apiBase:e,apiKey:t,projectId:n,token:o}){if(nt(n),!o)return{signedOut:!0};try{await fetch(`${e}/ingest/logout`,{method:"POST",headers:je({apiKey:t,token:o}),body:JSON.stringify({projectId:n})})}catch{}return{signedOut:!0}}let Ut=!1;if(typeof window<"u"&&window.addEventListener)for(const e of["pointerdown","keydown","touchstart"])window.addEventListener(e,()=>{Ut=!0},{once:!0,capture:!0,passive:!0});function Go(){return Ut}const ea=2e4,Pt=120,ot=200;function Kt(e){if(typeof e!="string"||!e.trim()||e.length>400)return null;try{return new RegExp(e.trim(),"gi")}catch{return null}}const _t=e=>String(e).replace(/\s+/g," ").trim().slice(0,Pt);function Vt(e,t){const n=e&&e.normalize;if(n==="phone"){const o=t.replace(/\D/g,"");return o.length===10?o:o.length===12&&o.startsWith("91")?o.slice(2):o.length===11&&o.startsWith("0")?o.slice(1):t}return n==="upper"?t.toUpperCase():t}function Ft(e){const t=e.length>1&&e[1]!==void 0?e[1]:e[0];return typeof t!="string"||!t.trim()?null:{value:_t(t),start:e.index,end:e.index+e[0].length}}function ta(e,t){return((e.slice(t.start,t.valueStart)+e.slice(t.valueEnd,t.end)).match(/[a-z]/gi)||[]).length}const na=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[A-Za-z0-9][\w-]{5,40}/gi,Wt=/[\w-]/;function oa(e,t){const n=(e||[]).filter(u=>u&&u.scan!==!1&&u.pattern),o=[],a=[],r=(t||[]).map(u=>typeof u=="string"?u.slice(0,ea):"");r.forEach((u,h)=>{u&&n.forEach((m,C)=>{const w=Kt(m.pattern);if(!w)return;let g,b=0;for(w.lastIndex=0;(g=w.exec(u))!==null&&!(++b>ot);){if(g[0]===""){w.lastIndex+=1;continue}const l=Ft(g);if(!l)continue;const S=g.length>1&&g[1]!==void 0?g[1]:g[0],y=g.index+Math.max(0,g[0].indexOf(S)),x={block:h,order:C,key:m.key,label:m.label,value:Vt(m,l.value),start:l.start,end:l.end,valueStart:y,valueEnd:y+S.length};x.weight=ta(u,x),o.push(x)}})});const i=o.filter(u=>!o.some(h=>h!==u&&h.block===u.block&&h.key!==u.key&&h.valueStart<=u.valueStart&&h.valueEnd>=u.valueEnd&&h.weight>u.weight)),s=new Map;for(const u of i){const h=u.value.toLowerCase();s.has(h)||s.set(h,{value:u.value,keys:new Map});const m=s.get(h);m.keys.has(u.key)||m.keys.set(u.key,{key:u.key,label:u.label,order:u.order})}const d=[],c=[],p=new Map;for(const u of s.values()){const h=[...u.keys.values()].sort((w,g)=>w.order-g.order);if(h.length>1){c.push({value:u.value,kinds:h.map(({key:w,label:g})=>({key:w,label:g}))});continue}const[{key:m,label:C}]=h;p.has(m)||p.set(m,[]),p.get(m).push({key:m,label:C,value:u.value})}for(const u of p.values())if(u.length===1)d.push(u[0]);else for(const h of u)c.push({value:h.value,kinds:[{key:h.key,label:h.label}]});const f=new Set(s.keys());return r.forEach((u,h)=>{if(!u)return;const m=o.filter(b=>b.block===h),C=new RegExp(na.source,"gi");let w,g=0;for(;(w=C.exec(u))!==null&&++g<=ot;){const b=w.index,l=b+w[0].length;if(m.some(T=>b<T.end&&l>T.start))continue;const S=u[b-1]||"",y=u[l]||"";if(Wt.test(S)||Wt.test(y)||S==="/"||S==="@"||y==="@"||S==="."||y==="."&&/\w/.test(u[l+1]||"")||!/\d/.test(w[0]))continue;const x=_t(w[0]),v=x.toLowerCase();if(f.has(v))continue;const k=(e||[]).filter(T=>T&&Yt(T,x)).map(({key:T,label:j})=>({key:T,label:j}));k.length&&(f.add(v),a.push({value:x,kinds:k}))}}),{found:d,conflicts:c,loose:a}}function Yt(e,t){const n=typeof t=="string"?t.trim():"";if(!n||n.length>Pt)return null;const o=Kt(e&&(e.valuePattern||e.pattern));if(!o)return null;let a,r=0;for(o.lastIndex=0;(a=o.exec(n))!==null&&!(++r>ot);){if(a[0]===""){o.lastIndex+=1;continue}const i=a.index+a[0].length===n.length,s=a.index===0||a.index===1;if(i&&s){const d=Ft(a);if(d)return Vt(e,d.value)}}return null}async function aa({apiBase:e,apiKey:t,projectId:n}){const o={policy:"off",fields:[]};try{const a=await fetch(`${e}/ingest/reference-fields?projectId=${encodeURIComponent(n)}`,{headers:{"X-BugCatch-Key":t}});if(!a.ok)return o;const r=await a.json(),i=r.policy==="optional"||r.policy==="required"?r.policy:"off",s=Array.isArray(r.fields)?r.fields:[];return s.length?{policy:i,fields:s}:o}catch{return o}}const ra=/Did this answer your question\?/i;async function ia({apiBase:e,apiKey:t,projectId:n}){try{const o=await fetch(`${e}/ingest/agent-issues?projectId=${encodeURIComponent(n)}`,{headers:{"X-BugCatch-Key":t}});if(!o.ok)return[];const a=await o.json();return(Array.isArray(a==null?void 0:a.issues)?a.issues:[]).filter(r=>r&&typeof r.key=="string"&&typeof r.title=="string").map(r=>({key:r.key,title:r.title,hint:typeof r.hint=="string"?r.hint:""}))}catch{return[]}}const sa=5*6e4,Xt="bugcatch:announcements:seen",ca=40,la=["info","success","warning","critical"],Jt=e=>`bugcatch:announcements:${e}`;async function da({apiBase:e,apiKey:t,projectId:n,fresh:o=!1}){var a;if(!o){const r=ma(n);if(r)return r}try{const r=await fetch(`${e}/ingest/announcements?projectId=${encodeURIComponent(n)}`,{headers:{"X-BugCatch-Key":t}}),i=r.ok?ba((a=await r.json())==null?void 0:a.announcements):[];return ya(n,i),i}catch{return[]}}function ua(e,{on:t=fa(),seen:n=Gt()}={}){return(e||[]).filter(o=>ga(o,t)&&!(o.dismissible&&n.includes(Zt(o))))}function pa(e){if(!(!(e!=null&&e.id)||!e.dismissible))try{const t=Zt(e),n=[...Gt().filter(o=>o!==t),t];localStorage.setItem(Xt,JSON.stringify(n.slice(-ca)))}catch{}}function ha(e){return typeof e!="string"||!e||e.startsWith("//")?null:e.startsWith("/")||/^(https?:\/\/|mailto:)./i.test(e)?e:null}function fa(e=new Date){const t=n=>String(n).padStart(2,"0");return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function ga(e,t){return!(e.startsOn&&t<e.startsOn||e.endsOn&&t>e.endsOn)}function Zt(e){return`${e.id}#${e.revision||0}`}function ba(e){return(Array.isArray(e)?e:[]).filter(t=>t&&typeof t.id=="string"&&typeof t.title=="string"&&t.title.trim()).map(t=>{const n=t.placement==="launcher"?"launcher":"panel",o=ha(t.ctaHref);return{id:t.id,revision:Number.isInteger(t.revision)?t.revision:0,title:t.title,body:typeof t.body=="string"?t.body:"",tone:la.includes(t.tone)?t.tone:"info",ctaLabel:o&&typeof t.ctaLabel=="string"?t.ctaLabel:"",ctaHref:o&&typeof t.ctaLabel=="string"?o:"",placement:n,dismissible:n==="launcher"||t.dismissible!==!1,startsOn:typeof t.startsOn=="string"?t.startsOn:"",endsOn:typeof t.endsOn=="string"?t.endsOn:""}})}function Gt(){try{const e=JSON.parse(localStorage.getItem(Xt)||"[]");return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}catch{return[]}}function ma(e){try{const t=JSON.parse(localStorage.getItem(Jt(e))||"null");if(!t||!Array.isArray(t.list)||typeof t.at!="number")return null;const n=Date.now()-t.at;return n>=0&&n<sa?t.list:null}catch{return null}}function ya(e,t){try{localStorage.setItem(Jt(e),JSON.stringify({at:Date.now(),list:t}))}catch{}}const Oe=120,wa=500,ze=30,va=1e3,at={loanId:["loanId","loanNumber"],applicationId:["applicationId"],customerNumber:["customerNumber","customerId"]},xa=/[\u0000-\u001f\u007f]/;function ka(e){if(typeof e=="number")return Number.isFinite(e)?String(e):null;if(typeof e!="string")return null;const t=e.trim();return!t||t.length>Oe||xa.test(t)?null:t}function ee(e){return e===null?"null":Array.isArray(e)?"an array":typeof e=="object"?"an object":`a ${typeof e}`}function rt(e,t,n,o,a){for(const r of n){if(!(r in e)||e[r]===void 0||e[r]===null||e[r]==="")continue;const i=ka(e[r]);if(i)return i;const s=e[r];a(typeof s=="string"&&s.trim().length>Oe?`${o}.${r} is longer than ${Oe} characters and was dropped — pass the identifier itself, not a sentence or a URL.`:`${o}.${r} should be a string or number, got ${ee(s)} — it was dropped.`)}return null}function en(e){if(e===null||typeof e=="boolean")return{ok:!0,value:e};if(typeof e=="number")return Number.isFinite(e)?{ok:!0,value:e}:{ok:!1};if(typeof e=="string")return{ok:!0,value:e.slice(0,wa)};if(typeof e=="object")try{const t=JSON.stringify(e);if(t&&t.length<=va)return{ok:!0,value:JSON.parse(t)}}catch{}return{ok:!1}}const tn=["email","name","phone"],Sa=new Set(["id","userId",...tn,...Object.values(at).flat()]);function nn(e,t=()=>{}){if(e==null)return null;if(typeof e!="object"||Array.isArray(e))return t(`identify() takes an object like { id, email, name } or null, got ${ee(e)} — ignored.`),null;const n={};try{const o=rt(e,"id",["id","userId"],"identify()",t);o&&(n.id=o);for(const r of tn){const i=e[r];if(i==null||i==="")continue;if(r==="phone"&&typeof i=="number"&&Number.isFinite(i)){n.phone=String(i);continue}if(typeof i!="string"){t(`identify().${r} should be a string, got ${ee(i)} — it was dropped.`);continue}const s=i.trim().slice(0,r==="name"?200:Oe);s&&(r==="email"&&!s.includes("@")&&t(`identify().email "${s}" does not look like an email address — reports cannot be threaded or followed up without one.`),n[r]=s)}for(const[r,i]of Object.entries(at)){const s=rt(e,r,i,"identify()",t);s&&(n[r]=s)}let a=0;for(const[r,i]of Object.entries(e)){if(Sa.has(r)||i===void 0||typeof i=="function")continue;if(a>=ze){t(`identify() was given more than ${ze} extra fields; the rest were dropped.`);break}const s=en(i);if(!s.ok){t(`identify().${r} could not be sent (${ee(i)} too large or not serialisable) — dropped.`);continue}n[r]=s.value,a+=1}}catch{}return!n.id&&!n.email&&t("identify() was called without an id or email — reports will not be attributed to anyone, and nothing can be looked up by user."),n}function on(e,t,n=()=>{}){if(t===null)return{};const o={...e||{}};if(t===void 0)return o;if(typeof t!="object"||Array.isArray(t))return n(`setContext() takes an object like { loanId, screen } or null, got ${ee(t)} — ignored.`),o;try{const a=new Map;for(const[r,i]of Object.entries(at))for(const s of i)a.set(s,r);for(const[r,i]of Object.entries(t)){const s=a.get(r);if(i==null){delete o[s||r];continue}if(s){const c=rt({[r]:i},s,[r],"setContext()",n);c?o[s]=c:delete o[s];continue}if(typeof i=="function")continue;if(!(r in o)&&Object.keys(o).length>=ze){n(`setContext() holds at most ${ze} keys; "${r}" was dropped.`);continue}const d=en(i);if(!d.ok){n(`setContext().${r} could not be sent (${ee(i)} too large or not serialisable) — dropped.`);continue}o[r]=d.value}}catch{}return o}const an=["apiBase","apiKey","projectId","consoleLimit","networkLimit","captureConsole","captureNetwork","captureErrors","widget","widgetPosition","theme","accent","attachments","maxAttachments","maxAttachmentBytes","maxRecordingMs","beforeSend","user","context","updates","updateToast","onUpdate","voice","onCallState","onIncomingCall","onReportSubmitted","onAssistantPhase","onError","debug","drafts","knownIssues","agentIssues","release","environment","buildId","chunkBase","announcements"],$a=["beforeSend","onUpdate","onCallState","onIncomingCall","onReportSubmitted","onAssistantPhase","onError"];function Ca(e){const t=e.toLowerCase().replace(/[-_]/g,"");return an.find(n=>n.toLowerCase()===t)||null}const rn=/^(your[_-]|<|xxx|todo|changeme)/i,Ta=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Ea(e,{pageHost:t=""}={}){const n=[],o=[];if(!e||typeof e!="object")return n.push("init() takes an options object: BugCatch.init({ apiBase, apiKey, projectId })."),{errors:n,warnings:o};const{apiKey:a,projectId:r,apiBase:i}=e;a?typeof a!="string"?n.push(`apiKey must be a string, got ${ee(a)}.`):rn.test(a)?n.push(`apiKey is still the placeholder "${a}" — paste the key you saved when you created it.`):Ta.test(a)?o.push("apiKey looks like a project id — did you swap apiKey and projectId?"):a.startsWith("bc_")||o.push('apiKey does not look like a BugCatch key (they start with "bc_live_") — reports will be refused with HTTP 401.'):n.push("apiKey is required — create one under Workspace Settings → API Keys."),r?typeof r!="string"?n.push(`projectId must be a string, got ${ee(r)}.`):rn.test(r)?n.push(`projectId is still the placeholder "${r}".`):r.startsWith("bc_")?o.push("projectId looks like an API key — did you swap apiKey and projectId?"):/\s/.test(r)&&o.push("projectId contains whitespace — check it was copied cleanly."):n.push("projectId is required — copy it from Project Settings → Web SDK."),i==null?!t||/^(localhost|127\.|0\.0\.0\.0|\[::1\])/.test(t)||o.push("apiBase is not set, so reports go to http://localhost:3000 — set apiBase to your BugCatch API URL."):(typeof i!="string"||!/^https?:\/\//.test(i))&&o.push(`apiBase should be an absolute http(s) URL, got ${JSON.stringify(i)}.`);for(const s of Object.keys(e)){if(an.includes(s))continue;const d=Ca(s);o.push(d?`unknown option "${s}" — did you mean "${d}"?`:`unknown option "${s}" is ignored.`)}for(const s of $a){const d=e[s];d!=null&&typeof d!="function"&&o.push(`${s} should be a function, got ${ee(d)} — it will not be called.`)}return{errors:n,warnings:o}}function Ia(e){return typeof e=="string"?e.replace(/\/+$/,""):e}const we={name:"@sphoro/bugcatch-web-sdk",version:"0.20.0"},ve={apiBase:"http://localhost:3000",apiKey:null,projectId:null,consoleLimit:100,networkLimit:50,captureConsole:!0,captureNetwork:!0,captureErrors:!0,widget:!0,widgetPosition:"bottom-right",theme:"auto",accent:null,announcements:!0,attachments:!0,maxAttachments:5,maxAttachmentBytes:25*1024*1024,maxRecordingMs:12e4,beforeSend:null,user:null,updates:!0,updateToast:!0,onUpdate:null,voice:!0,onCallState:null,onIncomingCall:null,onReportSubmitted:null,onAssistantPhase:null,onError:null,context:null,chunkBase:null,debug:!1};function La(e){const t=V();return t?{...e,watchToken:t}:e}class sn{constructor(){Rn(this,B);this.config={...ve},this.started=!1,this.teardown=[],this.consoleBuffer=$e(ve.consoleLimit),this.networkBuffer=$e(ve.networkLimit),this.stopWatching=null,this.notifier=null,this.call=null,this.callStarting=!1,this.ringing=null,this.listeners=new Map,this.context={},this.warned=new Set,this.phases=new Map}warn(t){this.warned.has(t)||(this.warned.add(t),console.warn(`[BugCatch] ${t}`))}debugLog(...t){this.config.debug&&console.info("[BugCatch]",...t)}init(t={}){if(this.started)return console.warn("[BugCatch] init() called twice — ignoring the second call."),this;const{errors:n,warnings:o}=Ea(t,{pageHost:typeof location<"u"?location.hostname:""});if(n.length)throw new Error(`[BugCatch] ${n[0]}`);for(const r of o)this.warn(r);const a=this.config.user;return this.config={...ve,...t,apiBase:Ia(t.apiBase??ve.apiBase)},this.config.user=t.user!==void 0?nn(t.user,r=>this.warn(r.replace("identify()","init({ user })"))):a||null,t.context&&this.setContext(t.context),this.consoleBuffer=$e(this.config.consoleLimit),this.networkBuffer=$e(this.config.networkLimit),this.config.captureConsole&&this.teardown.push(Fn(this.consoleBuffer)),this.config.captureNetwork&&this.teardown.push(Wn(this.networkBuffer)),this.config.captureErrors&&this.teardown.push(Yn(this.consoleBuffer)),vo(this.config.projectId),this.config.widget&&this.teardown.push(ao(this)),this.config.updates&&V()&&(this.startWatching(),queueMicrotask(()=>q(this,B,re).call(this))),this.started=!0,q(this,B,jn).call(this),this.debugLog("initialised",{version:we.version,apiBase:this.config.apiBase,projectId:this.config.projectId,user:this.config.user,context:this.context}),this}startWatching(){if(this.stopWatching)return this;this.stopWatching=jo({apiBase:this.config.apiBase,onUpdate:n=>{if(n!=null&&n.incomingCall){q(this,B,Dn).call(this,n);return}if(n!=null&&n.callWithdrawn){q(this,B,Ve).call(this,n.callWithdrawn.callId);return}const o=ko(n);typeof this.config.onUpdate=="function"&&this.config.onUpdate(o),this.emit("update",o),q(this,B,re).call(this)}}),this.teardown.push(()=>{var n;return(n=this.stopWatching)==null?void 0:n.call(this)}),this.teardown.push(()=>q(this,B,Ve).call(this));const t=n=>{(n.key===Be||n.key===null)&&q(this,B,re).call(this)};return window.addEventListener("storage",t),this.teardown.push(()=>window.removeEventListener("storage",t)),this}on(t,n){if(typeof n!="function")return()=>{};const o=this.listeners.get(t)||new Set;return o.add(n),this.listeners.set(t,o),()=>this.off(t,n)}off(t,n){var o;return(o=this.listeners.get(t))==null||o.delete(n),this}emit(t,n){for(const o of this.listeners.get(t)||[])try{o(n)}catch(a){console.error(`[BugCatch] a '${t}' listener threw:`,a)}}unreadUpdates(){return ye()}markUpdateRead(t){return So(t),q(this,B,re).call(this),this}markReportRead(t){return $o(t),q(this,B,re).call(this),this}markUpdatesRead(){return qt(),q(this,B,re).call(this),this}async verifyFix(t,{result:n,resolvedAt:o,note:a}){const r=n==="STILL_HAPPENING"?await q(this,B,_e).call(this,{}):{};return Vo({apiBase:this.config.apiBase,bugId:t,result:n,resolvedAt:o,note:a,metadata:r.metadata,logs:r.logs})}async rate(t,{score:n,comment:o}={}){return _o({apiBase:this.config.apiBase,bugId:t,score:n,comment:o})}async myReport(t){const n=await Eo({apiBase:this.config.apiBase,bugId:t});return q(this,B,On).call(this,t,n==null?void 0:n.assistant),n}replyToReport(t,{body:n,attachments:o}={}){return Io({apiBase:this.config.apiBase,bugId:t,body:n,attachments:o})}async canCallNow(){return!!await this.callKind()}async callKind(){return(await this.callKinds()).live?"live":null}async callKinds(){var n;const t={agent:!1,live:!1};return!this.config.voice||!((n=this.config.user)!=null&&n.email)?t:this.kinds!==void 0?this.kinds:(this.kinds=await Lo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId}),this.kinds)}canCall(t){return this.config.voice?Dt({apiBase:this.config.apiBase,bugId:t}):Promise.resolve(!1)}async startCall(t){var n;if(!this.config.voice)throw new Error("[BugCatch] calling is switched off.");if(this.call||this.callStarting)throw new Error("[BugCatch] a call is already running.");this.callStarting=!0;try{if(!await this.callKind())throw new Error((n=this.config.user)!=null&&n.email?"[BugCatch] calling is not available on this project.":"[BugCatch] a call needs to know who is calling — call identify() with an email first.");return await q(this,B,qn).call(this,t)}finally{this.callStarting=!1}}startLiveCall(t){return this.startCall(t)}canCallTeam(t){return this.config.voice?Dt({apiBase:this.config.apiBase,bugId:t}):Promise.resolve(!1)}endCall(){var t;return(t=this.call)==null||t.hangUp(),this.call=null,this}myReports(){return To({apiBase:this.config.apiBase})}hasReports(){return!!V()}forgetReports(){var t;return(t=this.stopWatching)==null||t.call(this),this.stopWatching=null,this.endCall(),ce(),q(this,B,re).call(this),this}identify(t){const n=nn(t,o=>this.warn(o));return t!=null&&!n?this:(this.config.user=n,this.debugLog("identify",n),this)}setContext(t){return this.context=on(this.context,t,n=>this.warn(n)),this.debugLog("context",this.context),this}getContext(){return{...this.context}}open(){return this.started?this.widgetControls?(this.widgetControls.open(),this):(this.warn("open() needs the built-in widget; it was turned off with widget: false."),this):(this.warn("open() was called before init() — nothing to open yet."),this)}close(){var t;return(t=this.widgetControls)==null||t.close(),this}isOpen(){var t;return!!((t=this.widgetControls)!=null&&t.isOpen())}async uploadAttachment(t,n,o){if(!this.started)throw new Error("[BugCatch] call init() first.");return mo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,blob:t,mime:n||(t==null?void 0:t.type),onProgress:o})}async report({title:t,description:n="",priority:o="MEDIUM",metadata:a={},attachments:r=[],references:i=[],context:s=null,issue:d=null}={}){var w,g,b,l,S,y,x,v;if(!this.started)throw new Error("[BugCatch] call init() first.");if(typeof t!="string"||!t.trim())throw new Error("[BugCatch] a title is required.");["LOW","MEDIUM","HIGH","CRITICAL"].includes(String(o).toUpperCase())||(this.warn(`priority "${o}" is not one of LOW, MEDIUM, HIGH, CRITICAL — sent as MEDIUM.`),o="MEDIUM");const c=(r||[]).filter(k=>(k==null?void 0:k.storageKey)&&Ie(k.mime,Ee)).map(k=>({type:k.type==="VIDEO"?"VIDEO":"SCREENSHOT",storageKey:k.storageKey,mime:Ie(k.mime,Ee)})),p=(Array.isArray(i)?i:[]).filter(k=>k&&typeof k.key=="string"&&k.key&&(typeof k.value=="string"||typeof k.value=="number")).map(k=>({key:k.key.slice(0,64),value:String(k.value).trim().slice(0,120)})).filter(k=>k.value);Array.isArray(i)&&p.length<i.length&&this.warn("report({ references }) takes [{ key, value }] with string values; malformed entries were dropped.");let f=await q(this,B,_e).call(this,{title:t.trim(),description:typeof n=="string"?n:String(n??""),priority:String(o).toUpperCase(),metadata:a,media:c,references:p,context:s,issue:typeof d=="string"&&d?d.slice(0,32):null});const u=q(this,B,ht).call(this,f);if(u===!1)return{cancelled:!0};f=u,this.debugLog("sending report",{title:f.title,user:(w=f.metadata)==null?void 0:w.user,context:(g=f.metadata)==null?void 0:g.context,references:f.references,console:(S=(l=(b=f.logs)==null?void 0:b.console)==null?void 0:l.entries)==null?void 0:S.length,network:(v=(x=(y=f.logs)==null?void 0:y.network)==null?void 0:x.entries)==null?void 0:v.length});const h=ae(this.config.projectId);let m;try{m=await fetch(`${this.config.apiBase}/ingest/bugs`,{method:"POST",headers:{"Content-Type":"application/json","X-BugCatch-Key":this.config.apiKey,...h!=null&&h.token?{"X-BugCatch-Session":h.token}:{}},body:JSON.stringify(La(f))})}catch(k){const T=new Error(`[BugCatch] could not reach ${this.config.apiBase} — check apiBase, and that this site's origin is allowed by the API.`);throw T.cause=k,q(this,B,Ke).call(this,"report",T),T}if(m.status===401&&h&&nt(this.config.projectId),!m.ok){let k="";try{const j=await m.json();k=Array.isArray(j.message)?j.message.join(", "):j.message||""}catch{}m.status===401&&!h&&(k||(k="the apiKey was not accepted")),m.status===403&&(k||(k="the apiKey is not allowed to report to this projectId"));const T=m.status===429?new Error(`[BugCatch] ${pe(k)}`):new Error(`[BugCatch] report failed (HTTP ${m.status})${k?": "+k:""}`);throw T.status=m.status,q(this,B,Ke).call(this,"report",T),T}const C=await m.json();return q(this,B,pt).call(this,C,{title:f.title??t.trim(),via:"form"}),C.watchToken&&(Ze(C.watchToken),this.config.updates&&this.startWatching()),C}loginState(){var t;return Yo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,token:(t=ae(this.config.projectId))==null?void 0:t.token})}referenceFields(){return this.refFields?this.refFields:(this.refFields=aa({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId}),this.refFields)}agentIssues(){return this.agentIssueList?this.agentIssueList:(this.agentIssueList=ia({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId}),this.agentIssueList)}async announcements(){const t=await da({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId});return ua(t)}dismissAnnouncement(t){pa(t)}signedInAs(){const t=ae(this.config.projectId);return t?{email:t.email,name:t.name}:null}signIn(t,{name:n}={}){var o;return Xo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,email:t,name:n??((o=this.config.user)==null?void 0:o.name)??null})}async confirmSignIn(t,n){var a;const o=await Jo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,email:t,code:n});return(a=this.config.user)!=null&&a.email||(this.config.user={email:o.email,name:o.name||void 0}),this.emit("signin",{email:o.email,name:o.name}),{email:o.email,name:o.name}}async signOut(){var o;const t=ae(this.config.projectId),n=await Zo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,token:t==null?void 0:t.token});return t!=null&&t.email&&((o=this.config.user)==null?void 0:o.email)===t.email&&(this.config.user=null),this.emit("signout",{email:(t==null?void 0:t.email)||null}),n}knownIssues(){var t;return No({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,sessionToken:(t=ae(this.config.projectId))==null?void 0:t.token})}matchKnownIssues(t,{signal:n}={}){var o;return Uo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,q:t||"",sessionToken:(o=ae(this.config.projectId))==null?void 0:o.token,signal:n})}async meToo(t,{email:n,name:o}={}){var i,s;const a=ae(this.config.projectId),r=await wt();return Po({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,bugId:t,reporterEmail:n||((i=this.config.user)==null?void 0:i.email),reporterName:o||((s=this.config.user)==null?void 0:s.name),metadata:{...r,user:this.config.user||void 0,...Object.keys(this.context).length?{context:this.context}:{},sdk:we},logs:{console:{entries:this.consoleBuffer.all()},network:{entries:this.networkBuffer.all()}},sessionToken:a==null?void 0:a.token})}snapshot(){return{user:this.config.user||null,context:{...this.context},console:this.consoleBuffer.all(),network:this.networkBuffer.all(),environment:vt()}}clear(){this.consoleBuffer.clear(),this.networkBuffer.clear()}destroy(){this.endCall(),this.teardown.forEach(t=>{try{t()}catch{}}),this.teardown=[],this.notifier=null,this.started=!1}}B=new WeakSet,Pe=function(t,n){const o=this.config[t];if(typeof o=="function")try{o(n)}catch(a){console.error(`[BugCatch] your ${t} callback threw:`,a)}},jn=function(){if(typeof window>"u"||typeof fetch!="function")return;const t=`bugcatch:hello:${this.config.projectId}`,n=new Date().toISOString().slice(0,10);try{if(window.localStorage.getItem(t)===n)return}catch{}const o=setTimeout(()=>{try{window.localStorage.setItem(t,n)}catch{}fetch(`${this.config.apiBase}/ingest/hello`,{method:"POST",keepalive:!0,headers:{"Content-Type":"application/json","X-BugCatch-Key":this.config.apiKey},body:JSON.stringify({projectId:this.config.projectId,version:we.version,identify:!!this.config.user,context:!!(this.context&&Object.keys(this.context).length),widget:!!this.config.widget,environment:this.config.environment||null,release:this.config.release||null})}).catch(()=>{})},5e3);this.teardown.push(()=>clearTimeout(o))},re=function(){const t=ye();if(this.emit("unread",{count:t.length,updates:t}),!!this.config.updateToast){if(!this.notifier){if(!t.length)return;this.notifier=Ho({accent:this.config.accent,position:this.config.widgetPosition,onRead:n=>this.markUpdateRead(n),onReadAll:()=>this.markUpdatesRead(),onCall:this.config.voice?n=>{this.markUpdateRead(n.id),this.startCall(n.bugId)}:null}),this.teardown.push(()=>{var n;return(n=this.notifier)==null?void 0:n.destroy()})}this.notifier.render(t)}},On=function(t,n){const o=n==null?void 0:n.phase;if(!t||typeof o!="string"||this.phases.get(t)===o)return;this.phases.set(t,o);const a={bugId:t,phase:o,title:n.title??null,detail:n.detail??null};this.debugLog("assistant",a),q(this,B,Pe).call(this,"onAssistantPhase",a),this.emit("assistant",a)},pt=function(t,{title:n,via:o}){if(!(t!=null&&t.id))return;const a={bugId:t.id,title:n??null,via:o,result:t};this.debugLog("report accepted",a),q(this,B,Pe).call(this,"onReportSubmitted",a),this.emit("report",a)},Ke=function(t,n){q(this,B,Pe).call(this,"onError",{action:t,error:n}),this.emit("error",{action:t,error:n})},_e=async function({title:t,description:n="",priority:o="MEDIUM",metadata:a={},media:r=[],references:i=[],context:s=null,issue:d=null}){var p,f;const c=s?on(this.context,s,u=>this.warn(u.replace("setContext()","report({ context })"))):this.context;return{projectId:this.config.projectId,...t?{title:t}:{},description:n,priority:o,url:window.location.href,reporterEmail:(p=this.config.user)==null?void 0:p.email,reporterName:(f=this.config.user)==null?void 0:f.name,metadata:{...await wt(),release:this.config.release,environment:this.config.environment,buildId:this.config.buildId,...a,user:this.config.user||void 0,...Object.keys(c).length?{context:c}:{},sdk:we},logs:{console:{entries:this.consoleBuffer.all()},network:{entries:this.networkBuffer.all()}},...r.length?{attachments:r}:{},...i.length?{references:i}:{},...d?{issue:d}:{}}},ht=function(t){if(typeof this.config.beforeSend!="function")return t;let n;try{n=this.config.beforeSend(t)}catch(o){return this.warn(`beforeSend threw, so nothing was sent: ${(o==null?void 0:o.message)||o}`),!1}return n===!1?!1:n&&typeof n=="object"?n:t},zn=async function(){const t=ae(this.config.projectId),n=q(this,B,ht).call(this,await q(this,B,_e).call(this,{}));if(n===!1)return this.debugLog("call cancelled by beforeSend"),{cancelled:!0};let o;try{o=await Ao({apiBase:this.config.apiBase,apiKey:this.config.apiKey,token:t==null?void 0:t.token,payload:n,watchToken:V()})}catch(a){throw a.status===401&&t&&nt(this.config.projectId),q(this,B,Ke).call(this,"call",a),a}return q(this,B,pt).call(this,o,{title:null,via:"call"}),o.watchToken&&(Ze(o.watchToken),this.config.updates&&this.startWatching()),o},qn=async function(t){const{joinLiveCall:n,liveCallSupported:o,openMicrophone:a}=await Ce(this.config.chunkBase);if(!o())throw new Error("[BugCatch] this browser cannot make live calls.");const r=await a();let i,s=null;try{if(t)i=await Mo({apiBase:this.config.apiBase,bugId:t});else if(s=await q(this,B,zn).call(this),t=s.id,i=s.live_call,!(i!=null&&i.realtime_url)){const c=new Error(`[BugCatch] the report was filed, but the team could not be rung${s.call_error?`: ${s.call_error}`:"."}`);throw c.filed=s,c.reason=s.call_error||null,c}}catch(c){for(const p of r.getTracks())p.stop();throw c}const d=await n({realtimeUrl:i.realtime_url,stream:r,ringsUntil:i.rings_until,onState:(c,p)=>{(c==="ended"||c==="failed"||c==="missed")&&(this.call=null),c==="missed"&&Bo({apiBase:this.config.apiBase,bugId:t,callId:i.call_id}),typeof this.config.onCallState=="function"&&this.config.onCallState(c,{bugId:t,live:!0,...p}),this.emit("call",{bugId:t,live:!0,state:c,...p})}});return this.call=d,Object.assign(d,{bugId:t,callId:i.call_id,live:!0,filed:s,recorded:!!i.recorded})},Dn=function(t){var a;const n=t.incomingCall;if(!this.config.voice||((a=this.ringing)==null?void 0:a.callId)===n.callId||this.call||this.callStarting)return;q(this,B,Ve).call(this);const o={callId:n.callId,dismiss:()=>{}};this.ringing=o,Ce(this.config.chunkBase).then(({liveCallSupported:r,showIncomingCall:i})=>{if(this.ringing!==o||(this.ringing=null,!r())||this.call||this.callStarting)return;const s=i({call:n,accent:this.config.accent,position:this.config.widgetPosition,touched:Go,onAnswer:()=>{q(this,B,Qn).call(this,t.bugId,n)},onDecline:()=>{this.ringing=null,Qt({apiBase:this.config.apiBase,bugId:t.bugId,callId:n.callId}),this.emit("incoming-call",{bugId:t.bugId,callId:n.callId,state:"declined"})},onExpire:()=>{this.ringing=null,this.emit("incoming-call",{bugId:t.bugId,callId:n.callId,state:"missed"})}});if(this.ringing={callId:n.callId,dismiss:s},typeof this.config.onIncomingCall=="function")try{this.config.onIncomingCall({bugId:t.bugId,...n})}catch{}this.emit("incoming-call",{bugId:t.bugId,callId:n.callId,state:"ringing"})},()=>{this.ringing===o&&(this.ringing=null)})},Ve=function(t){if(this.ringing&&!(t&&this.ringing.callId!==t)){try{this.ringing.dismiss()}catch{}this.ringing=null}},Qn=async function(t,n){if(this.ringing=null,this.call||this.callStarting)return;this.callStarting=!0;let o,a;try{const i=await Ce(this.config.chunkBase);a=i.joinLiveCall,o=await i.openMicrophone()}catch(i){this.callStarting=!1,Qt({apiBase:this.config.apiBase,bugId:t,callId:n.callId}),this.emit("incoming-call",{bugId:t,callId:n.callId,state:"failed",error:i});return}let r;try{r=await Ro({apiBase:this.config.apiBase,bugId:t,callId:n.callId})}catch(i){for(const s of o.getTracks())s.stop();this.callStarting=!1,this.emit("incoming-call",{bugId:t,callId:n.callId,state:"missed",error:i});return}try{const i=await a({realtimeUrl:r.realtime_url,stream:o,onState:(s,d)=>{(s==="ended"||s==="failed"||s==="missed")&&(this.call=null),typeof this.config.onCallState=="function"&&this.config.onCallState(s,{bugId:t,live:!0,incoming:!0,...d}),this.emit("call",{bugId:t,live:!0,incoming:!0,state:s,...d})}});this.call=i,this.emit("incoming-call",{bugId:t,callId:n.callId,state:"answered"})}catch(i){for(const s of o.getTracks())s.stop();this.emit("incoming-call",{bugId:t,callId:n.callId,state:"failed",error:i})}finally{this.callStarting=!1}};const it=new sn;it.Client=sn,it.version=we.version;const Aa='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5A1.5 1.5 0 0 1 4.5 7h2.2a1 1 0 0 0 .83-.45l.94-1.4A1 1 0 0 1 9.3 4.7h5.4a1 1 0 0 1 .83.45l.94 1.4a1 1 0 0 0 .83.45h2.2A1.5 1.5 0 0 1 21 8.5v9A1.5 1.5 0 0 1 19.5 19h-15A1.5 1.5 0 0 1 3 17.5z"/><circle cx="12" cy="13" r="3.4"/></svg>',Ma='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="6" width="12.5" height="12" rx="2.2"/><path d="M15.5 10.8l4.2-2.6a.6.6 0 0 1 .92.5v6.6a.6.6 0 0 1-.92.5l-4.2-2.6z"/></svg>',cn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 11.5l-7.6 7.6a4.6 4.6 0 0 1-6.5-6.5l8-8a3.2 3.2 0 0 1 4.5 4.5l-8 8a1.8 1.8 0 0 1-2.5-2.5l7.1-7.1"/></svg>',ln='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="2.5" width="6" height="11" rx="3"/><path d="M5.5 11a6.5 6.5 0 0 0 13 0M12 17.5V21M9 21h6"/></svg>',dn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12l16-8-6 16-2.6-6.2L4 12Z"/></svg>',Ba='<svg viewBox="0 0 24 24" fill="currentColor"><rect x="7" y="7" width="10" height="10" rx="2"/></svg>',Ra='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 5.5L8 12l6.5 6.5"/></svg>',qe='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M6.2 3.5h3l1.5 3.7-2 1.4a11.5 11.5 0 0 0 5.7 5.7l1.4-2 3.7 1.5v3a1.8 1.8 0 0 1-2 1.8A15.6 15.6 0 0 1 4.4 5.5a1.8 1.8 0 0 1 1.8-2z"/></svg>',ja='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 12a8 8 0 1 1-2.6-5.9M20 4v4.5h-4.5"/></svg>',Oa='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9.5 6l6 6-6 6"/></svg>',un='<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2.9l2.75 5.82 6.37.76-4.7 4.37 1.24 6.3L12 17.03l-5.66 3.12 1.24-6.3-4.7-4.37 6.37-.76z"/></svg>',za='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3.5 13.5l2.6-7.2A1.5 1.5 0 0 1 7.5 5.3h9a1.5 1.5 0 0 1 1.4 1L20.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5H5A1.5 1.5 0 0 1 3.5 18z"/><path d="M3.5 13.5h4.8l1.2 2.2h5l1.2-2.2h4.8"/></svg>',qa='<svg class="bc-brand" viewBox="0 0 254 60" fill="none" role="img" aria-label="sphoro BugCatch"><g fill="currentColor"><path transform="translate(0.00 40.00) scale(0.04000 -0.04000)" d="M276.00 -14.00Q179.00 -14.00 117.00 28.00Q55.00 70.00 42.00 148.00L158.00 178.00Q165.00 143.00 181.50 123.00Q198.00 103.00 222.50 94.50Q247.00 86.00 276.00 86.00Q320.00 86.00 341.00 101.50Q362.00 117.00 362.00 140.00Q362.00 163.00 342.00 175.50Q322.00 188.00 278.00 196.00L250.00 201.00Q198.00 211.00 155.00 228.50Q112.00 246.00 86.00 277.00Q60.00 308.00 60.00 357.00Q60.00 431.00 114.00 470.50Q168.00 510.00 256.00 510.00Q339.00 510.00 394.00 473.00Q449.00 436.00 466.00 376.00L349.00 340.00Q341.00 378.00 316.50 394.00Q292.00 410.00 256.00 410.00Q220.00 410.00 201.00 397.50Q182.00 385.00 182.00 363.00Q182.00 339.00 202.00 327.50Q222.00 316.00 256.00 310.00L284.00 305.00Q340.00 295.00 385.50 278.50Q431.00 262.00 457.50 231.50Q484.00 201.00 484.00 149.00Q484.00 71.00 427.50 28.50Q371.00 -14.00 276.00 -14.00Z"/><path transform="translate(19.56 40.00) scale(0.04000 -0.04000)" d="M70.00 -200.00V496.00H194.00V436.00H212.00Q229.00 465.00 265.00 487.50Q301.00 510.00 368.00 510.00Q428.00 510.00 479.00 480.50Q530.00 451.00 561.00 394.00Q592.00 337.00 592.00 256.00V240.00Q592.00 159.00 561.00 102.00Q530.00 45.00 479.00 15.50Q428.00 -14.00 368.00 -14.00Q323.00 -14.00 292.50 -3.50Q262.00 7.00 243.50 23.50Q225.00 40.00 214.00 57.00H196.00V-200.00ZM330.00 96.00Q389.00 96.00 427.50 133.50Q466.00 171.00 466.00 243.00V253.00Q466.00 325.00 427.00 362.50Q388.00 400.00 330.00 400.00Q272.00 400.00 233.00 362.50Q194.00 325.00 194.00 253.00V243.00Q194.00 171.00 233.00 133.50Q272.00 96.00 330.00 96.00Z"/><path transform="translate(43.68 40.00) scale(0.04000 -0.04000)" d="M70.00 0.00V700.00H196.00V435.00H214.00Q222.00 451.00 239.00 467.00Q256.00 483.00 284.50 493.50Q313.00 504.00 357.00 504.00Q415.00 504.00 458.50 477.50Q502.00 451.00 526.00 404.50Q550.00 358.00 550.00 296.00V0.00H424.00V286.00Q424.00 342.00 396.50 370.00Q369.00 398.00 318.00 398.00Q260.00 398.00 228.00 359.50Q196.00 321.00 196.00 252.00V0.00Z"/><path transform="translate(66.92 40.00) scale(0.04000 -0.04000)" d="M306.00 -14.00Q232.00 -14.00 173.00 16.00Q114.00 46.00 80.00 103.00Q46.00 160.00 46.00 240.00V256.00Q46.00 336.00 80.00 393.00Q114.00 450.00 173.00 480.00Q232.00 510.00 306.00 510.00Q380.00 510.00 439.00 480.00Q498.00 450.00 532.00 393.00Q566.00 336.00 566.00 256.00V240.00Q566.00 160.00 532.00 103.00Q498.00 46.00 439.00 16.00Q380.00 -14.00 306.00 -14.00ZM306.00 98.00Q364.00 98.00 402.00 135.50Q440.00 173.00 440.00 243.00V253.00Q440.00 323.00 402.50 360.50Q365.00 398.00 306.00 398.00Q248.00 398.00 210.00 360.50Q172.00 323.00 172.00 253.00V243.00Q172.00 173.00 210.00 135.50Q248.00 98.00 306.00 98.00Z"/><path transform="translate(90.00 40.00) scale(0.04000 -0.04000)" d="M70.00 0.00V496.00H194.00V440.00H212.00Q223.00 470.00 248.50 484.00Q274.00 498.00 308.00 498.00H368.00V386.00H306.00Q258.00 386.00 227.00 360.50Q196.00 335.00 196.00 282.00V0.00Z"/><path transform="translate(104.44 40.00) scale(0.04000 -0.04000)" d="M306.00 -14.00Q232.00 -14.00 173.00 16.00Q114.00 46.00 80.00 103.00Q46.00 160.00 46.00 240.00V256.00Q46.00 336.00 80.00 393.00Q114.00 450.00 173.00 480.00Q232.00 510.00 306.00 510.00Q380.00 510.00 439.00 480.00Q498.00 450.00 532.00 393.00Q566.00 336.00 566.00 256.00V240.00Q566.00 160.00 532.00 103.00Q498.00 46.00 439.00 16.00Q380.00 -14.00 306.00 -14.00ZM306.00 98.00Q364.00 98.00 402.00 135.50Q440.00 173.00 440.00 243.00V253.00Q440.00 323.00 402.50 360.50Q365.00 398.00 306.00 398.00Q248.00 398.00 210.00 360.50Q172.00 323.00 172.00 253.00V243.00Q172.00 173.00 210.00 135.50Q248.00 98.00 306.00 98.00Z"/></g><rect x="139.52" y="16" width="1.6" height="26" rx="0.8" fill="var(--bc-brand-mark, #5647ee)" opacity="0.4"/><g fill="var(--bc-brand-mark, #5647ee)"><path transform="translate(154.52 35.00) scale(0.01400 -0.01400)" d="M46.35 0.00V105.85H139.75V594.15H46.35V700.00H404.08Q467.38 700.00 514.79 678.41Q562.20 656.83 588.70 617.33Q615.20 577.83 615.20 523.35V513.70Q615.20 465.52 597.03 434.76Q578.85 404.00 553.91 387.24Q528.98 370.48 506.28 363.30V346.35Q528.98 340.35 555.24 323.50Q581.50 306.65 600.00 275.48Q618.50 244.30 618.50 194.48V184.48Q618.50 126.65 591.41 85.24Q564.33 43.83 516.83 21.91Q469.33 0.00 406.85 0.00ZM259.85 109.15H392.60Q441.20 109.15 469.80 132.60Q498.40 156.05 498.40 198.55V208.20Q498.40 250.70 470.21 274.15Q442.02 297.60 392.60 297.60H259.85ZM259.85 406.75H391.65Q437.55 406.75 466.32 430.11Q495.10 453.48 495.10 493.80V503.80Q495.10 544.95 466.74 567.90Q438.37 590.85 391.65 590.85H259.85Z"/><path transform="translate(167.00 35.00) scale(0.01400 -0.01400)" d="M335.30 -14.00Q251.22 -14.00 190.60 16.63Q129.97 47.25 97.56 104.96Q65.15 162.68 65.15 243.03V700.00H185.25V239.73Q185.25 170.48 224.03 131.99Q262.80 93.50 335.30 93.50Q407.80 93.50 446.57 131.99Q485.35 170.48 485.35 239.73V700.00H605.45V243.03Q605.45 162.68 573.13 104.96Q540.80 47.25 480.09 16.63Q419.38 -14.00 335.30 -14.00Z"/><path transform="translate(179.60 35.00) scale(0.01400 -0.01400)" d="M311.85 -14.00Q238.45 -14.00 179.69 18.50Q120.92 51.00 86.69 113.67Q52.45 176.35 52.45 266.87V433.13Q52.45 569.00 128.01 641.50Q203.57 714.00 332.35 714.00Q460.13 714.00 529.23 645.59Q598.33 577.17 598.33 460.87V456.70H479.87V464.52Q479.87 504.67 463.76 536.86Q447.65 569.05 414.99 587.77Q382.32 606.50 332.35 606.50Q257.63 606.50 215.09 560.70Q172.55 514.90 172.55 435.13V264.87Q172.55 185.93 215.09 138.89Q257.63 91.85 334.00 91.85Q410.02 91.85 445.12 132.83Q480.22 173.80 480.22 237.92V249.67H302.85V351.88H598.33V0.00H487.52V69.10H470.57Q462.70 50.87 446.06 31.44Q429.42 12.00 397.64 -1.00Q365.85 -14.00 311.85 -14.00Z"/><path transform="translate(192.05 35.00) scale(0.01400 -0.01400)" d="M332.35 -14.00Q203.57 -14.00 128.01 58.50Q52.45 131.00 52.45 266.87V433.13Q52.45 569.00 128.01 641.50Q203.57 714.00 332.35 714.00Q460.13 714.00 529.58 643.85Q599.03 573.70 599.03 451.57V445.75H480.57V455.22Q480.57 521.42 444.15 563.96Q407.72 606.50 332.35 606.50Q257.63 606.50 215.09 560.70Q172.55 514.90 172.55 435.13V264.87Q172.55 185.93 215.09 139.71Q257.63 93.50 332.35 93.50Q407.72 93.50 444.15 136.45Q480.57 179.40 480.57 244.78V262.25H599.03V248.43Q599.03 126.30 529.58 56.15Q460.13 -14.00 332.35 -14.00Z"/><path transform="translate(204.25 35.00) scale(0.01400 -0.01400)" d="M19.75 0.00 211.62 700.00H421.33L613.20 0.00H489.27L447.42 159.60H185.53L143.68 0.00ZM214.25 270.40H418.70L324.95 624.87H308.00Z"/><path transform="translate(216.31 35.00) scale(0.01400 -0.01400)" d="M233.95 0.00V590.85H24.70V700.00H563.30V590.85H354.05V0.00Z"/><path transform="translate(227.75 35.00) scale(0.01400 -0.01400)" d="M332.35 -14.00Q203.57 -14.00 128.01 58.50Q52.45 131.00 52.45 266.87V433.13Q52.45 569.00 128.01 641.50Q203.57 714.00 332.35 714.00Q460.13 714.00 529.58 643.85Q599.03 573.70 599.03 451.57V445.75H480.57V455.22Q480.57 521.42 444.15 563.96Q407.72 606.50 332.35 606.50Q257.63 606.50 215.09 560.70Q172.55 514.90 172.55 435.13V264.87Q172.55 185.93 215.09 139.71Q257.63 93.50 332.35 93.50Q407.72 93.50 444.15 136.45Q480.57 179.40 480.57 244.78V262.25H599.03V248.43Q599.03 126.30 529.58 56.15Q460.13 -14.00 332.35 -14.00Z"/><path transform="translate(239.95 35.00) scale(0.01400 -0.01400)" d="M69.50 0.00V700.00H189.60V405.58H466.40V700.00H586.50V0.00H466.40V296.42H189.60V0.00Z"/></g></svg>',Da=`
309
+ `)}return n}async function Mo({apiBase:e}){const t=F();if(!t)return{reporter:null,reports:[]};const n=await fetch(`${e}/ingest/watch/reports${Be()}`,{headers:{Authorization:`Bearer ${t}`}});if(n.status===401)return le(),{reporter:null,reports:[]};if(!n.ok)throw new Error(`[BugCatch] could not load your reports (HTTP ${n.status})`);return n.json()}async function Bo({apiBase:e,bugId:t}){const n=F();if(!n)return null;const o=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}${Be()}`,{headers:{Authorization:`Bearer ${n}`}});if(o.status===401)return le(),null;if(o.status===404)return null;if(!o.ok)throw new Error(`[BugCatch] could not load that report (HTTP ${o.status})`);return o.json()}async function Ro({apiBase:e,bugId:t,body:n,attachments:o}){const a=F();if(!a)throw new Error("[BugCatch] nothing filed from this browser yet.");const r=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/messages`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({...n?{body:n}:{},...o!=null&&o.length?{attachments:o}:{}})});if(r.status===401)throw le(),new Error("[BugCatch] this browser can no longer prove it filed that report.");if(!r.ok){let i="";try{const s=await r.json();i=Array.isArray(s.message)?s.message.join(", "):s.message||""}catch{}throw r.status===429?new Error(ce(i)):new Error(i||`[BugCatch] could not send that (HTTP ${r.status}).`)}return r.json()}async function jo({apiBase:e,apiKey:t,projectId:n}){const o={agent:!1,live:!1};try{const a=await fetch(`${e}/ingest/calls?projectId=${encodeURIComponent(n)}`,{headers:{"X-BugCatch-Key":t}});if(!a.ok)return o;const r=await a.json();return r!=null&&r.available?r.kinds&&typeof r.kinds=="object"?{agent:!1,live:!!r.kinds.live}:{agent:!1,live:r.kind==="live"}:o}catch{return o}}async function Oo({apiBase:e,apiKey:t,token:n,payload:o,watchToken:a}){const r=await fetch(`${e}/ingest/calls`,{method:"POST",headers:{"Content-Type":"application/json","X-BugCatch-Key":t,...n?{"X-BugCatch-Session":n}:{}},body:JSON.stringify(a?{...o,watchToken:a}:o)});if(!r.ok){let i="";try{const l=await r.json();i=Array.isArray(l.message)?l.message.join(", "):l.message||""}catch{}const s=new Error(r.status===429?ce(i):i||`[BugCatch] the call could not be started (HTTP ${r.status}).`);throw s.status=r.status,s}return r.json()}async function Nt({apiBase:e,bugId:t}){const n=F();if(!n)return!1;try{const o=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call`,{headers:{Authorization:`Bearer ${n}`}});if(!o.ok)return!1;const a=await o.json();return!!(a!=null&&a.offered)}catch{return!1}}async function zo({apiBase:e,bugId:t}){const n=F();if(!n)throw new Error("[BugCatch] nothing filed from this browser yet.");const o=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call`,{method:"POST",headers:{Authorization:`Bearer ${n}`}});if(o.status===401)throw le(),new Error("[BugCatch] this browser can no longer prove it filed that report.");if(!o.ok){let a="";try{const r=await o.json();a=Array.isArray(r.message)?r.message.join(", "):r.message||""}catch{}throw new Error(a||`[BugCatch] the call could not be started (HTTP ${o.status}).`)}return o.json()}async function qo({apiBase:e,bugId:t,callId:n}){const o=F();if(o)try{await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call/${encodeURIComponent(n)}/give-up`,{method:"POST",headers:{Authorization:`Bearer ${o}`}})}catch{}}async function Do({apiBase:e,bugId:t,callId:n}){const o=F();if(!o)throw new Error("[BugCatch] nothing filed from this browser yet.");const a=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call/${encodeURIComponent(n)}/answer`,{method:"POST",headers:{Authorization:`Bearer ${o}`}});if(a.status===401)throw le(),new Error("[BugCatch] this browser can no longer prove it filed that report.");if(a.status===409)throw new Error("[BugCatch] that call is no longer ringing.");if(!a.ok){let r="";try{const i=await a.json();r=Array.isArray(i.message)?i.message.join(", "):i.message||""}catch{}throw new Error(r||`[BugCatch] the call could not be answered (HTTP ${a.status}).`)}return a.json()}async function Kt({apiBase:e,bugId:t,callId:n}){const o=F();if(o)try{await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/live-call/${encodeURIComponent(n)}/decline`,{method:"POST",headers:{Authorization:`Bearer ${o}`}})}catch{}}function Ho({apiBase:e,onUpdate:t}){let n=!0,o=0,a=null;async function r(){const i=F();if(!i)throw new Error("nothing filed from this browser yet");a=new AbortController;const s=await fetch(`${e}/ingest/watch/stream${Be()}`,{headers:{Authorization:`Bearer ${i}`,Accept:"text/event-stream"},signal:a.signal});if(s.status===401)throw n=!1,le(),new Error("subscription no longer valid");if(!s.ok||!s.body)throw new Error(`stream failed (${s.status})`);const l=Date.now(),c=s.body.getReader(),h=new TextDecoder;let f="";try{for(;;){const{value:d,done:p}=await c.read();if(p)break;f+=h.decode(d,{stream:!0}),f=Ao(f,y=>{if(y.type!=="ping")try{t(y)}catch{}})}}finally{Date.now()-l>=$o&&(o=0)}}return(async()=>{for(;n;){try{await r()}catch(s){if((s==null?void 0:s.name)==="AbortError")return}if(!n)return;const i=Ht[Math.min(o,Ht.length-1)];o+=1,await new Promise(s=>setTimeout(s,i))}})(),()=>{n=!1,a==null||a.abort(),a=null}}const Qo={OPEN:"is open",IN_PROGRESS:"is being worked on",RESOLVED:"has been fixed",CLOSED:"has been closed"},No={status:null,severity:"#f2a54a",assignment:"#79a8ff",reply:"#4fd19a"},X={bg:"#111113",fg:"#f3f2ef",muted:"#b3b0aa",faint:"#8f8c86",ring:"rgba(255,255,255,.09)",brand:"#a59cff"};function Pt(e){return e!=null&&e.summary?e.summary:`Your report ${Qo[e==null?void 0:e.status]||"was updated"}`}function Ko(e){var t;return(e==null?void 0:e.kind)==="reply"&&((t=e.reply)!=null&&t.body)?`${e.reply.author?`${e.reply.author}: `:""}${e.reply.body}`:(e==null?void 0:e.title)||""}function Po(e){const t=Date.parse(e||"");if(!Number.isFinite(t))return"";const n=Math.round((Date.now()-t)/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const o=Math.round(n/60);if(o<24)return`${o}h ago`;const a=Math.round(o/24);return a===1?"yesterday":`${a}d ago`}function Uo(){var e;try{const t=document.querySelector('[data-bugcatch="widget"]'),n=(e=t==null?void 0:t.shadowRoot)==null?void 0:e.querySelector(".dock"),o=(n==null?void 0:n.getBoundingClientRect().height)||0;return o?Math.round(o)+12:0}catch{return 0}}function _o({accent:e=null,position:t="bottom-right",onRead:n=null,onReadAll:o=null,onCall:a=null}={}){const[r,i]=String(t).split("-"),s=r==="top",l=i==="left",c=new Map;let h=null,f=null;function d(){return h!=null&&h.isConnected||(h=document.createElement("div"),h.setAttribute("data-bugcatch","updates"),h.style.cssText=["position:fixed",`${s?"top":"bottom"}:${20+Uo()}px`,`${l?"left":"right"}:20px`,"z-index:2147482998","display:flex","flex-direction:column","gap:10px",`align-items:${l?"flex-start":"flex-end"}`,"width:min(320px,calc(100vw - 40px))","pointer-events:none"].join(";"),document.body.appendChild(h)),h}function p(u){if(!u._bcShown){u.remove();return}u.style.opacity="0",u.style.transform=`translateY(${s?-8:8}px)`,setTimeout(()=>u.remove(),250)}const y=e||Ee,k=e?Ge(e):Ze;function g(u,$){const C=document.createElement("button");return C.type="button",C.textContent=u,C.style.cssText=["padding:6px 12px","border:0",`box-shadow:${$?"none":`inset 0 0 0 1px ${X.ring}`}`,"border-radius:999px",`background:${$?y:"rgba(255,255,255,.06)"}`,`color:${$?k:X.fg}`,"font:560 12px/1.4 inherit","cursor:pointer","white-space:nowrap"].join(";"),C}function b(u){var O;const $=document.createElement("div");$.setAttribute("role","status"),$.style.cssText=["box-sizing:border-box","width:100%","padding:13px 14px","border-radius:14px",`background:${X.bg}`,`color:${X.fg}`,'font:13px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif',`box-shadow:0 0 0 1px ${X.ring},0 20px 44px -12px rgba(0,0,0,.55),0 4px 12px rgba(0,0,0,.25)`,"opacity:0",`transform:translateY(${s?-8:8}px)`,"transition:opacity .2s ease,transform .2s ease","pointer-events:auto"].join(";");const C=document.createElement("div");C.style.cssText="display:flex;align-items:baseline;gap:8px;font-weight:600;margin-bottom:2px";const x=document.createElement("span");x.setAttribute("aria-hidden","true"),x.style.cssText=`flex:none;width:7px;height:7px;border-radius:50%;transform:translateY(-1px);background:${No[u==null?void 0:u.kind]||e||X.brand}`;const w=document.createElement("span");w.textContent=Pt(u),C.append(x,w);const S=document.createElement("div");S.style.cssText=(u==null?void 0:u.kind)==="reply"?`color:${X.muted};padding-left:15px;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden`:`color:${X.muted};padding-left:15px`,S.textContent=Ko(u);const v=document.createElement("div");v.style.cssText="display:flex;align-items:center;gap:8px;margin-top:10px;padding-left:15px;flex-wrap:wrap";const M=document.createElement("span");M.style.cssText=`color:${X.faint};font-size:11px;margin-right:auto`,M.textContent=Po(u==null?void 0:u.at);const I=g("Mark as read",!1);if(I.setAttribute("aria-label",`Mark as read: ${Pt(u)}`),I.addEventListener("click",()=>n==null?void 0:n(u.id)),v.append(M,I),(O=u==null?void 0:u.call)!=null&&O.offered&&typeof a=="function"){const U=g("Talk it through",!0);U.addEventListener("click",()=>a(u)),v.insertBefore(U,I)}return $.append(C,S,v),$}function m(u){const $=document.createElement("div");$.style.cssText=["box-sizing:border-box","width:100%","display:flex","align-items:center","gap:8px","padding:8px 10px 8px 14px","border-radius:999px",`background:${X.bg}`,`color:${X.muted}`,'font:12px/1.4 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif',`box-shadow:0 0 0 1px ${X.ring},0 12px 30px -10px rgba(0,0,0,.5)`,"pointer-events:auto"].join(";");const C=document.createElement("span");C.style.cssText="margin-right:auto",C.textContent=`${u} more update${u===1?"":"s"}`;const x=g("Mark all as read",!1);return x.style.cssText+=";padding:4px 9px",x.addEventListener("click",()=>o==null?void 0:o()),$.append(C,x),$}return{render(u){const $=Array.isArray(u)?u:[];if(!$.length){for(const I of c.values())p(I);c.clear(),f==null||f.remove(),f=null,h==null||h.remove(),h=null;return}const C=$.slice(-3),x=new Set(C.map(I=>I.id)),w=d();for(const[I,O]of c)x.has(I)||(p(O),c.delete(I));const S=[];for(const I of C){if(c.has(I.id))continue;const O=b(I);c.set(I.id,O),S.push(O)}const v=s?[...C].reverse():C;for(const I of v)w.appendChild(c.get(I.id));const M=$.length-C.length;M>0?(f==null||f.remove(),f=m(M),s?w.appendChild(f):w.insertBefore(f,w.firstChild)):(f==null||f.remove(),f=null),requestAnimationFrame(()=>{for(const I of S)I.isConnected&&(I._bcShown=!0,I.style.opacity="1",I.style.transform="translateY(0)")})},destroy(){c.clear(),f=null,h==null||h.remove(),h=null}}}async function Vo({apiBase:e,apiKey:t,projectId:n,sessionToken:o}){try{const a=await fetch(`${e}/ingest/known-issues?projectId=${encodeURIComponent(n)}`,{headers:nt(t,o)});if(!a.ok)return[];const r=await a.json();return Array.isArray(r==null?void 0:r.issues)?r.issues:[]}catch{return[]}}async function Fo({apiBase:e,apiKey:t,projectId:n,q:o,sessionToken:a,signal:r}){try{const i=`${e}/ingest/known-issues/match?projectId=${encodeURIComponent(n)}&q=${encodeURIComponent(o)}`,s=await fetch(i,{headers:nt(t,a),signal:r});if(!s.ok)return[];const l=await s.json();return Array.isArray(l==null?void 0:l.issues)?l.issues:[]}catch{return[]}}async function Wo({apiBase:e,apiKey:t,projectId:n,bugId:o,reporterEmail:a,reporterName:r,metadata:i,logs:s,sessionToken:l}){const c=F(),h=await fetch(`${e}/ingest/known-issues/${encodeURIComponent(o)}/join`,{method:"POST",headers:nt(t,l),body:JSON.stringify({projectId:n,reporterEmail:a,reporterName:r,metadata:i,logs:s,...c?{watchToken:c}:{}})});if(!h.ok)throw new Error(await Yo(h));const f=await h.json();return f!=null&&f.watchToken&&tt(f.watchToken),f}function nt(e,t){return{"Content-Type":"application/json","X-BugCatch-Key":e,...t?{"X-BugCatch-Session":t}:{}}}async function Yo(e){let t="";try{const n=await e.json();t=Array.isArray(n.message)?n.message.join(", "):n.message||""}catch{}return e.status===429?ce(t):t||`Could not add you to this issue (HTTP ${e.status})`}async function Xo({apiBase:e,bugId:t,score:n,comment:o}){const a=F();if(!a)throw new Error("This browser cannot access that report.");const r=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/rating${Be()}`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${a}`},body:JSON.stringify({score:n,...o?{comment:o}:{}})}),i=await r.json().catch(()=>({}));if(!r.ok){const s=Array.isArray(i.message)?i.message.join(", "):i.message;throw new Error(s||"Could not send your rating. Please try again.")}return i}async function Jo({apiBase:e,bugId:t,...n}){const o=F();if(!o)throw new Error("This browser cannot access that report.");const a=await fetch(`${e}/ingest/watch/reports/${encodeURIComponent(t)}/verification`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(n)}),r=await a.json().catch(()=>({}));if(!a.ok)throw new Error(r.message||"Could not record feedback. Please refresh and try again.");return r}const Zo="bugcatch.session.",ot=e=>`${Zo}${e}`,at=new Map;function te(e){var t;if(!e)return null;try{const n=(t=window.localStorage)==null?void 0:t.getItem(ot(e));if(n){const o=JSON.parse(n);if(o!=null&&o.token)return o}}catch{}return at.get(e)||null}function Go(e,t){var o;if(!e||!(t!=null&&t.token))return;const n={token:t.token,email:t.email||null,name:t.name||null};at.set(e,n);try{(o=window.localStorage)==null||o.setItem(ot(e),JSON.stringify(n))}catch{}}function rt(e){var t;if(e){at.delete(e);try{(t=window.localStorage)==null||t.removeItem(ot(e))}catch{}}}function Oe({apiKey:e,token:t}){return{"Content-Type":"application/json","X-BugCatch-Key":e,...t?{"X-BugCatch-Session":t}:{}}}async function Ut(e){let t="";try{const n=await e.json();t=Array.isArray(n.message)?n.message.join(", "):n.message||""}catch{}return e.status===429?ce(t):t||`Request failed (HTTP ${e.status})`}async function ea({apiBase:e,apiKey:t,projectId:n,token:o}){const a={mode:"off",signedIn:null,signedOutReason:null};try{const r=await fetch(`${e}/ingest/login?projectId=${encodeURIComponent(n)}`,{headers:Oe({apiKey:t,token:o})});if(!r.ok)return a;const i=await r.json();return{mode:i.mode==="optional"||i.mode==="required"?i.mode:"off",signedIn:i.signedIn||null,signedOutReason:i.signedOutReason||null}}catch{return a}}async function ta({apiBase:e,apiKey:t,projectId:n,email:o,name:a}){const r=await fetch(`${e}/ingest/login/start`,{method:"POST",headers:Oe({apiKey:t}),body:JSON.stringify({projectId:n,email:o,...a?{name:a}:{}})});if(!r.ok)throw new Error(await Ut(r));return r.json()}async function na({apiBase:e,apiKey:t,projectId:n,email:o,code:a}){const r=await fetch(`${e}/ingest/login`,{method:"POST",headers:Oe({apiKey:t}),body:JSON.stringify({projectId:n,email:o,code:a})});if(!r.ok)throw new Error(await Ut(r));const i=await r.json(),s={token:i.sessionToken,email:i.email,name:i.name};return Go(n,s),s}async function oa({apiBase:e,apiKey:t,projectId:n,token:o}){if(rt(n),!o)return{signedOut:!0};try{await fetch(`${e}/ingest/logout`,{method:"POST",headers:Oe({apiKey:t,token:o}),body:JSON.stringify({projectId:n})})}catch{}return{signedOut:!0}}let _t=!1;if(typeof window<"u"&&window.addEventListener)for(const e of["pointerdown","keydown","touchstart"])window.addEventListener(e,()=>{_t=!0},{once:!0,capture:!0,passive:!0});function aa(){return _t}const ra=2e4,Vt=120,it=200;function Ft(e){if(typeof e!="string"||!e.trim()||e.length>400)return null;try{return new RegExp(e.trim(),"gi")}catch{return null}}const Wt=e=>String(e).replace(/\s+/g," ").trim().slice(0,Vt);function Yt(e,t){const n=e&&e.normalize;if(n==="phone"){const o=t.replace(/\D/g,"");return o.length===10?o:o.length===12&&o.startsWith("91")?o.slice(2):o.length===11&&o.startsWith("0")?o.slice(1):t}return n==="upper"?t.toUpperCase():t}function Xt(e){const t=e.length>1&&e[1]!==void 0?e[1]:e[0];return typeof t!="string"||!t.trim()?null:{value:Wt(t),start:e.index,end:e.index+e[0].length}}function ia(e,t){return((e.slice(t.start,t.valueStart)+e.slice(t.valueEnd,t.end)).match(/[a-z]/gi)||[]).length}const sa=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[A-Za-z0-9][\w-]{5,40}/gi,Jt=/[\w-]/;function ca(e,t){const n=(e||[]).filter(d=>d&&d.scan!==!1&&d.pattern),o=[],a=[],r=(t||[]).map(d=>typeof d=="string"?d.slice(0,ra):"");r.forEach((d,p)=>{d&&n.forEach((y,k)=>{const g=Ft(y.pattern);if(!g)return;let b,m=0;for(g.lastIndex=0;(b=g.exec(d))!==null&&!(++m>it);){if(b[0]===""){g.lastIndex+=1;continue}const u=Xt(b);if(!u)continue;const $=b.length>1&&b[1]!==void 0?b[1]:b[0],C=b.index+Math.max(0,b[0].indexOf($)),x={block:p,order:k,key:y.key,label:y.label,value:Yt(y,u.value),start:u.start,end:u.end,valueStart:C,valueEnd:C+$.length};x.weight=ia(d,x),o.push(x)}})});const i=o.filter(d=>!o.some(p=>p!==d&&p.block===d.block&&p.key!==d.key&&p.valueStart<=d.valueStart&&p.valueEnd>=d.valueEnd&&p.weight>d.weight)),s=new Map;for(const d of i){const p=d.value.toLowerCase();s.has(p)||s.set(p,{value:d.value,keys:new Map});const y=s.get(p);y.keys.has(d.key)||y.keys.set(d.key,{key:d.key,label:d.label,order:d.order})}const l=[],c=[],h=new Map;for(const d of s.values()){const p=[...d.keys.values()].sort((g,b)=>g.order-b.order);if(p.length>1){c.push({value:d.value,kinds:p.map(({key:g,label:b})=>({key:g,label:b}))});continue}const[{key:y,label:k}]=p;h.has(y)||h.set(y,[]),h.get(y).push({key:y,label:k,value:d.value})}for(const d of h.values())if(d.length===1)l.push(d[0]);else for(const p of d)c.push({value:p.value,kinds:[{key:p.key,label:p.label}]});const f=new Set(s.keys());return r.forEach((d,p)=>{if(!d)return;const y=o.filter(m=>m.block===p),k=new RegExp(sa.source,"gi");let g,b=0;for(;(g=k.exec(d))!==null&&++b<=it;){const m=g.index,u=m+g[0].length;if(y.some(v=>m<v.end&&u>v.start))continue;const $=d[m-1]||"",C=d[u]||"";if(Jt.test($)||Jt.test(C)||$==="/"||$==="@"||C==="@"||$==="."||C==="."&&/\w/.test(d[u+1]||"")||!/\d/.test(g[0]))continue;const x=Wt(g[0]),w=x.toLowerCase();if(f.has(w))continue;const S=(e||[]).filter(v=>v&&Zt(v,x)).map(({key:v,label:M})=>({key:v,label:M}));S.length&&(f.add(w),a.push({value:x,kinds:S}))}}),{found:l,conflicts:c,loose:a}}function Zt(e,t){const n=typeof t=="string"?t.trim():"";if(!n||n.length>Vt)return null;const o=Ft(e&&(e.valuePattern||e.pattern));if(!o)return null;let a,r=0;for(o.lastIndex=0;(a=o.exec(n))!==null&&!(++r>it);){if(a[0]===""){o.lastIndex+=1;continue}const i=a.index+a[0].length===n.length,s=a.index===0||a.index===1;if(i&&s){const l=Xt(a);if(l)return Yt(e,l.value)}}return null}async function la({apiBase:e,apiKey:t,projectId:n}){const o={policy:"off",fields:[]};try{const a=await fetch(`${e}/ingest/reference-fields?projectId=${encodeURIComponent(n)}`,{headers:{"X-BugCatch-Key":t}});if(!a.ok)return o;const r=await a.json(),i=r.policy==="optional"||r.policy==="required"?r.policy:"off",s=Array.isArray(r.fields)?r.fields:[];return s.length?{policy:i,fields:s}:o}catch{return o}}const da=/Did this answer your question\?/i;async function ua({apiBase:e,apiKey:t,projectId:n}){try{const o=await fetch(`${e}/ingest/agent-issues?projectId=${encodeURIComponent(n)}`,{headers:{"X-BugCatch-Key":t}});if(!o.ok)return[];const a=await o.json();return(Array.isArray(a==null?void 0:a.issues)?a.issues:[]).filter(r=>r&&typeof r.key=="string"&&typeof r.title=="string").map(r=>({key:r.key,title:r.title,hint:typeof r.hint=="string"?r.hint:""}))}catch{return[]}}const pa=5*6e4,Gt="bugcatch:announcements:seen",ha=40,fa=["info","success","warning","critical"],en=e=>`bugcatch:announcements:${e}`;async function ga({apiBase:e,apiKey:t,projectId:n,fresh:o=!1}){var a;if(!o){const r=ka(n);if(r)return r}try{const r=await fetch(`${e}/ingest/announcements?projectId=${encodeURIComponent(n)}`,{headers:{"X-BugCatch-Key":t}}),i=r.ok?xa((a=await r.json())==null?void 0:a.announcements):[];return Sa(n,i),i}catch{return[]}}function ba(e,{on:t=wa(),seen:n=nn()}={}){return(e||[]).filter(o=>va(o,t)&&!(o.dismissible&&n.includes(tn(o))))}function ma(e){if(!(!(e!=null&&e.id)||!e.dismissible))try{const t=tn(e),n=[...nn().filter(o=>o!==t),t];localStorage.setItem(Gt,JSON.stringify(n.slice(-ha)))}catch{}}function ya(e){return typeof e!="string"||!e||e.startsWith("//")?null:e.startsWith("/")||/^(https?:\/\/|mailto:)./i.test(e)?e:null}function wa(e=new Date){const t=n=>String(n).padStart(2,"0");return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function va(e,t){return!(e.startsOn&&t<e.startsOn||e.endsOn&&t>e.endsOn)}function tn(e){return`${e.id}#${e.revision||0}`}function xa(e){return(Array.isArray(e)?e:[]).filter(t=>t&&typeof t.id=="string"&&typeof t.title=="string"&&t.title.trim()).map(t=>{const n=t.placement==="launcher"?"launcher":"panel",o=ya(t.ctaHref);return{id:t.id,revision:Number.isInteger(t.revision)?t.revision:0,title:t.title,body:typeof t.body=="string"?t.body:"",tone:fa.includes(t.tone)?t.tone:"info",ctaLabel:o&&typeof t.ctaLabel=="string"?t.ctaLabel:"",ctaHref:o&&typeof t.ctaLabel=="string"?o:"",placement:n,dismissible:n==="launcher"||t.dismissible!==!1,startsOn:typeof t.startsOn=="string"?t.startsOn:"",endsOn:typeof t.endsOn=="string"?t.endsOn:""}})}function nn(){try{const e=JSON.parse(localStorage.getItem(Gt)||"[]");return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}catch{return[]}}function ka(e){try{const t=JSON.parse(localStorage.getItem(en(e))||"null");if(!t||!Array.isArray(t.list)||typeof t.at!="number")return null;const n=Date.now()-t.at;return n>=0&&n<pa?t.list:null}catch{return null}}function Sa(e,t){try{localStorage.setItem(en(e),JSON.stringify({at:Date.now(),list:t}))}catch{}}const on=["idea","praise","confusing","other"],$a=5,an=4e3;async function Ca({apiBase:e,apiKey:t,projectId:n}){try{const o=await fetch(`${e}/ingest/feedback?projectId=${encodeURIComponent(n)}`,{headers:{"X-BugCatch-Key":t}});if(!o.ok)return!1;const a=await o.json();return(a==null?void 0:a.enabled)===!0}catch{return!1}}function Ta({message:e,kind:t,score:n,email:o,name:a}={}){const r=typeof e=="string"?e.trim().slice(0,an):"";if(!r)throw new Error("[BugCatch] feedback needs a message.");const i=typeof n=="string"&&n.trim()!==""?Number(n):n,s=typeof o=="string"?o.trim():"",l=typeof a=="string"?a.trim():"";return{message:r,...on.includes(t)?{kind:t}:{},...Number.isInteger(i)&&i>=1&&i<=$a?{score:i}:{},...s?{email:s.slice(0,254)}:{},...l?{name:l.slice(0,120)}:{}}}async function Ea({apiBase:e,apiKey:t,token:n,payload:o}){let a;try{a=await fetch(`${e}/ingest/feedback`,{method:"POST",headers:{"Content-Type":"application/json","X-BugCatch-Key":t,...n?{"X-BugCatch-Session":n}:{}},body:JSON.stringify(o)})}catch(r){const i=new Error(`[BugCatch] could not reach ${e} — check your connection and try again.`);throw i.cause=r,i}if(!a.ok){let r="";try{const s=await a.json();r=Array.isArray(s.message)?s.message.join(", "):s.message||""}catch{}const i=a.status===429?new Error(`[BugCatch] ${ce(r)}`):new Error(`[BugCatch] ${r||`feedback could not be sent (HTTP ${a.status})`}`);throw i.status=a.status,i}return a.json()}const ze=120,Ia=500,qe=30,La=1e3,st={loanId:["loanId","loanNumber"],applicationId:["applicationId"],customerNumber:["customerNumber","customerId"]},Aa=/[\u0000-\u001f\u007f]/;function Ma(e){if(typeof e=="number")return Number.isFinite(e)?String(e):null;if(typeof e!="string")return null;const t=e.trim();return!t||t.length>ze||Aa.test(t)?null:t}function ne(e){return e===null?"null":Array.isArray(e)?"an array":typeof e=="object"?"an object":`a ${typeof e}`}function ct(e,t,n,o,a){for(const r of n){if(!(r in e)||e[r]===void 0||e[r]===null||e[r]==="")continue;const i=Ma(e[r]);if(i)return i;const s=e[r];a(typeof s=="string"&&s.trim().length>ze?`${o}.${r} is longer than ${ze} characters and was dropped — pass the identifier itself, not a sentence or a URL.`:`${o}.${r} should be a string or number, got ${ne(s)} — it was dropped.`)}return null}function rn(e){if(e===null||typeof e=="boolean")return{ok:!0,value:e};if(typeof e=="number")return Number.isFinite(e)?{ok:!0,value:e}:{ok:!1};if(typeof e=="string")return{ok:!0,value:e.slice(0,Ia)};if(typeof e=="object")try{const t=JSON.stringify(e);if(t&&t.length<=La)return{ok:!0,value:JSON.parse(t)}}catch{}return{ok:!1}}const sn=["email","name","phone"],Ba=new Set(["id","userId",...sn,...Object.values(st).flat()]);function cn(e,t=()=>{}){if(e==null)return null;if(typeof e!="object"||Array.isArray(e))return t(`identify() takes an object like { id, email, name } or null, got ${ne(e)} — ignored.`),null;const n={};try{const o=ct(e,"id",["id","userId"],"identify()",t);o&&(n.id=o);for(const r of sn){const i=e[r];if(i==null||i==="")continue;if(r==="phone"&&typeof i=="number"&&Number.isFinite(i)){n.phone=String(i);continue}if(typeof i!="string"){t(`identify().${r} should be a string, got ${ne(i)} — it was dropped.`);continue}const s=i.trim().slice(0,r==="name"?200:ze);s&&(r==="email"&&!s.includes("@")&&t(`identify().email "${s}" does not look like an email address — reports cannot be threaded or followed up without one.`),n[r]=s)}for(const[r,i]of Object.entries(st)){const s=ct(e,r,i,"identify()",t);s&&(n[r]=s)}let a=0;for(const[r,i]of Object.entries(e)){if(Ba.has(r)||i===void 0||typeof i=="function")continue;if(a>=qe){t(`identify() was given more than ${qe} extra fields; the rest were dropped.`);break}const s=rn(i);if(!s.ok){t(`identify().${r} could not be sent (${ne(i)} too large or not serialisable) — dropped.`);continue}n[r]=s.value,a+=1}}catch{}return!n.id&&!n.email&&t("identify() was called without an id or email — reports will not be attributed to anyone, and nothing can be looked up by user."),n}function lt(e,t,n=()=>{}){if(t===null)return{};const o={...e||{}};if(t===void 0)return o;if(typeof t!="object"||Array.isArray(t))return n(`setContext() takes an object like { loanId, screen } or null, got ${ne(t)} — ignored.`),o;try{const a=new Map;for(const[r,i]of Object.entries(st))for(const s of i)a.set(s,r);for(const[r,i]of Object.entries(t)){const s=a.get(r);if(i==null){delete o[s||r];continue}if(s){const c=ct({[r]:i},s,[r],"setContext()",n);c?o[s]=c:delete o[s];continue}if(typeof i=="function")continue;if(!(r in o)&&Object.keys(o).length>=qe){n(`setContext() holds at most ${qe} keys; "${r}" was dropped.`);continue}const l=rn(i);if(!l.ok){n(`setContext().${r} could not be sent (${ne(i)} too large or not serialisable) — dropped.`);continue}o[r]=l.value}}catch{}return o}const ln=["apiBase","apiKey","projectId","consoleLimit","networkLimit","captureConsole","captureNetwork","captureErrors","widget","widgetPosition","theme","accent","attachments","maxAttachments","maxAttachmentBytes","maxRecordingMs","beforeSend","user","context","updates","updateToast","onUpdate","voice","onCallState","onIncomingCall","onReportSubmitted","onAssistantPhase","onError","debug","drafts","knownIssues","agentIssues","release","environment","buildId","chunkBase","announcements","feedback"],Ra=["beforeSend","onUpdate","onCallState","onIncomingCall","onReportSubmitted","onAssistantPhase","onError"];function ja(e){const t=e.toLowerCase().replace(/[-_]/g,"");return ln.find(n=>n.toLowerCase()===t)||null}const dn=/^(your[_-]|<|xxx|todo|changeme)/i,Oa=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function za(e,{pageHost:t=""}={}){const n=[],o=[];if(!e||typeof e!="object")return n.push("init() takes an options object: BugCatch.init({ apiBase, apiKey, projectId })."),{errors:n,warnings:o};const{apiKey:a,projectId:r,apiBase:i}=e;a?typeof a!="string"?n.push(`apiKey must be a string, got ${ne(a)}.`):dn.test(a)?n.push(`apiKey is still the placeholder "${a}" — paste the key you saved when you created it.`):Oa.test(a)?o.push("apiKey looks like a project id — did you swap apiKey and projectId?"):a.startsWith("bc_")||o.push('apiKey does not look like a BugCatch key (they start with "bc_live_") — reports will be refused with HTTP 401.'):n.push("apiKey is required — create one under Workspace Settings → API Keys."),r?typeof r!="string"?n.push(`projectId must be a string, got ${ne(r)}.`):dn.test(r)?n.push(`projectId is still the placeholder "${r}".`):r.startsWith("bc_")?o.push("projectId looks like an API key — did you swap apiKey and projectId?"):/\s/.test(r)&&o.push("projectId contains whitespace — check it was copied cleanly."):n.push("projectId is required — copy it from Project Settings → Web SDK."),i==null?!t||/^(localhost|127\.|0\.0\.0\.0|\[::1\])/.test(t)||o.push("apiBase is not set, so reports go to http://localhost:3000 — set apiBase to your BugCatch API URL."):(typeof i!="string"||!/^https?:\/\//.test(i))&&o.push(`apiBase should be an absolute http(s) URL, got ${JSON.stringify(i)}.`);for(const s of Object.keys(e)){if(ln.includes(s))continue;const l=ja(s);o.push(l?`unknown option "${s}" — did you mean "${l}"?`:`unknown option "${s}" is ignored.`)}for(const s of Ra){const l=e[s];l!=null&&typeof l!="function"&&o.push(`${s} should be a function, got ${ne(l)} — it will not be called.`)}return{errors:n,warnings:o}}function qa(e){return typeof e=="string"?e.replace(/\/+$/,""):e}const fe={name:"@sphoro/bugcatch-web-sdk",version:"0.21.0"},ve={apiBase:"http://localhost:3000",apiKey:null,projectId:null,consoleLimit:100,networkLimit:50,captureConsole:!0,captureNetwork:!0,captureErrors:!0,widget:!0,widgetPosition:"bottom-right",theme:"auto",accent:null,announcements:!0,feedback:!0,attachments:!0,maxAttachments:5,maxAttachmentBytes:25*1024*1024,maxRecordingMs:12e4,beforeSend:null,user:null,updates:!0,updateToast:!0,onUpdate:null,voice:!0,onCallState:null,onIncomingCall:null,onReportSubmitted:null,onAssistantPhase:null,onError:null,context:null,chunkBase:null,debug:!1};function Da(e){const t=F();return t?{...e,watchToken:t}:e}class un{constructor(){Dn(this,R);this.config={...ve},this.started=!1,this.teardown=[],this.consoleBuffer=Ce(ve.consoleLimit),this.networkBuffer=Ce(ve.networkLimit),this.stopWatching=null,this.notifier=null,this.call=null,this.callStarting=!1,this.ringing=null,this.listeners=new Map,this.context={},this.warned=new Set,this.phases=new Map}warn(t){this.warned.has(t)||(this.warned.add(t),console.warn(`[BugCatch] ${t}`))}debugLog(...t){this.config.debug&&console.info("[BugCatch]",...t)}init(t={}){if(this.started)return console.warn("[BugCatch] init() called twice — ignoring the second call."),this;const{errors:n,warnings:o}=za(t,{pageHost:typeof location<"u"?location.hostname:""});if(n.length)throw new Error(`[BugCatch] ${n[0]}`);for(const r of o)this.warn(r);const a=this.config.user;return this.config={...ve,...t,apiBase:qa(t.apiBase??ve.apiBase)},this.config.user=t.user!==void 0?cn(t.user,r=>this.warn(r.replace("identify()","init({ user })"))):a||null,t.context&&this.setContext(t.context),this.consoleBuffer=Ce(this.config.consoleLimit),this.networkBuffer=Ce(this.config.networkLimit),this.config.captureConsole&&this.teardown.push(Zn(this.consoleBuffer)),this.config.captureNetwork&&this.teardown.push(Gn(this.networkBuffer)),this.config.captureErrors&&this.teardown.push(eo(this.consoleBuffer)),Co(this.config.projectId),this.config.widget&&this.teardown.push(lo(this)),this.config.updates&&F()&&(this.startWatching(),queueMicrotask(()=>D(this,R,ie).call(this))),this.started=!0,D(this,R,Hn).call(this),this.debugLog("initialised",{version:fe.version,apiBase:this.config.apiBase,projectId:this.config.projectId,user:this.config.user,context:this.context}),this}startWatching(){if(this.stopWatching)return this;this.stopWatching=Ho({apiBase:this.config.apiBase,onUpdate:n=>{if(n!=null&&n.incomingCall){D(this,R,Pn).call(this,n);return}if(n!=null&&n.callWithdrawn){D(this,R,We).call(this,n.callWithdrawn.callId);return}const o=Eo(n);typeof this.config.onUpdate=="function"&&this.config.onUpdate(o),this.emit("update",o),D(this,R,ie).call(this)}}),this.teardown.push(()=>{var n;return(n=this.stopWatching)==null?void 0:n.call(this)}),this.teardown.push(()=>D(this,R,We).call(this));const t=n=>{(n.key===Re||n.key===null)&&D(this,R,ie).call(this)};return window.addEventListener("storage",t),this.teardown.push(()=>window.removeEventListener("storage",t)),this}on(t,n){if(typeof n!="function")return()=>{};const o=this.listeners.get(t)||new Set;return o.add(n),this.listeners.set(t,o),()=>this.off(t,n)}off(t,n){var o;return(o=this.listeners.get(t))==null||o.delete(n),this}emit(t,n){for(const o of this.listeners.get(t)||[])try{o(n)}catch(a){console.error(`[BugCatch] a '${t}' listener threw:`,a)}}unreadUpdates(){return we()}markUpdateRead(t){return Io(t),D(this,R,ie).call(this),this}markReportRead(t){return Lo(t),D(this,R,ie).call(this),this}markUpdatesRead(){return Qt(),D(this,R,ie).call(this),this}async verifyFix(t,{result:n,resolvedAt:o,note:a}){const r=n==="STILL_HAPPENING"?await D(this,R,Ve).call(this,{}):{};return Jo({apiBase:this.config.apiBase,bugId:t,result:n,resolvedAt:o,note:a,metadata:r.metadata,logs:r.logs})}async rate(t,{score:n,comment:o}={}){return Xo({apiBase:this.config.apiBase,bugId:t,score:n,comment:o})}async myReport(t){const n=await Bo({apiBase:this.config.apiBase,bugId:t});return D(this,R,Qn).call(this,t,n==null?void 0:n.assistant),n}replyToReport(t,{body:n,attachments:o}={}){return Ro({apiBase:this.config.apiBase,bugId:t,body:n,attachments:o})}async canCallNow(){return!!await this.callKind()}async callKind(){return(await this.callKinds()).live?"live":null}async callKinds(){var n;const t={agent:!1,live:!1};return!this.config.voice||!((n=this.config.user)!=null&&n.email)?t:this.kinds!==void 0?this.kinds:(this.kinds=await jo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId}),this.kinds)}canCall(t){return this.config.voice?Nt({apiBase:this.config.apiBase,bugId:t}):Promise.resolve(!1)}async startCall(t){var n;if(!this.config.voice)throw new Error("[BugCatch] calling is switched off.");if(this.call||this.callStarting)throw new Error("[BugCatch] a call is already running.");this.callStarting=!0;try{if(!await this.callKind())throw new Error((n=this.config.user)!=null&&n.email?"[BugCatch] calling is not available on this project.":"[BugCatch] a call needs to know who is calling — call identify() with an email first.");return await D(this,R,Kn).call(this,t)}finally{this.callStarting=!1}}startLiveCall(t){return this.startCall(t)}canCallTeam(t){return this.config.voice?Nt({apiBase:this.config.apiBase,bugId:t}):Promise.resolve(!1)}endCall(){var t;return(t=this.call)==null||t.hangUp(),this.call=null,this}myReports(){return Mo({apiBase:this.config.apiBase})}hasReports(){return!!F()}forgetReports(){var t;return(t=this.stopWatching)==null||t.call(this),this.stopWatching=null,this.endCall(),le(),D(this,R,ie).call(this),this}identify(t){const n=cn(t,o=>this.warn(o));return t!=null&&!n?this:(this.config.user=n,this.debugLog("identify",n),this)}setContext(t){return this.context=lt(this.context,t,n=>this.warn(n)),this.debugLog("context",this.context),this}getContext(){return{...this.context}}open({mode:t}={}){return this.started?this.widgetControls?(t!==void 0&&t!=="report"&&t!=="feedback"&&(this.warn(`open({ mode: "${t}" }) is not 'report' or 'feedback' — opened the report form.`),t="report"),this.widgetControls.open(t),this):(this.warn("open() needs the built-in widget; it was turned off with widget: false."),this):(this.warn("open() was called before init() — nothing to open yet."),this)}close(){var t;return(t=this.widgetControls)==null||t.close(),this}isOpen(){var t;return!!((t=this.widgetControls)!=null&&t.isOpen())}async uploadAttachment(t,n,o){if(!this.started)throw new Error("[BugCatch] call init() first.");return ko({apiBase:this.config.apiBase,apiKey:this.config.apiKey,blob:t,mime:n||(t==null?void 0:t.type),onProgress:o})}async report({title:t,description:n="",priority:o="MEDIUM",metadata:a={},attachments:r=[],references:i=[],context:s=null,issue:l=null}={}){var g,b,m,u,$,C,x,w;if(!this.started)throw new Error("[BugCatch] call init() first.");if(typeof t!="string"||!t.trim())throw new Error("[BugCatch] a title is required.");["LOW","MEDIUM","HIGH","CRITICAL"].includes(String(o).toUpperCase())||(this.warn(`priority "${o}" is not one of LOW, MEDIUM, HIGH, CRITICAL — sent as MEDIUM.`),o="MEDIUM");const c=(r||[]).filter(S=>(S==null?void 0:S.storageKey)&&Le(S.mime,Ie)).map(S=>({type:S.type==="VIDEO"?"VIDEO":"SCREENSHOT",storageKey:S.storageKey,mime:Le(S.mime,Ie)})),h=(Array.isArray(i)?i:[]).filter(S=>S&&typeof S.key=="string"&&S.key&&(typeof S.value=="string"||typeof S.value=="number")).map(S=>({key:S.key.slice(0,64),value:String(S.value).trim().slice(0,120)})).filter(S=>S.value);Array.isArray(i)&&h.length<i.length&&this.warn("report({ references }) takes [{ key, value }] with string values; malformed entries were dropped.");let f=await D(this,R,Ve).call(this,{title:t.trim(),description:typeof n=="string"?n:String(n??""),priority:String(o).toUpperCase(),metadata:a,media:c,references:h,context:s,issue:typeof l=="string"&&l?l.slice(0,32):null});const d=D(this,R,Fe).call(this,f,{type:"report"});if(d===!1)return{cancelled:!0};f=d,this.debugLog("sending report",{title:f.title,user:(g=f.metadata)==null?void 0:g.user,context:(b=f.metadata)==null?void 0:b.context,references:f.references,console:($=(u=(m=f.logs)==null?void 0:m.console)==null?void 0:u.entries)==null?void 0:$.length,network:(w=(x=(C=f.logs)==null?void 0:C.network)==null?void 0:x.entries)==null?void 0:w.length});const p=te(this.config.projectId);let y;try{y=await fetch(`${this.config.apiBase}/ingest/bugs`,{method:"POST",headers:{"Content-Type":"application/json","X-BugCatch-Key":this.config.apiKey,...p!=null&&p.token?{"X-BugCatch-Session":p.token}:{}},body:JSON.stringify(Da(f))})}catch(S){const v=new Error(`[BugCatch] could not reach ${this.config.apiBase} — check apiBase, and that this site's origin is allowed by the API.`);throw v.cause=S,D(this,R,$e).call(this,"report",v),v}if(y.status===401&&p&&rt(this.config.projectId),!y.ok){let S="";try{const M=await y.json();S=Array.isArray(M.message)?M.message.join(", "):M.message||""}catch{}y.status===401&&!p&&(S||(S="the apiKey was not accepted")),y.status===403&&(S||(S="the apiKey is not allowed to report to this projectId"));const v=y.status===429?new Error(`[BugCatch] ${ce(S)}`):new Error(`[BugCatch] report failed (HTTP ${y.status})${S?": "+S:""}`);throw v.status=y.status,D(this,R,$e).call(this,"report",v),v}const k=await y.json();return D(this,R,mt).call(this,k,{title:f.title??t.trim(),via:"form"}),k.watchToken&&(tt(k.watchToken),this.config.updates&&this.startWatching()),k}loginState(){var t;return ea({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,token:(t=te(this.config.projectId))==null?void 0:t.token})}referenceFields(){return this.refFields?this.refFields:(this.refFields=la({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId}),this.refFields)}agentIssues(){return this.agentIssueList?this.agentIssueList:(this.agentIssueList=ua({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId}),this.agentIssueList)}async announcements(){const t=await ga({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId});return ba(t)}dismissAnnouncement(t){ma(t)}feedbackEnabled(){return this.feedbackState?this.feedbackState:(this.feedbackState=Ca({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId}),this.feedbackState)}async feedback({message:t,kind:n,score:o,email:a,name:r,context:i=null}={}){var f,d,p,y;if(!this.started)throw new Error("[BugCatch] call init() first.");const s=Ta({message:t,kind:n,score:o,email:a??((f=this.config.user)==null?void 0:f.email),name:r??((d=this.config.user)==null?void 0:d.name)});n!=null&&!s.kind&&this.warn(`feedback({ kind: "${n}" }) is not one of idea, praise, confusing, other — sent without one.`);const l=i?lt(this.context,i,k=>this.warn(k.replace("setContext()","feedback({ context })"))):this.context;let c={projectId:this.config.projectId,...s,url:window.location.href,metadata:{...await Je(),release:this.config.release,environment:this.config.environment,buildId:this.config.buildId,user:this.config.user||void 0,...Object.keys(l).length?{context:l}:{},sdk:fe}};const h=D(this,R,Fe).call(this,c,{type:"feedback"});if(h===!1)return{cancelled:!0};c=h,this.debugLog("sending feedback",{kind:c.kind,score:c.score,user:(p=c.metadata)==null?void 0:p.user});try{const k=await Ea({apiBase:this.config.apiBase,apiKey:this.config.apiKey,token:(y=te(this.config.projectId))==null?void 0:y.token,payload:c}),g={id:(k==null?void 0:k.id)??null,kind:c.kind??null,score:c.score??null};return this.debugLog("feedback accepted",g),this.emit("feedback",g),k}catch(k){throw D(this,R,$e).call(this,"feedback",k),k}}signedInAs(){const t=te(this.config.projectId);return t?{email:t.email,name:t.name}:null}signIn(t,{name:n}={}){var o;return ta({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,email:t,name:n??((o=this.config.user)==null?void 0:o.name)??null})}async confirmSignIn(t,n){var a;const o=await na({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,email:t,code:n});return(a=this.config.user)!=null&&a.email||(this.config.user={email:o.email,name:o.name||void 0}),this.emit("signin",{email:o.email,name:o.name}),{email:o.email,name:o.name}}async signOut(){var o;const t=te(this.config.projectId),n=await oa({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,token:t==null?void 0:t.token});return t!=null&&t.email&&((o=this.config.user)==null?void 0:o.email)===t.email&&(this.config.user=null),this.emit("signout",{email:(t==null?void 0:t.email)||null}),n}knownIssues(){var t;return Vo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,sessionToken:(t=te(this.config.projectId))==null?void 0:t.token})}matchKnownIssues(t,{signal:n}={}){var o;return Fo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,q:t||"",sessionToken:(o=te(this.config.projectId))==null?void 0:o.token,signal:n})}async meToo(t,{email:n,name:o}={}){var i,s;const a=te(this.config.projectId),r=await Je();return Wo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,projectId:this.config.projectId,bugId:t,reporterEmail:n||((i=this.config.user)==null?void 0:i.email),reporterName:o||((s=this.config.user)==null?void 0:s.name),metadata:{...r,user:this.config.user||void 0,...Object.keys(this.context).length?{context:this.context}:{},sdk:fe},logs:{console:{entries:this.consoleBuffer.all()},network:{entries:this.networkBuffer.all()}},sessionToken:a==null?void 0:a.token})}snapshot(){return{user:this.config.user||null,context:{...this.context},console:this.consoleBuffer.all(),network:this.networkBuffer.all(),environment:St()}}clear(){this.consoleBuffer.clear(),this.networkBuffer.clear()}destroy(){this.endCall(),this.teardown.forEach(t=>{try{t()}catch{}}),this.teardown=[],this.notifier=null,this.started=!1}}R=new WeakSet,_e=function(t,n){const o=this.config[t];if(typeof o=="function")try{o(n)}catch(a){console.error(`[BugCatch] your ${t} callback threw:`,a)}},Hn=function(){if(typeof window>"u"||typeof fetch!="function")return;const t=`bugcatch:hello:${this.config.projectId}`,n=new Date().toISOString().slice(0,10);try{if(window.localStorage.getItem(t)===n)return}catch{}const o=setTimeout(()=>{try{window.localStorage.setItem(t,n)}catch{}fetch(`${this.config.apiBase}/ingest/hello`,{method:"POST",keepalive:!0,headers:{"Content-Type":"application/json","X-BugCatch-Key":this.config.apiKey},body:JSON.stringify({projectId:this.config.projectId,version:fe.version,identify:!!this.config.user,context:!!(this.context&&Object.keys(this.context).length),widget:!!this.config.widget,environment:this.config.environment||null,release:this.config.release||null})}).catch(()=>{})},5e3);this.teardown.push(()=>clearTimeout(o))},ie=function(){const t=we();if(this.emit("unread",{count:t.length,updates:t}),!!this.config.updateToast){if(!this.notifier){if(!t.length)return;this.notifier=_o({accent:this.config.accent,position:this.config.widgetPosition,onRead:n=>this.markUpdateRead(n),onReadAll:()=>this.markUpdatesRead(),onCall:this.config.voice?n=>{this.markUpdateRead(n.id),this.startCall(n.bugId)}:null}),this.teardown.push(()=>{var n;return(n=this.notifier)==null?void 0:n.destroy()})}this.notifier.render(t)}},Qn=function(t,n){const o=n==null?void 0:n.phase;if(!t||typeof o!="string"||this.phases.get(t)===o)return;this.phases.set(t,o);const a={bugId:t,phase:o,title:n.title??null,detail:n.detail??null};this.debugLog("assistant",a),D(this,R,_e).call(this,"onAssistantPhase",a),this.emit("assistant",a)},mt=function(t,{title:n,via:o}){if(!(t!=null&&t.id))return;const a={bugId:t.id,title:n??null,via:o,result:t};this.debugLog("report accepted",a),D(this,R,_e).call(this,"onReportSubmitted",a),this.emit("report",a)},$e=function(t,n){D(this,R,_e).call(this,"onError",{action:t,error:n}),this.emit("error",{action:t,error:n})},Ve=async function({title:t,description:n="",priority:o="MEDIUM",metadata:a={},media:r=[],references:i=[],context:s=null,issue:l=null}){var h,f;const c=s?lt(this.context,s,d=>this.warn(d.replace("setContext()","report({ context })"))):this.context;return{projectId:this.config.projectId,...t?{title:t}:{},description:n,priority:o,url:window.location.href,reporterEmail:(h=this.config.user)==null?void 0:h.email,reporterName:(f=this.config.user)==null?void 0:f.name,metadata:{...await Je(),release:this.config.release,environment:this.config.environment,buildId:this.config.buildId,...a,user:this.config.user||void 0,...Object.keys(c).length?{context:c}:{},sdk:fe},logs:{console:{entries:this.consoleBuffer.all()},network:{entries:this.networkBuffer.all()}},...r.length?{attachments:r}:{},...i.length?{references:i}:{},...l?{issue:l}:{}}},Fe=function(t,n={type:"report"}){if(typeof this.config.beforeSend!="function")return t;let o;try{o=this.config.beforeSend(t,n)}catch(a){return this.warn(`beforeSend threw, so nothing was sent: ${(a==null?void 0:a.message)||a}`),!1}return o===!1?!1:o&&typeof o=="object"?o:t},Nn=async function(){const t=te(this.config.projectId),n=D(this,R,Fe).call(this,await D(this,R,Ve).call(this,{}));if(n===!1)return this.debugLog("call cancelled by beforeSend"),{cancelled:!0};let o;try{o=await Oo({apiBase:this.config.apiBase,apiKey:this.config.apiKey,token:t==null?void 0:t.token,payload:n,watchToken:F()})}catch(a){throw a.status===401&&t&&rt(this.config.projectId),D(this,R,$e).call(this,"call",a),a}return D(this,R,mt).call(this,o,{title:null,via:"call"}),o.watchToken&&(tt(o.watchToken),this.config.updates&&this.startWatching()),o},Kn=async function(t){const{joinLiveCall:n,liveCallSupported:o,openMicrophone:a}=await Te(this.config.chunkBase);if(!o())throw new Error("[BugCatch] this browser cannot make live calls.");const r=await a();let i,s=null;try{if(t)i=await zo({apiBase:this.config.apiBase,bugId:t});else if(s=await D(this,R,Nn).call(this),t=s.id,i=s.live_call,!(i!=null&&i.realtime_url)){const c=new Error(`[BugCatch] the report was filed, but the team could not be rung${s.call_error?`: ${s.call_error}`:"."}`);throw c.filed=s,c.reason=s.call_error||null,c}}catch(c){for(const h of r.getTracks())h.stop();throw c}const l=await n({realtimeUrl:i.realtime_url,stream:r,ringsUntil:i.rings_until,onState:(c,h)=>{(c==="ended"||c==="failed"||c==="missed")&&(this.call=null),c==="missed"&&qo({apiBase:this.config.apiBase,bugId:t,callId:i.call_id}),typeof this.config.onCallState=="function"&&this.config.onCallState(c,{bugId:t,live:!0,...h}),this.emit("call",{bugId:t,live:!0,state:c,...h})}});return this.call=l,Object.assign(l,{bugId:t,callId:i.call_id,live:!0,filed:s,recorded:!!i.recorded})},Pn=function(t){var a;const n=t.incomingCall;if(!this.config.voice||((a=this.ringing)==null?void 0:a.callId)===n.callId||this.call||this.callStarting)return;D(this,R,We).call(this);const o={callId:n.callId,dismiss:()=>{}};this.ringing=o,Te(this.config.chunkBase).then(({liveCallSupported:r,showIncomingCall:i})=>{if(this.ringing!==o||(this.ringing=null,!r())||this.call||this.callStarting)return;const s=i({call:n,accent:this.config.accent,position:this.config.widgetPosition,touched:aa,onAnswer:()=>{D(this,R,Un).call(this,t.bugId,n)},onDecline:()=>{this.ringing=null,Kt({apiBase:this.config.apiBase,bugId:t.bugId,callId:n.callId}),this.emit("incoming-call",{bugId:t.bugId,callId:n.callId,state:"declined"})},onExpire:()=>{this.ringing=null,this.emit("incoming-call",{bugId:t.bugId,callId:n.callId,state:"missed"})}});if(this.ringing={callId:n.callId,dismiss:s},typeof this.config.onIncomingCall=="function")try{this.config.onIncomingCall({bugId:t.bugId,...n})}catch{}this.emit("incoming-call",{bugId:t.bugId,callId:n.callId,state:"ringing"})},()=>{this.ringing===o&&(this.ringing=null)})},We=function(t){if(this.ringing&&!(t&&this.ringing.callId!==t)){try{this.ringing.dismiss()}catch{}this.ringing=null}},Un=async function(t,n){if(this.ringing=null,this.call||this.callStarting)return;this.callStarting=!0;let o,a;try{const i=await Te(this.config.chunkBase);a=i.joinLiveCall,o=await i.openMicrophone()}catch(i){this.callStarting=!1,Kt({apiBase:this.config.apiBase,bugId:t,callId:n.callId}),this.emit("incoming-call",{bugId:t,callId:n.callId,state:"failed",error:i});return}let r;try{r=await Do({apiBase:this.config.apiBase,bugId:t,callId:n.callId})}catch(i){for(const s of o.getTracks())s.stop();this.callStarting=!1,this.emit("incoming-call",{bugId:t,callId:n.callId,state:"missed",error:i});return}try{const i=await a({realtimeUrl:r.realtime_url,stream:o,onState:(s,l)=>{(s==="ended"||s==="failed"||s==="missed")&&(this.call=null),typeof this.config.onCallState=="function"&&this.config.onCallState(s,{bugId:t,live:!0,incoming:!0,...l}),this.emit("call",{bugId:t,live:!0,incoming:!0,state:s,...l})}});this.call=i,this.emit("incoming-call",{bugId:t,callId:n.callId,state:"answered"})}catch(i){for(const s of o.getTracks())s.stop();this.emit("incoming-call",{bugId:t,callId:n.callId,state:"failed",error:i})}finally{this.callStarting=!1}};const dt=new un;dt.Client=un,dt.version=fe.version;const Ha='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5A1.5 1.5 0 0 1 4.5 7h2.2a1 1 0 0 0 .83-.45l.94-1.4A1 1 0 0 1 9.3 4.7h5.4a1 1 0 0 1 .83.45l.94 1.4a1 1 0 0 0 .83.45h2.2A1.5 1.5 0 0 1 21 8.5v9A1.5 1.5 0 0 1 19.5 19h-15A1.5 1.5 0 0 1 3 17.5z"/><circle cx="12" cy="13" r="3.4"/></svg>',Qa='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="6" width="12.5" height="12" rx="2.2"/><path d="M15.5 10.8l4.2-2.6a.6.6 0 0 1 .92.5v6.6a.6.6 0 0 1-.92.5l-4.2-2.6z"/></svg>',pn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 11.5l-7.6 7.6a4.6 4.6 0 0 1-6.5-6.5l8-8a3.2 3.2 0 0 1 4.5 4.5l-8 8a1.8 1.8 0 0 1-2.5-2.5l7.1-7.1"/></svg>',hn='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="2.5" width="6" height="11" rx="3"/><path d="M5.5 11a6.5 6.5 0 0 0 13 0M12 17.5V21M9 21h6"/></svg>',ut='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12l16-8-6 16-2.6-6.2L4 12Z"/></svg>',Na='<svg viewBox="0 0 24 24" fill="currentColor"><rect x="7" y="7" width="10" height="10" rx="2"/></svg>',Ka='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14.5 5.5L8 12l6.5 6.5"/></svg>',De='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M6.2 3.5h3l1.5 3.7-2 1.4a11.5 11.5 0 0 0 5.7 5.7l1.4-2 3.7 1.5v3a1.8 1.8 0 0 1-2 1.8A15.6 15.6 0 0 1 4.4 5.5a1.8 1.8 0 0 1 1.8-2z"/></svg>',Pa='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M8 6a4 4 0 0 1 8 0"/><rect x="7" y="7.5" width="10" height="12" rx="5"/><path d="M7 11H3.5M7 15.5H4M17 11h3.5M17 15.5h3M12 8v11.5"/></svg>',Ua='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 12a8 8 0 1 1-2.6-5.9M20 4v4.5h-4.5"/></svg>',_a='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9.5 6l6 6-6 6"/></svg>',fn='<svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2.9l2.75 5.82 6.37.76-4.7 4.37 1.24 6.3L12 17.03l-5.66 3.12 1.24-6.3-4.7-4.37 6.37-.76z"/></svg>',Va='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M3.5 13.5l2.6-7.2A1.5 1.5 0 0 1 7.5 5.3h9a1.5 1.5 0 0 1 1.4 1L20.5 13.5V18a1.5 1.5 0 0 1-1.5 1.5H5A1.5 1.5 0 0 1 3.5 18z"/><path d="M3.5 13.5h4.8l1.2 2.2h5l1.2-2.2h4.8"/></svg>',Fa='<svg class="bc-brand" viewBox="0 0 254 60" fill="none" role="img" aria-label="sphoro BugCatch"><g fill="currentColor"><path transform="translate(0.00 40.00) scale(0.04000 -0.04000)" d="M276.00 -14.00Q179.00 -14.00 117.00 28.00Q55.00 70.00 42.00 148.00L158.00 178.00Q165.00 143.00 181.50 123.00Q198.00 103.00 222.50 94.50Q247.00 86.00 276.00 86.00Q320.00 86.00 341.00 101.50Q362.00 117.00 362.00 140.00Q362.00 163.00 342.00 175.50Q322.00 188.00 278.00 196.00L250.00 201.00Q198.00 211.00 155.00 228.50Q112.00 246.00 86.00 277.00Q60.00 308.00 60.00 357.00Q60.00 431.00 114.00 470.50Q168.00 510.00 256.00 510.00Q339.00 510.00 394.00 473.00Q449.00 436.00 466.00 376.00L349.00 340.00Q341.00 378.00 316.50 394.00Q292.00 410.00 256.00 410.00Q220.00 410.00 201.00 397.50Q182.00 385.00 182.00 363.00Q182.00 339.00 202.00 327.50Q222.00 316.00 256.00 310.00L284.00 305.00Q340.00 295.00 385.50 278.50Q431.00 262.00 457.50 231.50Q484.00 201.00 484.00 149.00Q484.00 71.00 427.50 28.50Q371.00 -14.00 276.00 -14.00Z"/><path transform="translate(19.56 40.00) scale(0.04000 -0.04000)" d="M70.00 -200.00V496.00H194.00V436.00H212.00Q229.00 465.00 265.00 487.50Q301.00 510.00 368.00 510.00Q428.00 510.00 479.00 480.50Q530.00 451.00 561.00 394.00Q592.00 337.00 592.00 256.00V240.00Q592.00 159.00 561.00 102.00Q530.00 45.00 479.00 15.50Q428.00 -14.00 368.00 -14.00Q323.00 -14.00 292.50 -3.50Q262.00 7.00 243.50 23.50Q225.00 40.00 214.00 57.00H196.00V-200.00ZM330.00 96.00Q389.00 96.00 427.50 133.50Q466.00 171.00 466.00 243.00V253.00Q466.00 325.00 427.00 362.50Q388.00 400.00 330.00 400.00Q272.00 400.00 233.00 362.50Q194.00 325.00 194.00 253.00V243.00Q194.00 171.00 233.00 133.50Q272.00 96.00 330.00 96.00Z"/><path transform="translate(43.68 40.00) scale(0.04000 -0.04000)" d="M70.00 0.00V700.00H196.00V435.00H214.00Q222.00 451.00 239.00 467.00Q256.00 483.00 284.50 493.50Q313.00 504.00 357.00 504.00Q415.00 504.00 458.50 477.50Q502.00 451.00 526.00 404.50Q550.00 358.00 550.00 296.00V0.00H424.00V286.00Q424.00 342.00 396.50 370.00Q369.00 398.00 318.00 398.00Q260.00 398.00 228.00 359.50Q196.00 321.00 196.00 252.00V0.00Z"/><path transform="translate(66.92 40.00) scale(0.04000 -0.04000)" d="M306.00 -14.00Q232.00 -14.00 173.00 16.00Q114.00 46.00 80.00 103.00Q46.00 160.00 46.00 240.00V256.00Q46.00 336.00 80.00 393.00Q114.00 450.00 173.00 480.00Q232.00 510.00 306.00 510.00Q380.00 510.00 439.00 480.00Q498.00 450.00 532.00 393.00Q566.00 336.00 566.00 256.00V240.00Q566.00 160.00 532.00 103.00Q498.00 46.00 439.00 16.00Q380.00 -14.00 306.00 -14.00ZM306.00 98.00Q364.00 98.00 402.00 135.50Q440.00 173.00 440.00 243.00V253.00Q440.00 323.00 402.50 360.50Q365.00 398.00 306.00 398.00Q248.00 398.00 210.00 360.50Q172.00 323.00 172.00 253.00V243.00Q172.00 173.00 210.00 135.50Q248.00 98.00 306.00 98.00Z"/><path transform="translate(90.00 40.00) scale(0.04000 -0.04000)" d="M70.00 0.00V496.00H194.00V440.00H212.00Q223.00 470.00 248.50 484.00Q274.00 498.00 308.00 498.00H368.00V386.00H306.00Q258.00 386.00 227.00 360.50Q196.00 335.00 196.00 282.00V0.00Z"/><path transform="translate(104.44 40.00) scale(0.04000 -0.04000)" d="M306.00 -14.00Q232.00 -14.00 173.00 16.00Q114.00 46.00 80.00 103.00Q46.00 160.00 46.00 240.00V256.00Q46.00 336.00 80.00 393.00Q114.00 450.00 173.00 480.00Q232.00 510.00 306.00 510.00Q380.00 510.00 439.00 480.00Q498.00 450.00 532.00 393.00Q566.00 336.00 566.00 256.00V240.00Q566.00 160.00 532.00 103.00Q498.00 46.00 439.00 16.00Q380.00 -14.00 306.00 -14.00ZM306.00 98.00Q364.00 98.00 402.00 135.50Q440.00 173.00 440.00 243.00V253.00Q440.00 323.00 402.50 360.50Q365.00 398.00 306.00 398.00Q248.00 398.00 210.00 360.50Q172.00 323.00 172.00 253.00V243.00Q172.00 173.00 210.00 135.50Q248.00 98.00 306.00 98.00Z"/></g><rect x="139.52" y="16" width="1.6" height="26" rx="0.8" fill="var(--bc-brand-mark, #5647ee)" opacity="0.4"/><g fill="var(--bc-brand-mark, #5647ee)"><path transform="translate(154.52 35.00) scale(0.01400 -0.01400)" d="M46.35 0.00V105.85H139.75V594.15H46.35V700.00H404.08Q467.38 700.00 514.79 678.41Q562.20 656.83 588.70 617.33Q615.20 577.83 615.20 523.35V513.70Q615.20 465.52 597.03 434.76Q578.85 404.00 553.91 387.24Q528.98 370.48 506.28 363.30V346.35Q528.98 340.35 555.24 323.50Q581.50 306.65 600.00 275.48Q618.50 244.30 618.50 194.48V184.48Q618.50 126.65 591.41 85.24Q564.33 43.83 516.83 21.91Q469.33 0.00 406.85 0.00ZM259.85 109.15H392.60Q441.20 109.15 469.80 132.60Q498.40 156.05 498.40 198.55V208.20Q498.40 250.70 470.21 274.15Q442.02 297.60 392.60 297.60H259.85ZM259.85 406.75H391.65Q437.55 406.75 466.32 430.11Q495.10 453.48 495.10 493.80V503.80Q495.10 544.95 466.74 567.90Q438.37 590.85 391.65 590.85H259.85Z"/><path transform="translate(167.00 35.00) scale(0.01400 -0.01400)" d="M335.30 -14.00Q251.22 -14.00 190.60 16.63Q129.97 47.25 97.56 104.96Q65.15 162.68 65.15 243.03V700.00H185.25V239.73Q185.25 170.48 224.03 131.99Q262.80 93.50 335.30 93.50Q407.80 93.50 446.57 131.99Q485.35 170.48 485.35 239.73V700.00H605.45V243.03Q605.45 162.68 573.13 104.96Q540.80 47.25 480.09 16.63Q419.38 -14.00 335.30 -14.00Z"/><path transform="translate(179.60 35.00) scale(0.01400 -0.01400)" d="M311.85 -14.00Q238.45 -14.00 179.69 18.50Q120.92 51.00 86.69 113.67Q52.45 176.35 52.45 266.87V433.13Q52.45 569.00 128.01 641.50Q203.57 714.00 332.35 714.00Q460.13 714.00 529.23 645.59Q598.33 577.17 598.33 460.87V456.70H479.87V464.52Q479.87 504.67 463.76 536.86Q447.65 569.05 414.99 587.77Q382.32 606.50 332.35 606.50Q257.63 606.50 215.09 560.70Q172.55 514.90 172.55 435.13V264.87Q172.55 185.93 215.09 138.89Q257.63 91.85 334.00 91.85Q410.02 91.85 445.12 132.83Q480.22 173.80 480.22 237.92V249.67H302.85V351.88H598.33V0.00H487.52V69.10H470.57Q462.70 50.87 446.06 31.44Q429.42 12.00 397.64 -1.00Q365.85 -14.00 311.85 -14.00Z"/><path transform="translate(192.05 35.00) scale(0.01400 -0.01400)" d="M332.35 -14.00Q203.57 -14.00 128.01 58.50Q52.45 131.00 52.45 266.87V433.13Q52.45 569.00 128.01 641.50Q203.57 714.00 332.35 714.00Q460.13 714.00 529.58 643.85Q599.03 573.70 599.03 451.57V445.75H480.57V455.22Q480.57 521.42 444.15 563.96Q407.72 606.50 332.35 606.50Q257.63 606.50 215.09 560.70Q172.55 514.90 172.55 435.13V264.87Q172.55 185.93 215.09 139.71Q257.63 93.50 332.35 93.50Q407.72 93.50 444.15 136.45Q480.57 179.40 480.57 244.78V262.25H599.03V248.43Q599.03 126.30 529.58 56.15Q460.13 -14.00 332.35 -14.00Z"/><path transform="translate(204.25 35.00) scale(0.01400 -0.01400)" d="M19.75 0.00 211.62 700.00H421.33L613.20 0.00H489.27L447.42 159.60H185.53L143.68 0.00ZM214.25 270.40H418.70L324.95 624.87H308.00Z"/><path transform="translate(216.31 35.00) scale(0.01400 -0.01400)" d="M233.95 0.00V590.85H24.70V700.00H563.30V590.85H354.05V0.00Z"/><path transform="translate(227.75 35.00) scale(0.01400 -0.01400)" d="M332.35 -14.00Q203.57 -14.00 128.01 58.50Q52.45 131.00 52.45 266.87V433.13Q52.45 569.00 128.01 641.50Q203.57 714.00 332.35 714.00Q460.13 714.00 529.58 643.85Q599.03 573.70 599.03 451.57V445.75H480.57V455.22Q480.57 521.42 444.15 563.96Q407.72 606.50 332.35 606.50Q257.63 606.50 215.09 560.70Q172.55 514.90 172.55 435.13V264.87Q172.55 185.93 215.09 139.71Q257.63 93.50 332.35 93.50Q407.72 93.50 444.15 136.45Q480.57 179.40 480.57 244.78V262.25H599.03V248.43Q599.03 126.30 529.58 56.15Q460.13 -14.00 332.35 -14.00Z"/><path transform="translate(239.95 35.00) scale(0.01400 -0.01400)" d="M69.50 0.00V700.00H189.60V405.58H466.40V700.00H586.50V0.00H466.40V296.42H189.60V0.00Z"/></g></svg>',Wa='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4.5 5.5h15a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1h-8l-4.3 3.2a.5.5 0 0 1-.8-.4v-2.8H4.5a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1z"/><path d="M12 8.4l.9 1.9 2 .3-1.5 1.4.4 2-1.8-1-1.8 1 .4-2-1.5-1.4 2-.3z"/></svg>',Ya='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M9 17.5h6M10 21h4"/><path d="M12 3a6 6 0 0 0-3.6 10.8c.6.5 1 1.2 1 2V17h5.2v-1.2c0-.8.4-1.5 1-2A6 6 0 0 0 12 3z"/></svg>',Xa='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 20s-7.5-4.6-7.5-10.2A4.3 4.3 0 0 1 12 7.2a4.3 4.3 0 0 1 7.5 2.6C19.5 15.4 12 20 12 20z"/></svg>',Ja='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M9.6 9.4a2.5 2.5 0 0 1 4.8.9c0 1.7-2.4 2.2-2.4 3.6M12 17h.01"/></svg>',Za='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.8" stroke-linecap="round"><path d="M6.5 12h.01M12 12h.01M17.5 12h.01"/></svg>',Ga=`
310
310
  @keyframes bc-fade-in { from { opacity: 0 } to { opacity: 1 } }
311
311
  @keyframes bc-fade-out { to { opacity: 0 } }
312
312
  @keyframes bc-panel-in { from { opacity: 0; transform: translateY(14px) scale(.965) } to { opacity: 1; transform: none } }
@@ -604,6 +604,53 @@ textarea { min-height: 76px; resize: vertical; }
604
604
  .seg button[aria-pressed=true]::before { opacity: 1; }
605
605
  .seg button:focus-visible { outline-offset: -2px; }
606
606
 
607
+ /* ---------- report a bug, or give feedback ----------
608
+ The same stone track as the severity control, two wide segments, under the
609
+ header so it stays put while the form scrolls. Each form's own parts carry
610
+ bug-only or fb-only; the other screens (history, a conversation, a call)
611
+ carry neither, so a mode left on the panel cannot hide anything of theirs. */
612
+ .modes {
613
+ flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
614
+ margin: 12px var(--bc-pad) 0; padding: 3px; background: var(--bc-stone); border-radius: 999px;
615
+ }
616
+ .modes button {
617
+ display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 0;
618
+ height: 32px; padding: 0 8px; font: inherit; font-size: var(--bc-fs-sm); font-weight: 520; line-height: 1; white-space: nowrap;
619
+ color: var(--bc-muted); background: none; border: none; border-radius: 999px;
620
+ cursor: pointer; transition: background 180ms var(--bc-ease), color 180ms, box-shadow 180ms;
621
+ }
622
+ .modes button svg { font-size: 15px; flex: none; }
623
+ .modes button:hover { color: var(--bc-fg); }
624
+ .modes button[aria-pressed=true] {
625
+ background: var(--bc-raised); color: var(--bc-fg); font-weight: 600;
626
+ box-shadow: 0 1px 2px rgba(20,18,14,.10), 0 0 0 .5px rgba(20,18,14,.08);
627
+ }
628
+ .modes button:focus-visible { outline-offset: -2px; }
629
+ .panel[data-mode="feedback"] .bug-only,
630
+ .panel:not([data-mode="feedback"]) .fb-only { display: none !important; }
631
+
632
+ /* ---------- feedback ---------- */
633
+ .feedback { animation: bc-fade-in 200ms ease both; }
634
+ .feedback textarea { min-height: 96px; }
635
+ .feedback .kinds { display: flex; flex-wrap: wrap; gap: 6px; }
636
+ .feedback .kinds .tool[aria-pressed=true] { background: var(--bc-accent); border-color: var(--bc-accent); color: var(--bc-on-accent); }
637
+ .feedback .kinds .tool[aria-pressed=true] svg { color: currentColor; }
638
+ .faces { display: flex; gap: 6px; }
639
+ .face {
640
+ flex: 1 1 0; display: grid; place-items: center; height: 42px; padding: 0;
641
+ font: inherit; font-size: 24px; color: var(--bc-muted); background: var(--bc-stone);
642
+ border: 1px solid transparent; border-radius: var(--bc-r-md); cursor: pointer;
643
+ transition: background 160ms, color 160ms, transform 160ms var(--bc-ease);
644
+ }
645
+ .face:hover { color: var(--bc-fg); background: color-mix(in srgb, var(--bc-fg) 8%, var(--bc-stone)); }
646
+ .face:active { transform: scale(.94); }
647
+ .face[aria-pressed=true] { color: var(--bc-on-accent); background: var(--bc-accent); }
648
+ .face:focus-visible { outline-offset: 2px; }
649
+ .face-word { font-weight: 560; color: var(--bc-muted); }
650
+ .fb-as { margin: 0; font-size: var(--bc-fs-xs); line-height: 1.45; color: var(--bc-muted); }
651
+ .fb-as strong { color: var(--bc-fg); font-weight: 600; word-break: break-all; }
652
+ .fb-who:empty { display: none; }
653
+
607
654
  /* ---------- attachments ----------
608
655
  Three ring pills in a row: optional, so they take one line, not a band of
609
656
  dashed drop zones. */
@@ -1339,29 +1386,29 @@ div.done { padding: 44px 26px 44px; text-align: center; animation: bc-fade-in 24
1339
1386
  @media (hover: none) {
1340
1387
  .tool:hover:not(:disabled) { transform: none; }
1341
1388
  }
1342
- `;function st({title:e,sub:t,id:n="",back:o=!1,theme:a=""}){return`
1389
+ `;function pt({title:e,sub:t,id:n="",back:o=!1,theme:a=""}){return`
1343
1390
  <div class="head">
1344
- ${o?`<button class="icon-btn back" type="button" data-act="back" aria-label="Back to your reports">${Ra}</button>`:""}
1391
+ ${o?`<button class="icon-btn back" type="button" data-act="back" aria-label="Back to your reports">${Ka}</button>`:""}
1345
1392
  <span class="orb mark" aria-hidden="true"></span>
1346
1393
  <div class="titles">
1347
1394
  <h2${n?` id="${n}"`:""}>${E(e)}</h2>
1348
1395
  <p>${E(t)}</p>
1349
1396
  </div>
1350
1397
  ${a?`<button class="icon-btn theme" type="button" data-act="theme" title="Theme: ${E(a)}"
1351
- aria-label="Theme: ${E(a)}. Change theme"><span class="m-light">${kt}</span><span class="m-dark">${St}</span><span class="m-auto">${$t}</span></button>`:""}
1352
- <button class="icon-btn" type="button" data-act="close" aria-label="Close">${ge}</button>
1353
- </div>`}function ct(e,t){return`<div class="empty"><span class="empty-ico" aria-hidden="true">${t}</span>${E(e)}</div>`}function Qa(e){return Array.from({length:e},()=>`
1398
+ aria-label="Theme: ${E(a)}. Change theme"><span class="m-light">${Ct}</span><span class="m-dark">${Tt}</span><span class="m-auto">${Et}</span></button>`:""}
1399
+ <button class="icon-btn" type="button" data-act="close" aria-label="Close">${be}</button>
1400
+ </div>`}function ht(e,t){return`<div class="empty"><span class="empty-ico" aria-hidden="true">${t}</span>${E(e)}</div>`}function er(e){return Array.from({length:e},()=>`
1354
1401
  <div class="row" aria-hidden="true">
1355
1402
  <span class="row-ico"></span>
1356
1403
  <span class="who"><span class="skel" style="width:70%"></span><span class="skel" style="width:40%;height:9px"></span></span>
1357
- </div>`).join("")+'<span class="sr-only">Loading…</span>'}function Ha(){return`
1404
+ </div>`).join("")+'<span class="sr-only">Loading…</span>'}function tr(){return`
1358
1405
  <div aria-hidden="true" style="display:flex;flex-direction:column;gap:10px;padding-top:6px">
1359
1406
  <span class="skel" style="width:42%;height:34px;border-radius:16px;align-self:center"></span>
1360
1407
  <span class="skel" style="width:66%;height:52px;border-radius:18px"></span>
1361
1408
  <span class="skel" style="width:48%;height:38px;border-radius:18px;align-self:flex-end"></span>
1362
1409
  </div>
1363
- <span class="sr-only">Loading…</span>`}function Na(e){const t=String(e).trim().split(/\s+/).filter(Boolean);return t.length?(t[0][0]+(t.length>1?t[t.length-1][0]:"")).toUpperCase():"?"}function xe(e){const t=new Date(e);return Number.isFinite(t.getTime())?`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`:null}function Ua(e){const t=new Date(e),n=new Date,o=new Date(n.getFullYear(),n.getMonth(),n.getDate()-1);if(xe(t)===xe(n))return"Today";if(xe(t)===xe(o))return"Yesterday";try{return t.toLocaleDateString(void 0,{weekday:"short",day:"numeric",month:"short",...t.getFullYear()!==n.getFullYear()?{year:"numeric"}:{}})}catch{return Se(e)}}function pn(e){const t=new Date(e);if(!Number.isFinite(t.getTime()))return"";try{return t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return""}}function hn(e){return e.scrollHeight-e.scrollTop-e.clientHeight<40}function ke(e,{smooth:t=!1}={}){const n=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches;t&&!n&&e.scrollTo?e.scrollTo({top:e.scrollHeight,behavior:"smooth"}):e.scrollTop=e.scrollHeight}function lt(e){return{OPEN:"Open",IN_PROGRESS:"In progress",RESOLVED:"Fixed",CLOSED:"Closed"}[e]||String(e||"").toLowerCase()}function Se(e){const t=new Date(e).getTime();if(!Number.isFinite(t))return"";const n=Math.floor((Date.now()-t)/864e5);if(n<=0)return"today";if(n===1)return"yesterday";if(n<30)return`${n} days ago`;const o=Math.floor(n/30);return o===1?"a month ago":`${o} months ago`}function E(e){return String(e).replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t])}const Pa=7*24*60*60*1e3;let De;function Ka(){return De||(De=new Promise((e,t)=>{const n=indexedDB.open("bugcatch-drafts",1);n.onupgradeneeded=()=>n.result.createObjectStore("drafts"),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error),n.onblocked=()=>t(new Error("Draft storage is blocked."))}).catch(e=>{throw De=null,e})),De}function _a(e,t){var n,o;return JSON.stringify([e.apiBase,e.projectId,t||((n=e.user)==null?void 0:n.email)||((o=e.user)==null?void 0:o.id)||"anonymous"])}async function Qe(e,t){const n=await Ka();return new Promise((o,a)=>{const r=n.transaction("drafts",t===void 0?"readonly":"readwrite"),i=r.objectStore("drafts"),s=t===void 0?i.get(e):t===null?i.delete(e):i.put({...t,savedAt:Date.now()},e);r.oncomplete=()=>o(s.result),r.onerror=()=>a(r.error),r.onabort=()=>a(r.error||new Error("Draft was not saved."))})}async function Va(e){const t=await Qe(e);return t&&Date.now()-t.savedAt>Pa?(await Qe(e,null),null):t||null}const fn=[{value:"LOW",label:"Low"},{value:"MEDIUM",label:"Medium"},{value:"HIGH",label:"High"},{value:"CRITICAL",label:"Critical"}],gn="MEDIUM";function Fa(e){const t=e.attachments!==!1,n=t&&ho(),o=t&&po();return`
1364
- <div class="compose">
1410
+ <span class="sr-only">Loading…</span>`}function nr(e){const t=String(e).trim().split(/\s+/).filter(Boolean);return t.length?(t[0][0]+(t.length>1?t[t.length-1][0]:"")).toUpperCase():"?"}function xe(e){const t=new Date(e);return Number.isFinite(t.getTime())?`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`:null}function or(e){const t=new Date(e),n=new Date,o=new Date(n.getFullYear(),n.getMonth(),n.getDate()-1);if(xe(t)===xe(n))return"Today";if(xe(t)===xe(o))return"Yesterday";try{return t.toLocaleDateString(void 0,{weekday:"short",day:"numeric",month:"short",...t.getFullYear()!==n.getFullYear()?{year:"numeric"}:{}})}catch{return Se(e)}}function gn(e){const t=new Date(e);if(!Number.isFinite(t.getTime()))return"";try{return t.toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}catch{return""}}function bn(e){return e.scrollHeight-e.scrollTop-e.clientHeight<40}function ke(e,{smooth:t=!1}={}){const n=typeof matchMedia=="function"&&matchMedia("(prefers-reduced-motion: reduce)").matches;t&&!n&&e.scrollTo?e.scrollTo({top:e.scrollHeight,behavior:"smooth"}):e.scrollTop=e.scrollHeight}function ft(e){return{OPEN:"Open",IN_PROGRESS:"In progress",RESOLVED:"Fixed",CLOSED:"Closed"}[e]||String(e||"").toLowerCase()}function Se(e){const t=new Date(e).getTime();if(!Number.isFinite(t))return"";const n=Math.floor((Date.now()-t)/864e5);if(n<=0)return"today";if(n===1)return"yesterday";if(n<30)return`${n} days ago`;const o=Math.floor(n/30);return o===1?"a month ago":`${o} months ago`}function E(e){return String(e).replace(/[&<>"']/g,t=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[t])}const ar=7*24*60*60*1e3;let He;function rr(){return He||(He=new Promise((e,t)=>{const n=indexedDB.open("bugcatch-drafts",1);n.onupgradeneeded=()=>n.result.createObjectStore("drafts"),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error),n.onblocked=()=>t(new Error("Draft storage is blocked."))}).catch(e=>{throw He=null,e})),He}function ir(e,t){var n,o;return JSON.stringify([e.apiBase,e.projectId,t||((n=e.user)==null?void 0:n.email)||((o=e.user)==null?void 0:o.id)||"anonymous"])}async function Qe(e,t){const n=await rr();return new Promise((o,a)=>{const r=n.transaction("drafts",t===void 0?"readonly":"readwrite"),i=r.objectStore("drafts"),s=t===void 0?i.get(e):t===null?i.delete(e):i.put({...t,savedAt:Date.now()},e);r.oncomplete=()=>o(s.result),r.onerror=()=>a(r.error),r.onabort=()=>a(r.error||new Error("Draft was not saved."))})}async function sr(e){const t=await Qe(e);return t&&Date.now()-t.savedAt>ar?(await Qe(e,null),null):t||null}const mn=[{value:"LOW",label:"Low"},{value:"MEDIUM",label:"Medium"},{value:"HIGH",label:"High"},{value:"CRITICAL",label:"Critical"}],yn="MEDIUM";function cr(e){const t=e.attachments!==!1,n=t&&yo(),o=t&&mo();return`
1411
+ <div class="compose bug-only">
1365
1412
  <div class="field">
1366
1413
  <label for="bc-title">What went wrong?</label>
1367
1414
  <input id="bc-title" type="text" placeholder="e.g. The checkout button does nothing" autocomplete="off"
@@ -1380,8 +1427,8 @@ div.done { padding: 44px 26px 44px; text-align: center; animation: bc-fade-in 24
1380
1427
  <div class="field">
1381
1428
  <label id="bc-prio-l">How much is it getting in your way?</label>
1382
1429
  <div class="seg" role="group" aria-labelledby="bc-prio-l">
1383
- ${fn.map(a=>`
1384
- <button type="button" data-prio="${a.value}" aria-pressed="${a.value===gn}">${a.label}</button>
1430
+ ${mn.map(a=>`
1431
+ <button type="button" data-prio="${a.value}" aria-pressed="${a.value===yn}">${a.label}</button>
1385
1432
  `).join("")}
1386
1433
  </div>
1387
1434
  </div>
@@ -1392,269 +1439,314 @@ div.done { padding: 44px 26px 44px; text-align: center; animation: bc-fade-in 24
1392
1439
  <span class="count" aria-live="polite"></span>
1393
1440
  </div>
1394
1441
  <div class="tools" role="group" aria-labelledby="bc-att-l">
1395
- ${n?`<button class="tool" type="button" data-act="shot">${Aa}Screenshot</button>`:""}
1396
- ${o?`<button class="tool" type="button" data-act="rec">${Ma}Record screen</button>`:""}
1397
- <button class="tool" type="button" data-act="file">${cn}Upload file</button>
1442
+ ${n?`<button class="tool" type="button" data-act="shot">${Ha}Screenshot</button>`:""}
1443
+ ${o?`<button class="tool" type="button" data-act="rec">${Qa}Record screen</button>`:""}
1444
+ <button class="tool" type="button" data-act="file">${pn}Upload file</button>
1398
1445
  </div>
1399
1446
  <div class="thumbs"></div>
1400
- <input type="file" accept="${Ee.join(",")}" multiple hidden />
1447
+ <input type="file" accept="${Ie.join(",")}" multiple hidden />
1401
1448
  </div>`:""}
1402
- </div>`}function Wa(e){var fe,de,ue,z;const{client:t,cfg:n,root:o,host:a,dock:r,scrim:i,$:s,say:d,titleInput:c,descInput:p,compose:f,sendBtn:u,note:h}=e,m=s(".thumbs"),C=i.querySelector("input[type=file]"),w=[];let g=gn,b=null;const l=document.createElement("div");l.setAttribute("role","status"),l.className="note",f.prepend(l);const S=_a(n,(fe=t.signedInAs())==null?void 0:fe.email);let y=n.drafts===!1,x=!1,v=Promise.resolve(),k;function T(){if(clearTimeout(k),!y||x||n.drafts===!1)return v;const $=c.value||p.value||w.length?{title:c.value,description:p.value,priority:g,items:w.map(({blob:A,mime:H,kind:N})=>({blob:A,mime:H,kind:N}))}:null;return v=v.catch(()=>{}).then(()=>Qe(S,$)).then(()=>{l.textContent=$?"Draft saved on this device":""}).catch(()=>{l.textContent="Draft could not be saved. Keep this tab open."}),v}function j(){clearTimeout(k),k=setTimeout(T,250)}f.addEventListener("input",j),f.addEventListener("change",j);const O=()=>{T()};window.addEventListener("pagehide",O);function _(){w.filter($=>$.status==="failed").forEach(J)}window.addEventListener("online",_),n.drafts!==!1&&(f.inert=!0,Va(S).then($=>{e.closed||!$||(l.innerHTML='<span>You have an unfinished report on this device.</span> <button type="button" data-resume>Resume report</button> <button type="button" data-discard>Discard</button>',l.querySelector("[data-resume]").onclick=()=>{c.value=$.title||"",p.value=$.description||"",g=fn.some(A=>A.value===$.priority)?$.priority:"MEDIUM",i.querySelectorAll("[data-prio]").forEach(A=>A.setAttribute("aria-pressed",String(A.dataset.prio===g)));for(const A of($.items||[]).slice(0,n.maxAttachments??5))te(A);y=!0,T()},l.querySelector("[data-discard]").onclick=()=>{y=!0,T()})}).catch(()=>{l.textContent="Draft storage is unavailable. Keep this tab open."}).finally(()=>{f.inert=e.mustRate(),l.querySelector("[data-resume]")||(y=!0)})),e.onDestroy(()=>{var $;T(),clearTimeout(k),window.removeEventListener("pagehide",O),window.removeEventListener("online",_),b==null||b.cancel(),w.forEach(A=>A.previewUrl&&URL.revokeObjectURL(A.previewUrl)),($=o.querySelector(".recbar"))==null||$.remove()}),i.querySelectorAll("[data-prio]").forEach($=>{$.addEventListener("click",()=>{g=$.dataset.prio,j(),i.querySelectorAll("[data-prio]").forEach(A=>{A.setAttribute("aria-pressed",String(A===$))})})});const Y=s("#bc-title-err");function L($){Y.hidden=!$,Y.innerHTML=$?`${se}<span>${E($)}</span>`:"",c.classList.toggle("invalid",!!$),c.setAttribute("aria-invalid",String(!!$))}c.addEventListener("input",()=>{c.value.trim()&&L("")});function D(){const $=w.some(P=>P.status==="uploading"),A=e.mustRate();u.disabled=e.sending||$||A||w.some(P=>P.status==="failed"),h.textContent=A?"Rate your last report to send a new one.":$?"Waiting for the upload to finish…":w.some(P=>P.status==="failed")?"Retry or remove failed attachments before sending.":"";const H=n.maxAttachments??5;i.querySelectorAll(".tool").forEach(P=>{P.disabled=e.sending||w.length>=H});const N=s(".field-head .count");N&&(N.textContent=w.length?`${w.length} of ${H}`:"")}e.refreshSendState=D;function R($){var ne;const A=$.el,H=$.kind==="VIDEO"?"Video":"Shot",N=$.kind==="VIDEO"?`<video src="${$.previewUrl}" muted playsinline preload="metadata"></video>`:`<img src="${$.previewUrl}" alt="" />`;let P="";$.status==="uploading"?P=`<div class="veil"><div class="spinner"></div><div class="bar"><i style="width:${Math.round($.progress*100)}%"></i></div></div>`:$.status==="failed"&&(P=`<div class="veil err"><button type="button" data-act="retry" aria-label="Retry upload">${ja}</button>Failed</div>`),A.innerHTML=`
1403
- ${N}
1404
- <span class="kind">${H} · ${he($.size)}</span>
1405
- <button class="drop" type="button" data-act="drop" aria-label="Remove ${H.toLowerCase()}">${ge}</button>
1406
- ${P}`,A.querySelector('[data-act="drop"]').addEventListener("click",()=>Q($)),(ne=A.querySelector('[data-act="retry"]'))==null||ne.addEventListener("click",()=>J($))}function Q($){const A=w.indexOf($);A>=0&&w.splice(A,1),$.previewUrl&&URL.revokeObjectURL($.previewUrl),$.el.remove(),T(),D()}async function J($){$.status="uploading",$.progress=0,R($),D();try{const{storageKey:A,mime:H}=await t.uploadAttachment($.blob,$.mime,N=>{$.progress=N;const P=$.el.querySelector(".bar i");P&&(P.style.width=`${Math.round(N*100)}%`)});$.storageKey=A,$.mime=H,$.status="ready"}catch(A){$.status="failed",d(A.message.replace("[BugCatch] ",""))}R($),D()}function te({blob:$,mime:A,kind:H}){const N=n.maxAttachmentBytes??26214400;if($.size>N){d(`That file is ${he($.size)} — the limit is ${he(N)}.`);return}const P=Ie(A||$.type,Ee);if(!P){d("Only PNG, JPEG, WebP, WebM and MP4 files can be attached to a report.");return}const ne={blob:$,kind:H,mime:P,size:$.size,previewUrl:URL.createObjectURL($),status:"uploading",progress:0,storageKey:null,el:document.createElement("div")};ne.el.className="thumb",w.push(ne),m.appendChild(ne.el),d(""),T(),J(ne)}async function le($){a.style.opacity="0",a.style.pointerEvents="none",await new Promise(A=>requestAnimationFrame(()=>requestAnimationFrame(A)));try{return await $()}finally{a.style.opacity="",a.style.pointerEvents=""}}(de=i.querySelector('[data-act="shot"]'))==null||de.addEventListener("click",async()=>{try{const $=await le(fo);te($)}catch($){($==null?void 0:$.name)!=="NotAllowedError"&&d(`Screenshot failed: ${$.message}`)}}),(ue=i.querySelector('[data-act="file"]'))==null||ue.addEventListener("click",()=>C.click()),C==null||C.addEventListener("change",()=>{const $=(n.maxAttachments??5)-w.length;[...C.files].slice(0,Math.max($,0)).forEach(A=>{te({blob:A,mime:A.type,kind:A.type.startsWith("video/")?"VIDEO":"SCREENSHOT"})}),C.value=""}),(z=i.querySelector('[data-act="rec"]'))==null||z.addEventListener("click",async()=>{const $=n.maxRecordingMs??12e4;let A;try{b=await go({maxMs:$,onTick:H=>{A&&(A.querySelector(".time").textContent=Le(H))},onAutoStop:()=>{b&&Z({keep:!0})}})}catch(H){(H==null?void 0:H.name)!=="NotAllowedError"&&d(`Recording failed: ${H.message}`);return}i.style.display="none",r.hidden=!0,A=document.createElement("div"),A.className="recbar",A.innerHTML=`
1449
+ </div>`}function lr(e){var ge,ue,pe,q;const{client:t,cfg:n,root:o,host:a,dock:r,scrim:i,$:s,say:l,titleInput:c,descInput:h,compose:f,sendBtn:d,note:p}=e,y=s(".thumbs"),k=i.querySelector("input[type=file]"),g=[];let b=yn,m=null;const u=document.createElement("div");u.setAttribute("role","status"),u.className="note",f.prepend(u);const $=ir(n,(ge=t.signedInAs())==null?void 0:ge.email);let C=n.drafts===!1,x=!1,w=Promise.resolve(),S;function v(){if(clearTimeout(S),!C||x||n.drafts===!1)return w;const T=c.value||h.value||g.length?{title:c.value,description:h.value,priority:b,items:g.map(({blob:B,mime:N,kind:K})=>({blob:B,mime:N,kind:K}))}:null;return w=w.catch(()=>{}).then(()=>Qe($,T)).then(()=>{u.textContent=T?"Draft saved on this device":""}).catch(()=>{u.textContent="Draft could not be saved. Keep this tab open."}),w}function M(){clearTimeout(S),S=setTimeout(v,250)}f.addEventListener("input",M),f.addEventListener("change",M);const I=()=>{v()};window.addEventListener("pagehide",I);function O(){g.filter(T=>T.status==="failed").forEach(J)}window.addEventListener("online",O),n.drafts!==!1&&(f.inert=!0,sr($).then(T=>{e.closed||!T||(u.innerHTML='<span>You have an unfinished report on this device.</span> <button type="button" data-resume>Resume report</button> <button type="button" data-discard>Discard</button>',u.querySelector("[data-resume]").onclick=()=>{c.value=T.title||"",h.value=T.description||"",b=mn.some(B=>B.value===T.priority)?T.priority:"MEDIUM",i.querySelectorAll("[data-prio]").forEach(B=>B.setAttribute("aria-pressed",String(B.dataset.prio===b)));for(const B of(T.items||[]).slice(0,n.maxAttachments??5))oe(B);C=!0,v()},u.querySelector("[data-discard]").onclick=()=>{C=!0,v()})}).catch(()=>{u.textContent="Draft storage is unavailable. Keep this tab open."}).finally(()=>{f.inert=e.mustRate(),u.querySelector("[data-resume]")||(C=!0)})),e.onDestroy(()=>{var T;v(),clearTimeout(S),window.removeEventListener("pagehide",I),window.removeEventListener("online",O),m==null||m.cancel(),g.forEach(B=>B.previewUrl&&URL.revokeObjectURL(B.previewUrl)),(T=o.querySelector(".recbar"))==null||T.remove()}),i.querySelectorAll("[data-prio]").forEach(T=>{T.addEventListener("click",()=>{b=T.dataset.prio,M(),i.querySelectorAll("[data-prio]").forEach(B=>{B.setAttribute("aria-pressed",String(B===T))})})});const U=s("#bc-title-err");function A(T){U.hidden=!T,U.innerHTML=T?`${re}<span>${E(T)}</span>`:"",c.classList.toggle("invalid",!!T),c.setAttribute("aria-invalid",String(!!T))}c.addEventListener("input",()=>{c.value.trim()&&A("")});function H(){const T=g.some(_=>_.status==="uploading"),B=e.mustRate();d.disabled=e.sending||T||B||g.some(_=>_.status==="failed"),p.textContent=B?"Rate your last report to send a new one.":T?"Waiting for the upload to finish…":g.some(_=>_.status==="failed")?"Retry or remove failed attachments before sending.":"";const N=n.maxAttachments??5;i.querySelectorAll(".tool").forEach(_=>{_.disabled=e.sending||g.length>=N});const K=s(".field-head .count");K&&(K.textContent=g.length?`${g.length} of ${N}`:"")}e.refreshSendState=H;function z(T){var ae;const B=T.el,N=T.kind==="VIDEO"?"Video":"Shot",K=T.kind==="VIDEO"?`<video src="${T.previewUrl}" muted playsinline preload="metadata"></video>`:`<img src="${T.previewUrl}" alt="" />`;let _="";T.status==="uploading"?_=`<div class="veil"><div class="spinner"></div><div class="bar"><i style="width:${Math.round(T.progress*100)}%"></i></div></div>`:T.status==="failed"&&(_=`<div class="veil err"><button type="button" data-act="retry" aria-label="Retry upload">${Ua}</button>Failed</div>`),B.innerHTML=`
1450
+ ${K}
1451
+ <span class="kind">${N} · ${he(T.size)}</span>
1452
+ <button class="drop" type="button" data-act="drop" aria-label="Remove ${N.toLowerCase()}">${be}</button>
1453
+ ${_}`,B.querySelector('[data-act="drop"]').addEventListener("click",()=>Q(T)),(ae=B.querySelector('[data-act="retry"]'))==null||ae.addEventListener("click",()=>J(T))}function Q(T){const B=g.indexOf(T);B>=0&&g.splice(B,1),T.previewUrl&&URL.revokeObjectURL(T.previewUrl),T.el.remove(),v(),H()}async function J(T){T.status="uploading",T.progress=0,z(T),H();try{const{storageKey:B,mime:N}=await t.uploadAttachment(T.blob,T.mime,K=>{T.progress=K;const _=T.el.querySelector(".bar i");_&&(_.style.width=`${Math.round(K*100)}%`)});T.storageKey=B,T.mime=N,T.status="ready"}catch(B){T.status="failed",l(B.message.replace("[BugCatch] ",""))}z(T),H()}function oe({blob:T,mime:B,kind:N}){const K=n.maxAttachmentBytes??26214400;if(T.size>K){l(`That file is ${he(T.size)} — the limit is ${he(K)}.`);return}const _=Le(B||T.type,Ie);if(!_){l("Only PNG, JPEG, WebP, WebM and MP4 files can be attached to a report.");return}const ae={blob:T,kind:N,mime:_,size:T.size,previewUrl:URL.createObjectURL(T),status:"uploading",progress:0,storageKey:null,el:document.createElement("div")};ae.el.className="thumb",g.push(ae),y.appendChild(ae.el),l(""),v(),J(ae)}async function de(T){a.style.opacity="0",a.style.pointerEvents="none",await new Promise(B=>requestAnimationFrame(()=>requestAnimationFrame(B)));try{return await T()}finally{a.style.opacity="",a.style.pointerEvents=""}}(ue=i.querySelector('[data-act="shot"]'))==null||ue.addEventListener("click",async()=>{try{const T=await de(wo);oe(T)}catch(T){(T==null?void 0:T.name)!=="NotAllowedError"&&l(`Screenshot failed: ${T.message}`)}}),(pe=i.querySelector('[data-act="file"]'))==null||pe.addEventListener("click",()=>k.click()),k==null||k.addEventListener("change",()=>{const T=(n.maxAttachments??5)-g.length;[...k.files].slice(0,Math.max(T,0)).forEach(B=>{oe({blob:B,mime:B.type,kind:B.type.startsWith("video/")?"VIDEO":"SCREENSHOT"})}),k.value=""}),(q=i.querySelector('[data-act="rec"]'))==null||q.addEventListener("click",async()=>{const T=n.maxRecordingMs??12e4;let B;try{m=await vo({maxMs:T,onTick:N=>{B&&(B.querySelector(".time").textContent=Ae(N))},onAutoStop:()=>{m&&Z({keep:!0})}})}catch(N){(N==null?void 0:N.name)!=="NotAllowedError"&&l(`Recording failed: ${N.message}`);return}i.style.display="none",r.hidden=!0,B=document.createElement("div"),B.className="recbar",B.innerHTML=`
1407
1454
  <span class="dot"></span>
1408
1455
  <span class="time">0:00</span>
1409
- <span class="hint">Recording — up to ${Le(Math.round($/1e3))}</span>
1456
+ <span class="hint">Recording — up to ${Ae(Math.round(T/1e3))}</span>
1410
1457
  <button class="stop" type="button">Stop</button>
1411
- <button class="ghost" type="button">Discard</button>`,A.querySelector(".stop").addEventListener("click",()=>Z({keep:!0})),A.querySelector(".ghost").addEventListener("click",()=>Z({keep:!1})),o.appendChild(A),A.querySelector(".stop").focus()});async function Z({keep:$}){var H;const A=b;if(A){if(b=null,(H=o.querySelector(".recbar"))==null||H.remove(),i.style.display="",r.hidden=!1,!$){A.cancel(),c.focus();return}try{const N=await A.stop();N.blob.size?te(N):d("That recording came back empty — nothing was captured.")}catch(N){d(`Recording failed: ${N.message}`)}c.focus()}}e.isRecording=()=>!!b,e.stopRecording=Z,u.addEventListener("click",async()=>{var H;const $=c.value;if(!$.trim()){L("Add a few words about what went wrong — a short sentence is plenty."),c.focus();return}if(e.holdForReference())return;e.sending=!0,d(""),D();const A=u.innerHTML;u.innerHTML='<span class="spinner" aria-hidden="true"></span>Sending…';try{const N=await t.report({title:$,description:p.value,priority:g,references:e.answeredReference(),issue:((H=e.pickedIssue())==null?void 0:H.key)||null,attachments:w.filter(P=>P.status==="ready").map(P=>({type:P.kind,storageKey:P.storageKey,mime:P.mime}))});if(N!=null&&N.cancelled){e.sending=!1,u.innerHTML=A,D();return}x=!0,clearTimeout(k),await v,n.drafts!==!1&&await Qe(S,null).catch(()=>{}),e.succeed(N)}catch(N){e.sending=!1,u.innerHTML=A,d(N.message.replace("[BugCatch] ","")),D(),e.recheckSignIn()}})}function Ya(e){const{client:t,say:n,titleInput:o,descInput:a,sendBtn:r,refsBox:i}=e;let s={policy:"off",fields:[]},d=!1,c=null,p="",f="",u=[],h="ask",m=!1,C=!1;t.referenceFields().then(L=>{s=L,y()}).catch(()=>{});function w(){return s.policy==="off"||!s.fields.length?{found:[],conflicts:[],loose:[]}:oa(s.fields,[o.value,a.value])}function g(L=w()){return L.found.length>0&&L.conflicts.length===0}function b(){return!c||!p.trim()?[]:[{key:c,value:p.trim().slice(0,120)}]}const l=document.createElement("p");l.className="ref-found",l.setAttribute("aria-live","polite"),l.hidden=!0,a.closest(".field").after(l);let S;function y(){const L=w();if(g(L)){const D=L.found.slice(0,2).map(R=>`${E(R.label)} <b>${E(v(R.value))}</b>`).join(", ");l.innerHTML=`${oe}<span>Found your ${D} — no need to add it again.</span>`,l.hidden=!1,d&&!b().length&&(d=!1,j())}else l.hidden=!0,l.innerHTML=""}const x=()=>{clearTimeout(S),S=setTimeout(y,250)};o.addEventListener("input",x),a.addEventListener("input",x);function v(L){return L.length>20?`${L.slice(0,8)}…${L.slice(-4)}`:L}function k(L){const D=L.trim().toLowerCase();return u.find(R=>R.value.toLowerCase()===D)||null}function T(L){p=L.value,L.kinds.length===1?c=L.kinds[0].key:L.kinds.some(D=>D.key===c)||(c=null),f="",C=!1}function j(){var de,ue;if(!d){i.hidden=!0,i.innerHTML="";return}const L=s.fields.find(z=>z.key===c)||null,D=s.policy!=="required",R=k(p),Q=R&&R.kinds.length>1?s.fields.filter(z=>R.kinds.some($=>$.key===z.key)):s.fields,J=u.length>1&&u.every(z=>z.kinds.length===1&&z.kinds[0].key===u[0].kinds[0].key),te={confirm:u.length>1?["Which one is this about?","We found more than one ID in your message. Pick the one this problem is about."]:["Is this the right ID?","This could be more than one kind of ID. Tell us which it is."],suggest:["Is this your ID?","We spotted this in your message. Tell us what it is so we can find your record."],ask:D?["One more thing","So we can find your record — this helps us answer faster."]:["We need one detail","We need one of these to look this up."]}[h];i.hidden=!1;const le=Q.length>6;i.innerHTML=`
1458
+ <button class="ghost" type="button">Discard</button>`,B.querySelector(".stop").addEventListener("click",()=>Z({keep:!0})),B.querySelector(".ghost").addEventListener("click",()=>Z({keep:!1})),o.appendChild(B),B.querySelector(".stop").focus()});async function Z({keep:T}){var N;const B=m;if(B){if(m=null,(N=o.querySelector(".recbar"))==null||N.remove(),i.style.display="",r.hidden=!1,!T){B.cancel(),c.focus();return}try{const K=await B.stop();K.blob.size?oe(K):l("That recording came back empty — nothing was captured.")}catch(K){l(`Recording failed: ${K.message}`)}c.focus()}}e.isRecording=()=>!!m,e.stopRecording=Z,d.addEventListener("click",async()=>{var N;const T=c.value;if(!T.trim()){A("Add a few words about what went wrong — a short sentence is plenty."),c.focus();return}if(e.holdForReference())return;e.sending=!0,l(""),H();const B=d.innerHTML;d.innerHTML='<span class="spinner" aria-hidden="true"></span>Sending…';try{const K=await t.report({title:T,description:h.value,priority:b,references:e.answeredReference(),issue:((N=e.pickedIssue())==null?void 0:N.key)||null,attachments:g.filter(_=>_.status==="ready").map(_=>({type:_.kind,storageKey:_.storageKey,mime:_.mime}))});if(K!=null&&K.cancelled){e.sending=!1,d.innerHTML=B,H();return}x=!0,clearTimeout(S),await w,n.drafts!==!1&&await Qe($,null).catch(()=>{}),e.succeed(K)}catch(K){e.sending=!1,d.innerHTML=B,l(K.message.replace("[BugCatch] ","")),H(),e.recheckSignIn()}})}function dr(e){const{client:t,say:n,titleInput:o,descInput:a,sendBtn:r,refsBox:i}=e;let s={policy:"off",fields:[]},l=!1,c=null,h="",f="",d=[],p="ask",y=!1,k=!1;t.referenceFields().then(A=>{s=A,C()}).catch(()=>{});function g(){return s.policy==="off"||!s.fields.length?{found:[],conflicts:[],loose:[]}:ca(s.fields,[o.value,a.value])}function b(A=g()){return A.found.length>0&&A.conflicts.length===0}function m(){return!c||!h.trim()?[]:[{key:c,value:h.trim().slice(0,120)}]}const u=document.createElement("p");u.className="ref-found",u.setAttribute("aria-live","polite"),u.hidden=!0,a.closest(".field").after(u);let $;function C(){const A=g();if(b(A)){const H=A.found.slice(0,2).map(z=>`${E(z.label)} <b>${E(w(z.value))}</b>`).join(", ");u.innerHTML=`${ee}<span>Found your ${H} — no need to add it again.</span>`,u.hidden=!1,l&&!m().length&&(l=!1,M())}else u.hidden=!0,u.innerHTML=""}const x=()=>{clearTimeout($),$=setTimeout(C,250)};o.addEventListener("input",x),a.addEventListener("input",x);function w(A){return A.length>20?`${A.slice(0,8)}…${A.slice(-4)}`:A}function S(A){const H=A.trim().toLowerCase();return d.find(z=>z.value.toLowerCase()===H)||null}function v(A){h=A.value,A.kinds.length===1?c=A.kinds[0].key:A.kinds.some(H=>H.key===c)||(c=null),f="",k=!1}function M(){var ue,pe;if(!l){i.hidden=!0,i.innerHTML="";return}const A=s.fields.find(q=>q.key===c)||null,H=s.policy!=="required",z=S(h),Q=z&&z.kinds.length>1?s.fields.filter(q=>z.kinds.some(T=>T.key===q.key)):s.fields,J=d.length>1&&d.every(q=>q.kinds.length===1&&q.kinds[0].key===d[0].kinds[0].key),oe={confirm:d.length>1?["Which one is this about?","We found more than one ID in your message. Pick the one this problem is about."]:["Is this the right ID?","This could be more than one kind of ID. Tell us which it is."],suggest:["Is this your ID?","We spotted this in your message. Tell us what it is so we can find your record."],ask:H?["One more thing","So we can find your record — this helps us answer faster."]:["We need one detail","We need one of these to look this up."]}[p];i.hidden=!1;const de=Q.length>6;i.innerHTML=`
1412
1459
  <div class="ask-head">
1413
1460
  <span class="avatar orb" aria-hidden="true"></span>
1414
1461
  <div>
1415
- <strong>${E(te[0])}</strong>
1416
- <p class="why">${E(te[1])}</p>
1462
+ <strong>${E(oe[0])}</strong>
1463
+ <p class="why">${E(oe[1])}</p>
1417
1464
  </div>
1418
1465
  </div>
1419
- ${u.length>1?`
1466
+ ${d.length>1?`
1420
1467
  <div class="chips cands" role="group" aria-label="IDs found in your message">
1421
- ${u.map((z,$)=>`
1422
- <button type="button" data-ref-cand="${$}" title="${E(z.value)}"
1423
- aria-pressed="${!!R&&R===z}">${E(v(z.value))}</button>
1468
+ ${d.map((q,T)=>`
1469
+ <button type="button" data-ref-cand="${T}" title="${E(q.value)}"
1470
+ aria-pressed="${!!z&&z===q}">${E(w(q.value))}</button>
1424
1471
  `).join("")}
1425
1472
  </div>`:""}
1426
- ${Q.length>1&&!le&&!J?`
1473
+ ${Q.length>1&&!de&&!J?`
1427
1474
  <div class="chips" role="group" aria-label="Which detail you are giving">
1428
- ${Q.map(z=>`
1429
- <button type="button" data-ref-kind="${E(z.key)}" aria-pressed="${!!L&&z.key===L.key}">${E(z.label)}</button>
1475
+ ${Q.map(q=>`
1476
+ <button type="button" data-ref-kind="${E(q.key)}" aria-pressed="${!!A&&q.key===A.key}">${E(q.label)}</button>
1430
1477
  `).join("")}
1431
1478
  </div>`:""}
1432
1479
  <div class="row">
1433
- ${le?`
1480
+ ${de?`
1434
1481
  <select class="ref-kind" aria-label="Which detail you are giving">
1435
- ${L?"":'<option value="" selected disabled>What is it?</option>'}
1436
- ${Q.map(z=>`
1437
- <option value="${E(z.key)}" ${L&&z.key===L.key?"selected":""}>${E(z.label)}</option>
1482
+ ${A?"":'<option value="" selected disabled>What is it?</option>'}
1483
+ ${Q.map(q=>`
1484
+ <option value="${E(q.key)}" ${A&&q.key===A.key?"selected":""}>${E(q.label)}</option>
1438
1485
  `).join("")}
1439
1486
  </select>`:""}
1440
- <input class="ref-value${f?" invalid":""}" type="${(L==null?void 0:L.inputMode)==="email"?"email":"text"}"
1441
- inputmode="${E((L==null?void 0:L.inputMode)==="numeric"||(L==null?void 0:L.inputMode)==="tel"?"numeric":"text")}"
1442
- value="${E(p)}"
1443
- placeholder="${E(L?L.placeholder||L.label:"Your ID")}"
1444
- aria-label="${E(L?L.label:"Your ID")}" ${f?'aria-invalid="true"':""} />
1487
+ <input class="ref-value${f?" invalid":""}" type="${(A==null?void 0:A.inputMode)==="email"?"email":"text"}"
1488
+ inputmode="${E((A==null?void 0:A.inputMode)==="numeric"||(A==null?void 0:A.inputMode)==="tel"?"numeric":"text")}"
1489
+ value="${E(h)}"
1490
+ placeholder="${E(A?A.placeholder||A.label:"Your ID")}"
1491
+ aria-label="${E(A?A.label:"Your ID")}" ${f?'aria-invalid="true"':""} />
1445
1492
  </div>
1446
- ${L!=null&&L.hint?`<p class="hint">${E(L.hint)}</p>`:""}
1447
- ${f?`<p class="field-err" role="alert">${se}<span>${E(f)}</span></p>`:""}
1448
- ${D?`<button type="button" class="link" data-act="ref-skip">${h==="ask"?"I don't have this — send without it":"Not sure — send as it is"}</button>`:""}`,i.querySelectorAll("[data-ref-cand]").forEach(z=>{z.addEventListener("click",()=>{T(u[Number(z.dataset.refCand)]),j()})}),i.querySelectorAll("[data-ref-kind]").forEach(z=>{z.addEventListener("click",()=>{c=z.dataset.refKind,f="",C=!1,j()})});const Z=i.querySelector(".ref-value");Z.addEventListener("input",()=>{p=Z.value,f="",C=!1}),Z.addEventListener("keydown",z=>{z.key==="Enter"&&(z.preventDefault(),r.click())}),(de=i.querySelector(".ref-kind"))==null||de.addEventListener("change",z=>{var $;c=z.target.value,f="",j(),($=i.querySelector(".ref-value"))==null||$.focus()}),(ue=i.querySelector('[data-act="ref-skip"]'))==null||ue.addEventListener("click",()=>{m=!0,d=!1,c=null,p="",f="",C=!1,j(),n("")}),((!L&&p?i.querySelector("[data-ref-kind], .ref-kind"):null)||Z).focus()}function O(L){if(u=L.conflicts.length?L.conflicts:L.loose.slice(0,4),h=L.conflicts.length?"confirm":L.loose.length?"suggest":"ask",d=!0,u.length)if(u.length===1)T(u[0]);else{p="";const[D]=u;c=u.every(Q=>Q.kinds.length===1&&Q.kinds[0].key===D.kinds[0].key)?D.kinds[0].key:null}else c=c||s.fields[0].key;j()}function _(){if(s.policy==="off"||!s.fields.length||b().length)return!1;const L=w();return g(L)||m&&s.policy!=="required"?!1:L}function Y(){if(d&&p.trim()&&!c)return f="Pick what this ID is.",j(),!0;const L=_();if(L)return d?j():O(L),n(""),!0;if(c&&p.trim()){const D=s.fields.find(R=>R.key===c);if(!C&&D&&!Yt(D,p))return f=`That does not look like a ${D.label.toLowerCase()}. Press Send again to use it anyway.`,C=!0,j(),!0}return!1}e.holdForReference=Y,e.answeredReference=b}const Xa=3;function Ja(e){const{client:t,cfg:n,notices:o}=e;let a=[];function r(){const s=a.slice(0,Xa);o.replaceChildren(...s.map(d=>Lt(d,{where:"panel",onDismiss:i}))),o.hidden=s.length===0}function i(s){t.dismissAnnouncement(s),a=a.filter(d=>d!==s),r(),e.titleInput.focus()}n.announcements!==!1&&typeof t.announcements=="function"&&t.announcements().then(s=>{e.closed||(a=s,r())}).catch(()=>{})}function Za(e){const{client:t,cfg:n,titleInput:o,known:a}=e;let r=[],i="",s=null,d=null;function c(){n.knownIssues!==!1&&t.knownIssues().then(m=>{r=m,u()}).catch(()=>{})}let p=null;function f(m){if(n.knownIssues===!1)return;clearTimeout(p),d==null||d.abort();const C=(m||"").trim();if(C.length<3){c();return}p=setTimeout(()=>{d=new AbortController,t.matchKnownIssues(C,{signal:d.signal}).then(w=>{w.length&&(r=w,u())}).catch(()=>{})},250)}function u(){if(!r.length){a.hidden=!0,a.innerHTML="";return}a.hidden=!1,a.innerHTML=`
1493
+ ${A!=null&&A.hint?`<p class="hint">${E(A.hint)}</p>`:""}
1494
+ ${f?`<p class="field-err" role="alert">${re}<span>${E(f)}</span></p>`:""}
1495
+ ${H?`<button type="button" class="link" data-act="ref-skip">${p==="ask"?"I don't have this — send without it":"Not sure — send as it is"}</button>`:""}`,i.querySelectorAll("[data-ref-cand]").forEach(q=>{q.addEventListener("click",()=>{v(d[Number(q.dataset.refCand)]),M()})}),i.querySelectorAll("[data-ref-kind]").forEach(q=>{q.addEventListener("click",()=>{c=q.dataset.refKind,f="",k=!1,M()})});const Z=i.querySelector(".ref-value");Z.addEventListener("input",()=>{h=Z.value,f="",k=!1}),Z.addEventListener("keydown",q=>{q.key==="Enter"&&(q.preventDefault(),r.click())}),(ue=i.querySelector(".ref-kind"))==null||ue.addEventListener("change",q=>{var T;c=q.target.value,f="",M(),(T=i.querySelector(".ref-value"))==null||T.focus()}),(pe=i.querySelector('[data-act="ref-skip"]'))==null||pe.addEventListener("click",()=>{y=!0,l=!1,c=null,h="",f="",k=!1,M(),n("")}),((!A&&h?i.querySelector("[data-ref-kind], .ref-kind"):null)||Z).focus()}function I(A){if(d=A.conflicts.length?A.conflicts:A.loose.slice(0,4),p=A.conflicts.length?"confirm":A.loose.length?"suggest":"ask",l=!0,d.length)if(d.length===1)v(d[0]);else{h="";const[H]=d;c=d.every(Q=>Q.kinds.length===1&&Q.kinds[0].key===H.kinds[0].key)?H.kinds[0].key:null}else c=c||s.fields[0].key;M()}function O(){if(s.policy==="off"||!s.fields.length||m().length)return!1;const A=g();return b(A)||y&&s.policy!=="required"?!1:A}function U(){if(l&&h.trim()&&!c)return f="Pick what this ID is.",M(),!0;const A=O();if(A)return l?M():I(A),n(""),!0;if(c&&h.trim()){const H=s.fields.find(z=>z.key===c);if(!k&&H&&!Zt(H,h))return f=`That does not look like a ${H.label.toLowerCase()}. Press Send again to use it anyway.`,k=!0,M(),!0}return!1}e.holdForReference=U,e.answeredReference=m}const ur=3;function pr(e){const{client:t,cfg:n,notices:o}=e;let a=[];function r(){const s=a.slice(0,ur);o.replaceChildren(...s.map(l=>Bt(l,{where:"panel",onDismiss:i}))),o.hidden=s.length===0}function i(s){t.dismissAnnouncement(s),a=a.filter(l=>l!==s),r(),e.titleInput.focus()}n.announcements!==!1&&typeof t.announcements=="function"&&t.announcements().then(s=>{e.closed||(a=s,r())}).catch(()=>{})}function hr(e){const{client:t,cfg:n,titleInput:o,known:a}=e;let r=[],i="",s=null,l=null;function c(){n.knownIssues!==!1&&t.knownIssues().then(y=>{r=y,d()}).catch(()=>{})}let h=null;function f(y){if(n.knownIssues===!1)return;clearTimeout(h),l==null||l.abort();const k=(y||"").trim();if(k.length<3){c();return}h=setTimeout(()=>{l=new AbortController,t.matchKnownIssues(k,{signal:l.signal}).then(g=>{g.length&&(r=g,d())}).catch(()=>{})},250)}function d(){if(!r.length){a.hidden=!0,a.innerHTML="";return}a.hidden=!1,a.innerHTML=`
1449
1496
  <p class="known-h">Already reported</p>
1450
- ${r.map(m=>`
1451
- <div class="issue ${m.joined?"is-joined":""}">
1497
+ ${r.map(y=>`
1498
+ <div class="issue ${y.joined?"is-joined":""}">
1452
1499
  <span class="who">
1453
- <span class="t">${E(m.title)}</span>
1454
- <span class="meta">${E(h(m))}</span>
1500
+ <span class="t">${E(y.title)}</span>
1501
+ <span class="meta">${E(p(y))}</span>
1455
1502
  </span>
1456
- <button class="join" type="button" data-join="${E(m.id)}"
1457
- ${m.joined?"disabled":""}>${m.joined?"Following":"Me too"}</button>
1503
+ <button class="join" type="button" data-join="${E(y.id)}"
1504
+ ${y.joined?"disabled":""}>${y.joined?"Following":"Me too"}</button>
1458
1505
  </div>
1459
- ${s===m.id?`
1506
+ ${s===y.id?`
1460
1507
  <div class="ask">
1461
1508
  <input type="email" class="join-email" placeholder="you@example.com"
1462
1509
  aria-label="Your email, so we can tell you when this is fixed" />
1463
- <button class="ghost" type="button" data-join-confirm="${E(m.id)}">Follow</button>
1510
+ <button class="ghost" type="button" data-join-confirm="${E(y.id)}">Follow</button>
1464
1511
  </div>`:""}
1465
1512
  `).join("")}
1466
- ${i?`<p class="err">${E(i)}</p>`:""}`}function h(m){const C=m.status==="IN_PROGRESS"?"Being worked on now":"Not fixed yet",w=m.affectedCount===0?"":` · ${m.affectedCount} ${m.affectedCount===1?"person has":"people have"} said this is happening to them`;return`${C} · reported ${Se(m.since)}${w}`}a.addEventListener("click",async m=>{var l,S,y,x,v;const C=m.target.closest("[data-join]"),w=m.target.closest("[data-join-confirm]");if(!C&&!w)return;const g=(w||C).getAttribute(w?"data-join-confirm":"data-join");i="";const b=((S=(l=a.querySelector(".join-email"))==null?void 0:l.value)==null?void 0:S.trim())||((y=t.signedInAs())==null?void 0:y.email)||((x=t.config.user)==null?void 0:x.email);if(!b){s=g,u(),(v=a.querySelector(".join-email"))==null||v.focus();return}try{const k=await t.meToo(g,{email:b});s=null,r=r.map(T=>T.id===g?{...T,joined:!0,affectedCount:k.affectedCount??T.affectedCount}:T),u()}catch(k){i=k.message.replace("[BugCatch] ",""),u()}}),c(),o.addEventListener("input",()=>f(o.value))}function Ga(e){const{client:t,cfg:n,titleInput:o,descInput:a,picks:r}=e;let i=[],s=null;function d(){if(!i.length){r.hidden=!0,r.innerHTML="";return}r.hidden=!1,r.innerHTML=`
1513
+ ${i?`<p class="err">${E(i)}</p>`:""}`}function p(y){const k=y.status==="IN_PROGRESS"?"Being worked on now":"Not fixed yet",g=y.affectedCount===0?"":` · ${y.affectedCount} ${y.affectedCount===1?"person has":"people have"} said this is happening to them`;return`${k} · reported ${Se(y.since)}${g}`}a.addEventListener("click",async y=>{var u,$,C,x,w;const k=y.target.closest("[data-join]"),g=y.target.closest("[data-join-confirm]");if(!k&&!g)return;const b=(g||k).getAttribute(g?"data-join-confirm":"data-join");i="";const m=(($=(u=a.querySelector(".join-email"))==null?void 0:u.value)==null?void 0:$.trim())||((C=t.signedInAs())==null?void 0:C.email)||((x=t.config.user)==null?void 0:x.email);if(!m){s=b,d(),(w=a.querySelector(".join-email"))==null||w.focus();return}try{const S=await t.meToo(b,{email:m});s=null,r=r.map(v=>v.id===b?{...v,joined:!0,affectedCount:S.affectedCount??v.affectedCount}:v),d()}catch(S){i=S.message.replace("[BugCatch] ",""),d()}}),c(),o.addEventListener("input",()=>f(o.value))}function fr(e){const{client:t,cfg:n,titleInput:o,descInput:a,picks:r}=e;let i=[],s=null;function l(){if(!i.length){r.hidden=!0,r.innerHTML="";return}r.hidden=!1,r.innerHTML=`
1467
1514
  <p class="picks-h">Get an answer right away</p>
1468
1515
  <div class="picks-grid" role="group" aria-label="Common questions">
1469
- ${i.map((c,p)=>`
1516
+ ${i.map((c,h)=>`
1470
1517
  <button type="button" class="pick" data-pick="${E(c.key)}"
1471
- ${c.hint?`title="${E(c.hint)}" aria-describedby="bc-pick-h${p}"`:""}
1518
+ ${c.hint?`title="${E(c.hint)}" aria-describedby="bc-pick-h${h}"`:""}
1472
1519
  aria-pressed="${(s==null?void 0:s.key)===c.key}">
1473
1520
  <span class="t">${E(c.title)}</span>
1474
- ${c.hint?`<span class="h sr-only" id="bc-pick-h${p}">${E(c.hint)}</span>`:""}
1521
+ ${c.hint?`<span class="h sr-only" id="bc-pick-h${h}">${E(c.hint)}</span>`:""}
1475
1522
  </button>`).join("")}
1476
1523
  </div>
1477
- ${s?`<p class="picks-note">${oe}<span>Our assistant will check your account and reply here. Add anything else below, then send.</span></p>`:""}`}r.addEventListener("click",c=>{const p=c.target.closest("[data-pick]");if(!p)return;const f=i.find(h=>h.key===p.dataset.pick);if(!f)return;const u=s&&o.value.trim()===s.title;(s==null?void 0:s.key)===f.key?(s=null,u&&(o.value="")):(s=f,(!o.value.trim()||u)&&(o.value=f.title)),o.dispatchEvent(new Event("input",{bubbles:!0})),d(),s&&a.focus()}),n.agentIssues!==!1&&typeof t.agentIssues=="function"&&t.agentIssues().then(c=>{i=c,d()}).catch(()=>{}),e.pickedIssue=()=>s}function er(e){const{client:t,scrim:n,say:o,callBtn:a,close:r}=e;let i=!1;function s(){t.callKind().then(p=>{p&&(i=!0,e.preloadCall(),a.hidden=e.mustSignIn()||e.mustRate())}).catch(()=>{})}s(),a.addEventListener("click",async()=>{e.sending=!0,o(""),e.refreshSendState(),a.disabled=!0,a.innerHTML='<span class="spinner"></span>Ringing…';try{const p=await t.startCall();d(p)}catch(p){e.sending=!1,a.disabled=!1,a.innerHTML=`${qe}Talk to the team`,e.refreshSendState(),p.filed?e.succeed(p.filed,{callFailed:p.reason||"The call could not be started."}):(o(p.message.replace("[BugCatch] ","")),e.recheckSignIn())}});function d(p){const f=n.querySelector(".panel"),u=p!=null&&p.bugId?String(p.bugId).slice(0,8):null;f.innerHTML=`
1524
+ ${s?`<p class="picks-note">${ee}<span>Our assistant will check your account and reply here. Add anything else below, then send.</span></p>`:""}`}r.addEventListener("click",c=>{const h=c.target.closest("[data-pick]");if(!h)return;const f=i.find(p=>p.key===h.dataset.pick);if(!f)return;const d=s&&o.value.trim()===s.title;(s==null?void 0:s.key)===f.key?(s=null,d&&(o.value="")):(s=f,(!o.value.trim()||d)&&(o.value=f.title)),o.dispatchEvent(new Event("input",{bubbles:!0})),l(),s&&a.focus()}),n.agentIssues!==!1&&typeof t.agentIssues=="function"&&t.agentIssues().then(c=>{i=c,l()}).catch(()=>{}),e.pickedIssue=()=>s}function gr(e){const{client:t,scrim:n,say:o,callBtn:a,close:r}=e;let i=!1;function s(){t.callKind().then(h=>{h&&(i=!0,e.preloadCall(),a.hidden=e.mustSignIn()||e.mustRate())}).catch(()=>{})}s(),a.addEventListener("click",async()=>{e.sending=!0,o(""),e.refreshSendState(),a.disabled=!0,a.innerHTML='<span class="spinner"></span>Ringing…';try{const h=await t.startCall();l(h)}catch(h){e.sending=!1,a.disabled=!1,a.innerHTML=`${De}Talk to the team`,e.refreshSendState(),h.filed?e.succeed(h.filed,{callFailed:h.reason||"The call could not be started."}):(o(h.message.replace("[BugCatch] ","")),e.recheckSignIn())}});function l(h){const f=n.querySelector(".panel"),d=h!=null&&h.bugId?String(h.bugId).slice(0,8):null;f.innerHTML=`
1478
1525
  <div class="call">
1479
1526
  <div class="call-head">
1480
1527
  <span class="call-dot" aria-hidden="true"></span>
1481
1528
  <strong class="call-state">Ringing…</strong>
1482
1529
  </div>
1483
1530
  <p class="call-note">
1484
- We're ringing the team now. Someone will pick up if they're free — your report${u?` <code>${E(u)}</code>`:""} is already filed either way, so nothing is lost if nobody answers.
1531
+ We're ringing the team now. Someone will pick up if they're free — your report${d?` <code>${E(d)}</code>`:""} is already filed either way, so nothing is lost if nobody answers.
1485
1532
  </p>
1486
1533
  <div class="foot">
1487
1534
  <span class="spacer"></span>
1488
1535
  <button class="primary" type="button" data-act="hangup">Cancel</button>
1489
1536
  </div>
1490
- </div>`;const h=f.querySelector(".call-state"),m=f.querySelector(".call-dot"),C={ringing:"Ringing the team…",connecting:"Someone answered — connecting…",connected:"Connected",missed:"Nobody was free",ended:"Call ended",failed:"The call dropped"},w=["ended","failed","missed"],g=t.on("call",({state:b})=>{if(h.textContent=C[b]||b,m.classList.toggle("off",w.includes(b)),w.includes(b)&&(f.querySelector('[data-act="hangup"]').textContent="Close",b==="missed")){const l=f.querySelector(".call-note");l&&(l.textContent="Nobody was free to pick up just now. Your report is filed and the team will reply in the chat.")}});f.querySelector('[data-act="hangup"]').addEventListener("click",()=>{g(),t.endCall(),r()})}function c(p,f,u){const h=document.createElement("div");h.className="livecall",h.innerHTML=`
1537
+ </div>`;const p=f.querySelector(".call-state"),y=f.querySelector(".call-dot"),k={ringing:"Ringing the team…",connecting:"Someone answered — connecting…",connected:"Connected",missed:"Nobody was free",ended:"Call ended",failed:"The call dropped"},g=["ended","failed","missed"],b=t.on("call",({state:m})=>{if(p.textContent=k[m]||m,y.classList.toggle("off",g.includes(m)),g.includes(m)&&(f.querySelector('[data-act="hangup"]').textContent="Close",m==="missed")){const u=f.querySelector(".call-note");u&&(u.textContent="Nobody was free to pick up just now. Your report is filed and the team will reply in the chat.")}});f.querySelector('[data-act="hangup"]').addEventListener("click",()=>{b(),t.endCall(),r()})}function c(h,f,d){const p=document.createElement("div");p.className="livecall",p.innerHTML=`
1491
1538
  <span class="call-dot" aria-hidden="true"></span>
1492
1539
  <span class="who" role="status" aria-live="polite">Calling the team…</span>
1493
1540
  <span class="secs" hidden></span>
1494
- ${u!=null&&u.recorded?'<span class="call-kept">This call is recorded.</span>':""}
1541
+ ${d!=null&&d.recorded?'<span class="call-kept">This call is recorded.</span>':""}
1495
1542
  <button class="act" type="button" data-act="mute" hidden>Mute</button>
1496
- <button class="act danger" type="button" data-act="hangup">Cancel</button>`,p.insertBefore(h,f);const m=h.querySelector(".who"),C=h.querySelector(".secs"),w=h.querySelector(".call-dot"),g=h.querySelector('[data-act="mute"]'),b=h.querySelector('[data-act="hangup"]');let l=null;const S=()=>{l&&(clearInterval(l),l=null)},y=v=>{S(),w.classList.add("off"),h.classList.add("over"),m.textContent=v,C.hidden=!0,g.hidden=!0,b.textContent="Dismiss",b.classList.remove("danger")},x=t.on("call",({state:v})=>{if(v==="ringing"&&(m.textContent="Calling the team…"),v==="connecting"&&(m.textContent="Someone answered — connecting…"),v==="connected"){m.textContent="You're on a call with the team",g.hidden=!1,C.hidden=!1;const k=Date.now();S(),l=setInterval(()=>{C.textContent=Le(Math.floor((Date.now()-k)/1e3))},1e3),C.textContent="0s"}v==="missed"&&y("Nobody was free. Send a message instead and the team will pick it up."),v==="ended"&&y("Call ended."),v==="failed"&&y("The call dropped.")});g.addEventListener("click",()=>{const v=u.setMuted(!u.isMuted());g.textContent=v?"Unmute":"Mute",m.textContent=v?"You're muted":"You're on a call with the team"}),b.addEventListener("click",()=>{x(),S(),t.endCall(),h.remove(),e.refreshThread(e.openReportId())})}e.offerCall=s,e.callOffered=()=>i,e.showLiveCall=c}function tr(e){var x;const{client:t,say:n,compose:o,sendBtn:a,historyBtn:r,callBtn:i,whoami:s}=e;let d={mode:t.lastLoginMode||"off",signedIn:null},c="idle",p=((x=t.config.user)==null?void 0:x.email)||"",f="",u=!1,h="";const m=()=>d.mode==="required"&&!d.signedIn;function C(){const v=m();o.hidden=v,a.hidden=v,r&&(r.hidden=v),v?i.hidden=!0:e.callOffered()&&!e.mustRate()&&(i.hidden=!1)}function w(){var k;if(d.mode==="off"){s.hidden=!0,s.innerHTML="";return}s.hidden=!1,s.classList.toggle("asking",c!=="idle");const v=h?`<div class="after err">${E(h)}</div>`:"";if(c==="idle"){if(d.signedIn){s.innerHTML=`<span class="who">Signed in as <strong>${E(d.signedIn.email)}</strong></span><button type="button" class="link" data-act="signout">Sign out</button>`;return}const T=(k=t.config.user)==null?void 0:k.email;s.innerHTML=`<span class="who">${d.mode==="required"?"Sign in to report a bug here.":T?`Reporting as <strong>${E(T)}</strong>.`:"Reporting anonymously — sign in and we can tell you what happens next."}</span><button type="button" class="link" data-act="signin">Sign in</button>`;return}if(c==="email"){s.innerHTML=`
1543
+ <button class="act danger" type="button" data-act="hangup">Cancel</button>`,h.insertBefore(p,f);const y=p.querySelector(".who"),k=p.querySelector(".secs"),g=p.querySelector(".call-dot"),b=p.querySelector('[data-act="mute"]'),m=p.querySelector('[data-act="hangup"]');let u=null;const $=()=>{u&&(clearInterval(u),u=null)},C=w=>{$(),g.classList.add("off"),p.classList.add("over"),y.textContent=w,k.hidden=!0,b.hidden=!0,m.textContent="Dismiss",m.classList.remove("danger")},x=t.on("call",({state:w})=>{if(w==="ringing"&&(y.textContent="Calling the team…"),w==="connecting"&&(y.textContent="Someone answered — connecting…"),w==="connected"){y.textContent="You're on a call with the team",b.hidden=!1,k.hidden=!1;const S=Date.now();$(),u=setInterval(()=>{k.textContent=Ae(Math.floor((Date.now()-S)/1e3))},1e3),k.textContent="0s"}w==="missed"&&C("Nobody was free. Send a message instead and the team will pick it up."),w==="ended"&&C("Call ended."),w==="failed"&&C("The call dropped.")});b.addEventListener("click",()=>{const w=d.setMuted(!d.isMuted());b.textContent=w?"Unmute":"Mute",y.textContent=w?"You're muted":"You're on a call with the team"}),m.addEventListener("click",()=>{x(),$(),t.endCall(),p.remove(),e.refreshThread(e.openReportId())})}e.offerCall=s,e.callOffered=()=>i,e.showLiveCall=c}function br(e){var x;const{client:t,say:n,compose:o,sendBtn:a,historyBtn:r,callBtn:i,whoami:s}=e;let l={mode:t.lastLoginMode||"off",signedIn:null},c="idle",h=((x=t.config.user)==null?void 0:x.email)||"",f="",d=!1,p="";const y=()=>l.mode==="required"&&!l.signedIn;function k(){const w=y();o.hidden=w,a.hidden=w,r&&(r.hidden=w),w?i.hidden=!0:e.callOffered()&&!e.mustRate()&&(i.hidden=!1)}function g(){var S;if(l.mode==="off"){s.hidden=!0,s.innerHTML="";return}s.hidden=!1,s.classList.toggle("asking",c!=="idle");const w=p?`<div class="after err">${E(p)}</div>`:"";if(c==="idle"){if(l.signedIn){s.innerHTML=`<span class="who">Signed in as <strong>${E(l.signedIn.email)}</strong></span><button type="button" class="link" data-act="signout">Sign out</button>`;return}const v=(S=t.config.user)==null?void 0:S.email;s.innerHTML=`<span class="who">${l.mode==="required"?"Sign in to report a bug here.":v?`Reporting as <strong>${E(v)}</strong>.`:"Reporting anonymously — sign in and we can tell you what happens next."}</span><button type="button" class="link" data-act="signin">Sign in</button>`;return}if(c==="email"){s.innerHTML=`
1497
1544
  <p class="why">Sign in with any email address — we'll send you a code.
1498
- It's how you hear back about this report${d.mode==="required"?", and this project asks for it":""}.</p>
1545
+ It's how you hear back about this report${l.mode==="required"?", and this project asks for it":""}.</p>
1499
1546
  <div class="row">
1500
- <input type="email" data-fld="email" value="${E(p)}"
1547
+ <input type="email" data-fld="email" value="${E(h)}"
1501
1548
  placeholder="you@example.com" autocomplete="email" spellcheck="false"
1502
- aria-label="Your email address" ${u?"disabled":""} />
1503
- <button type="button" class="primary" data-act="code" ${u?"disabled":""}>
1504
- ${u?"Sending…":"Send code"}
1549
+ aria-label="Your email address" ${d?"disabled":""} />
1550
+ <button type="button" class="primary" data-act="code" ${d?"disabled":""}>
1551
+ ${d?"Sending…":"Send code"}
1505
1552
  </button>
1506
1553
  </div>
1507
- ${v}
1508
- ${d.mode==="optional"?'<div class="after"><button type="button" class="link" data-act="skip">Not now</button></div>':""}`;return}s.innerHTML=`
1509
- <p class="why">We sent a code to <strong>${E(p)}</strong>. It expires in ten minutes.</p>
1554
+ ${w}
1555
+ ${l.mode==="optional"?'<div class="after"><button type="button" class="link" data-act="skip">Not now</button></div>':""}`;return}s.innerHTML=`
1556
+ <p class="why">We sent a code to <strong>${E(h)}</strong>. It expires in ten minutes.</p>
1510
1557
  <div class="row">
1511
1558
  <input type="text" class="code" data-fld="code" value="${E(f)}"
1512
1559
  placeholder="123456" inputmode="numeric" autocomplete="one-time-code"
1513
- maxlength="8" aria-label="The code we emailed you" ${u?"disabled":""} />
1514
- <button type="button" class="primary" data-act="confirm" ${u?"disabled":""}>
1515
- ${u?"Checking…":"Sign in"}
1560
+ maxlength="8" aria-label="The code we emailed you" ${d?"disabled":""} />
1561
+ <button type="button" class="primary" data-act="confirm" ${d?"disabled":""}>
1562
+ ${d?"Checking…":"Sign in"}
1516
1563
  </button>
1517
1564
  </div>
1518
- ${v}
1565
+ ${w}
1519
1566
  <div class="after">
1520
- <button type="button" class="link" data-act="resend" ${u?"disabled":""}>Send it again</button>
1521
- <button type="button" class="link" data-act="signin-back" ${u?"disabled":""}>Use another address</button>
1522
- </div>`}function g({focus:v=!1}={}){var T;if(w(),C(),!v||u)return;const k=s.querySelector("[data-fld]");k&&(k.focus(),(T=k.setSelectionRange)==null||T.call(k,k.value.length,k.value.length))}s.addEventListener("input",v=>{const k=v.target.closest("[data-fld]");k&&(k.dataset.fld==="email"?p=k.value:f=k.value)}),s.addEventListener("keydown",v=>{v.key!=="Enter"||!v.target.closest("[data-fld]")||(v.preventDefault(),c==="email"?b():l())});async function b({resent:v=!1}={}){const k=p.trim();if(!k){h="Enter the address to send the code to.",g({focus:!0});return}u=!0,h="",g();try{await t.signIn(k),p=k,v||(f=""),c="code"}catch(T){h=T.message}finally{u=!1,g({focus:!0})}}async function l(){const v=f.trim();if(!v){h="Enter the code we emailed you.",g({focus:!0});return}u=!0,h="",g();try{const k=await t.confirmSignIn(p.trim(),v);d.signedIn=k,c="idle",f="",n(""),e.offerCall()}catch(k){h=k.message}finally{u=!1,g({focus:c!=="idle"})}}s.addEventListener("click",async v=>{const k=v.target.closest("button[data-act]");if(!k)return;const T=k.dataset.act;if(T==="signin"){c="email",h="",g({focus:!0});return}if(T==="skip"){c="idle",h="",g();return}if(T==="signin-back"){c="email",h="",f="",g({focus:!0});return}if(T==="code"){b();return}if(T==="resend"){b({resent:!0});return}if(T==="confirm"){l();return}if(T==="signout"){u=!0,g();try{await t.signOut()}finally{d.signedIn=null,u=!1,c=d.mode==="required"?"email":"idle",g({focus:c!=="idle"})}}});async function S({announce:v=!1}={}){const k=await t.loginState();d={mode:k.mode,signedIn:k.signedIn},t.lastLoginMode=k.mode,m()&&c==="idle"&&(c="email"),d.signedIn&&(c="idle"),v&&k.signedOutReason&&n(k.signedOutReason,"info"),g()}S({announce:!0}).catch(()=>{});function y(){d.mode!=="off"&&S().catch(()=>{})}e.mustSignIn=m,e.recheckSignIn=y}function bn(e){const t=e||[];if(!t.length)return"";let n=null,o=null;return t.map(a=>{var p,f,u,h;const r=xe(a.at),i=r&&r!==n?`<div class="day-sep" role="separator">${E(Ua(a.at))}</div>`:"";if(i&&(n=r,o=null),!a.from)return o=null,i+or(a);const s={from:a.from,author:(p=a.reply)==null?void 0:p.author,automated:(f=a.reply)==null?void 0:f.automated,body:(u=a.reply)==null?void 0:u.body,at:a.at,attachments:(h=a.reply)==null?void 0:h.attachments},d=nr(s),c=o&&o.who===d&&Math.abs(new Date(a.at).getTime()-new Date(o.at).getTime())<5*6e4;return o={who:d,at:a.at},i+mn(s,c?"cont":"")}).join("")}function nr(e){return e.from==="reporter"?"me":e.automated?"assistant":`team:${e.author||""}`}function or(e){const t=pn(e.at);return`
1567
+ <button type="button" class="link" data-act="resend" ${d?"disabled":""}>Send it again</button>
1568
+ <button type="button" class="link" data-act="signin-back" ${d?"disabled":""}>Use another address</button>
1569
+ </div>`}function b({focus:w=!1}={}){var v;if(g(),k(),!w||d)return;const S=s.querySelector("[data-fld]");S&&(S.focus(),(v=S.setSelectionRange)==null||v.call(S,S.value.length,S.value.length))}s.addEventListener("input",w=>{const S=w.target.closest("[data-fld]");S&&(S.dataset.fld==="email"?h=S.value:f=S.value)}),s.addEventListener("keydown",w=>{w.key!=="Enter"||!w.target.closest("[data-fld]")||(w.preventDefault(),c==="email"?m():u())});async function m({resent:w=!1}={}){const S=h.trim();if(!S){p="Enter the address to send the code to.",b({focus:!0});return}d=!0,p="",b();try{await t.signIn(S),h=S,w||(f=""),c="code"}catch(v){p=v.message}finally{d=!1,b({focus:!0})}}async function u(){const w=f.trim();if(!w){p="Enter the code we emailed you.",b({focus:!0});return}d=!0,p="",b();try{const S=await t.confirmSignIn(h.trim(),w);l.signedIn=S,c="idle",f="",n(""),e.offerCall()}catch(S){p=S.message}finally{d=!1,b({focus:c!=="idle"})}}s.addEventListener("click",async w=>{const S=w.target.closest("button[data-act]");if(!S)return;const v=S.dataset.act;if(v==="signin"){c="email",p="",b({focus:!0});return}if(v==="skip"){c="idle",p="",b();return}if(v==="signin-back"){c="email",p="",f="",b({focus:!0});return}if(v==="code"){m();return}if(v==="resend"){m({resent:!0});return}if(v==="confirm"){u();return}if(v==="signout"){d=!0,b();try{await t.signOut()}finally{l.signedIn=null,d=!1,c=l.mode==="required"?"email":"idle",b({focus:c!=="idle"})}}});async function $({announce:w=!1}={}){const S=await t.loginState();l={mode:S.mode,signedIn:S.signedIn},t.lastLoginMode=S.mode,y()&&c==="idle"&&(c="email"),l.signedIn&&(c="idle"),w&&S.signedOutReason&&n(S.signedOutReason,"info"),b()}$({announce:!0}).catch(()=>{});function C(){l.mode!=="off"&&$().catch(()=>{})}e.mustSignIn=y,e.recheckSignIn=C}function wn(e){const t=e||[];if(!t.length)return"";let n=null,o=null;return t.map(a=>{var h,f,d,p;const r=xe(a.at),i=r&&r!==n?`<div class="day-sep" role="separator">${E(or(a.at))}</div>`:"";if(i&&(n=r,o=null),!a.from)return o=null,i+yr(a);const s={from:a.from,author:(h=a.reply)==null?void 0:h.author,automated:(f=a.reply)==null?void 0:f.automated,body:(d=a.reply)==null?void 0:d.body,at:a.at,attachments:(p=a.reply)==null?void 0:p.attachments},l=mr(s),c=o&&o.who===l&&Math.abs(new Date(a.at).getTime()-new Date(o.at).getTime())<5*6e4;return o={who:l,at:a.at},i+vn(s,c?"cont":"")}).join("")}function mr(e){return e.from==="reporter"?"me":e.automated?"assistant":`team:${e.author||""}`}function yr(e){const t=gn(e.at);return`
1523
1570
  <div class="sys k-${E(e.kind)}">
1524
1571
  <span class="dot" aria-hidden="true"></span>${E(e.summary||"")}${t?`
1525
1572
  <span class="t">· ${E(t)}</span>`:""}
1526
- </div>`}function mn(e,t=""){const n=e.from==="reporter",o=e.body||"",a=e.attachments||[],r=!n&&!!e.automated,i=o?`<span class="msg-text">${E(o)}</span>`:"",s=a.length?`<div class="att">${a.map(rr).join("")}</div>`:"";let d="",c="";if(r)d='<span class="msg-who auto">Assistant <span class="tag">AI</span></span>',c='<span class="av bot orb" aria-hidden="true"></span>';else if(!n){const f=e.author||"Support team";d=`<span class="msg-who">${E(f)}</span>`,c=`<span class="av" aria-hidden="true">${E(Na(f))}</span>`}t.includes("cont")&&(d="");const p=r&&/it goes to the same person/i.test(o)?`<div class="quick" role="group" aria-label="Answer">
1527
- <button type="button" data-quick="Yes, this is the problem">${oe}That's right</button>
1573
+ </div>`}function vn(e,t=""){const n=e.from==="reporter",o=e.body||"",a=e.attachments||[],r=!n&&!!e.automated,i=o?`<span class="msg-text">${E(o)}</span>`:"",s=a.length?`<div class="att">${a.map(vr).join("")}</div>`:"";let l="",c="";if(r)l='<span class="msg-who auto">Assistant <span class="tag">AI</span></span>',c='<span class="av bot orb" aria-hidden="true"></span>';else if(!n){const f=e.author||"Support team";l=`<span class="msg-who">${E(f)}</span>`,c=`<span class="av" aria-hidden="true">${E(nr(f))}</span>`}t.includes("cont")&&(l="");const h=r&&/it goes to the same person/i.test(o)?`<div class="quick" role="group" aria-label="Answer">
1574
+ <button type="button" data-quick="Yes, this is the problem">${ee}That's right</button>
1528
1575
  <button type="button" data-quick="No, that is not the problem">That's not it</button>
1529
- </div>`:r&&ra.test(o)?`<div class="quick" role="group" aria-label="Did this answer your question?">
1530
- <button type="button" data-quick="Yes, that answers it">${oe}Yes, that answers it</button>
1576
+ </div>`:r&&da.test(o)?`<div class="quick" role="group" aria-label="Did this answer your question?">
1577
+ <button type="button" data-quick="Yes, that answers it">${ee}Yes, that answers it</button>
1531
1578
  <button type="button" data-quick="No, I still need help">No, I still need help</button>
1532
1579
  </div>`:"";return`
1533
1580
  <div class="msg-row ${n?"mine":"theirs"} ${r?"auto":""} ${t}">
1534
1581
  ${c}
1535
- ${d}
1582
+ ${l}
1536
1583
  <div class="bubble ${o?"":"silent"}">${i}${s}</div>
1537
- ${p}
1538
- <span class="msg-when">${E(pn(e.at)||Se(e.at))}</span>
1539
- </div>`}function ar(){return`
1584
+ ${h}
1585
+ <span class="msg-when">${E(gn(e.at)||Se(e.at))}</span>
1586
+ </div>`}function wr(){return`
1540
1587
  <div class="typing-row">
1541
1588
  <span class="av bot orb" aria-hidden="true"></span>
1542
1589
  <span class="msg-who auto">Assistant <span class="tag">AI</span></span>
1543
1590
  <div class="bubble typing" role="img" aria-label="The assistant is working on it"><i></i><i></i><i></i></div>
1544
- </div>`}function rr(e){const t=E(e.name||"attachment");if(!e.url)return`<span class="file"><span class="nm">${t}</span></span>`;const n=E(e.url);return e.type==="SCREENSHOT"?`<a href="${n}" target="_blank" rel="noopener noreferrer"><img src="${n}" alt="${t}" loading="lazy"></a>`:e.type==="AUDIO"?`<audio controls preload="metadata" src="${n}"></audio>`:e.type==="VIDEO"?`<video controls preload="metadata" src="${n}"></video>`:`
1591
+ </div>`}function vr(e){const t=E(e.name||"attachment");if(!e.url)return`<span class="file"><span class="nm">${t}</span></span>`;const n=E(e.url);return e.type==="SCREENSHOT"?`<a href="${n}" target="_blank" rel="noopener noreferrer"><img src="${n}" alt="${t}" loading="lazy"></a>`:e.type==="AUDIO"?`<audio controls preload="metadata" src="${n}"></audio>`:e.type==="VIDEO"?`<video controls preload="metadata" src="${n}"></video>`:`
1545
1592
  <a class="file" href="${n}" target="_blank" rel="noopener noreferrer" download>
1546
1593
  <span class="nm">${t}</span>
1547
1594
  ${e.size?`<span class="sz">${E(he(e.size))}</span>`:""}
1548
- </a>`}function ir(e,t,n,o){var y;const{client:a,cfg:r}=e,i=document.createElement("div");i.className="composer",i.innerHTML=`
1595
+ </a>`}function xr(e,t,n,o){var C;const{client:a,cfg:r}=e,i=document.createElement("div");i.className="composer",i.innerHTML=`
1549
1596
  <div class="staged" hidden></div>
1550
1597
  <div class="row">
1551
1598
  <div class="tools">
1552
1599
  ${r.attachments===!1?"":`
1553
- <button class="tool" type="button" data-act="attach" title="Attach a file" aria-label="Attach a file">${cn}</button>
1554
- <button class="tool" type="button" data-act="voice" title="Record a voice note" aria-label="Record a voice note">${ln}</button>`}
1555
- <button class="tool" type="button" data-act="livecall" title="Call the team" aria-label="Call the team" hidden>${qe}</button>
1600
+ <button class="tool" type="button" data-act="attach" title="Attach a file" aria-label="Attach a file">${pn}</button>
1601
+ <button class="tool" type="button" data-act="voice" title="Record a voice note" aria-label="Record a voice note">${hn}</button>`}
1602
+ <button class="tool" type="button" data-act="livecall" title="Call the team" aria-label="Call the team" hidden>${De}</button>
1556
1603
  </div>
1557
1604
  <textarea rows="1" placeholder="Write a reply…" aria-label="Write a reply"></textarea>
1558
- <button class="send" type="button" data-act="send" title="Send" aria-label="Send" disabled>${dn}</button>
1605
+ <button class="send" type="button" data-act="send" title="Send" aria-label="Send" disabled>${ut}</button>
1559
1606
  </div>
1560
1607
  <div class="note" hidden></div>
1561
- <input type="file" hidden multiple accept="${Ot.join(",")}">`,t.appendChild(i);const s=i.querySelector(".staged"),d=i.querySelector("textarea"),c=i.querySelector('[data-act="send"]'),p=i.querySelector('[data-act="voice"]'),f=i.querySelector('[data-act="livecall"]'),u=i.querySelector("input[type=file]"),h=i.querySelector(".note"),m=[];let C=null,w=!1;function g(x,v=""){h.hidden=!x,h.className=`note ${v}`,h.textContent=x||""}function b(){const x=m.filter(v=>v.storageKey);c.disabled=w||!d.value.trim()&&!x.length,s.hidden=!m.length,s.innerHTML=m.map((v,k)=>`
1562
- <span class="chip ${v.storageKey?"":"uploading"}">
1563
- <span class="nm">${E(v.name)}</span>
1564
- <span class="sz">${v.storageKey?he(v.size):"sending…"}</span>
1565
- <button type="button" data-drop="${k}" aria-label="Remove ${E(v.name)}">${ge}</button>
1566
- </span>`).join("");for(const v of s.querySelectorAll("[data-drop]"))v.addEventListener("click",()=>{m.splice(Number(v.dataset.drop),1),b()})}async function l(x,v,k){const T={name:k,size:x.size,storageKey:null};m.push(T),b();try{const{storageKey:j,mime:O}=await a.uploadAttachment(x,v);T.storageKey=j,T.mime=O}catch(j){m.splice(m.indexOf(T),1),g(j.message||"That file could not be sent.","err")}b()}d.addEventListener("input",()=>{d.style.height="auto",d.style.height=`${Math.min(d.scrollHeight,120)}px`,b()}),d.addEventListener("keydown",x=>{x.key==="Enter"&&!x.shiftKey&&!x.isComposing&&(x.preventDefault(),S())}),(y=i.querySelector('[data-act="attach"]'))==null||y.addEventListener("click",()=>u.click()),u.addEventListener("change",()=>{g("");for(const x of u.files){if(x.size>a.config.maxAttachmentBytes){g(`${x.name} is larger than ${he(a.config.maxAttachmentBytes)}.`,"err");continue}l(x,x.type,x.name)}u.value=""}),p&&!uo()&&(p.disabled=!0,p.title="This browser cannot record audio"),p==null||p.addEventListener("click",async()=>{if(C){const x=C;C=null,p.classList.remove("recording"),p.innerHTML=ln,g("");const{blob:v,mime:k}=await x.stop();v.size&&l(v,k,"Voice note");return}try{g(""),C=await bo({maxMs:a.config.maxRecordingMs,onTick:x=>g(`Recording — ${Le(x)}. Tap the mic to stop.`),onAutoStop:()=>p.click()}),p.classList.add("recording"),p.innerHTML=Ba}catch{C=null,g("The microphone is not available — check the browser permission.","err")}}),a.canCallTeam(o).then(x=>{x&&(f.hidden=!1,e.preloadCall())}).catch(()=>{}),f.addEventListener("click",async()=>{f.disabled=!0,g("");try{const x=await a.startLiveCall(o);e.showLiveCall(t,n,x)}catch(x){g(x.message.replace("[BugCatch] ",""),"err")}finally{f.disabled=!1}}),c.addEventListener("click",S),n.addEventListener("click",x=>{var k,T;const v=(T=(k=x.target).closest)==null?void 0:T.call(k,"[data-quick]");!v||w||(d.value=v.dataset.quick,S())});async function S(){var k;const x=d.value.trim(),v=m.filter(T=>T.storageKey);if(!(w||!x&&!v.length)){w=!0,b(),g(""),n.insertAdjacentHTML("beforeend",mn({from:"reporter",body:x,at:new Date().toISOString(),attachments:v.map(T=>({type:"FILE",name:T.name,size:T.size}))},"pending")),ke(n,{smooth:!0});try{await a.replyToReport(o,{body:x,attachments:v.map(T=>({storageKey:T.storageKey,mime:T.mime,name:T.name,size:T.size}))}),d.value="",d.style.height="auto",m.length=0,await e.refreshThread(o)}catch(T){(k=n.querySelector(".msg-row.pending"))==null||k.classList.replace("pending","failed"),g(T.message||"That could not be sent — try again.","err")}finally{w=!1,b()}}}b()}function yn(e){return JSON.stringify(e?[e.score,e.current,e.comment||null]:null)}function dt(e,{client:t,report:n,rating:o,justRated:a=!1,question:r=null,onRated:i=null,onError:s=null}){var w;e.dataset.key=yn(o);const d=o!=null&&o.current?o.score:0,c=o?o.current?a?"Thanks — the team will see that.":`You rated this ${o.score} out of 5.`:`You rated an earlier fix ${o.score} out of 5. How did this one go?`:r||"How did we do?",p=a&&(o==null?void 0:o.current)&&!o.comment;e.innerHTML=`
1608
+ <input type="file" hidden multiple accept="${Dt.join(",")}">`,t.appendChild(i);const s=i.querySelector(".staged"),l=i.querySelector("textarea"),c=i.querySelector('[data-act="send"]'),h=i.querySelector('[data-act="voice"]'),f=i.querySelector('[data-act="livecall"]'),d=i.querySelector("input[type=file]"),p=i.querySelector(".note"),y=[];let k=null,g=!1;function b(x,w=""){p.hidden=!x,p.className=`note ${w}`,p.textContent=x||""}function m(){const x=y.filter(w=>w.storageKey);c.disabled=g||!l.value.trim()&&!x.length,s.hidden=!y.length,s.innerHTML=y.map((w,S)=>`
1609
+ <span class="chip ${w.storageKey?"":"uploading"}">
1610
+ <span class="nm">${E(w.name)}</span>
1611
+ <span class="sz">${w.storageKey?he(w.size):"sending…"}</span>
1612
+ <button type="button" data-drop="${S}" aria-label="Remove ${E(w.name)}">${be}</button>
1613
+ </span>`).join("");for(const w of s.querySelectorAll("[data-drop]"))w.addEventListener("click",()=>{y.splice(Number(w.dataset.drop),1),m()})}async function u(x,w,S){const v={name:S,size:x.size,storageKey:null};y.push(v),m();try{const{storageKey:M,mime:I}=await a.uploadAttachment(x,w);v.storageKey=M,v.mime=I}catch(M){y.splice(y.indexOf(v),1),b(M.message||"That file could not be sent.","err")}m()}l.addEventListener("input",()=>{l.style.height="auto",l.style.height=`${Math.min(l.scrollHeight,120)}px`,m()}),l.addEventListener("keydown",x=>{x.key==="Enter"&&!x.shiftKey&&!x.isComposing&&(x.preventDefault(),$())}),(C=i.querySelector('[data-act="attach"]'))==null||C.addEventListener("click",()=>d.click()),d.addEventListener("change",()=>{b("");for(const x of d.files){if(x.size>a.config.maxAttachmentBytes){b(`${x.name} is larger than ${he(a.config.maxAttachmentBytes)}.`,"err");continue}u(x,x.type,x.name)}d.value=""}),h&&!bo()&&(h.disabled=!0,h.title="This browser cannot record audio"),h==null||h.addEventListener("click",async()=>{if(k){const x=k;k=null,h.classList.remove("recording"),h.innerHTML=hn,b("");const{blob:w,mime:S}=await x.stop();w.size&&u(w,S,"Voice note");return}try{b(""),k=await xo({maxMs:a.config.maxRecordingMs,onTick:x=>b(`Recording — ${Ae(x)}. Tap the mic to stop.`),onAutoStop:()=>h.click()}),h.classList.add("recording"),h.innerHTML=Na}catch{k=null,b("The microphone is not available — check the browser permission.","err")}}),a.canCallTeam(o).then(x=>{x&&(f.hidden=!1,e.preloadCall())}).catch(()=>{}),f.addEventListener("click",async()=>{f.disabled=!0,b("");try{const x=await a.startLiveCall(o);e.showLiveCall(t,n,x)}catch(x){b(x.message.replace("[BugCatch] ",""),"err")}finally{f.disabled=!1}}),c.addEventListener("click",$),n.addEventListener("click",x=>{var S,v;const w=(v=(S=x.target).closest)==null?void 0:v.call(S,"[data-quick]");!w||g||(l.value=w.dataset.quick,$())});async function $(){var S;const x=l.value.trim(),w=y.filter(v=>v.storageKey);if(!(g||!x&&!w.length)){g=!0,m(),b(""),n.insertAdjacentHTML("beforeend",vn({from:"reporter",body:x,at:new Date().toISOString(),attachments:w.map(v=>({type:"FILE",name:v.name,size:v.size}))},"pending")),ke(n,{smooth:!0});try{await a.replyToReport(o,{body:x,attachments:w.map(v=>({storageKey:v.storageKey,mime:v.mime,name:v.name,size:v.size}))}),l.value="",l.style.height="auto",y.length=0,await e.refreshThread(o)}catch(v){(S=n.querySelector(".msg-row.pending"))==null||S.classList.replace("pending","failed"),b(v.message||"That could not be sent — try again.","err")}finally{g=!1,m()}}}m()}function xn(e){return JSON.stringify(e?[e.score,e.current,e.comment||null]:null)}function gt(e,{client:t,report:n,rating:o,justRated:a=!1,question:r=null,onRated:i=null,onError:s=null}){var g;e.dataset.key=xn(o);const l=o!=null&&o.current?o.score:0,c=o?o.current?a?"Thanks — the team will see that.":`You rated this ${o.score} out of 5.`:`You rated an earlier fix ${o.score} out of 5. How did this one go?`:r||"How did we do?",h=a&&(o==null?void 0:o.current)&&!o.comment;e.innerHTML=`
1567
1614
  <p class="fr-q">${E(c)}</p>
1568
- <div class="stars" role="group" aria-label="Rate how this was handled, 1 to 5">${[1,2,3,4,5].map(g=>`
1569
- <button type="button" data-score="${g}" aria-pressed="${g===d}" aria-label="${g} out of 5${g===1?", poor":g===5?", great":""}" class="${g<=d?"on":""}">${un}</button>`).join("")}
1615
+ <div class="stars" role="group" aria-label="Rate how this was handled, 1 to 5">${[1,2,3,4,5].map(b=>`
1616
+ <button type="button" data-score="${b}" aria-pressed="${b===l}" aria-label="${b} out of 5${b===1?", poor":b===5?", great":""}" class="${b<=l?"on":""}">${fn}</button>`).join("")}
1570
1617
  </div>
1571
1618
  ${o!=null&&o.current&&o.comment?`<p class="fr-said">“${E(o.comment)}”</p>`:""}
1572
- ${p?`
1619
+ ${h?`
1573
1620
  <div class="fr-note">
1574
1621
  <textarea maxlength="2000" aria-label="Add a note to your rating" placeholder="${o.score<=2?"What went wrong? (optional)":"Anything to add? (optional)"}"></textarea>
1575
1622
  <button type="button" data-act="rating-note">Add note</button>
1576
1623
  </div>`:""}
1577
1624
  ${o?"":'<p class="fr-hint">1 is poor, 5 is great.</p>'}
1578
- <p class="feedback-status" role="status"></p>`;const f=[...e.querySelectorAll("[data-score]")],u=g=>f.forEach(b=>b.classList.toggle("on",Number(b.dataset.score)<=g)),h=g=>e.querySelectorAll("button, textarea").forEach(b=>{b.disabled=g}),m=e.querySelector(".feedback-status");async function C(g,b){var l;h(!0),m.textContent="";try{const S=await t.rate(n.id,{score:g,comment:b});dt(e,{client:t,report:n,rating:S,justRated:!0,question:r,onRated:i,onError:s}),(l=e.querySelector(".fr-note textarea"))==null||l.focus(),i==null||i(S)}catch(S){m.textContent=S.message,h(!1),u(d),s==null||s(S)}}for(const g of f){const b=Number(g.dataset.score);g.addEventListener("mouseenter",()=>u(b)),g.addEventListener("focus",()=>u(b)),g.addEventListener("blur",()=>u(d)),g.addEventListener("click",()=>C(b))}e.querySelector(".stars").addEventListener("mouseleave",()=>u(d)),(w=e.querySelector('[data-act="rating-note"]'))==null||w.addEventListener("click",()=>{var b;const g=e.querySelector(".fr-note textarea").value.trim();if(!g){(b=e.querySelector(".fr-note"))==null||b.remove();return}C(o.score,g)})}const ut=new WeakMap;function sr(e){return e.rating?` · <span class="rated" aria-label="You rated this ${Number(e.rating)} out of 5">${un}${Number(e.rating)}</span>`:e.ratingAsked?' · <span class="rate-ask">Rate it</span>':""}function cr(e){var C;const{client:t,scrim:n,close:o}=e;let a=null;function r(w,{callFailed:g=null}={}){if(w!=null&&w.id&&!g){d(w.id,{fresh:!0}).then(b=>{b||i(w,{callFailed:g})});return}i(w,{callFailed:g})}function i(w,{callFailed:g=null}={}){var y;const b=w!=null&&w.id?String(w.id).slice(0,8):null,l=(y=w==null?void 0:w.estimate)!=null&&y.label?String(w.estimate.label):null,S=g?`<p class="eta">${E(g)} Your report is filed, and the team will reply in the chat.</p>`:"";n.querySelector(".panel").innerHTML=`
1625
+ <p class="feedback-status" role="status"></p>`;const f=[...e.querySelectorAll("[data-score]")],d=b=>f.forEach(m=>m.classList.toggle("on",Number(m.dataset.score)<=b)),p=b=>e.querySelectorAll("button, textarea").forEach(m=>{m.disabled=b}),y=e.querySelector(".feedback-status");async function k(b,m){var u;p(!0),y.textContent="";try{const $=await t.rate(n.id,{score:b,comment:m});gt(e,{client:t,report:n,rating:$,justRated:!0,question:r,onRated:i,onError:s}),(u=e.querySelector(".fr-note textarea"))==null||u.focus(),i==null||i($)}catch($){y.textContent=$.message,p(!1),d(l),s==null||s($)}}for(const b of f){const m=Number(b.dataset.score);b.addEventListener("mouseenter",()=>d(m)),b.addEventListener("focus",()=>d(m)),b.addEventListener("blur",()=>d(l)),b.addEventListener("click",()=>k(m))}e.querySelector(".stars").addEventListener("mouseleave",()=>d(l)),(g=e.querySelector('[data-act="rating-note"]'))==null||g.addEventListener("click",()=>{var m;const b=e.querySelector(".fr-note textarea").value.trim();if(!b){(m=e.querySelector(".fr-note"))==null||m.remove();return}k(o.score,b)})}const bt=new WeakMap;function kr(e){return e.rating?` · <span class="rated" aria-label="You rated this ${Number(e.rating)} out of 5">${fn}${Number(e.rating)}</span>`:e.ratingAsked?' · <span class="rate-ask">Rate it</span>':""}function Sr(e){var k;const{client:t,scrim:n,close:o}=e;let a=null;function r(g,{callFailed:b=null}={}){if(g!=null&&g.id&&!b){l(g.id,{fresh:!0}).then(m=>{m||i(g,{callFailed:b})});return}i(g,{callFailed:b})}function i(g,{callFailed:b=null}={}){var C;const m=g!=null&&g.id?String(g.id).slice(0,8):null,u=(C=g==null?void 0:g.estimate)!=null&&C.label?String(g.estimate.label):null,$=b?`<p class="eta">${E(b)} Your report is filed, and the team will reply in the chat.</p>`:"";n.querySelector(".panel").innerHTML=`
1579
1626
  <div class="done">
1580
- <div class="tick">${oe}</div>
1627
+ <div class="tick">${ee}</div>
1581
1628
  <h3>Thanks — that's on its way.</h3>
1582
- <p>${b?`Filed as <code>${E(b)}</code>.`:"The team has what they need to reproduce it."}</p>
1583
- ${S}
1584
- ${l?`<p class="eta">Reports like this usually take <strong>${E(l)}</strong>. We'll let you know when it moves.</p>`:""}
1585
- </div>`,setTimeout(o,S?6e3:l?4e3:2e3)}async function s(){const w=n.querySelector(".panel");clearTimeout(c),a=null,w.classList.remove("is-chat"),w.innerHTML=`
1586
- ${st({title:"Your reports",sub:"Where each one has got to.",theme:e.themeLabel()})}
1587
- <div class="history" aria-busy="true">${Qa(3)}</div>`,w.querySelector('[data-act="close"]').addEventListener("click",o);let g=[];try{({reports:g}=await t.myReports())}catch{const l=w.querySelector(".history");l&&(l.innerHTML=ct("Couldn't load your reports just now.",se));return}const b=w.querySelector(".history");if(b){b.removeAttribute("aria-busy"),b.innerHTML=g.length?g.map((l,S)=>`
1588
- <button class="row" type="button" data-report="${E(l.id)}" style="animation-delay:${Math.min(S,8)*30}ms">
1589
- <span class="row-ico" aria-hidden="true">${Xn}</span>
1629
+ <p>${m?`Filed as <code>${E(m)}</code>.`:"The team has what they need to reproduce it."}</p>
1630
+ ${$}
1631
+ ${u?`<p class="eta">Reports like this usually take <strong>${E(u)}</strong>. We'll let you know when it moves.</p>`:""}
1632
+ </div>`,setTimeout(o,$?6e3:u?4e3:2e3)}async function s(){const g=n.querySelector(".panel");clearTimeout(c),a=null,g.classList.remove("is-chat"),g.innerHTML=`
1633
+ ${pt({title:"Your reports",sub:"Where each one has got to.",theme:e.themeLabel()})}
1634
+ <div class="history" aria-busy="true">${er(3)}</div>`,g.querySelector('[data-act="close"]').addEventListener("click",o);let b=[];try{({reports:b}=await t.myReports())}catch{const u=g.querySelector(".history");u&&(u.innerHTML=ht("Couldn't load your reports just now.",re));return}const m=g.querySelector(".history");if(m){m.removeAttribute("aria-busy"),m.innerHTML=b.length?b.map((u,$)=>`
1635
+ <button class="row" type="button" data-report="${E(u.id)}" style="animation-delay:${Math.min($,8)*30}ms">
1636
+ <span class="row-ico" aria-hidden="true">${to}</span>
1590
1637
  <span class="who">
1591
- <span class="ttl">${E(l.title)}</span>
1592
- <span class="sub">${E(l.reference)} · ${E(Se(l.createdAt))}${sr(l)}</span>
1638
+ <span class="ttl">${E(u.title)}</span>
1639
+ <span class="sub">${E(u.reference)} · ${E(Se(u.createdAt))}${kr(u)}</span>
1593
1640
  </span>
1594
- <span class="pill ${E(String(l.status).toLowerCase())}">${E(lt(l.status))}</span>
1595
- <span class="chev" aria-hidden="true">${Oa}</span>
1596
- </button>`).join(""):ct("You haven't reported anything yet.",za);for(const l of b.querySelectorAll("[data-report]"))l.addEventListener("click",()=>d(l.dataset.report))}}async function d(w,{fresh:g=!1}={}){var v;const b=n.querySelector(".panel");clearTimeout(c),b.classList.add("is-chat"),b.innerHTML=`
1597
- ${st({back:!0,title:g?"Looking into it":"Your report",sub:g?"It may ask you a question here.":"Updates, and a way to reply.",theme:e.themeLabel()})}
1598
- <div class="history chatting" aria-busy="true"><div class="thread">${Ha()}</div></div>`,b.querySelector('[data-act="close"]').addEventListener("click",o),b.querySelector('[data-act="back"]').addEventListener("click",s);let l=null;try{l=await t.myReport(w)}catch{l=null}const S=b.querySelector(".history");if(!S||!b.querySelector('[data-act="back"]'))return!1;if(!l)return g?(b.classList.remove("is-chat"),!1):(S.removeAttribute("aria-busy"),S.innerHTML=ct("Couldn't load that report just now.",se),!1);a=w,t.markReportRead(w);const y=bn(l.timeline);S.classList.add("chatting"),S.removeAttribute("aria-busy"),S.innerHTML=`
1641
+ <span class="pill ${E(String(u.status).toLowerCase())}">${E(ft(u.status))}</span>
1642
+ <span class="chev" aria-hidden="true">${_a}</span>
1643
+ </button>`).join(""):ht("You haven't reported anything yet.",Va);for(const u of m.querySelectorAll("[data-report]"))u.addEventListener("click",()=>l(u.dataset.report))}}async function l(g,{fresh:b=!1}={}){var w;const m=n.querySelector(".panel");clearTimeout(c),m.classList.add("is-chat"),m.innerHTML=`
1644
+ ${pt({back:!0,title:b?"Looking into it":"Your report",sub:b?"It may ask you a question here.":"Updates, and a way to reply.",theme:e.themeLabel()})}
1645
+ <div class="history chatting" aria-busy="true"><div class="thread">${tr()}</div></div>`,m.querySelector('[data-act="close"]').addEventListener("click",o),m.querySelector('[data-act="back"]').addEventListener("click",s);let u=null;try{u=await t.myReport(g)}catch{u=null}const $=m.querySelector(".history");if(!$||!m.querySelector('[data-act="back"]'))return!1;if(!u)return b?(m.classList.remove("is-chat"),!1):($.removeAttribute("aria-busy"),$.innerHTML=ht("Couldn't load that report just now.",re),!1);a=g,t.markReportRead(g);const C=wn(u.timeline);$.classList.add("chatting"),$.removeAttribute("aria-busy"),$.innerHTML=`
1599
1646
  <div class="report-head">
1600
- <span class="ttl">${E(l.title)}</span>
1601
- <span class="sub">${E(l.reference)} · ${E(l.project||"")}</span>
1602
- <span class="pill ${E(String(l.status).toLowerCase())}">${E(lt(l.status))}</span>
1603
- ${(v=l.estimate)!=null&&v.label?`<span class="eta-line">Usually takes ${E(String(l.estimate.label))}</span>`:""}
1647
+ <span class="ttl">${E(u.title)}</span>
1648
+ <span class="sub">${E(u.reference)} · ${E(u.project||"")}</span>
1649
+ <span class="pill ${E(String(u.status).toLowerCase())}">${E(ft(u.status))}</span>
1650
+ ${(w=u.estimate)!=null&&w.label?`<span class="eta-line">Usually takes ${E(String(u.estimate.label))}</span>`:""}
1604
1651
  </div>
1605
- <div class="thread" role="log" aria-live="polite" aria-label="Conversation">${y}</div>`;const x=S.querySelector(".thread");return ut.set(x,y),ke(x),f(S,l),u(S,l),l.canReply&&ir(e,S,x,w),p(S,l,w),ke(x),!0}let c=null;function p(w,g,b){var Y,L,D;clearTimeout(c);const l=g.assistant,S=w.querySelector(".thread");let y=w.querySelector(".assistant");if(!l){y==null||y.remove(),(Y=S==null?void 0:S.querySelector(".typing-row"))==null||Y.remove();return}const x=(y==null?void 0:y.dataset.phase)||null;y||(y=document.createElement("div"),y.setAttribute("role","status"),y.setAttribute("aria-live","polite"),(L=w.querySelector(".report-head"))==null||L.after(y)),y.className=`assistant ${E(l.phase)}`,y.dataset.phase=l.phase;const v=l.steps||[],k=v.filter(R=>R.state==="done").length,T=v.some(R=>R.state==="active")?.5:0,j=v.length?Math.round((k+T)/v.length*100):0,O=`
1606
- <div class="as-body${x&&x!==l.phase?" entering":""}">
1652
+ <div class="thread" role="log" aria-live="polite" aria-label="Conversation">${C}</div>`;const x=$.querySelector(".thread");return bt.set(x,C),ke(x),f($,u),d($,u),u.canReply&&xr(e,$,x,g),h($,u,g),ke(x),!0}let c=null;function h(g,b,m){var U,A,H;clearTimeout(c);const u=b.assistant,$=g.querySelector(".thread");let C=g.querySelector(".assistant");if(!u){C==null||C.remove(),(U=$==null?void 0:$.querySelector(".typing-row"))==null||U.remove();return}const x=(C==null?void 0:C.dataset.phase)||null;C||(C=document.createElement("div"),C.setAttribute("role","status"),C.setAttribute("aria-live","polite"),(A=g.querySelector(".report-head"))==null||A.after(C)),C.className=`assistant ${E(u.phase)}`,C.dataset.phase=u.phase;const w=u.steps||[],S=w.filter(z=>z.state==="done").length,v=w.some(z=>z.state==="active")?.5:0,M=w.length?Math.round((S+v)/w.length*100):0,I=`
1653
+ <div class="as-body${x&&x!==u.phase?" entering":""}">
1607
1654
  <div class="as-top">
1608
- <span class="as-orb${l.phase==="calling"||l.phase==="resolved"?"":" orb"}" aria-hidden="true">${l.phase==="calling"?qe:l.phase==="resolved"?oe:""}</span>
1655
+ <span class="as-orb${u.phase==="calling"||u.phase==="resolved"?"":" orb"}" aria-hidden="true">${u.phase==="calling"?De:u.phase==="resolved"?ee:""}</span>
1609
1656
  <div class="as-text">
1610
- <div class="as-title">${E(l.title)}</div>
1611
- <div class="as-detail">${E(l.detail)}</div>
1657
+ <div class="as-title">${E(u.title)}</div>
1658
+ <div class="as-detail">${E(u.detail)}</div>
1612
1659
  </div>
1613
1660
  </div>
1614
1661
  </div>
1615
- ${v.length?`
1616
- <div class="as-progress" role="progressbar" aria-label="Progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${j}"><i style="width:${j}%"></i></div>
1617
- <ol class="as-steps">${v.map(R=>`<li class="${E(R.state)}"${R.state==="active"?' aria-current="step"':""}><span class="dot"></span><span class="lbl">${E(R.label)}</span></li>`).join("")}</ol>`:""}`,_=JSON.stringify([l.phase,l.title,l.detail,v]);if(y.dataset.key!==_){const R=y.querySelector(".as-progress i"),Q=R==null?void 0:R.style.width;y.innerHTML=O,y.dataset.key=_;const J=y.querySelector(".as-progress i");J&&Q&&(J.style.width=Q,requestAnimationFrame(()=>{J.style.width=`${j}%`}))}if(S){const R=hn(S),Q=S.querySelector(".typing-row");l.phase!=="analyzing"?Q==null||Q.remove():(!Q||Q!==S.lastElementChild)&&(Q==null||Q.remove(),S.insertAdjacentHTML("beforeend",ar()),R&&ke(S))}l.phase==="analyzing"?c=setTimeout(()=>h(b),3e3):l.phase==="calling"?c=setTimeout(()=>h(b),1e4):l.phase==="needs_info"&&x!=="needs_info"&&((D=w.querySelector(".composer textarea"))==null||D.focus())}function f(w,g){var l,S;if((l=w.querySelector(".fix-verification"))==null||l.remove(),!g.resolvedAt||!["RESOLVED","CLOSED"].includes(g.status))return;const b=document.createElement("div");b.className="fix-verification",g.verification?b.textContent=g.verification==="CONFIRMED"?"You confirmed that this fix works.":"Your feedback was recorded.":(b.innerHTML='<p>Does the fix work for you?</p><textarea maxlength="4000" aria-label="Fix feedback" placeholder="What happens when you try again? (optional)"></textarea><button type="button" data-result="CONFIRMED">It works now</button> <button type="button" data-result="STILL_HAPPENING">Still happening</button><p class="feedback-status" role="status"></p>',b.querySelectorAll("[data-result]").forEach(y=>{y.onclick=async()=>{b.querySelectorAll("button").forEach(x=>{x.disabled=!0});try{await t.verifyFix(g.id,{result:y.dataset.result,resolvedAt:g.resolvedAt,note:b.querySelector("textarea").value}),await d(g.id)}catch(x){b.querySelector(".feedback-status").textContent=x.message,b.querySelectorAll("button").forEach(v=>{v.disabled=!1})}}})),(S=w.querySelector(".report-head"))==null||S.after(b)}function u(w,g){var S;let b=w.querySelector(".fix-rating");if(!["RESOLVED","CLOSED"].includes(g.status)||!g.ratingAsked){b==null||b.remove();return}b&&b.dataset.key===yn(g.rating)||(b||(b=document.createElement("div"),b.className="fix-rating",(S=w.querySelector(".fix-verification")||w.querySelector(".report-head"))==null||S.after(b)),dt(b,{client:t,report:g,rating:g.rating||null}))}async function h(w){const g=n.querySelector(".history.chatting"),b=g==null?void 0:g.querySelector(".thread");if(!b||a!==w)return;let l=null;try{l=await t.myReport(w)}catch{}if(e.closed||!l||a!==w)return;f(g,l),u(g,l);const S=hn(b),y=bn(l.timeline);ut.get(b)!==y&&(b.innerHTML=y,ut.set(b,y)),p(g,l,w),S&&ke(b);const x=g.querySelector(".report-head .pill");x&&(x.className=`pill ${String(l.status).toLowerCase()}`,x.textContent=lt(l.status))}const m=t.on("update",w=>{!a||(w==null?void 0:w.bugId)!==a||(t.markReportRead(a),h(a))});e.onDestroy(()=>{m(),clearTimeout(c)}),(C=n.querySelector('[data-act="history"]'))==null||C.addEventListener("click",s),e.succeed=r,e.refreshThread=h,e.openReportId=()=>a}const wn="bugcatch.rateLater",lr=50;function vn(){try{const e=JSON.parse(window.localStorage.getItem(wn)||"[]");return Array.isArray(e)?e:[]}catch{return[]}}function dr(e){try{const t=vn().filter(n=>n!==e);t.push(e),window.localStorage.setItem(wn,JSON.stringify(t.slice(-lr)))}catch{}}function ur(e,t=vn()){const n=new Set(t),o=(e||[]).filter(r=>r.ratingDue==="require"||r.ratingDue==="ask"&&!n.has(r.id));if(!o.length)return null;const a=r=>new Date(r.resolvedAt||r.updatedAt||0).getTime()||0;return o.reduce((r,i)=>a(i)>a(r)?i:r)}function pr(e){const{client:t,rateDue:n,compose:o,picks:a,known:r,callBtn:i,titleInput:s,scrim:d}=e;let c=!1;e.mustRate=()=>c;function p(m){c=m;for(const C of[o,a,r])C.classList.toggle("held",m),C.inert=m;m?i.hidden=!0:e.callOffered()&&!e.mustSignIn()&&(i.hidden=!1),e.refreshSendState()}function f(){c&&p(!1)}function u(){n.hidden=!0,n.replaceChildren(),f(),s.focus()}function h(m){var b;const C=m.ratingDue==="require",w=m.resolvedAt?Se(m.resolvedAt):"",g=m.status==="CLOSED"?"closed":"fixed";if(n.hidden=!1,n.classList.toggle("is-required",C),n.innerHTML=`
1662
+ ${w.length?`
1663
+ <div class="as-progress" role="progressbar" aria-label="Progress" aria-valuemin="0" aria-valuemax="100" aria-valuenow="${M}"><i style="width:${M}%"></i></div>
1664
+ <ol class="as-steps">${w.map(z=>`<li class="${E(z.state)}"${z.state==="active"?' aria-current="step"':""}><span class="dot"></span><span class="lbl">${E(z.label)}</span></li>`).join("")}</ol>`:""}`,O=JSON.stringify([u.phase,u.title,u.detail,w]);if(C.dataset.key!==O){const z=C.querySelector(".as-progress i"),Q=z==null?void 0:z.style.width;C.innerHTML=I,C.dataset.key=O;const J=C.querySelector(".as-progress i");J&&Q&&(J.style.width=Q,requestAnimationFrame(()=>{J.style.width=`${M}%`}))}if($){const z=bn($),Q=$.querySelector(".typing-row");u.phase!=="analyzing"?Q==null||Q.remove():(!Q||Q!==$.lastElementChild)&&(Q==null||Q.remove(),$.insertAdjacentHTML("beforeend",wr()),z&&ke($))}u.phase==="analyzing"?c=setTimeout(()=>p(m),3e3):u.phase==="calling"?c=setTimeout(()=>p(m),1e4):u.phase==="needs_info"&&x!=="needs_info"&&((H=g.querySelector(".composer textarea"))==null||H.focus())}function f(g,b){var u,$;if((u=g.querySelector(".fix-verification"))==null||u.remove(),!b.resolvedAt||!["RESOLVED","CLOSED"].includes(b.status))return;const m=document.createElement("div");m.className="fix-verification",b.verification?m.textContent=b.verification==="CONFIRMED"?"You confirmed that this fix works.":"Your feedback was recorded.":(m.innerHTML='<p>Does the fix work for you?</p><textarea maxlength="4000" aria-label="Fix feedback" placeholder="What happens when you try again? (optional)"></textarea><button type="button" data-result="CONFIRMED">It works now</button> <button type="button" data-result="STILL_HAPPENING">Still happening</button><p class="feedback-status" role="status"></p>',m.querySelectorAll("[data-result]").forEach(C=>{C.onclick=async()=>{m.querySelectorAll("button").forEach(x=>{x.disabled=!0});try{await t.verifyFix(b.id,{result:C.dataset.result,resolvedAt:b.resolvedAt,note:m.querySelector("textarea").value}),await l(b.id)}catch(x){m.querySelector(".feedback-status").textContent=x.message,m.querySelectorAll("button").forEach(w=>{w.disabled=!1})}}})),($=g.querySelector(".report-head"))==null||$.after(m)}function d(g,b){var $;let m=g.querySelector(".fix-rating");if(!["RESOLVED","CLOSED"].includes(b.status)||!b.ratingAsked){m==null||m.remove();return}m&&m.dataset.key===xn(b.rating)||(m||(m=document.createElement("div"),m.className="fix-rating",($=g.querySelector(".fix-verification")||g.querySelector(".report-head"))==null||$.after(m)),gt(m,{client:t,report:b,rating:b.rating||null}))}async function p(g){const b=n.querySelector(".history.chatting"),m=b==null?void 0:b.querySelector(".thread");if(!m||a!==g)return;let u=null;try{u=await t.myReport(g)}catch{}if(e.closed||!u||a!==g)return;f(b,u),d(b,u);const $=bn(m),C=wn(u.timeline);bt.get(m)!==C&&(m.innerHTML=C,bt.set(m,C)),h(b,u,g),$&&ke(m);const x=b.querySelector(".report-head .pill");x&&(x.className=`pill ${String(u.status).toLowerCase()}`,x.textContent=ft(u.status))}const y=t.on("update",g=>{!a||(g==null?void 0:g.bugId)!==a||(t.markReportRead(a),p(a))});e.onDestroy(()=>{y(),clearTimeout(c)}),(k=n.querySelector('[data-act="history"]'))==null||k.addEventListener("click",s),e.succeed=r,e.refreshThread=p,e.openReportId=()=>a}const kn="bugcatch.rateLater",$r=50;function Sn(){try{const e=JSON.parse(window.localStorage.getItem(kn)||"[]");return Array.isArray(e)?e:[]}catch{return[]}}function Cr(e){try{const t=Sn().filter(n=>n!==e);t.push(e),window.localStorage.setItem(kn,JSON.stringify(t.slice(-$r)))}catch{}}function Tr(e,t=Sn()){const n=new Set(t),o=(e||[]).filter(r=>r.ratingDue==="require"||r.ratingDue==="ask"&&!n.has(r.id));if(!o.length)return null;const a=r=>new Date(r.resolvedAt||r.updatedAt||0).getTime()||0;return o.reduce((r,i)=>a(i)>a(r)?i:r)}function Er(e){const{client:t,rateDue:n,compose:o,picks:a,known:r,callBtn:i,titleInput:s,scrim:l}=e;let c=!1;e.mustRate=()=>c;function h(y){c=y;for(const k of[o,a,r])k.classList.toggle("held",y),k.inert=y;y?i.hidden=!0:e.callOffered()&&!e.mustSignIn()&&(i.hidden=!1),e.refreshSendState()}function f(){c&&h(!1)}function d(){n.hidden=!0,n.replaceChildren(),f(),s.focus()}function p(y){var m;const k=y.ratingDue==="require",g=y.resolvedAt?Se(y.resolvedAt):"",b=y.status==="CLOSED"?"closed":"fixed";if(n.hidden=!1,n.classList.toggle("is-required",k),n.innerHTML=`
1618
1665
  <div class="rd-head">
1619
- <span class="rd-eyebrow">${C?"Before you report something new":`Your report was ${g}`}</span>
1620
- ${C?"":'<button type="button" class="link rd-later" data-act="rate-later">Not now</button>'}
1666
+ <span class="rd-eyebrow">${k?"Before you report something new":`Your report was ${b}`}</span>
1667
+ ${k?"":'<button type="button" class="link rd-later" data-act="rate-later">Not now</button>'}
1621
1668
  </div>
1622
1669
  <p class="rd-report">
1623
- <span class="rd-ico" aria-hidden="true">${oe}</span>
1624
- <span class="rd-ttl">${E(m.title)}</span>
1625
- <span class="rd-sub">${E(m.reference)}${w?` · ${g} ${E(w)}`:""}</span>
1670
+ <span class="rd-ico" aria-hidden="true">${ee}</span>
1671
+ <span class="rd-ttl">${E(y.title)}</span>
1672
+ <span class="rd-sub">${E(y.reference)}${g?` · ${b} ${E(g)}`:""}</span>
1626
1673
  </p>
1627
- <div class="rd-stars"></div>`,(b=n.querySelector('[data-act="rate-later"]'))==null||b.addEventListener("click",()=>{dr(m.id),u()}),dt(n.querySelector(".rd-stars"),{client:t,report:m,rating:null,question:C?"How did we handle it? Rate it to send a new one.":"How did we do?",onRated:()=>{var l;n.querySelector(".rd-eyebrow").textContent=`Your report was ${g}`,(l=n.querySelector('[data-act="skip"]'))==null||l.remove(),n.classList.remove("is-required"),f()},onError:()=>{if(!c||n.querySelector('[data-act="skip"]'))return;const l=document.createElement("button");l.type="button",l.className="link rd-later",l.dataset.act="skip",l.textContent="Skip for now",l.addEventListener("click",u),n.querySelector(".rd-head").append(l)}}),C){p(!0);const l=d.getRootNode().activeElement;(!l||!n.contains(l))&&n.focus()}}t.hasReports()&&t.myReports().then(({reports:m})=>{if(e.closed)return;const C=ur(m);C&&h(C)}).catch(()=>{})}function hr({root:e,host:t,dock:n,client:o,onClose:a,preloadCall:r=()=>{},themeControls:i=null}){fr(e);const s=o.config,d=()=>(i==null?void 0:i.label())||"",c=document.createElement("div");c.className=`scrim ${n.classList.contains("at-left")?"at-left":"at-right"} ${n.classList.contains("at-top")?"at-top":"at-bottom"}`,c.style.setProperty("--bc-dock-h",`${Math.round(n.getBoundingClientRect().height)}px`),c.innerHTML=`
1628
- <div class="panel" role="dialog" aria-modal="true" aria-labelledby="bc-h">
1629
- ${st({id:"bc-h",title:"Report a bug",sub:"We attach the page details for you.",theme:d()})}
1674
+ <div class="rd-stars"></div>`,(m=n.querySelector('[data-act="rate-later"]'))==null||m.addEventListener("click",()=>{Cr(y.id),d()}),gt(n.querySelector(".rd-stars"),{client:t,report:y,rating:null,question:k?"How did we handle it? Rate it to send a new one.":"How did we do?",onRated:()=>{var u;n.querySelector(".rd-eyebrow").textContent=`Your report was ${b}`,(u=n.querySelector('[data-act="skip"]'))==null||u.remove(),n.classList.remove("is-required"),f()},onError:()=>{if(!c||n.querySelector('[data-act="skip"]'))return;const u=document.createElement("button");u.type="button",u.className="link rd-later",u.dataset.act="skip",u.textContent="Skip for now",u.addEventListener("click",d),n.querySelector(".rd-head").append(u)}}),k){h(!0);const u=l.getRootNode().activeElement;(!u||!n.contains(u))&&n.focus()}}t.hasReports()&&t.myReports().then(({reports:y})=>{if(e.closed)return;const k=Tr(y);k&&p(k)}).catch(()=>{})}const $n={idea:{label:"Idea",icon:Ya},praise:{label:"Praise",icon:Xa},confusing:{label:"Confusing",icon:Ja},other:{label:"Other",icon:Za}},Cn=[{score:1,word:"Terrible",mouth:"M7.8 17.2c1.1-2 2.5-2.9 4.2-2.9s3.1.9 4.2 2.9M8 8l2.4 1.2M16 8l-2.4 1.2"},{score:2,word:"Not great",mouth:"M8.6 16c1-.8 2.1-1.2 3.4-1.2s2.4.4 3.4 1.2"},{score:3,word:"Okay",mouth:"M8.8 15.2h6.4"},{score:4,word:"Good",mouth:"M8.6 14.4c1 .9 2.1 1.4 3.4 1.4s2.4-.5 3.4-1.4"},{score:5,word:"Great",mouth:"M7.8 13.2h8.4a4.2 4.2 0 0 1-8.4 0z"}];function Ir(e){return`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9.2"/><path d="M9 9.9h.01M15 9.9h.01" stroke-width="2.6"/><path d="${e}"/></svg>`}function Lr(){return`
1675
+ <div class="feedback fb-only">
1676
+ <div class="field">
1677
+ <label for="bc-fb-msg">What's on your mind?</label>
1678
+ <textarea id="bc-fb-msg" maxlength="${an}" aria-describedby="bc-fb-err"
1679
+ placeholder="An idea, something you like, or something that confused you."></textarea>
1680
+ <p class="field-err" id="bc-fb-err" hidden></p>
1681
+ </div>
1682
+ <div class="field">
1683
+ <label id="bc-fb-kind-l">What kind is it? <span class="opt">(optional)</span></label>
1684
+ <div class="kinds" role="group" aria-labelledby="bc-fb-kind-l">
1685
+ ${on.map(e=>`
1686
+ <button class="tool" type="button" data-kind="${e}" aria-pressed="false">${$n[e].icon}${$n[e].label}</button>
1687
+ `).join("")}
1688
+ </div>
1689
+ </div>
1690
+ <div class="field">
1691
+ <div class="field-head">
1692
+ <label id="bc-fb-score-l">How's your experience so far? <span class="opt">(optional)</span></label>
1693
+ <span class="count face-word" aria-hidden="true"></span>
1694
+ </div>
1695
+ <div class="faces" role="group" aria-labelledby="bc-fb-score-l">
1696
+ ${Cn.map(e=>`
1697
+ <button class="face" type="button" data-score="${e.score}" aria-pressed="false"
1698
+ aria-label="${e.word}" title="${e.word}">${Ir(e.mouth)}</button>
1699
+ `).join("")}
1700
+ </div>
1701
+ </div>
1702
+ <!-- Who it is from: an address to write back to when the page knows
1703
+ none, and a line saying which one when it does. -->
1704
+ <div class="field fb-who"></div>
1705
+ </div>`}function Ar(e){var v,M;const{client:t,cfg:n,scrim:o,$:a,say:r,close:i}=e,s=a(".feedback"),l=a("#bc-fb-msg"),c=a("#bc-fb-err"),h=a('[data-act="send-feedback"]'),f=a(".face-word");let d=null,p=null,y=!1,k=!1;const g=a(".fb-who"),b=((v=t.signedInAs())==null?void 0:v.email)||((M=n.user)==null?void 0:M.email)||null;b?g.innerHTML=`<p class="fb-as">Sent as <strong>${E(b)}</strong></p>`:g.innerHTML=`
1706
+ <label for="bc-fb-email">Your email <span class="opt">(optional — only if you'd like a reply)</span></label>
1707
+ <input id="bc-fb-email" type="email" autocomplete="email" placeholder="you@example.com" />`;const m=a("#bc-fb-email"),u=`bugcatch.feedbackDraft:${n.projectId||""}`,$=n.drafts!==!1;if($)try{l.value=localStorage.getItem(u)||""}catch{}let C;function x(){if(clearTimeout(C),!!$)try{l.value.trim()?localStorage.setItem(u,l.value):localStorage.removeItem(u)}catch{}}l.addEventListener("input",()=>{l.value.trim()&&w(""),clearTimeout(C),C=setTimeout(x,250)}),e.onDestroy(()=>{k||x()}),s.querySelectorAll("[data-kind]").forEach(I=>{I.addEventListener("click",()=>{d=d===I.dataset.kind?null:I.dataset.kind,s.querySelectorAll("[data-kind]").forEach(O=>O.setAttribute("aria-pressed",String(O.dataset.kind===d)))})}),s.querySelectorAll("[data-score]").forEach(I=>{I.addEventListener("click",()=>{const O=Number(I.dataset.score);p=p===O?null:O,s.querySelectorAll("[data-score]").forEach(U=>U.setAttribute("aria-pressed",String(Number(U.dataset.score)===p))),f.textContent=p?Cn[p-1].word:""})});function w(I){c.hidden=!I,c.innerHTML=I?`${re}<span>${E(I)}</span>`:"",l.classList.toggle("invalid",!!I),l.setAttribute("aria-invalid",String(!!I))}h.addEventListener("click",async()=>{if(y)return;if(!l.value.trim()){w("Write a few words — a sentence is plenty."),l.focus();return}y=!0,e.sending=!0,r("");const I=h.innerHTML;h.disabled=!0,h.innerHTML='<span class="spinner" aria-hidden="true"></span>Sending…';try{const O=await t.feedback({message:l.value,kind:d,score:p,...m&&m.value.trim()?{email:m.value.trim()}:{}});if(O!=null&&O.cancelled)throw Object.assign(new Error(""),{quiet:!0});if(k=!0,clearTimeout(C),$)try{localStorage.removeItem(u)}catch{}S()}catch(O){y=!1,e.sending=!1,h.disabled=!1,h.innerHTML=I,O.quiet||r(String(O.message||"That did not send. Please try again.").replace("[BugCatch] ",""))}});function S(){e.sending=!1,o.querySelector(".panel").innerHTML=`
1708
+ <div class="done">
1709
+ <div class="tick">${ee}</div>
1710
+ <h3>Thanks — that's with the team.</h3>
1711
+ <p>Everything sent here is read by the people who build this.</p>
1712
+ </div>`,setTimeout(i,2600)}e.focusFeedback=()=>l.focus()}const Ne={report:{title:"Report a bug",sub:"We attach the page details for you."},feedback:{title:"Give feedback",sub:"The team reads every note."}};function Mr({root:e,host:t,dock:n,client:o,onClose:a,preloadCall:r=()=>{},themeControls:i=null,mode:s="report"}){Br(e);const l=o.config,c=()=>(i==null?void 0:i.label())||"",h=l.feedback!==!1;let f=h&&s==="feedback"?"feedback":"report";const d=document.createElement("div");d.className=`scrim ${n.classList.contains("at-left")?"at-left":"at-right"} ${n.classList.contains("at-top")?"at-top":"at-bottom"}`,d.style.setProperty("--bc-dock-h",`${Math.round(n.getBoundingClientRect().height)}px`),d.innerHTML=`
1713
+ <div class="panel" role="dialog" aria-modal="true" aria-labelledby="bc-h" data-mode="${f}">
1714
+ ${pt({id:"bc-h",title:Ne[f].title,sub:Ne[f].sub,theme:c()})}
1715
+ ${h?`
1716
+ <div class="modes" role="group" aria-label="What would you like to do?">
1717
+ <button type="button" data-mode="report" aria-pressed="${f==="report"}">${Pa}Report a bug</button>
1718
+ <button type="button" data-mode="feedback" aria-pressed="${f==="feedback"}">${Wa}Give feedback</button>
1719
+ </div>`:""}
1630
1720
  <div class="body">
1631
1721
  <div class="slot" role="alert"></div>
1632
1722
  <!-- A settled report still waiting for its rating. Drawn only when the
1633
1723
  project asks for one here; see rate-due.js. -->
1634
- <div class="rate-due fix-rating" tabindex="-1" hidden></div>
1724
+ <div class="rate-due fix-rating bug-only" tabindex="-1" hidden></div>
1635
1725
  <!-- What the project's team is telling visitors. Drawn only when it
1636
1726
  has published something. -->
1637
1727
  <div class="notices" hidden></div>
1638
- <div class="whoami" hidden></div>
1728
+ <div class="whoami bug-only" hidden></div>
1639
1729
  <!-- The questions the assistant can answer from their account and
1640
1730
  close by itself. Drawn only when the project offers any. -->
1641
- <div class="picks" hidden></div>
1642
- <div class="known" hidden></div>
1643
- ${Fa(s)}
1731
+ <div class="picks bug-only" hidden></div>
1732
+ <div class="known bug-only" hidden></div>
1733
+ ${cr(l)}
1734
+ ${h?Lr():""}
1644
1735
  </div>
1645
1736
  <div class="foot">
1646
- <span class="note" aria-live="polite"></span>
1737
+ <span class="note bug-only" aria-live="polite"></span>
1647
1738
  ${o.hasReports()?'<button class="quiet" type="button" data-act="history">Your reports</button>':""}
1648
1739
  <span class="spacer"></span>
1649
1740
  <!-- Hidden until the API confirms this project can take a call, which
1650
1741
  most cannot. Drawn here rather than as a second launcher because it
1651
1742
  is the same errand as Send report — the difference is only whether
1652
1743
  the reporter would rather say it than type it. -->
1653
- <button class="ghost" type="button" data-act="call" hidden>${qe}Talk to the team</button>
1654
- <button class="primary" type="button" data-act="send">Send report ${dn}</button>
1744
+ <button class="ghost bug-only" type="button" data-act="call" hidden>${De}Talk to the team</button>
1745
+ <button class="primary bug-only" type="button" data-act="send">Send report ${ut}</button>
1746
+ ${h?`<button class="primary fb-only" type="button" data-act="send-feedback">Send feedback ${ut}</button>`:""}
1655
1747
  </div>
1656
1748
  <div class="powered">Powered by
1657
- <a class="brand-credit" href="https://bugcatch.sphoro.com" target="_blank" rel="noopener noreferrer" aria-label="BugCatch">${qa}</a>
1749
+ <a class="brand-credit" href="https://bugcatch.sphoro.com" target="_blank" rel="noopener noreferrer" aria-label="BugCatch">${Fa}</a>
1658
1750
  </div>
1659
- </div>`;const p=y=>c.querySelector(y),f=p(".slot"),u=[],h={client:o,cfg:s,root:e,host:t,dock:n,scrim:c,$:p,titleInput:p("#bc-title"),descInput:p("#bc-desc"),compose:p(".compose"),sendBtn:p('[data-act="send"]'),callBtn:p('[data-act="call"]'),historyBtn:p('[data-act="history"]'),note:p(".foot .note"),whoami:p(".whoami"),refsBox:p(".refs"),notices:p(".notices"),known:p(".known"),picks:p(".picks"),rateDue:p(".rate-due"),sending:!1,closed:!1,say:S,close:b,preloadCall:r,themeLabel:d,onDestroy:y=>{u.push(y)},refreshSendState:null,isRecording:null,stopRecording:null,holdForReference:null,answeredReference:null,pickedIssue:null,offerCall:null,callOffered:null,showLiveCall:null,mustSignIn:null,recheckSignIn:null,mustRate:()=>!1,succeed:null,refreshThread:null,openReportId:null};Wa(h),Ya(h),Ja(h),Za(h),Ga(h),er(h),tr(h),cr(h),pr(h);const m=document.activeElement,C=document.documentElement.style,w=C.overflow;C.overflow="hidden";function g(){h.closed||(u.forEach(y=>y()),h.closed=!0,C.overflow=w,document.removeEventListener("keydown",l,!0),c.remove(),n.hidden=!1,t.style.opacity="",a==null||a())}function b(){var y;if(!h.closed){c.classList.add("closing"),setTimeout(g,160);try{(y=m==null?void 0:m.focus)==null||y.call(m)}catch{}}}function l(y){if(y.key==="Escape"){if(y.stopPropagation(),h.isRecording()){h.stopRecording({keep:!1});return}h.sending||b();return}if(y.key!=="Tab"||h.isRecording())return;const x=[...c.querySelectorAll("button:not(:disabled), input:not([hidden]), textarea, select, [href]")].filter(j=>j.offsetParent!==null||j===document.activeElement);if(!x.length)return;const v=x[0],k=x[x.length-1],T=c.getRootNode().activeElement;y.shiftKey&&T===v?(y.preventDefault(),k.focus()):!y.shiftKey&&T===k&&(y.preventDefault(),v.focus())}document.addEventListener("keydown",l,!0),c.addEventListener("click",y=>{y.target===c&&!h.sending&&b()}),p('[data-act="close"]').addEventListener("click",b),c.addEventListener("click",y=>{const x=y.target.closest('[data-act="theme"]');if(!x||!i)return;const v=i.cycle();x.title=`Theme: ${v.label}`,x.setAttribute("aria-label",`Theme: ${v.label}. Change theme`)});function S(y,x="err"){f.innerHTML=y?`<div class="msg ${x}">${x==="err"?se:""}<span>${E(y)}</span></div>`:""}return e.appendChild(c),h.refreshSendState(),h.titleInput.focus(),{destroy:g,close:b}}function fr(e){if(e.querySelector("style[data-panel]"))return;const t=document.createElement("style");t.setAttribute("data-panel",""),t.textContent=Da;const n=e.querySelector("style");n?n.after(t):e.prepend(t)}const gr=Object.freeze(Object.defineProperty({__proto__:null,openPanel:hr},Symbol.toStringTag,{value:"Module"})),xn=8e3;function br(e=xn){const t=window.AudioContext||window.webkitAudioContext;try{return new t({sampleRate:e})}catch{return new t}}async function mr(e){if(e.state==="suspended")try{await e.resume()}catch{}}function yr(e,t,n){const o=t/n,a=new Float32Array(Math.floor(e.length/o));for(let r=0;r<a.length;r++){const i=Math.floor(r*o),s=Math.min(Math.floor((r+1)*o),e.length);let d=0;for(let c=i;c<s;c++)d+=e[c];a[r]=s>i?d/(s-i):0}return a}const wr=132,kn=32635;function vr(e){const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++){const o=Math.max(-1,Math.min(1,e[n]));let a=Math.round(o*32767);const r=a<0?128:0;r&&(a=-a),a>kn&&(a=kn),a+=wr;let i=7;for(let d=16384;!(a&d)&&i>0;i--,d>>=1);const s=a>>i+3&15;t[n]=~(r|i<<4|s)&255}return t}const xr=512;function kr(e,t,n,o=xn){const a=e.createMediaStreamSource(t),r=e.createScriptProcessor(xr,1,1);r.onaudioprocess=s=>{const d=s.inputBuffer.getChannelData(0),c=e.sampleRate===o?d:yr(d,e.sampleRate,o);n(vr(c))},a.connect(r);const i=e.createGain();return i.gain.value=0,r.connect(i),i.connect(e.destination),{stop(){r.onaudioprocess=null;try{a.disconnect()}catch{}try{r.disconnect()}catch{}try{i.disconnect()}catch{}}}}const Sr="voiceai.realtime.v1",$r=[{urls:"stun:stun.l.google.com:19302"}];function Sn(){return navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0,channelCount:1}})}function $n(){var e;return typeof window<"u"&&typeof window.RTCPeerConnection=="function"&&!!((e=navigator.mediaDevices)!=null&&e.getUserMedia)}async function Cr({realtimeUrl:e,stream:t,ringsUntil:n,onState:o,onAudioBlocked:a,onMicrophone:r}){const i=(I,M)=>{try{o==null||o(I,M)}catch{}},s=I=>{try{a==null||a(I)}catch{}},d=I=>{try{r==null||r(I)}catch{}};if(!$n()){const I=new Error("[BugCatch] this browser cannot make live calls.");throw i("failed",{reason:"unsupported"}),I}let c=t;if(!c)try{c=await Sn()}catch(I){throw i("failed",{reason:"microphone",error:String((I==null?void 0:I.name)||I)}),I}let p;try{p=await Tr(e)}catch(I){throw Tn(c),i("failed",{reason:"connect"}),I}let f=null,u=null,h=!1,m=null,C=null,w=null,g=!1,b=null,l=null,S=!1;const y=[];let x=!1,v=!1,k=!1,T=null,j=null,O=0;const _=2e3,Y=5e3,L=3e4,D=4,R=(I,M)=>{if(!h){h=!0,m&&(clearTimeout(m),m=null),A(),l==null||l(),l=null,te(),b==null||b(),b=null;try{f==null||f.close()}catch{}Tn(c),u&&(u.srcObject=null,u.remove(),u=null);try{p.readyState===WebSocket.OPEN&&p.close(1e3,"call over")}catch{}i(I,M)}},Q=I=>{p.readyState===WebSocket.OPEN&&p.send(JSON.stringify(I))},J=async()=>{if(S||w||h||!C||!C.audio&&!C.transcript)return;S=!0;const I=C.encoding||"mulaw";if(I!=="mulaw"){Cn(`this call is kept as ${I}, which this SDK cannot produce.`);return}const M=Number(C.sample_rate)||8e3;try{const U=br(M);if(await mr(U),h){try{U.close()}catch{}return}const G=kr(U,c,W=>{p.readyState===WebSocket.OPEN&&p.send(W)},M);w={context:U,tap:G}}catch(U){Cn(`could not send the copy this call is keeping: ${String((U==null?void 0:U.message)||U)}`)}};function te(){if(S=!1,!w)return;const{context:I,tap:M}=w;w=null;try{M.stop()}catch{}try{I.close()}catch{}}function le(){var M;if(!u||h)return;let I;try{I=(M=u.play)==null?void 0:M.call(u)}catch{fe();return}if(!I||typeof I.then!="function"){Z();return}I.then(Z,fe)}function Z(){b==null||b(),b=null,g&&(g=!1,s(!1))}function fe(){h||(g||(g=!0,s(!0)),de())}function de(){if(b||typeof window>"u"||typeof window.addEventListener!="function")return;const I=()=>le(),M=["pointerdown","keydown","touchstart"];for(const U of M)window.addEventListener(U,I,{capture:!0,passive:!0});b=()=>{for(const U of M)try{window.removeEventListener(U,I,{capture:!0})}catch{}}}const ue=I=>{f=new RTCPeerConnection({iceServers:I!=null&&I.length?I:$r});for(const M of c.getAudioTracks())f.addTrack(M,c);l=P(),f.onicecandidate=M=>{M.candidate&&Q({type:"signal",signal:{kind:"candidate",payload:M.candidate.toJSON()}})},f.ontrack=M=>{var G;const[U]=M.streams;U&&(u||(u=document.createElement("audio"),u.autoplay=!0,u.playsInline=!0,(G=u.setAttribute)==null||G.call(u,"playsinline",""),u.style.cssText="position:fixed;width:0;height:0;opacity:0;pointer-events:none",document.body.appendChild(u)),u.srcObject=U,le())},f.onconnectionstatechange=z,f.oniceconnectionstatechange=z};function z(){if(!f||h)return;const I=f.connectionState||f.iceConnectionState;if(I==="connected"||I==="completed"){v=!0,O=0,A(),k=!1,i("connected");return}if(I==="disconnected"){if(!v)return;$(_);return}if(I==="failed"){if(!v){R("failed",{reason:"ice"});return}$(0)}}function $(I){h||(k||(k=!0,i("reconnecting"),j=setTimeout(()=>R("failed",{reason:"network"}),L)),!T&&(T=setTimeout(H,I)))}function A(){T&&(clearTimeout(T),T=null),j&&(clearTimeout(j),j=null)}async function H(){if(T=null,h||!f)return;const I=f.connectionState||f.iceConnectionState;if(!(I==="connected"||I==="completed")){if(!x){Q({type:"signal",signal:{kind:"restart",payload:{}}}),T=setTimeout(H,Y);return}O>=D||(O+=1,await N(),T=setTimeout(H,Y))}}async function N(){if(!(h||!f))try{const I=await f.createOffer({iceRestart:!0});await f.setLocalDescription(I),Q({type:"signal",signal:{kind:"offer",payload:f.localDescription.toJSON()}})}catch{}}function P(){let M=null,U=!1;const G=W=>{if(M&&(clearTimeout(M),M=null),W){if(!U)return;U=!1,d(!0);return}U||(M=setTimeout(()=>{M=null,!h&&(U=!0,d(!1))},600))};for(const W of c.getAudioTracks())W.onmute=()=>G(!1),W.onunmute=()=>G(!0),W.onended=()=>{M&&(clearTimeout(M),M=null),!U&&(U=!0,d(!1))};return()=>{M&&(clearTimeout(M),M=null);for(const W of c.getAudioTracks())W.onmute=null,W.onunmute=null,W.onended=null}}const ne=async()=>{try{const I=await f.createOffer();await f.setLocalDescription(I),Q({type:"signal",signal:{kind:"offer",payload:f.localDescription.toJSON()}})}catch{R("failed",{reason:"negotiation"})}},Br=async I=>{try{await f.setRemoteDescription(new RTCSessionDescription(I));const M=await f.createAnswer();await f.setLocalDescription(M),Q({type:"signal",signal:{kind:"answer",payload:f.localDescription.toJSON()}}),await In()}catch{R("failed",{reason:"negotiation"})}},In=async()=>{for(;y.length;){const I=y.shift();try{await f.addIceCandidate(new RTCIceCandidate(I))}catch{}}};let Ln=Promise.resolve();p.onmessage=I=>{Ln=Ln.then(()=>Rr(I)).catch(()=>{})};const Rr=async I=>{var U,G,W,An,Mn;if(typeof I.data!="string")return;let M;try{M=JSON.parse(I.data)}catch{return}switch(M.type){case"session.created":{if(ue((U=M.data)==null?void 0:U.ice_servers),C=((G=M.data)==null?void 0:G.capture)||null,(W=M.data)!=null&&W.peer_present){i("connecting"),J();break}i("ringing"),jr();break}case"peer.joined":{m&&(clearTimeout(m),m=null),i("connecting"),x=!!((An=M.data)!=null&&An.should_offer),x&&await ne(),J();break}case"signal":{if(!f)break;const{kind:Ne,payload:Ue}=M.data||{};if(Ne==="offer")await Br(Ue);else if(Ne==="answer")try{await f.setRemoteDescription(new RTCSessionDescription(Ue)),await In()}catch{R("failed",{reason:"negotiation"})}else if(Ne==="candidate")if(f.remoteDescription)try{await f.addIceCandidate(new RTCIceCandidate(Ue))}catch{}else y.push(Ue);else Ne==="restart"&&x&&await N();break}case"peer.left":R("ended",{reason:"peer_left"});break;case"error":R("failed",{reason:"server",detail:(Mn=M.error)==null?void 0:Mn.detail});break;case"session.ended":R("ended",{reason:"server"});break}};p.onclose=()=>R("ended",{reason:"disconnected"}),p.onerror=()=>R("failed",{reason:"socket"});function jr(){if(!n)return;const I=new Date(n).getTime()-Date.now();Number.isFinite(I)&&(m=setTimeout(()=>R("missed"),Math.max(0,I)))}return{hangUp(){Q({type:"session.end"}),R("ended",{reason:"hung_up"})},setMuted(I){for(const M of c.getAudioTracks())M.enabled=!I;return I},isMuted(){return c.getAudioTracks().every(I=>!I.enabled)}}}function Tr(e){return new Promise((t,n)=>{let o;try{o=new WebSocket(e,Sr)}catch(a){n(a);return}o.onopen=()=>{o.onopen=null,o.onerror=null,t(o)},o.onerror=()=>{o.onopen=null,o.onerror=null,n(new Error("[BugCatch] could not connect the call."))}})}function Cn(e){try{console.warn(`[BugCatch] ${e}`)}catch{}}function Tn(e){var t;for(const n of((t=e==null?void 0:e.getTracks)==null?void 0:t.call(e))??[])try{n.stop()}catch{}}const He={cycleMs:3e3,peak:.045,bursts:[{at:0,seconds:.4,hz:[440,660]},{at:.55,seconds:.4,hz:[440,660]}]};function Er(){var e;try{return!!((e=navigator.userActivation)!=null&&e.hasBeenActive)}catch{return!1}}function Ir(e){if(!e()&&!Er())return()=>{};const t=typeof window<"u"&&(window.AudioContext||window.webkitAudioContext);if(!t)return()=>{};let n;try{n=new t}catch{return()=>{}}let o=!1,a=null;const r=[],i=({at:c,seconds:p,hz:f})=>{const u=n.currentTime+c,h=n.createGain();h.connect(n.destination),h.gain.setValueAtTime(0,u),h.gain.linearRampToValueAtTime(He.peak,u+.02),h.gain.setValueAtTime(He.peak,u+p-.06),h.gain.linearRampToValueAtTime(0,u+p);for(const m of f){const C=n.createOscillator();C.type="sine",C.frequency.value=m,C.connect(h),C.start(u),C.stop(u+p+.02),r.push(C)}},s=()=>{if(!o)try{He.bursts.forEach(i)}catch{}},d=()=>{o||(s(),a=setInterval(s,He.cycleMs))};return n.state==="running"?d():n.resume().then(d).catch(()=>{}),()=>{o=!0,a&&clearInterval(a);for(const c of r)try{c.stop()}catch{}try{n.close()}catch{}}}function Lr(e){const t=Date.parse(e||"");return Number.isNaN(t)?0:Math.max(0,Math.round((t-Date.now())/1e3))}const En=["flex:1","padding:9px 12px","border:0","border-radius:999px","font:560 13px/1.4 inherit","cursor:pointer"].join(";");function Ar({call:e,accent:t=null,position:n="bottom-right",onAnswer:o,onDecline:a,onExpire:r,touched:i=()=>!1}){if(typeof document>"u"||!document.body)return()=>{};const[s,d]=String(n).split("-"),c=document.createElement("div");c.setAttribute("role","alertdialog"),c.setAttribute("aria-live","assertive"),c.setAttribute("aria-label",`${e.from||"Support"} is calling about ${e.reference}`),c.style.cssText=["position:fixed",`${s==="top"?"top":"bottom"}:20px`,`${d==="left"?"left":"right"}:20px`,"z-index:2147483647","width:300px","max-width:calc(100vw - 40px)","padding:16px","border-radius:16px","background:#111113","color:#f3f2ef",'font:13px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif',`box-shadow:0 0 0 1px ${t?`color-mix(in srgb, ${t} 55%, transparent)`:"rgba(255,255,255,.12)"},0 24px 50px -12px rgba(0,0,0,.6)`,"opacity:0","transform:translateY(8px)","transition:opacity .2s ease,transform .2s ease"].join(";");const p=document.createElement("div");p.style.cssText="font-weight:600;font-size:14px;margin-bottom:2px",p.textContent=`${e.from||"Support"} is calling`;const f=document.createElement("div");f.style.cssText="color:#b3b0aa;margin-bottom:10px",f.textContent=e.project?`About your report ${e.reference} · ${e.project}`:`About your report ${e.reference}`;const u=document.createElement("div");u.style.cssText="color:#8f8c86;font-size:12px;margin-bottom:10px";const h=document.createElement("button");h.type="button",h.textContent="Answer",h.style.cssText=`${En};background:${t||Te};color:${t?Xe(t):Ye}`;const m=document.createElement("button");m.type="button",m.textContent="Not now",m.style.cssText=`${En};background:rgba(255,255,255,.08);color:#f3f2ef`;const C=document.createElement("div");if(C.style.cssText="display:flex;gap:8px",C.append(h,m),c.append(p,f,u),e.recorded){const y=document.createElement("div");y.style.cssText="color:#8f8c86;font-size:12px;margin-bottom:10px",y.textContent="This call will be recorded.",c.append(y)}c.append(C),document.body.appendChild(c);const w=Ir(i);let g=!1,b=null;const l=()=>{g||(g=!0,b&&clearInterval(b),w(),c.style.opacity="0",c.style.transform="translateY(8px)",setTimeout(()=>c.remove(),250))},S=()=>{const y=Lr(e.ringsUntil);if(u.textContent=y?`Ringing — ${y}s`:"The call has stopped ringing.",!y){l();try{r==null||r()}catch{}}};return S(),b=setInterval(S,1e3),h.addEventListener("click",()=>{l();try{o==null||o()}catch{}}),m.addEventListener("click",()=>{l();try{a==null||a()}catch{}}),requestAnimationFrame(()=>{c.style.opacity="1",c.style.transform="translateY(0)"}),l}const Mr=Object.freeze(Object.defineProperty({__proto__:null,joinLiveCall:Cr,liveCallSupported:$n,openMicrophone:Sn,showIncomingCall:Ar},Symbol.toStringTag,{value:"Module"}));return it});
1751
+ </div>`;const p=v=>d.querySelector(v),y=p(".slot"),k=[],g={client:o,cfg:l,root:e,host:t,dock:n,scrim:d,$:p,titleInput:p("#bc-title"),descInput:p("#bc-desc"),compose:p(".compose"),sendBtn:p('[data-act="send"]'),callBtn:p('[data-act="call"]'),historyBtn:p('[data-act="history"]'),note:p(".foot .note"),whoami:p(".whoami"),refsBox:p(".refs"),notices:p(".notices"),known:p(".known"),picks:p(".picks"),rateDue:p(".rate-due"),sending:!1,closed:!1,say:S,close:x,preloadCall:r,themeLabel:c,onDestroy:v=>{k.push(v)},refreshSendState:null,isRecording:null,stopRecording:null,holdForReference:null,answeredReference:null,pickedIssue:null,offerCall:null,callOffered:null,showLiveCall:null,mustSignIn:null,recheckSignIn:null,mustRate:()=>!1,focusFeedback:()=>{},succeed:null,refreshThread:null,openReportId:null};lr(g),dr(g),pr(g),hr(g),fr(g),gr(g),br(g),Sr(g),Er(g),h&&Ar(g);function b(v,{focus:M=!0}={}){const I=v==="feedback"&&p(".modes")?"feedback":"report",O=d.querySelector(".panel");g.closed||g.sending||!O||!d.querySelector(".modes")||I==="feedback"&&g.isRecording()||(f=I,O.dataset.mode=I,O.querySelector("#bc-h").textContent=Ne[I].title,O.querySelector(".head .titles p").textContent=Ne[I].sub,d.querySelectorAll(".modes [data-mode]").forEach(U=>{U.setAttribute("aria-pressed",String(U.dataset.mode===I))}),S(""),M&&(I==="feedback"?g.focusFeedback():g.titleInput.focus()))}d.querySelectorAll(".modes [data-mode]").forEach(v=>{v.addEventListener("click",()=>b(v.dataset.mode))}),h&&o.feedbackEnabled().then(v=>{var I,O,U;if(v||g.closed||g.sending)return;b("report",{focus:f==="feedback"}),(I=d.querySelector(".modes"))==null||I.remove(),(O=d.querySelector(".feedback"))==null||O.remove(),(U=d.querySelector('[data-act="send-feedback"]'))==null||U.remove()});const m=document.activeElement,u=document.documentElement.style,$=u.overflow;u.overflow="hidden";function C(){g.closed||(k.forEach(v=>v()),g.closed=!0,u.overflow=$,document.removeEventListener("keydown",w,!0),d.remove(),n.hidden=!1,t.style.opacity="",a==null||a())}function x(){var v;if(!g.closed){d.classList.add("closing"),setTimeout(C,160);try{(v=m==null?void 0:m.focus)==null||v.call(m)}catch{}}}function w(v){if(v.key==="Escape"){if(v.stopPropagation(),g.isRecording()){g.stopRecording({keep:!1});return}g.sending||x();return}if(v.key!=="Tab"||g.isRecording())return;const M=[...d.querySelectorAll("button:not(:disabled), input:not([hidden]), textarea, select, [href]")].filter(A=>A.offsetParent!==null||A===document.activeElement);if(!M.length)return;const I=M[0],O=M[M.length-1],U=d.getRootNode().activeElement;v.shiftKey&&U===I?(v.preventDefault(),O.focus()):!v.shiftKey&&U===O&&(v.preventDefault(),I.focus())}document.addEventListener("keydown",w,!0),d.addEventListener("click",v=>{v.target===d&&!g.sending&&x()}),p('[data-act="close"]').addEventListener("click",x),d.addEventListener("click",v=>{const M=v.target.closest('[data-act="theme"]');if(!M||!i)return;const I=i.cycle();M.title=`Theme: ${I.label}`,M.setAttribute("aria-label",`Theme: ${I.label}. Change theme`)});function S(v,M="err"){y.innerHTML=v?`<div class="msg ${M}">${M==="err"?re:""}<span>${E(v)}</span></div>`:""}return e.appendChild(d),g.refreshSendState(),f==="feedback"?g.focusFeedback():g.titleInput.focus(),{destroy:C,close:x,setMode:b}}function Br(e){if(e.querySelector("style[data-panel]"))return;const t=document.createElement("style");t.setAttribute("data-panel",""),t.textContent=Ga;const n=e.querySelector("style");n?n.after(t):e.prepend(t)}const Rr=Object.freeze(Object.defineProperty({__proto__:null,openPanel:Mr},Symbol.toStringTag,{value:"Module"})),Tn=8e3;function jr(e=Tn){const t=window.AudioContext||window.webkitAudioContext;try{return new t({sampleRate:e})}catch{return new t}}async function Or(e){if(e.state==="suspended")try{await e.resume()}catch{}}function zr(e,t,n){const o=t/n,a=new Float32Array(Math.floor(e.length/o));for(let r=0;r<a.length;r++){const i=Math.floor(r*o),s=Math.min(Math.floor((r+1)*o),e.length);let l=0;for(let c=i;c<s;c++)l+=e[c];a[r]=s>i?l/(s-i):0}return a}const qr=132,En=32635;function Dr(e){const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++){const o=Math.max(-1,Math.min(1,e[n]));let a=Math.round(o*32767);const r=a<0?128:0;r&&(a=-a),a>En&&(a=En),a+=qr;let i=7;for(let l=16384;!(a&l)&&i>0;i--,l>>=1);const s=a>>i+3&15;t[n]=~(r|i<<4|s)&255}return t}const Hr=512;function Qr(e,t,n,o=Tn){const a=e.createMediaStreamSource(t),r=e.createScriptProcessor(Hr,1,1);r.onaudioprocess=s=>{const l=s.inputBuffer.getChannelData(0),c=e.sampleRate===o?l:zr(l,e.sampleRate,o);n(Dr(c))},a.connect(r);const i=e.createGain();return i.gain.value=0,r.connect(i),i.connect(e.destination),{stop(){r.onaudioprocess=null;try{a.disconnect()}catch{}try{r.disconnect()}catch{}try{i.disconnect()}catch{}}}}const Nr="voiceai.realtime.v1",Kr=[{urls:"stun:stun.l.google.com:19302"}];function In(){return navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0,channelCount:1}})}function Ln(){var e;return typeof window<"u"&&typeof window.RTCPeerConnection=="function"&&!!((e=navigator.mediaDevices)!=null&&e.getUserMedia)}async function Pr({realtimeUrl:e,stream:t,ringsUntil:n,onState:o,onAudioBlocked:a,onMicrophone:r}){const i=(L,j)=>{try{o==null||o(L,j)}catch{}},s=L=>{try{a==null||a(L)}catch{}},l=L=>{try{r==null||r(L)}catch{}};if(!Ln()){const L=new Error("[BugCatch] this browser cannot make live calls.");throw i("failed",{reason:"unsupported"}),L}let c=t;if(!c)try{c=await In()}catch(L){throw i("failed",{reason:"microphone",error:String((L==null?void 0:L.name)||L)}),L}let h;try{h=await Ur(e)}catch(L){throw Mn(c),i("failed",{reason:"connect"}),L}let f=null,d=null,p=!1,y=null,k=null,g=null,b=!1,m=null,u=null,$=!1;const C=[];let x=!1,w=!1,S=!1,v=null,M=null,I=0;const O=2e3,U=5e3,A=3e4,H=4,z=(L,j)=>{if(!p){p=!0,y&&(clearTimeout(y),y=null),B(),u==null||u(),u=null,oe(),m==null||m(),m=null;try{f==null||f.close()}catch{}Mn(c),d&&(d.srcObject=null,d.remove(),d=null);try{h.readyState===WebSocket.OPEN&&h.close(1e3,"call over")}catch{}i(L,j)}},Q=L=>{h.readyState===WebSocket.OPEN&&h.send(JSON.stringify(L))},J=async()=>{if($||g||p||!k||!k.audio&&!k.transcript)return;$=!0;const L=k.encoding||"mulaw";if(L!=="mulaw"){An(`this call is kept as ${L}, which this SDK cannot produce.`);return}const j=Number(k.sample_rate)||8e3;try{const P=jr(j);if(await Or(P),p){try{P.close()}catch{}return}const G=Qr(P,c,Y=>{h.readyState===WebSocket.OPEN&&h.send(Y)},j);g={context:P,tap:G}}catch(P){An(`could not send the copy this call is keeping: ${String((P==null?void 0:P.message)||P)}`)}};function oe(){if($=!1,!g)return;const{context:L,tap:j}=g;g=null;try{j.stop()}catch{}try{L.close()}catch{}}function de(){var j;if(!d||p)return;let L;try{L=(j=d.play)==null?void 0:j.call(d)}catch{ge();return}if(!L||typeof L.then!="function"){Z();return}L.then(Z,ge)}function Z(){m==null||m(),m=null,b&&(b=!1,s(!1))}function ge(){p||(b||(b=!0,s(!0)),ue())}function ue(){if(m||typeof window>"u"||typeof window.addEventListener!="function")return;const L=()=>de(),j=["pointerdown","keydown","touchstart"];for(const P of j)window.addEventListener(P,L,{capture:!0,passive:!0});m=()=>{for(const P of j)try{window.removeEventListener(P,L,{capture:!0})}catch{}}}const pe=L=>{f=new RTCPeerConnection({iceServers:L!=null&&L.length?L:Kr});for(const j of c.getAudioTracks())f.addTrack(j,c);u=_(),f.onicecandidate=j=>{j.candidate&&Q({type:"signal",signal:{kind:"candidate",payload:j.candidate.toJSON()}})},f.ontrack=j=>{var G;const[P]=j.streams;P&&(d||(d=document.createElement("audio"),d.autoplay=!0,d.playsInline=!0,(G=d.setAttribute)==null||G.call(d,"playsinline",""),d.style.cssText="position:fixed;width:0;height:0;opacity:0;pointer-events:none",document.body.appendChild(d)),d.srcObject=P,de())},f.onconnectionstatechange=q,f.oniceconnectionstatechange=q};function q(){if(!f||p)return;const L=f.connectionState||f.iceConnectionState;if(L==="connected"||L==="completed"){w=!0,I=0,B(),S=!1,i("connected");return}if(L==="disconnected"){if(!w)return;T(O);return}if(L==="failed"){if(!w){z("failed",{reason:"ice"});return}T(0)}}function T(L){p||(S||(S=!0,i("reconnecting"),M=setTimeout(()=>z("failed",{reason:"network"}),A)),!v&&(v=setTimeout(N,L)))}function B(){v&&(clearTimeout(v),v=null),M&&(clearTimeout(M),M=null)}async function N(){if(v=null,p||!f)return;const L=f.connectionState||f.iceConnectionState;if(!(L==="connected"||L==="completed")){if(!x){Q({type:"signal",signal:{kind:"restart",payload:{}}}),v=setTimeout(N,U);return}I>=H||(I+=1,await K(),v=setTimeout(N,U))}}async function K(){if(!(p||!f))try{const L=await f.createOffer({iceRestart:!0});await f.setLocalDescription(L),Q({type:"signal",signal:{kind:"offer",payload:f.localDescription.toJSON()}})}catch{}}function _(){let j=null,P=!1;const G=Y=>{if(j&&(clearTimeout(j),j=null),Y){if(!P)return;P=!1,l(!0);return}P||(j=setTimeout(()=>{j=null,!p&&(P=!0,l(!1))},600))};for(const Y of c.getAudioTracks())Y.onmute=()=>G(!1),Y.onunmute=()=>G(!0),Y.onended=()=>{j&&(clearTimeout(j),j=null),!P&&(P=!0,l(!1))};return()=>{j&&(clearTimeout(j),j=null);for(const Y of c.getAudioTracks())Y.onmute=null,Y.onunmute=null,Y.onended=null}}const ae=async()=>{try{const L=await f.createOffer();await f.setLocalDescription(L),Q({type:"signal",signal:{kind:"offer",payload:f.localDescription.toJSON()}})}catch{z("failed",{reason:"negotiation"})}},Xr=async L=>{try{await f.setRemoteDescription(new RTCSessionDescription(L));const j=await f.createAnswer();await f.setLocalDescription(j),Q({type:"signal",signal:{kind:"answer",payload:f.localDescription.toJSON()}}),await Rn()}catch{z("failed",{reason:"negotiation"})}},Rn=async()=>{for(;C.length;){const L=C.shift();try{await f.addIceCandidate(new RTCIceCandidate(L))}catch{}}};let jn=Promise.resolve();h.onmessage=L=>{jn=jn.then(()=>Jr(L)).catch(()=>{})};const Jr=async L=>{var P,G,Y,On,zn;if(typeof L.data!="string")return;let j;try{j=JSON.parse(L.data)}catch{return}switch(j.type){case"session.created":{if(pe((P=j.data)==null?void 0:P.ice_servers),k=((G=j.data)==null?void 0:G.capture)||null,(Y=j.data)!=null&&Y.peer_present){i("connecting"),J();break}i("ringing"),Zr();break}case"peer.joined":{y&&(clearTimeout(y),y=null),i("connecting"),x=!!((On=j.data)!=null&&On.should_offer),x&&await ae(),J();break}case"signal":{if(!f)break;const{kind:Pe,payload:Ue}=j.data||{};if(Pe==="offer")await Xr(Ue);else if(Pe==="answer")try{await f.setRemoteDescription(new RTCSessionDescription(Ue)),await Rn()}catch{z("failed",{reason:"negotiation"})}else if(Pe==="candidate")if(f.remoteDescription)try{await f.addIceCandidate(new RTCIceCandidate(Ue))}catch{}else C.push(Ue);else Pe==="restart"&&x&&await K();break}case"peer.left":z("ended",{reason:"peer_left"});break;case"error":z("failed",{reason:"server",detail:(zn=j.error)==null?void 0:zn.detail});break;case"session.ended":z("ended",{reason:"server"});break}};h.onclose=()=>z("ended",{reason:"disconnected"}),h.onerror=()=>z("failed",{reason:"socket"});function Zr(){if(!n)return;const L=new Date(n).getTime()-Date.now();Number.isFinite(L)&&(y=setTimeout(()=>z("missed"),Math.max(0,L)))}return{hangUp(){Q({type:"session.end"}),z("ended",{reason:"hung_up"})},setMuted(L){for(const j of c.getAudioTracks())j.enabled=!L;return L},isMuted(){return c.getAudioTracks().every(L=>!L.enabled)}}}function Ur(e){return new Promise((t,n)=>{let o;try{o=new WebSocket(e,Nr)}catch(a){n(a);return}o.onopen=()=>{o.onopen=null,o.onerror=null,t(o)},o.onerror=()=>{o.onopen=null,o.onerror=null,n(new Error("[BugCatch] could not connect the call."))}})}function An(e){try{console.warn(`[BugCatch] ${e}`)}catch{}}function Mn(e){var t;for(const n of((t=e==null?void 0:e.getTracks)==null?void 0:t.call(e))??[])try{n.stop()}catch{}}const Ke={cycleMs:3e3,peak:.045,bursts:[{at:0,seconds:.4,hz:[440,660]},{at:.55,seconds:.4,hz:[440,660]}]};function _r(){var e;try{return!!((e=navigator.userActivation)!=null&&e.hasBeenActive)}catch{return!1}}function Vr(e){if(!e()&&!_r())return()=>{};const t=typeof window<"u"&&(window.AudioContext||window.webkitAudioContext);if(!t)return()=>{};let n;try{n=new t}catch{return()=>{}}let o=!1,a=null;const r=[],i=({at:c,seconds:h,hz:f})=>{const d=n.currentTime+c,p=n.createGain();p.connect(n.destination),p.gain.setValueAtTime(0,d),p.gain.linearRampToValueAtTime(Ke.peak,d+.02),p.gain.setValueAtTime(Ke.peak,d+h-.06),p.gain.linearRampToValueAtTime(0,d+h);for(const y of f){const k=n.createOscillator();k.type="sine",k.frequency.value=y,k.connect(p),k.start(d),k.stop(d+h+.02),r.push(k)}},s=()=>{if(!o)try{Ke.bursts.forEach(i)}catch{}},l=()=>{o||(s(),a=setInterval(s,Ke.cycleMs))};return n.state==="running"?l():n.resume().then(l).catch(()=>{}),()=>{o=!0,a&&clearInterval(a);for(const c of r)try{c.stop()}catch{}try{n.close()}catch{}}}function Fr(e){const t=Date.parse(e||"");return Number.isNaN(t)?0:Math.max(0,Math.round((t-Date.now())/1e3))}const Bn=["flex:1","padding:9px 12px","border:0","border-radius:999px","font:560 13px/1.4 inherit","cursor:pointer"].join(";");function Wr({call:e,accent:t=null,position:n="bottom-right",onAnswer:o,onDecline:a,onExpire:r,touched:i=()=>!1}){if(typeof document>"u"||!document.body)return()=>{};const[s,l]=String(n).split("-"),c=document.createElement("div");c.setAttribute("role","alertdialog"),c.setAttribute("aria-live","assertive"),c.setAttribute("aria-label",`${e.from||"Support"} is calling about ${e.reference}`),c.style.cssText=["position:fixed",`${s==="top"?"top":"bottom"}:20px`,`${l==="left"?"left":"right"}:20px`,"z-index:2147483647","width:300px","max-width:calc(100vw - 40px)","padding:16px","border-radius:16px","background:#111113","color:#f3f2ef",'font:13px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif',`box-shadow:0 0 0 1px ${t?`color-mix(in srgb, ${t} 55%, transparent)`:"rgba(255,255,255,.12)"},0 24px 50px -12px rgba(0,0,0,.6)`,"opacity:0","transform:translateY(8px)","transition:opacity .2s ease,transform .2s ease"].join(";");const h=document.createElement("div");h.style.cssText="font-weight:600;font-size:14px;margin-bottom:2px",h.textContent=`${e.from||"Support"} is calling`;const f=document.createElement("div");f.style.cssText="color:#b3b0aa;margin-bottom:10px",f.textContent=e.project?`About your report ${e.reference} · ${e.project}`:`About your report ${e.reference}`;const d=document.createElement("div");d.style.cssText="color:#8f8c86;font-size:12px;margin-bottom:10px";const p=document.createElement("button");p.type="button",p.textContent="Answer",p.style.cssText=`${Bn};background:${t||Ee};color:${t?Ge(t):Ze}`;const y=document.createElement("button");y.type="button",y.textContent="Not now",y.style.cssText=`${Bn};background:rgba(255,255,255,.08);color:#f3f2ef`;const k=document.createElement("div");if(k.style.cssText="display:flex;gap:8px",k.append(p,y),c.append(h,f,d),e.recorded){const C=document.createElement("div");C.style.cssText="color:#8f8c86;font-size:12px;margin-bottom:10px",C.textContent="This call will be recorded.",c.append(C)}c.append(k),document.body.appendChild(c);const g=Vr(i);let b=!1,m=null;const u=()=>{b||(b=!0,m&&clearInterval(m),g(),c.style.opacity="0",c.style.transform="translateY(8px)",setTimeout(()=>c.remove(),250))},$=()=>{const C=Fr(e.ringsUntil);if(d.textContent=C?`Ringing — ${C}s`:"The call has stopped ringing.",!C){u();try{r==null||r()}catch{}}};return $(),m=setInterval($,1e3),p.addEventListener("click",()=>{u();try{o==null||o()}catch{}}),y.addEventListener("click",()=>{u();try{a==null||a()}catch{}}),requestAnimationFrame(()=>{c.style.opacity="1",c.style.transform="translateY(0)"}),u}const Yr=Object.freeze(Object.defineProperty({__proto__:null,joinLiveCall:Pr,liveCallSupported:Ln,openMicrophone:In,showIncomingCall:Wr},Symbol.toStringTag,{value:"Module"}));return dt});
1660
1752
  //# sourceMappingURL=bugcatch.standalone.umd.js.map