@webority/support-react 0.122.0 → 0.124.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.
package/dist/guidance.json
CHANGED
package/dist/support-react.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{createSseParser as e}from"@webority/
|
|
1
|
+
import{createSseParser as e}from"@webority/chat-core";import{createContext as t,useCallback as n,useContext as r,useEffect as i,useId as a,useMemo as o,useRef as s,useState as c}from"react";import{AppActionIcon as l,AppAlert as u,AppAvatar as d,AppBadge as f,AppButton as p,AppCard as m,AppChip as h,AppChipGroup as g,AppConfirmDialog as _,AppCopyButton as v,AppDataTable as y,AppDescriptions as b,AppDrawer as x,AppEmptyState as S,AppFileAttachment as C,AppIcon as w,AppInput as T,AppLink as E,AppModal as D,AppSearch as O,AppSelect as k,AppSkeleton as A,AppSpinner as j,AppStatusBadge as M,AppTabs as N,AppTextarea as P,useFloatingStack as F,warnInvalidValue as I}from"@webority/ui-react";import{toBlob as L}from"html-to-image";import{createPortal as R}from"react-dom";import{IST_TIME_ZONE as z,formatDateTime as B,formatFileSize as ee,timeZoneLabel as te}from"@webority/ui-elements/helpers";import{Fragment as V,jsx as H,jsxs as U}from"react/jsx-runtime";import{ChatComposer as ne,ChatMarkdown as re,DEFAULT_CHAT_LABELS as ie}from"@webority/chat-react";var W=`Something went wrong. Please try again.`,G=class extends Error{constructor(e,t,n){super(t),this.name=`SupportApiError`,this.code=e,this.status=n}};async function ae(e){if(e&&typeof Blob<`u`&&e instanceof Blob)try{return JSON.parse(await e.text())}catch{return null}if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null}async function oe(e){if(e instanceof G)return e;let t=e?.response;if(!t)return new G(`network`,W);let n=await ae(t.data);return new G(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.detail==`string`&&n.detail.trim()?n.detail:W,t.status)}async function K(e){try{return(await e()).data}catch(e){throw await oe(e)}}function q(e,t,n){n!=null&&String(n).trim()!==``&&e.append(t,String(n))}function se(e,t,n,r){(n??[]).forEach((n,i)=>{let a=n?.name||`${r}-${i+1}.png`;e.append(t,n,a)})}var ce=20;function le(e,t){return(e??[]).map((e,n)=>e?.name||`${t}-${n+1}.png`).join(`|`)}function ue(e){return e instanceof G&&typeof e.status==`number`&&e.status>=400&&e.status<=499&&e.status!==408&&e.status!==429}function de(e,t=`/api/support`){let n=(typeof t==`string`?t:t?.base??`/api/support`).replace(/\/+$/,``),r=e=>`${n}/tickets/${encodeURIComponent(e)}`,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map;function o(){for(let e of i.keys()){if(i.size<=ce)return;a.has(e)||i.delete(e)}}async function s(e,t){let n=i.get(e)||crypto.randomUUID();i.delete(e),i.set(e,n),a.set(e,(a.get(e)??0)+1),o();try{let r=await t(n);return i.delete(e),r}catch(t){throw ue(t)&&i.delete(e),t}finally{let t=a.get(e)-1;t>0?a.set(e,t):a.delete(e)}}return{getConfig:()=>K(()=>e.get(`${n}/settings`)),listTickets:({status:t,search:r,page:i,pageSize:a}={})=>{let o=new URLSearchParams;q(o,`status`,t),q(o,`search`,r?.trim()),q(o,`page`,i),q(o,`pageSize`,a);let s=o.toString();return K(()=>e.get(`${n}/tickets${s?`?${s}`:``}`))},getTicketCounts:()=>K(()=>e.get(`${n}/tickets/counts`)),getTicket:t=>K(()=>e.get(r(t))),createTicket:({category:t,subject:r,body:i,pageUrl:a,userAgent:o,appVersion:c,files:l,screenshots:u})=>{let d=new FormData;return d.append(`category`,t??``),d.append(`subject`,r??``),d.append(`body`,i??``),q(d,`pageUrl`,a),q(d,`userAgent`,o),q(d,`appVersion`,c),se(d,`files`,l,`file`),se(d,`screenshots`,u,`screenshot`),s([`ticket`,t,r,i,le(l,`file`),le(u,`screenshot`)].join(`\0`),t=>K(()=>e.post(`${n}/tickets`,d,{headers:{"Idempotency-Key":t}})))},getSuggestions:async(t,{signal:r}={})=>{try{return await K(()=>e.get(`${n}/suggestions`,{params:{subject:t},signal:r}))}catch(e){if(e instanceof G&&e.status===404)return[];throw e}},reply:(t,{body:n,files:i,screenshots:a})=>{let o=new FormData;return o.append(`body`,n??``),se(o,`files`,i,`file`),se(o,`screenshots`,a,`screenshot`),s([`reply`,t,n,le(i,`file`),le(a,`screenshot`)].join(`\0`),n=>K(()=>e.post(`${r(t)}/replies`,o,{headers:{"Idempotency-Key":n}})))},reopen:t=>K(()=>e.post(`${r(t)}/reopen`)),cancel:t=>K(()=>e.post(`${r(t)}/cancel`)),rate:(t,{satisfaction:n,comment:i})=>{let a={satisfaction:n};return i!=null&&i.trim()!==``&&(a.comment=i.trim()),K(()=>e.post(`${r(t)}/rating`,a))},fetchAttachment:t=>K(()=>e.get(`${n}/attachments/${encodeURIComponent(t)}`,{responseType:`blob`})),confirmAction:t=>K(()=>e.post(`${n}/actions/confirm`,{token:t}))}}var fe=`Something went wrong. Please try again.`;async function pe(e){if(e&&typeof Blob<`u`&&e instanceof Blob)try{return JSON.parse(await e.text())}catch{return null}if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null}async function me(e){if(e instanceof G)return e;let t=e?.response;if(!t)return new G(`network`,fe);let n=await pe(t.data);return new G(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.message==`string`&&n.message?n.message:fe,t.status)}async function J(e){try{return(await e()).data}catch(e){throw await me(e)}}function he({http:e,baseUrl:t=`/api/support`}){let n=t.replace(/\/+$/,``),r=e=>`${n}/chats/${encodeURIComponent(e)}`;return{start:t=>{let r={};for(let e of[`pageUrl`,`userAgent`,`appVersion`]){let n=t?.[e];typeof n==`string`&&n.trim()!==``&&(r[e]=n)}return J(()=>e.post(`${n}/chats`,r))},current:()=>J(()=>e.get(`${n}/chats/current`)),get:t=>J(()=>e.get(r(t))),send:async(t,{body:n,files:i,idempotencyKey:a})=>{if(typeof a!=`string`||a.trim()===``)throw TypeError(`send needs an idempotencyKey from crypto.randomUUID().`);let o=new FormData;return o.append(`body`,n??``),(i??[]).forEach((e,t)=>{o.append(`files`,e,e?.name||`file-${t+1}.png`)}),J(()=>e.post(`${r(t)}/messages`,o,{headers:{"Idempotency-Key":a}}))},requestAgent:t=>J(()=>e.post(`${r(t)}/agent`)),typing:async t=>{await J(()=>e.post(`${r(t)}/typing`))},close:t=>J(()=>e.post(`${r(t)}/close`))}}var ge=`Something went wrong. Please try again.`;function _e(e){let t=e?.event?.target;if(t&&typeof t.responseText==`string`&&!(typeof t.status==`number`&&(t.status<200||t.status>=300)))return t.responseText}function ve(e){if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null}function ye(e){let t=e?.response,n=ve(t?.data),r=typeof n?.code==`string`&&n.code?n.code:`unknown`,i=typeof n?.message==`string`&&n.message?n.message:ge;return{status:t?.status,code:r,message:i}}var be=e=>e===void 0||e===408||e===429||e>=500;function xe(){let e=``,t=null;return{push(n){e=(e+n).replace(/\r\n/g,`
|
|
2
2
|
`).replace(/\r(?!$)/g,`
|
|
3
3
|
`);let r=e.split(`
|
|
4
4
|
|
|
5
5
|
`);e=r.pop();for(let e of r)for(let n of e.split(`
|
|
6
|
-
`)){if(!n.startsWith(`id:`))continue;let e=n.slice(3);if(e.startsWith(` `)&&(e=e.slice(1)),!/^\d+$/.test(e))continue;let r=Number(e);t=t===null?r:Math.max(t,r)}},get last(){return t}}}function Ce({http:t,baseUrl:n=`/api/support`,retryDelaysMs:r,stallTimeoutMs:i=9e4}){let a=n.replace(/\/+$/,``),o=Array.isArray(r)&&r.length>0?r:[1e3];return{watch(n,r,s){let c=Number.isFinite(r)?r:null,l=!1,u=null,d=null,f=null,p=null,m=!1,h=!1,g=!1,_=null,v=0,y=e=>{Number.isFinite(e)&&(c=Math.max(c??0,e))};function b(e,t){if(!l){h=!0;try{e===`snapshot`?(y(t?.sequence),s.onSnapshot?.(t)):e===`message`?(y(t?.message?.sequence),s.onMessage?.(t)):e===`state`?s.onState?.(t):e===`typing`?s.onTyping?.(t):e===`delta`&&s.onDelta?.(t)}catch{s.onError?.(new W(`handler_failed`,_e))}}}function x(){clearTimeout(d),d=setTimeout(()=>{g=!0,u.abort()},i)}async function S(){u=new AbortController,m=!1,h=!1,g=!1,_=null;let r=0,i=Se(),o=e(({name:e,data:t})=>{if(!(l||_)){if(e===`error`){t?.code===`invalid-response`||t?.code===`stream_ended`?_=`retry`:t?.code===`chat_not_found`?(s.onError?.(t),_=`stop`):(s.onError?.(t),_=`retry`);return}b(e,t)}}),f=e=>{if(l||typeof e!=`string`||e.length<=r)return;let t=e.slice(r);r=e.length,o.push(t),i.push(t),i.last!==null&&(c=Math.max(c??0,i.last)),m=!0,x()},p=`${a}/chats/${encodeURIComponent(n)}/events${c===null?``:`?after=${c}`}`;x();let v;try{v=await t.get(p,{responseType:`text`,headers:{Accept:`text/event-stream`},signal:u.signal,timeout:0,onDownloadProgress:e=>f(ve(e))})}catch(e){if(l)return`stop`;if(g)return`retry`;let t=be(e);return xe(t.status)?`retry`:(s.onError?.({code:t.code,message:t.message}),`stop`)}finally{clearTimeout(d)}return f(v.data),clearTimeout(d),o.end(),_??`retry`}function C(e){return new Promise(t=>{p=t,f=setTimeout(t,e)})}async function w(){let e=0;for(;!l;){let t=await S();if(l||t===`stop`)return;if(m&&(e=0),v=h?0:v+1,v>=10){s.onError?.(new W(`connection_lost`,`We lost the connection to support. Check your internet and try again.`));return}let n=o[Math.min(e,o.length-1)];e+=1,await C(n)}}function T(){l=!0,u?.abort(),clearTimeout(d),clearTimeout(f),p?.()}return w(),T}}}var we=t(null);function Te(){let e=r(we);if(!e)throw Error(`Support components and hooks must be used inside <SupportProvider>.`);return e}function J(){return Te().client}function Ee(){return Te().timeZone}function De(){return Te().renderTime??null}function Oe(e,t,r=!0){let[a,o]=c({data:null,loading:r,error:null}),[l,u]=c(0),d=s(e);d.current=e;let f=s(t);i(()=>{let e=f.current!==t;if(f.current=t,!r){o({data:null,loading:!1,error:null});return}let n=!0;return o(t=>({data:e?null:t.data,loading:!0,error:null})),d.current(l>0).then(e=>n&&o({data:e,loading:!1,error:null}),e=>n&&o(t=>({...t,loading:!1,error:e}))),()=>{n=!1}},[t,r,l]);let p=n(()=>u(e=>e+1),[]),m=n(e=>o(t=>({...t,data:e})),[]);return{...a,reload:p,setData:m}}function Y(){let{loadConfig:e}=Te(),{data:t,loading:n,error:r,reload:i}=Oe(e,`config`);return{config:t,loading:n,error:r,reload:i}}function ke(e={}){let t=J(),{status:n,search:r,page:i,pageSize:a}=e,{data:o,loading:s,error:c,reload:l}=Oe(()=>t.listTickets({status:n,search:r,page:i,pageSize:a}),JSON.stringify([`tickets`,n??null,r??null,i??null,a??null]));return{tickets:o?.items??[],totalCount:o?.totalCount??0,totalPages:o?.totalPages??0,loading:s,error:c,reload:l}}function Ae(){let e=J(),{data:t,loading:n,error:r,reload:i}=Oe(()=>e.getTicketCounts(),`ticket-counts`);return{counts:t,loading:n,error:r,reload:i}}function je(e){let t=J(),{data:r,loading:i,error:a,reload:o,setData:s}=Oe(()=>t.getTicket(e),e??``,!!e),c=n(async e=>{let t=await e();return s(t),t},[s]);return{ticket:r,loading:i,error:a,reload:o,reply:n(n=>c(()=>t.reply(e,n)),[c,t,e]),reopen:n(()=>c(()=>t.reopen(e)),[c,t,e]),cancel:n(()=>c(()=>t.cancel(e)),[c,t,e]),rate:n(n=>c(()=>t.rate(e,n)),[c,t,e])}}var Me=`We could not reach support. Check your connection and try again.`;function X(e,t){if(e instanceof W){if(e.code===`network`)return Me;if(e.code!==`unknown`)return e.message}return t}function Ne(e){return(e?.allowedContentTypes??[]).join(`,`)}function Pe(e,t){if(t.length===0)return!0;let n=(e||``).toLowerCase();return t.some(e=>{let t=e.toLowerCase();return t.endsWith(`/*`)?n.startsWith(t.slice(0,-1)):n===t})}function Z(e,t){let n=e??[],r=t?.maxAttachmentsPerMessage??0,i=t?.maxAttachmentBytes??0,a=t?.allowedContentTypes??[];if(r>0&&n.length>r)return r===1?`You can attach one file.`:`You can attach up to ${r} files.`;for(let e of n){let t=e.name||`This file`;if(!Pe(e.type,a))return`${t} is a file type we cannot accept.`;if(i>0&&e.size>i)return`${t} is larger than ${ne(i)}.`}return null}var Fe=e=>e===1?`You can attach one file.`:`You can attach up to ${e} files.`;function Ie(e){return`${e.name}|${e.size}|${e.lastModified}`}function Le(e,t,n){let r=n?.maxAttachmentsPerMessage??0,i=new Set(e.map(Ie)),a=[],o=null;for(let e of t){let t=Ie(e);if(i.has(t)){o??=e.name;continue}i.add(t),a.push(e)}let s=r>0?Math.max(0,r-e.length):a.length,c=[...e,...a.slice(0,s)];return{files:c,notice:(a.length>s?Fe(r):null)??Z(c,n)??(o?`${o} is already attached.`:``)}}function Re(e){let t=Array.from(e.clipboardData?.items??[]),n=Date.now();return t.filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(Boolean).map((e,t)=>{let r=(e.type.split(`/`)[1]||`png`).replace(`jpeg`,`jpg`);return new File([e],`pasted-image-${n}-${t+1}.${r}`,{type:e.type})})}function ze(e,t){let[n,r]=c(e);return i(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function Be({id:e,label:t=`Attachments`,files:n,onChange:r,config:i,error:a}){let o=i?.maxAttachmentBytes??0,s=o>0?Math.max(.1,Math.round(o/(1024*1024)*10)/10):0;return B(C,{id:e,label:t,optional:!0,multiple:!0,value:n,onChange:r,accept:Ne(i),maxSizeMb:s,validate:!1,error:a||void 0})}function Ve({items:e}){return e.length===0?null:B(m,{variant:`muted`,padding:`sm`,title:`These may already answer your question`,children:B(`ul`,{className:`list-unstyled mb-0 d-flex flex-column gap-2`,children:e.map(e=>V(`li`,{children:[B(`div`,{className:`fw-semibold`,children:e.title}),B(`div`,{className:`small text-body-secondary`,children:e.summary})]},e.title))})})}var He=500,Ue=3,We=5;function Ge(e,t){return t&&e.includes(t)?t:``}function Ke({id:e,config:t,defaultCategory:n,initialValues:r,onValuesChange:a,extraFiles:o=[],onSubmit:s,onBusyChange:l,children:d}){let f=t?.categories??[],[p,m]=c(()=>r?.category??Ge(f,n)),[h,g]=c(r?.subject??``),[_,v]=c(r?.body??``),[y,b]=c(r?.files??[]),[x,S]=c({}),[C,w]=c(``),E=J(),[D,O]=c(``),[A,j]=c([]),M=ze(h.trim(),He);i(()=>{a?.({category:p,subject:h,body:_,files:y})},[p,h,_,y,a]),i(()=>{O(M)},[M]),i(()=>{if(D.length<Ue){j([]);return}let e=!0,t=new AbortController;return j([]),E.getSuggestions(D,{signal:t.signal}).then(t=>{e&&j(Array.isArray(t)?t.slice(0,We):[])},()=>{e&&j([])}),()=>{e=!1,t.abort()}},[E,D]);let N=e=>{b(e),S(n=>({...n,files:Z([...o,...e],t)??void 0}))},F=e=>{let t=Re(e);t.length>0&&N([...y,...t])};function I(){let e={};h.trim()||(e.subject=`Enter a subject.`),_.trim()||(e.body=`Enter what happened.`);let n=Z([...o,...y],t);return n&&(e.files=n),S(e),Object.keys(e).length===0}async function L(e){if(e.preventDefault(),w(``),I()){l?.(!0);try{await s({category:p,subject:h.trim(),body:_.trim(),files:y})}catch(e){w(X(e,`Your ticket did not send. Please try again.`))}finally{l?.(!1)}}}return V(`form`,{id:e,onSubmit:L,noValidate:!0,className:`d-flex flex-column gap-3`,children:[C&&B(u,{tone:`danger`,children:C}),B(k,{id:`${e}-category`,label:`Category`,value:p,onChange:m,options:f.map(e=>({value:e,label:e})),placeholder:`Choose a category`,hint:`Not sure? Leave it empty and we will sort it.`,error:x.category}),B(T,{id:`${e}-subject`,label:`Subject`,required:!0,maxLength:t?.subjectMaxLength,showCount:!0,placeholder:`A short summary`,value:h,onChange:e=>g(e.target.value),onBlur:()=>O(h.trim()),error:x.subject}),B(Ve,{items:A}),B(P,{id:`${e}-body`,label:`Message`,required:!0,rows:6,maxLength:t?.bodyMaxLength,showCount:!0,placeholder:`What happened, and what did you expect to happen?`,value:_,onChange:e=>v(e.target.value),onPaste:F,hint:`You can paste an image into the message.`,error:x.body}),d,B(Be,{id:`${e}-files`,files:y,onChange:N,config:t,error:x.files})]})}var qe=`supportCapture`,Je={zIndex:`var(--wui-z-fixed)`,bottom:0,insetInlineEnd:0},Ye={zIndex:`var(--wui-z-fixed)`},Xe={maxWidth:`20rem`},Ze=e=>e.dataset?.[qe]===`exclude`||e.matches?.(`.modal-backdrop`)?!1:!(e.matches?.(`.modal`)&&e.querySelector?.(`[data-support-capture="exclude"]`)),Qe=()=>new Promise(e=>requestAnimationFrame(()=>e()));async function $e(){let e=await L(document.body,{filter:Ze,pixelRatio:Math.min(window.devicePixelRatio||1,2),style:{overflow:`visible`,paddingRight:`0px`}});if(!e)throw Error(`The page capture came back empty.`);return new File([e],`screenshot.png`,{type:`image/png`})}function et({file:e,failed:t,disabled:n,hintId:r,controlRef:a,onAdd:o,onRemove:s}){let[l,d]=c(null);return i(()=>{if(!e)return;let t=URL.createObjectURL(e);return d(t),()=>URL.revokeObjectURL(t)},[e]),V(`div`,{className:`d-flex flex-column gap-2`,children:[B(`span`,{className:`wui-text-sm fw-semibold`,children:`Screenshot`}),e&&l&&B(`img`,{src:l,alt:`Screenshot of the page you were on`,className:`d-block w-100 border rounded`,style:Xe}),B(`div`,{ref:a,className:`d-flex flex-wrap gap-2`,children:e?V(z,{children:[B(p,{variant:`outline`,size:`sm`,leftIcon:`refresh-cw`,onClick:o,disabled:n,"aria-describedby":r,children:`Retake`}),B(p,{variant:`ghost`,size:`sm`,leftIcon:`x`,onClick:s,disabled:n,children:`Remove screenshot`})]}):B(p,{variant:`outline`,size:`sm`,leftIcon:`camera`,onClick:o,disabled:n,"aria-describedby":r,children:`Add a screenshot`})}),B(`span`,{id:r,className:`wui-text-sm text-body-secondary`,children:`Only what is on your screen now. You can remove it before sending.`}),t&&B(u,{tone:`info`,children:`We could not take a screenshot of this page. You can attach an image instead, or send the report without one.`})]})}function tt({label:e=`Report an issue`,floating:t=!1,compact:n=!1,defaultCategory:r=`Bug report`,appVersion:o,getTicketHref:l,onOpenTicket:d,onCreated:f,className:m,style:h}){let g=J(),{config:_,error:v}=Y(),y=`support-report-${a().replace(/[^a-zA-Z0-9-]/g,``)}`,[b,x]=c(!1),[S,C]=c(!1),[T,E]=c(null),[O,k]=c(!1),[A,j]=c(!1),[M,N]=c(null),[P,I]=c(null),L=F(`end`,t&&n),ee=s(null),te=s(!1);i(()=>{S||!te.current||(te.current=!1,ee.current?.querySelector(`button`)?.focus())},[S]);function ne(){N(null),E(null),k(!1),I(null),x(!0)}async function re(){C(!0),k(!1),await Qe(),await Qe();try{E(await $e())}catch{E(null),k(!0)}finally{te.current=!0,C(!1)}}let H=()=>{A||(x(!1),E(null),k(!1),N(null),I(null))};async function ie(e){let t=await g.createTicket({...e,pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:o,screenshots:T?[T]:[]});N(t),E(null),f?.(t)}let ae=!M&&(!!T||!!P&&(P.subject.trim()!==``||P.body.trim()!==``||P.files.length>0)),U=M&&l?l(M.id):void 0,W=M?V(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[B(p,{variant:`secondary`,onClick:H,children:`Close`}),M&&(U||d)?B(p,{href:U,onClick:U?void 0:()=>{x(!1),N(null),d(M)},children:`View ticket`}):null]}):V(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[B(p,{variant:`secondary`,onClick:H,disabled:A,children:`Cancel`}),B(p,{type:`submit`,form:y,loading:A,disabled:!_,children:`Submit`})]}),oe=n?B(p,{variant:`secondary`,className:`wui-floating-btn wui-floating-btn--secondary`,disabled:S,onClick:ne,"aria-haspopup":`dialog`,"aria-label":e,tooltip:e,tooltipPlacement:`start`,children:B(w,{name:`bug`,size:22})}):B(p,{leftIcon:`bug`,variant:t?`primary`:`outline`,disabled:S,onClick:ne,"aria-haspopup":`dialog`,children:e});return V(z,{children:[t&&n?L&&R(B(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--secondary`,m].filter(Boolean).join(` `),style:h,children:oe}),L):B(`span`,{"data-support-capture":`exclude`,className:[t?`position-fixed m-3`:`d-inline-block`,m].filter(Boolean).join(` `),style:t?{...Je,...h}:h,children:oe}),S&&V(`div`,{"data-support-capture":`exclude`,role:`status`,className:`position-fixed top-0 start-50 translate-middle-x mt-3 d-flex align-items-center gap-2 px-3 py-2 bg-body border rounded-pill shadow-sm wui-text-sm`,style:Ye,children:[B(`span`,{className:`spinner-border spinner-border-sm`,"aria-hidden":`true`}),`Taking a screenshot`]}),B(D,{open:b,size:`lg`,title:`Report an issue`,subtitle:`Tell us what went wrong. You can add a screenshot of this page if it helps.`,headerIcon:`bug`,confirmDiscard:`Discard this report?`,dirty:ae&&!A,onClose:H,footer:W,"data-support-capture":`exclude`,children:M?B(u,{tone:`success`,role:`status`,title:`Ticket ${M.number} is with the support team`,children:`We reply by email. You can follow the ticket on your support page.`}):_?B(Ke,{id:y,config:_,defaultCategory:r,initialValues:P,onValuesChange:I,extraFiles:T?[T]:[],onSubmit:ie,onBusyChange:j,children:B(et,{file:T,failed:O,disabled:A||S,hintId:`${y}-screenshot-hint`,controlRef:ee,onAdd:re,onRemove:()=>E(null)})}):B(u,{tone:v?`danger`:`info`,children:v?X(v,`We could not load the support settings.`):`Loading the form.`})})]})}function nt({open:e,onClose:t,onCreated:n,config:r,defaultCategory:i,appVersion:o}){let s=J(),l=`support-new-${a().replace(/[^a-zA-Z0-9-]/g,``)}`,[u,d]=c(!1),[f,m]=c(null),h=!!f&&(f.subject.trim()!==``||f.body.trim()!==``||f.files.length>0);async function g(e){n(await s.createTicket({...e,userAgent:typeof navigator>`u`?void 0:navigator.userAgent,appVersion:o}))}return B(D,{open:e,size:`lg`,title:`New ticket`,subtitle:`Tell us what you need. We reply by email and on this page.`,headerIcon:`message-square`,confirmDiscard:`Discard this ticket?`,dirty:h&&!u,onClose:()=>{u||t()},footer:V(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[B(p,{variant:`secondary`,onClick:t,disabled:u,children:`Cancel`}),B(p,{type:`submit`,form:l,loading:u,children:`Send ticket`})]}),children:e&&B(Ke,{id:l,config:r,defaultCategory:i,onSubmit:g,onBusyChange:d,onValuesChange:m})})}var rt={Open:`warning`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`};function it(e){return rt[e]??`neutral`}var at=6e4,ot=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`application/pdf`];function st({attachment:e}){let t=J(),[n,r]=c(!1),[i,a]=c(!1);async function o(){r(!0),a(!1);let n=ot.includes(e.contentType)?window.open(``,`_blank`):null;n&&(n.opener=null);try{let r=await t.fetchAttachment(e.id),i=URL.createObjectURL(r);if(setTimeout(()=>URL.revokeObjectURL(i),at),n)n.location.href=i;else{let t=document.createElement(`a`);t.href=i,t.download=e.fileName,t.click()}}catch{n?.close(),a(!0)}finally{r(!1)}}let s=Number.isFinite(e.sizeBytes)?ne(e.sizeBytes):`-`;return V(z,{children:[B(h,{leadingIcon:i?`x-circle`:`paperclip`,label:n?V(z,{children:[B(j,{size:`sm`,label:`Loading ${e.fileName}`}),` `,e.fileName]}):e.fileName,onClick:o,disabled:n,"aria-busy":n||void 0,title:`${e.fileName}, ${s}`}),i&&B(`span`,{role:`status`,className:`wui-text-xs text-danger align-self-center`,children:`Could not load this file. Click to try again.`})]})}function Q({iso:e,className:t}){let n=De(),r=Ee();return n?n(e):B(`time`,{dateTime:e,className:t,children:te(e,{timeZone:r})})}var ct={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`};function lt({messages:e}){return B(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:e.map(e=>{let t=B(Q,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return V(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[B(`span`,{className:`d-block`,children:e.body}),t]},e.id);let n=e.authorKind===`Customer`,r=e.authorName||(n?`You`:`Support team`);return V(`li`,{className:`d-flex align-items-start gap-2${n?` flex-row-reverse`:``}`,"data-author":n?`customer`:`agent`,children:[B(d,{name:r,size:32,tone:n?`neutral`:`primary`}),V(m,{className:`flex-grow-1 border`,padding:`sm`,variant:n?`default`:`accent`,style:{minWidth:0},children:[V(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2 mb-2`,children:[V(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2 fw-semibold wui-text-sm text-break`,children:[r,!n&&B(f,{tone:`primary`,children:`Support`})]}),t]}),B(`div`,{className:`wui-text-sm`,style:ct,children:e.body}),e.attachments?.length>0&&B(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.attachments.map(e=>B(st,{attachment:e},e.id))})]})]},e.id)})})}function ut({satisfaction:e,comment:t,canRate:n=!1,commentMaxLength:r,onRate:i}){let o=a(),[s,l]=c(``),[d,f]=c(null),[h,g]=c(``);if(e)return V(u,{tone:e===`Satisfied`?`success`:`info`,role:`status`,children:[e===`Satisfied`?`You told us this solved your problem.`:`You told us this did not solve your problem.`,t?V(`span`,{className:`d-block mt-1`,children:[`Your comment: `,t]}):null]});if(!n)return null;async function _(e){g(``),f(e);try{await i({satisfaction:e,comment:s})}catch(e){g(X(e,`Your rating did not send. Please try again.`))}finally{f(null)}}return B(m,{padding:`sm`,className:`border`,title:`Did this solve your problem?`,children:V(`div`,{className:`d-flex flex-column gap-2`,children:[h&&B(u,{tone:`danger`,children:h}),B(P,{id:`${o}-comment`,label:`Anything to add?`,rows:2,maxLength:r,value:s,onChange:e=>l(e.target.value),hint:`Optional. Your comment goes to the support team.`}),V(`div`,{className:`d-flex flex-wrap gap-2`,children:[B(p,{variant:`outline`,leftIcon:`check-circle`,loading:d===`Satisfied`,disabled:d!==null,onClick:()=>_(`Satisfied`),children:`Yes, it is solved`}),B(p,{variant:`outline`,leftIcon:`x-circle`,loading:d===`Unsatisfied`,disabled:d!==null,onClick:()=>_(`Unsatisfied`),children:`No, it is not`})]})]})})}function dt({onSend:e,config:t,reopens:n=!1}){let r=a(),[i,o]=c(``),[s,d]=c([]),[f,m]=c(``),[_,v]=c(``),[y,b]=c(!1),x=e=>{let n=Le(s,e,t);d(n.files),m(n.notice)},S=e=>{let n=s.filter((t,n)=>n!==e);d(n),m(Z(n,t)??``)},C=e=>{let t=Re(e);t.length>0&&x(t)};async function w(n){n.preventDefault();let r=i.trim();if(!r){v(`Write a message before you send it.`);return}let a=Z(s,t);if(a){m(a);return}v(``),b(!0);try{await e({body:r,files:s}),o(``),d([]),m(``)}catch(e){v(X(e,`Your reply did not send. Please try again.`))}finally{b(!1)}}let T=_||f;return V(`form`,{onSubmit:w,noValidate:!0,className:`d-flex flex-column gap-2`,"aria-label":`Reply to this ticket`,children:[T&&B(u,{tone:`danger`,children:T}),B(P,{id:`${r}-body`,label:`Your reply`,rows:4,autoGrow:!0,maxLength:t?.bodyMaxLength,value:i,onChange:e=>o(e.target.value),onPaste:C,hint:n?`Sending a reply reopens this ticket. You can paste an image into the message.`:`You can paste an image into the message.`,required:!0}),s.length>0&&B(g,{label:`Attached files`,children:s.map((e,t)=>B(h,{leadingIcon:`paperclip`,label:e.name,removeLabel:`Remove ${e.name}`,onRemove:()=>S(t)},Ie(e)))}),V(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[B(l,{iconVariant:`bulk`,icon:`paperclip`,label:`Attach a file`,multiple:t?.maxAttachmentsPerMessage!==1,accept:Ne(t),onFiles:x}),B(p,{type:`submit`,leftIcon:`send`,loading:y,children:`Send reply`})]})]})}function ft({ticketId:e,onBack:t,onChanged:n,onOpenTicket:r}){let{config:i}=Y(),a=Ee(),o=De(),{ticket:s,loading:l,error:d,reload:f,reply:h,reopen:g,cancel:v,rate:y}=je(e),[x,S]=c(!1),[C,T]=c(!1),[E,D]=c(!1),[O,k]=c(``),j=async e=>{let t=await e();return n?.(),t};async function N(){k(``),S(!0);try{await j(g)}catch(e){k(X(e,`The ticket did not reopen. Please try again.`))}finally{S(!1)}}async function P(){k(``),D(!0);try{await j(v)}catch(e){k(X(e,`The request was not withdrawn. Please try again.`))}finally{D(!1),T(!1)}}let F=B(p,{variant:`ghost`,size:`sm`,leftIcon:`arrow-left`,onClick:t,className:`align-self-start`,children:`Back to tickets`});if(!s)return V(`section`,{className:`d-flex flex-column gap-3`,"aria-busy":l||void 0,children:[F,d?V(u,{tone:`danger`,children:[X(d,`We could not load this ticket.`),` `,B(p,{variant:`ghost`,size:`sm`,onClick:f,children:`Try again`})]}):B(A,{height:160})]});let I=it(s.status),L=[{key:`status`,label:`Status`,value:s.statusLabel?B(M,{label:s.statusLabel,tone:I}):`-`},{key:`category`,label:`Category`,value:s.category||`-`},{key:`ticket`,label:`Ticket`,value:s.number},{key:`opened`,label:`Opened`,value:B(Q,{iso:s.createdDateTimeUtc})},{key:`updated`,label:`Last update`,value:B(Q,{iso:s.updatedDateTimeUtc})}];return V(`section`,{className:`d-flex flex-column gap-3`,"aria-labelledby":`support-ticket-${s.id}`,children:[F,V(`div`,{className:`row g-3`,children:[V(`div`,{className:`col-12 col-lg-8 d-flex flex-column gap-3`,children:[V(`header`,{className:`d-flex flex-column gap-2`,children:[V(`div`,{className:`d-flex flex-wrap align-items-center gap-2`,children:[B(`h2`,{id:`support-ticket-${s.id}`,className:`h5 mb-0 text-break`,children:s.subject}),s.statusLabel&&B(M,{label:s.statusLabel,tone:I})]}),V(`ul`,{className:`list-unstyled d-flex flex-wrap gap-3 mb-0 wui-text-sm text-body-secondary`,"aria-label":`Ticket summary`,children:[s.number&&V(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[B(w,{variant:`bulk`,name:`receipt-text`,size:16}),s.number]}),s.category&&V(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[B(w,{variant:`bulk`,name:`folder-2`,size:16}),s.category]}),V(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[B(w,{variant:`bulk`,name:`calendar-1`,size:16}),`Opened `,B(Q,{iso:s.createdDateTimeUtc})]})]}),o===null&&V(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:[`Times are shown in `,re(a),`.`]})]}),O&&B(u,{tone:`danger`,children:O}),s.mergedInto&&V(u,{tone:`info`,role:`status`,children:[`This ticket was merged into `,s.mergedInto.number,`. The conversation carries on there.`,` `,r&&V(p,{variant:`ghost`,size:`sm`,onClick:()=>r(s.mergedInto.id),children:[`Open `,s.mergedInto.number]})]}),s.canReopen&&B(u,{tone:`success`,role:`status`,children:`If you still need help, reopen the ticket or send a reply.`}),s.status===`WaitingOnCustomer`&&B(u,{tone:`warning`,role:`status`,children:`We need your answer to carry on. Reply below and the ticket goes back to our team.`}),!s.canReopen&&B(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:`Our team marks this resolved once your question is answered. Replying reopens it.`}),s.canReopen&&B(p,{variant:`secondary`,leftIcon:`history`,loading:x,onClick:N,className:`align-self-start`,children:`Reopen ticket`}),s.canCancel&&B(p,{variant:`secondary`,onClick:()=>T(!0),className:`align-self-start`,children:`Withdraw request`}),B(_,{open:C,title:`Withdraw this request?`,message:`Our team will stop working on this ticket. You can open a new ticket later if you still need help.`,confirmLabel:`Withdraw request`,danger:!0,loading:E,onConfirm:P,onClose:()=>T(!1)}),B(ut,{satisfaction:s.satisfaction,comment:s.satisfactionComment,canRate:s.canRate,commentMaxLength:i?.satisfactionCommentMaxLength,onRate:e=>j(()=>y(e))}),B(lt,{messages:s.messages??[]}),s.mergedTickets?.length>0&&V(`section`,{"aria-labelledby":`support-merged-${s.id}`,className:`d-flex flex-column gap-1`,children:[B(`h3`,{id:`support-merged-${s.id}`,className:`h6 mb-0`,children:`Merged into this ticket`}),B(`ul`,{className:`list-unstyled d-flex flex-column gap-1 mb-0 wui-text-sm`,children:s.mergedTickets.map(e=>B(`li`,{children:r?V(p,{variant:`ghost`,size:`sm`,onClick:()=>r(e.id),children:[e.number,`: `,e.subject]}):`${e.number}: ${e.subject}`},e.id))})]}),!s.mergedInto&&B(dt,{config:i,reopens:s.canReopen,onSend:e=>j(()=>h(e))})]}),B(`aside`,{"aria-label":`Ticket details`,className:`col-12 col-lg-4`,children:V(m,{padding:`sm`,className:`border`,children:[B(`h3`,{className:`h6`,children:`Ticket details`}),B(b,{columns:1,items:L})]})})]})]})}var pt=`ticket`;function mt(){return typeof window>`u`?null:new URLSearchParams(window.location.search).get(pt)}function ht(e){if(typeof window>`u`)return e?`?${pt}=${encodeURIComponent(e)}`:`?`;let t=new URL(window.location.href);return e?t.searchParams.set(pt,e):t.searchParams.delete(pt),`${t.pathname}${t.search}${t.hash}`}function gt(e){if(typeof window>`u`)return;let t=ht(e);t!==`${window.location.pathname}${window.location.search}${window.location.hash}`&&window.history.replaceState(window.history.state,``,t)}var _t=[{key:`all`,label:`All`,countKey:`total`},{key:`Open`,label:`Open`,countKey:`open`},{key:`InProgress`,label:`In progress`,countKey:`inProgress`},{key:`WaitingOnCustomer`,label:`Waiting on you`,countKey:`waitingOnCustomer`},{key:`Resolved`,label:`Resolved`,countKey:`resolved`},{key:`Closed`,label:`Closed`,countKey:`closed`},{key:`Cancelled`,label:`Cancelled`,countKey:null}],vt=[`tabs`,`select`,`none`];function yt({tickets:e,loading:t,error:n,onRetry:r,onOpen:i,status:a,onStatusChange:o,statusFilter:s=`tabs`,counts:c,search:d,onSearchChange:f,pagination:m}){I(`SupportCenter`,`statusFilter`,s,vt);let h=_t.map(({key:e,label:t,countKey:n})=>{let r=c?.[n];return{value:e,label:r==null?t:`${t} (${r})`}}),g=(e,t)=>{e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),i(t))};return V(`div`,{className:`d-flex flex-column gap-3`,children:[n&&V(u,{tone:`danger`,children:[X(n,`We could not load your tickets.`),` `,B(p,{variant:`ghost`,size:`sm`,onClick:r,children:`Try again`})]}),V(`div`,{className:`d-flex flex-column flex-md-row gap-2 align-items-md-center justify-content-between`,children:[s===`none`?null:s===`select`?B(k,{label:`Status`,value:a,onChange:o,options:h}):B(N,{tabs:_t.map(({key:e,label:t,countKey:n})=>({key:e,label:t,count:c?.[n]})),value:a,onChange:o,ariaLabel:`Filter tickets by status`,className:`flex-grow-1`}),B(O,{value:d,onChange:f,placeholder:`Search tickets`,ariaLabel:`Search tickets`})]}),B(y,{columns:[{key:`subject`,label:`Subject`,render:e=>V(`div`,{className:`d-flex flex-column`,style:{minWidth:0},children:[B(E,{href:ht(e.id),animation:`none`,className:`fw-semibold text-break`,onClick:t=>g(t,e.id),children:e.subject}),V(`span`,{className:`wui-text-xs text-body-secondary`,children:[e.number,`, `,e.category,e.awaitingCustomer?`. Waiting for your reply`:``]})]})},{key:`status`,label:`Status`,render:e=>e.statusLabel?B(M,{label:e.statusLabel,tone:it(e.status)}):`-`},{key:`messageCount`,label:`Messages`,cellClassName:`wui-text-sm text-body-secondary`,render:e=>e.messageCount},{key:`updatedDateTimeUtc`,label:`Last update`,cellClassName:`wui-text-sm text-body-secondary text-nowrap`,render:e=>B(Q,{iso:e.updatedDateTimeUtc})}],rows:e,loading:t,skeletonRows:4,ariaLabel:`Support tickets`,rowActionsLabel:`Actions`,rowActions:e=>B(l,{icon:`eye`,label:`Open ticket ${e.subject}`,href:ht(e.id),onClick:t=>g(t,e.id)}),stickyActions:!0,stackOnMobile:!0,sourceCount:c?.total??0,pagination:m,empty:B(S,{variant:`table`,icon:`message-square`,title:`No tickets yet`,text:`When you raise a ticket, it shows here with its status.`}),emptyFiltered:B(S,{variant:`table`,icon:`search`,title:`No tickets match`,text:`Try another search or status.`})})]})}var bt=300,xt=10;function St({initialTicketId:e,defaultCategory:t,appVersion:n,status:r,defaultStatus:a=`all`,onStatusChange:o,statusFilter:s=`tabs`}){let{config:l,error:d,reload:f}=Y(),[m,h]=c(a),g=r!==void 0,_=g?r:m,v=e=>{g||h(e),o?.(e)},[y,b]=c(``),x=ze(y.trim(),bt),[S,C]=c(xt),w=`${_}|${x}|${S}`,[T,E]=c({key:w,page:1}),D=T.key===w?T.page:1,O=e=>E({key:w,page:e}),k=ke({status:_===`all`?void 0:_,search:x||void 0,page:D,pageSize:S}),{counts:A,reload:j}=Ae(),[M,N]=c(()=>e||mt()),[P,F]=c(!1),I=k.totalPages;i(()=>{I>0&&D>I&&E({key:w,page:I})},[I,D,w]);let L=()=>{k.reload(),j()},R=e=>{N(e),gt(e)};if(M)return B(ft,{ticketId:M,onBack:()=>R(null),onChanged:L,onOpenTicket:R},M);let ee={page:D,totalPages:Math.max(1,k.totalPages),pageSize:S,total:k.totalCount,setPage:O,setPageSize:C};return V(`section`,{className:`d-flex flex-column gap-3 min-w-0`,"aria-labelledby":`support-center-title`,children:[V(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[B(`h2`,{id:`support-center-title`,className:`h5 mb-0`,children:`Your tickets`}),B(p,{leftIcon:`plus`,onClick:()=>F(!0),disabled:!l,children:`New ticket`})]}),d&&V(u,{tone:`warning`,children:[X(d,`We could not load the support settings.`),` `,B(p,{variant:`ghost`,size:`sm`,onClick:f,children:`Try again`})]}),B(yt,{tickets:k.tickets,loading:k.loading,error:k.error,onRetry:L,onOpen:R,status:_,onStatusChange:v,statusFilter:s,counts:A,search:y,onSearchChange:b,pagination:ee}),l&&B(nt,{open:P,onClose:()=>F(!1),config:l,defaultCategory:t,appVersion:n,onCreated:e=>{F(!1),L(),R(e.id)}})]})}function Ct(e){return e===0?`You are next in the queue.`:e===1?`1 person is ahead of you.`:`${e} people are ahead of you.`}function wt({position:e}){return V(`div`,{className:`d-flex flex-column gap-1`,children:[V(`div`,{className:`d-flex align-items-center gap-2`,children:[B(j,{size:`sm`,label:`Waiting for a person`}),B(`span`,{className:`wui-text-sm`,children:`Waiting for a person to join.`})]}),typeof e==`number`&&B(`span`,{className:`wui-text-sm text-body-secondary`,children:Ct(e)}),B(`span`,{className:`wui-text-sm text-body-secondary`,children:`If no one is free, we will reply here and by email.`})]})}var Tt={CustomerEnded:`You ended this chat.`,AgentEnded:`Our team ended this chat.`,NoAgentAvailable:`No one was free to join. We will reply to you here and by email.`,Idle:`This chat ended because it was quiet for a while.`};function Et({state:e,closeReason:t,agentName:n,ticketNumber:r,ticketId:i,waitingPosition:a,canRequestAgent:o=!1,requesting:s=!1,onRequestAgent:c,onOpenTicket:l,onRestart:u}){return V(`div`,{role:`status`,className:`d-flex flex-column gap-2 pb-3 mb-3 border-bottom`,children:[e===`Assistant`&&V(z,{children:[B(`div`,{children:B(f,{tone:`neutral`,children:`AI assistant`})}),B(`p`,{className:`wui-text-sm mb-0`,children:`You are chatting with our AI assistant.`}),o&&B(`div`,{children:B(p,{variant:`outline`,size:`sm`,leftIcon:`user`,loading:s,onClick:c,children:`Talk to a person`})})]}),e===`WaitingForAgent`&&V(z,{children:[B(`div`,{children:B(f,{tone:`info`,children:`In the queue`})}),B(wt,{position:a??null})]}),e===`WithAgent`&&V(z,{children:[B(`div`,{children:B(f,{tone:`success`,children:`Live agent`})}),B(`p`,{className:`wui-text-sm mb-0`,children:n?`${n} from our team is chatting with you.`:`A member of our team is chatting with you.`})]}),e===`Closed`&&V(z,{children:[B(`div`,{children:B(f,{tone:`neutral`,children:`Chat ended`})}),B(`p`,{className:`wui-text-sm mb-0`,children:Tt[t]??`This chat has ended.`}),r&&B(`p`,{className:`wui-text-sm mb-0`,children:`Your ticket number is ${r}.`}),V(`div`,{className:`d-flex flex-wrap gap-2`,children:[l&&i&&B(p,{variant:`outline`,size:`sm`,onClick:()=>l({id:i,number:r}),children:`View ticket`}),B(p,{size:`sm`,leftIcon:`plus`,onClick:u,children:`Start a new chat`})]})]})]})}var Dt={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},Ot={...Dt,maxWidth:`85%`};function kt(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function At(e){if(!e?.parentElement)return;let t=()=>{let t=kt(e);t&&(t.scrollTop=t.scrollHeight)};t();let n=new MutationObserver(t);return n.observe(e.parentElement,{childList:!0,subtree:!0,characterData:!0}),()=>n.disconnect()}function jt({attachments:e}){return e?.length?B(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.map(e=>B(st,{attachment:e},e.id))}):null}function Mt({message:e,resolveLink:t,linkComponent:n}){let r=B(Q,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return V(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[B(`span`,{className:`d-block`,children:e.body}),r]});if(e.authorKind===`Customer`)return B(`li`,{className:`d-flex justify-content-end`,"data-author":`customer`,children:V(m,{padding:`sm`,variant:`muted`,style:Ot,children:[B(`span`,{className:`visually-hidden`,children:`You: `}),B(`div`,{className:`wui-text-sm`,style:Dt,children:e.body}),B(jt,{attachments:e.attachments}),B(`div`,{className:`mt-1`,children:r})]})});if(e.authorKind===`Assistant`)return V(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,children:[B(d,{name:`Assistant`,size:32,tone:`primary`}),V(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[V(`div`,{className:`d-flex flex-wrap align-items-center gap-2 mb-1`,children:[B(`span`,{className:`fw-semibold`,children:`Assistant`}),B(f,{tone:`neutral`,children:`AI`})]}),B(`span`,{className:`visually-hidden`,children:`Assistant: `}),B(ie,{text:e.body,resolveLink:t,linkComponent:n}),B(jt,{attachments:e.attachments}),B(`div`,{className:`mt-1`,children:r})]})]});let i=e.authorName||`Support team`;return V(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`agent`,children:[B(d,{name:i,size:32,tone:`primary`}),V(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[V(`div`,{className:`d-flex flex-wrap align-items-center gap-2 mb-1`,children:[B(`span`,{className:`fw-semibold`,children:i}),B(f,{tone:`primary`,children:`Support`})]}),B(`div`,{style:Dt,children:e.body}),B(jt,{attachments:e.attachments}),B(`div`,{className:`mt-1`,children:r})]})]})}function Nt({item:e,onRetry:t,onDiscard:n}){return V(`li`,{className:`d-flex flex-column align-items-end gap-1`,"data-author":`customer`,children:[B(m,{padding:`sm`,variant:`muted`,style:Ot,children:B(`div`,{className:`wui-text-sm`,style:Dt,children:e.body})}),e.status===`sending`&&B(`span`,{className:`wui-text-xs text-body-secondary`,children:`Sending`}),e.status===`failed`&&V(u,{tone:`danger`,size:`sm`,children:[B(`div`,{children:e.error}),V(`div`,{className:`d-flex gap-2 mt-2`,children:[B(p,{size:`sm`,variant:`outline`,onClick:()=>t(e.localId),children:`Try again`}),B(p,{size:`sm`,variant:`ghost`,onClick:()=>n(e.localId),children:`Discard`})]})]})]})}function Pt({messages:e,pending:t,assistantText:n,assistantWriting:r,agentName:i,agentTyping:a,onRetry:o,onDiscard:s,resolveLink:c,linkComponent:l}){return e.length===0&&t.length===0&&!n&&!r&&!a?B(S,{icon:`sparkles`,size:`sm`,title:`How can we help?`,text:`Ask a question and our AI assistant will answer it. You can ask to talk to a person once you have sent a message.`}):V(z,{children:[V(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:[e.map(e=>B(Mt,{message:e,resolveLink:c,linkComponent:l},e.id)),t.map(e=>B(Nt,{item:e,onRetry:o,onDiscard:s},e.localId)),n?V(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,"aria-busy":`true`,children:[B(d,{name:`Assistant`,size:32,tone:`primary`}),V(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[B(`span`,{className:`fw-semibold`,children:`Assistant`}),B(ie,{text:n,resolveLink:c,linkComponent:l})]})]}):r&&V(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,children:[B(d,{name:`Assistant`,size:32,tone:`primary`}),V(`div`,{className:`d-flex align-items-center gap-2 wui-text-sm`,children:[B(j,{size:`sm`,label:`The assistant is writing`}),B(`span`,{children:`The assistant is writing`})]})]}),a&&B(`li`,{className:`wui-text-sm text-body-secondary`,"aria-live":`polite`,children:`${i||`Our team`} is typing`})]}),B(`div`,{ref:At})]})}var Ft=3e3,It=`This chat is no longer available.`,Lt=(e,t)=>e.sequence-t.sequence;function Rt(e,t){return e.some(e=>e.id===t.id)?e:[...e,t].sort(Lt)}function zt(e){let t=new Map;for(let n of e)t.has(n.id)||t.set(n.id,n);return[...t.values()].sort(Lt)}function Bt(e,t){if(!e)return;let n=Date.parse(e)-Date.now();if(!(n>0))return;let r=setTimeout(t,n);return()=>clearTimeout(r)}function Vt({chatClient:e,connection:t,open:r,appVersion:a}){let[o,l]=c(`idle`),[u,d]=c(``),[f,p]=c(null),[m,h]=c([]),[g,_]=c([]),[v,y]=c(``),[b,x]=c(null),[S,C]=c(null),[w,T]=c(``),[E,D]=c(!1),[,O]=c(0),k=s(null),A=s(null),j=s(0),M=n(e=>{let t=A.current;A.current=e.id;let{messages:n,...r}=e;p(r),h(zt(n??[])),t!==e.id&&_([])},[]);i(()=>Bt(b,()=>O(e=>e+1)),[b]),i(()=>Bt(S,()=>O(e=>e+1)),[S]);let N=n(()=>{let n=!0,r=()=>{},i=e=>({onSnapshot(t){t.id===e&&(M(t),y(``))},onMessage(t){t.chatId===e&&(h(e=>Rt(e,t.message)),t.message.authorKind===`Assistant`&&y(``))},onState(t){t.chatId===e&&(p(e=>e&&{...e,state:t.state,closeReason:t.closeReason,ticketId:t.ticketId,ticketNumber:t.ticketNumber,agentName:t.agentName,waitingPosition:t.state===`WaitingForAgent`?t.waitingPosition:null}),y(``))},onTyping(t){t.chatId===e&&(t.who===`Agent`?x(t.untilDateTimeUtc):t.who===`Assistant`&&C(t.untilDateTimeUtc))},onDelta(t){t.chatId===e&&y(e=>e+t.text)},onError(e){if(e.code===`chat_not_found`){p(e=>e&&{...e,state:`Closed`,closeReason:null}),T(It);return}T(typeof e.message==`string`&&e.message?e.message:`The chat connection had a problem. We are reconnecting.`)}});return l(`loading`),e.start({pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:a}).then(e=>{n&&(M(e),d(``),l(`ready`),r=t.watch(e.id,e.sequence,i(e.id)))}).catch(e=>{n&&(d(X(e,`We could not start the chat. Please try again.`)),l(`error`))}),()=>{n=!1,r()}},[e,t,M,a]);i(()=>{if(!r)return;let e=N();return k.current=()=>{e(),e=N()},()=>{k.current=null,e()}},[r,N]);let P=(t,n)=>e.get(t).then(M).catch(e=>T(X(e,n)));async function F(t){let n=f.id;try{let r=await e.send(n,{body:t.body,idempotencyKey:t.key});if(A.current!==n)return;h(e=>{let t=Rt(e,r.message);return r.reply?Rt(t,r.reply):t}),_(e=>e.filter(e=>e.localId!==t.localId)),r.reply&&y(``)}catch(e){if(A.current!==n)return;if(e?.code===`chat_closed`){_(e=>e.filter(e=>e.localId!==t.localId)),await P(n,It);return}_(n=>n.map(n=>n.localId===t.localId?{...n,status:`failed`,error:X(e,`Your message did not send. Please try again.`)}:n))}}return{phase:o,startError:u,chat:f,messages:m,pending:g,assistantText:v,agentTypingUntil:b,assistantTypingUntil:S,notice:w,requesting:E,send:e=>{let t={localId:crypto.randomUUID(),key:crypto.randomUUID(),body:e,status:`sending`,error:``};_(e=>[...e,t]),F(t)},retry:e=>{let t=g.find(t=>t.localId===e);if(!t)return;let n={...t,status:`sending`,error:``};_(t=>t.map(t=>t.localId===e?n:t)),F(n)},discard:e=>{_(t=>t.filter(t=>t.localId!==e))},requestAgent:async()=>{let t=f.id;D(!0);try{M(await e.requestAgent(t))}catch(e){let n=`We could not reach the team. Please try again.`;e?.code===`chat_not_with_assistant`?await P(t,n):T(X(e,n))}finally{D(!1)}},end:async()=>{try{M(await e.close(f.id))}catch(e){T(X(e,`We could not end the chat. Please try again.`))}},restart:()=>{A.current=null,p(null),h([]),_([]),y(``),T(``),x(null),C(null),l(`loading`),k.current?.()},retryStart:()=>{k.current?.()},notifyTyping:()=>{if(o!==`ready`||f?.state!==`WithAgent`)return;let t=Date.now();t-j.current<Ft||(j.current=t,e.typing(f.id).catch(()=>{}))}}}var Ht={composer:`Your message`,placeholder:`Type your message`},Ut=e=>!!e&&Date.now()<Date.parse(e);function Wt({chatClient:e,connection:t,open:r,onClose:a,appVersion:o,onOpenTicket:d,resolveLink:f,linkComponent:m,title:h=`Chat with us`,width:g=`440px`}){let{config:v}=Y(),y=Vt({chatClient:e,connection:t,open:r,appVersion:o}),[b,S]=c(!1),C=s(null),T=s(y.notifyTyping);i(()=>{T.current=y.notifyTyping});let E=n(()=>T.current(),[]),D=n(e=>{C.current?.removeEventListener(`input`,E),C.current=e,e?.addEventListener(`input`,E)},[E]),O=y.phase===`ready`&&y.chat!==null,k=y.chat?.state,A=O&&k!==`Closed`,M=Ut(y.assistantTypingUntil)||k===`Assistant`&&y.pending.some(e=>e.status===`sending`),N=Ut(y.agentTypingUntil),P=y.messages.some(e=>e.authorKind===`Customer`)&&!!y.chat?.assistantAvailable;i(()=>{r&&O&&C.current?.focus()},[r,O]);let F=V(`div`,{className:`drawer-header`,children:[V(`div`,{className:`drawer-title`,children:[B(`span`,{className:`drawer-title-ic`,children:B(w,{name:`message-circle`,size:18})}),h]}),V(`div`,{className:`d-flex align-items-center gap-1`,children:[A&&B(p,{variant:`ghost`,size:`sm`,onClick:()=>S(!0),children:`End chat`}),B(l,{icon:`x`,label:`Close`,onClick:a})]})]}),I;return I=y.phase===`error`?V(u,{tone:`danger`,children:[y.startError,B(`div`,{className:`mt-2`,children:B(p,{size:`sm`,variant:`outline`,onClick:y.retryStart,children:`Try again`})})]}):O?V(z,{children:[B(Et,{state:k,closeReason:y.chat.closeReason,agentName:y.chat.agentName,ticketNumber:y.chat.ticketNumber,ticketId:y.chat.ticketId,waitingPosition:y.chat.waitingPosition,canRequestAgent:P,requesting:y.requesting,onRequestAgent:y.requestAgent,onOpenTicket:d,onRestart:y.restart}),B(Pt,{messages:y.messages,pending:y.pending,assistantText:y.assistantText,assistantWriting:M,agentName:y.chat.agentName,agentTyping:N,onRetry:y.retry,onDiscard:y.discard,resolveLink:f,linkComponent:m}),y.notice&&B(u,{tone:`danger`,size:`sm`,children:y.notice})]}):B(`div`,{className:`d-flex justify-content-center py-4`,children:B(j,{label:`Starting your chat`})}),V(z,{children:[B(x,{open:r,onClose:a,sheet:!1,width:g,header:F,footer:A?V(`div`,{className:`d-flex flex-column gap-2`,children:[B(H,{onSubmit:y.send,busy:y.pending.length>0||!!y.assistantText,maxLength:v?.bodyMaxLength??4e3,inputRef:D,labels:Ht}),k===`Assistant`&&B(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:ae.disclaimer})]}):void 0,ariaLabel:h,onOpened:()=>C.current?.focus(),children:I}),B(_,{open:b,title:`End this chat?`,message:k===`Assistant`?`You can start a new chat whenever you like.`:`Our team can still see this conversation on your ticket.`,confirmLabel:`End chat`,cancelLabel:`Keep chatting`,onConfirm:()=>{S(!1),y.end()},onClose:()=>S(!1)})]})}var Gt={zIndex:`var(--wui-z-fixed)`,bottom:`var(--wui-consent-banner-block, 0px)`},Kt={end:{insetInlineEnd:0},start:{insetInlineStart:0}};function qt({onClick:e,open:t=!1,label:n=`Chat with us`,position:r=`end`,icon:i=`message-circle`,compact:a=!1,className:o,style:s}){return a?B(Jt,{onClick:e,open:t,label:n,position:r,icon:i,className:o,style:s}):B(`span`,{"data-support-capture":`exclude`,className:[`position-fixed m-3`,o].filter(Boolean).join(` `),style:{...Gt,...Kt[r],...s},children:B(p,{leftIcon:i,className:`rounded-pill`,onClick:e,"aria-haspopup":`dialog`,"aria-expanded":t,children:n})})}function Jt({onClick:e,open:t,label:n,position:r,icon:i,className:a,style:o}){let s=F(r);return s?R(B(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--primary`,a].filter(Boolean).join(` `),style:o,children:B(p,{className:`wui-floating-btn`,onClick:e,"aria-label":n,"aria-haspopup":`dialog`,"aria-expanded":t,tooltip:n,tooltipPlacement:r===`start`?`end`:`start`,children:B(w,{name:i,size:24})})}),s):null}var $=e=>typeof e==`string`&&e.trim()!==``;function Yt({className:e}){let{config:t}=Y();if(!t)return null;let n=[];return $(t.supportEmail)&&n.push({key:`email`,icon:`mail`,label:`Email`,value:V(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2`,children:[B(`a`,{href:`mailto:${t.supportEmail}`,className:`text-break`,children:t.supportEmail}),B(v,{text:t.supportEmail,size:`sm`,label:`Copy email`,copiedLabel:`Email copied`})]})}),$(t.supportPhone)&&n.push({key:`phone`,icon:`phone`,label:`Phone`,value:t.supportPhone,href:`tel:${t.supportPhone.replace(/[^\d+]/g,``)}`}),$(t.supportHours)&&n.push({key:`hours`,icon:`clock`,label:`Hours`,value:t.supportHours}),n.length===0?null:V(`section`,{className:e,"aria-label":$(t.supportName)?`Contact ${t.supportName}`:`Contact support`,children:[$(t.supportName)&&B(`p`,{className:`fw-semibold mb-2`,children:t.supportName}),B(b,{items:n,layout:`list`,columns:1})]})}function Xt({client:e,timeZone:t=ee,renderTime:r,children:i}){let a=s(null),c=n((t=!1)=>{let n=a.current;if(t||!n||n.client!==e){let t=e.getConfig(),n={client:e,pending:t};return a.current=n,t.catch(()=>{a.current===n&&(a.current=null)}),t}return n.pending},[e]),l=o(()=>({client:e,loadConfig:c,timeZone:t,renderTime:r}),[e,c,t,r]);return B(we.Provider,{value:l,children:i})}export{tt as ReportIssue,W as SupportApiError,St as SupportCenter,Wt as SupportChat,qt as SupportChatLauncher,Yt as SupportContact,Xt as SupportProvider,Ce as createSseChatConnection,ge as createSupportChatClient,fe as createSupportClient,J as useSupportClient,Y as useSupportConfig,je as useSupportTicket,Ae as useSupportTicketCounts,ke as useSupportTickets};
|
|
6
|
+
`)){if(!n.startsWith(`id:`))continue;let e=n.slice(3);if(e.startsWith(` `)&&(e=e.slice(1)),!/^\d+$/.test(e))continue;let r=Number(e);t=t===null?r:Math.max(t,r)}},get last(){return t}}}function Se({http:t,baseUrl:n=`/api/support`,retryDelaysMs:r,stallTimeoutMs:i=9e4}){let a=n.replace(/\/+$/,``),o=Array.isArray(r)&&r.length>0?r:[1e3];return{watch(n,r,s){let c=Number.isFinite(r)?r:null,l=!1,u=null,d=null,f=null,p=null,m=!1,h=!1,g=!1,_=null,v=0,y=e=>{Number.isFinite(e)&&(c=Math.max(c??0,e))};function b(e,t){if(!l){h=!0;try{e===`snapshot`?(y(t?.sequence),s.onSnapshot?.(t)):e===`message`?(y(t?.message?.sequence),s.onMessage?.(t)):e===`state`?s.onState?.(t):e===`typing`?s.onTyping?.(t):e===`delta`&&s.onDelta?.(t)}catch{s.onError?.(new G(`handler_failed`,ge))}}}function x(){clearTimeout(d),d=setTimeout(()=>{g=!0,u.abort()},i)}async function S(){u=new AbortController,m=!1,h=!1,g=!1,_=null;let r=0,i=xe(),o=e(({name:e,data:t})=>{l||_||(e===`error`?t?.code===`invalid-response`||t?.code===`stream_ended`?_=`retry`:t?.code===`chat_not_found`?(s.onError?.(t),_=`stop`):(s.onError?.(t),_=`retry`):b(e,t))}),f=e=>{if(l||typeof e!=`string`||e.length<=r)return;let t=e.slice(r);r=e.length,o.push(t),i.push(t),i.last!==null&&(c=Math.max(c??0,i.last)),m=!0,x()},p=`${a}/chats/${encodeURIComponent(n)}/events${c===null?``:`?after=${c}`}`;x();let v;try{v=await t.get(p,{responseType:`text`,headers:{Accept:`text/event-stream`},signal:u.signal,timeout:0,onDownloadProgress:e=>f(_e(e))})}catch(e){if(l)return`stop`;if(g)return`retry`;let t=ye(e);return be(t.status)?`retry`:(s.onError?.({code:t.code,message:t.message}),`stop`)}finally{clearTimeout(d)}return f(v.data),clearTimeout(d),o.end(),_??`retry`}function C(e){return new Promise(t=>{p=t,f=setTimeout(t,e)})}async function w(){let e=0;for(;!l;){let t=await S();if(l||t===`stop`)return;if(m&&(e=0),v=h?0:v+1,v>=10){s.onError?.(new G(`connection_lost`,`We lost the connection to support. Check your internet and try again.`));return}let n=o[Math.min(e,o.length-1)];e+=1,await C(n)}}function T(){l=!0,u?.abort(),clearTimeout(d),clearTimeout(f),p?.()}return w(),T}}}var Ce=t(null);function we(){let e=r(Ce);if(!e)throw Error(`Support components and hooks must be used inside <SupportProvider>.`);return e}function Y(){return we().client}function Te(){return we().timeZone}function Ee(){return we().renderTime??null}function De(e,t,r=!0){let[a,o]=c({data:null,loading:r,error:null}),[l,u]=c(0),d=s(e);d.current=e;let f=s(t);i(()=>{let e=f.current!==t;if(f.current=t,!r){o({data:null,loading:!1,error:null});return}let n=!0;return o(t=>({data:e?null:t.data,loading:!0,error:null})),d.current(l>0).then(e=>n&&o({data:e,loading:!1,error:null}),e=>n&&o(t=>({...t,loading:!1,error:e}))),()=>{n=!1}},[t,r,l]);let p=n(()=>u(e=>e+1),[]),m=n(e=>o(t=>({...t,data:e})),[]);return{...a,reload:p,setData:m}}function X(){let{loadConfig:e}=we(),{data:t,loading:n,error:r,reload:i}=De(e,`config`);return{config:t,loading:n,error:r,reload:i}}function Oe(e={}){let t=Y(),{status:n,search:r,page:i,pageSize:a}=e,{data:o,loading:s,error:c,reload:l}=De(()=>t.listTickets({status:n,search:r,page:i,pageSize:a}),JSON.stringify([`tickets`,n??null,r??null,i??null,a??null]));return{tickets:o?.items??[],totalCount:o?.totalCount??0,totalPages:o?.totalPages??0,loading:s,error:c,reload:l}}function ke(){let e=Y(),{data:t,loading:n,error:r,reload:i}=De(()=>e.getTicketCounts(),`ticket-counts`);return{counts:t,loading:n,error:r,reload:i}}function Ae(e){let t=Y(),{data:r,loading:i,error:a,reload:o,setData:s}=De(()=>t.getTicket(e),e??``,!!e),c=n(async e=>{let t=await e();return s(t),t},[s]);return{ticket:r,loading:i,error:a,reload:o,reply:n(n=>c(()=>t.reply(e,n)),[c,t,e]),reopen:n(()=>c(()=>t.reopen(e)),[c,t,e]),cancel:n(()=>c(()=>t.cancel(e)),[c,t,e]),rate:n(n=>c(()=>t.rate(e,n)),[c,t,e])}}var je=`We could not reach support. Check your connection and try again.`;function Z(e,t){if(e instanceof G){if(e.code===`network`)return je;if(e.code!==`unknown`)return e.message}return t}function Me(e){return(e?.allowedContentTypes??[]).join(`,`)}function Ne(e,t){if(t.length===0)return!0;let n=(e||``).toLowerCase();return t.some(e=>{let t=e.toLowerCase();return t.endsWith(`/*`)?n.startsWith(t.slice(0,-1)):n===t})}function Q(e,t){let n=e??[],r=t?.maxAttachmentsPerMessage??0,i=t?.maxAttachmentBytes??0,a=t?.allowedContentTypes??[];if(r>0&&n.length>r)return r===1?`You can attach one file.`:`You can attach up to ${r} files.`;for(let e of n){let t=e.name||`This file`;if(!Ne(e.type,a))return`${t} is a file type we cannot accept.`;if(i>0&&e.size>i)return`${t} is larger than ${ee(i)}.`}return null}var Pe=e=>e===1?`You can attach one file.`:`You can attach up to ${e} files.`;function Fe(e){return`${e.name}|${e.size}|${e.lastModified}`}function Ie(e,t,n){let r=n?.maxAttachmentsPerMessage??0,i=new Set(e.map(Fe)),a=[],o=null;for(let e of t){let t=Fe(e);i.has(t)?o??=e.name:(i.add(t),a.push(e))}let s=r>0?Math.max(0,r-e.length):a.length,c=[...e,...a.slice(0,s)];return{files:c,notice:(a.length>s?Pe(r):null)??Q(c,n)??(o?`${o} is already attached.`:``)}}function Le(e){let t=Array.from(e.clipboardData?.items??[]),n=Date.now();return t.filter(e=>e.kind===`file`&&e.type.startsWith(`image/`)).map(e=>e.getAsFile()).filter(Boolean).map((e,t)=>{let r=(e.type.split(`/`)[1]||`png`).replace(`jpeg`,`jpg`);return new File([e],`pasted-image-${n}-${t+1}.${r}`,{type:e.type})})}function Re(e,t){let[n,r]=c(e);return i(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function ze({id:e,label:t=`Attachments`,files:n,onChange:r,config:i,error:a}){let o=i?.maxAttachmentBytes??0,s=o>0?Math.max(.1,Math.round(o/1048576*10)/10):0;return/* @__PURE__ */ H(C,{id:e,label:t,optional:!0,multiple:!0,value:n,onChange:r,accept:Me(i),maxSizeMb:s,validate:!1,error:a||void 0})}function Be({items:e}){return e.length===0?null:/* @__PURE__ */ H(m,{variant:`muted`,padding:`sm`,title:`These may already answer your question`,children:/* @__PURE__ */ H(`ul`,{className:`list-unstyled mb-0 d-flex flex-column gap-2`,children:e.map(e=>/* @__PURE__ */ U(`li`,{children:[/* @__PURE__ */ H(`div`,{className:`fw-semibold`,children:e.title}),/* @__PURE__ */ H(`div`,{className:`small text-body-secondary`,children:e.summary})]},e.title))})})}var Ve=500,He=3,Ue=5;function We(e,t){return t&&e.includes(t)?t:``}function Ge({id:e,config:t,defaultCategory:n,initialValues:r,onValuesChange:a,extraFiles:o=[],onSubmit:s,onBusyChange:l,children:d}){let f=t?.categories??[],[p,m]=c(()=>r?.category??We(f,n)),[h,g]=c(r?.subject??``),[_,v]=c(r?.body??``),[y,b]=c(r?.files??[]),[x,S]=c({}),[C,w]=c(``),E=Y(),[D,O]=c(``),[A,j]=c([]),M=Re(h.trim(),Ve);i(()=>{a?.({category:p,subject:h,body:_,files:y})},[p,h,_,y,a]),i(()=>{O(M)},[M]),i(()=>{if(D.length<He){j([]);return}let e=!0,t=new AbortController;return j([]),E.getSuggestions(D,{signal:t.signal}).then(t=>{e&&j(Array.isArray(t)?t.slice(0,Ue):[])},()=>{e&&j([])}),()=>{e=!1,t.abort()}},[E,D]);let N=e=>{b(e),S(n=>({...n,files:Q([...o,...e],t)??void 0}))},F=e=>{let t=Le(e);t.length>0&&N([...y,...t])};function I(){let e={};h.trim()||(e.subject=`Enter a subject.`),_.trim()||(e.body=`Enter what happened.`);let n=Q([...o,...y],t);return n&&(e.files=n),S(e),Object.keys(e).length===0}async function L(e){if(e.preventDefault(),w(``),I()){l?.(!0);try{await s({category:p,subject:h.trim(),body:_.trim(),files:y})}catch(e){w(Z(e,`Your ticket did not send. Please try again.`))}finally{l?.(!1)}}}return/* @__PURE__ */ U(`form`,{id:e,onSubmit:L,noValidate:!0,className:`d-flex flex-column gap-3`,children:[C&&/* @__PURE__ */ H(u,{tone:`danger`,children:C}),/* @__PURE__ */ H(k,{id:`${e}-category`,label:`Category`,value:p,onChange:m,options:f.map(e=>({value:e,label:e})),placeholder:`Choose a category`,hint:`Not sure? Leave it empty and we will sort it.`,error:x.category}),/* @__PURE__ */ H(T,{id:`${e}-subject`,label:`Subject`,required:!0,maxLength:t?.subjectMaxLength,showCount:!0,placeholder:`A short summary`,value:h,onChange:e=>g(e.target.value),onBlur:()=>O(h.trim()),error:x.subject}),/* @__PURE__ */ H(Be,{items:A}),/* @__PURE__ */ H(P,{id:`${e}-body`,label:`Message`,required:!0,rows:6,maxLength:t?.bodyMaxLength,showCount:!0,placeholder:`What happened, and what did you expect to happen?`,value:_,onChange:e=>v(e.target.value),onPaste:F,hint:`You can paste an image into the message.`,error:x.body}),d,/* @__PURE__ */ H(ze,{id:`${e}-files`,files:y,onChange:N,config:t,error:x.files})]})}var Ke=`supportCapture`,qe={zIndex:`var(--wui-z-fixed)`,bottom:0,insetInlineEnd:0},Je={zIndex:`var(--wui-z-fixed)`},Ye={maxWidth:`20rem`},Xe=e=>e.dataset?.[Ke]===`exclude`||e.matches?.(`.modal-backdrop`)?!1:!(e.matches?.(`.modal`)&&e.querySelector?.(`[data-support-capture="exclude"]`)),Ze=()=>new Promise(e=>requestAnimationFrame(()=>e()));async function Qe(){let e=await L(document.body,{filter:Xe,pixelRatio:Math.min(window.devicePixelRatio||1,2),style:{overflow:`visible`,paddingRight:`0px`}});if(!e)throw Error(`The page capture came back empty.`);return new File([e],`screenshot.png`,{type:`image/png`})}function $e({file:e,failed:t,disabled:n,hintId:r,controlRef:a,onAdd:o,onRemove:s}){let[l,d]=c(null);return i(()=>{if(!e)return;let t=URL.createObjectURL(e);return d(t),()=>URL.revokeObjectURL(t)},[e]),/* @__PURE__ */ U(`div`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ H(`span`,{className:`wui-text-sm fw-semibold`,children:`Screenshot`}),e&&l&&/* @__PURE__ */ H(`img`,{src:l,alt:`Screenshot of the page you were on`,className:`d-block w-100 border rounded`,style:Ye}),/* @__PURE__ */ H(`div`,{ref:a,className:`d-flex flex-wrap gap-2`,children:e?/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(p,{variant:`outline`,size:`sm`,leftIcon:`refresh-cw`,onClick:o,disabled:n,"aria-describedby":r,children:`Retake`}),/* @__PURE__ */ H(p,{variant:`ghost`,size:`sm`,leftIcon:`x`,onClick:s,disabled:n,children:`Remove screenshot`})]}):/* @__PURE__ */ H(p,{variant:`outline`,size:`sm`,leftIcon:`camera`,onClick:o,disabled:n,"aria-describedby":r,children:`Add a screenshot`})}),/* @__PURE__ */ H(`span`,{id:r,className:`wui-text-sm text-body-secondary`,children:`Only what is on your screen now. You can remove it before sending.`}),t&&/* @__PURE__ */ H(u,{tone:`info`,children:`We could not take a screenshot of this page. You can attach an image instead, or send the report without one.`})]})}function et({label:e=`Report an issue`,floating:t=!1,compact:n=!1,defaultCategory:r=`Bug report`,appVersion:o,getTicketHref:l,onOpenTicket:d,onCreated:f,className:m,style:h}){let g=Y(),{config:_,error:v}=X(),y=`support-report-${a().replace(/[^a-zA-Z0-9-]/g,``)}`,[b,x]=c(!1),[S,C]=c(!1),[T,E]=c(null),[O,k]=c(!1),[A,j]=c(!1),[M,N]=c(null),[P,I]=c(null),L=F(`end`,t&&n),z=s(null),B=s(!1);i(()=>{!S&&B.current&&(B.current=!1,z.current?.querySelector(`button`)?.focus())},[S]);function ee(){N(null),E(null),k(!1),I(null),x(!0)}async function te(){C(!0),k(!1),await Ze(),await Ze();try{E(await Qe())}catch{E(null),k(!0)}finally{B.current=!0,C(!1)}}let ne=()=>{A||(x(!1),E(null),k(!1),N(null),I(null))};async function re(e){let t=await g.createTicket({...e,pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:o,screenshots:T?[T]:[]});N(t),E(null),f?.(t)}let ie=!M&&(!!T||!!P&&(P.subject.trim()!==``||P.body.trim()!==``||P.files.length>0)),W=M&&l?l(M.id):void 0,G=M?/* @__PURE__ */ U(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[/* @__PURE__ */ H(p,{variant:`secondary`,onClick:ne,children:`Close`}),M&&(W||d)?/* @__PURE__ */ H(p,{href:W,onClick:W?void 0:()=>{x(!1),N(null),d(M)},children:`View ticket`}):null]}):/* @__PURE__ */ U(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[/* @__PURE__ */ H(p,{variant:`secondary`,onClick:ne,disabled:A,children:`Cancel`}),/* @__PURE__ */ H(p,{type:`submit`,form:y,loading:A,disabled:!_,children:`Submit`})]}),ae=n?/* @__PURE__ */ H(p,{variant:`secondary`,className:`wui-floating-btn wui-floating-btn--secondary`,disabled:S,onClick:ee,"aria-haspopup":`dialog`,"aria-label":e,tooltip:e,tooltipPlacement:`start`,children:/* @__PURE__ */ H(w,{name:`bug`,size:22})}):/* @__PURE__ */ H(p,{leftIcon:`bug`,variant:t?`primary`:`outline`,disabled:S,onClick:ee,"aria-haspopup":`dialog`,children:e});return/* @__PURE__ */ U(V,{children:[t&&n?L&&R(/* @__PURE__ */ H(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--secondary`,m].filter(Boolean).join(` `),style:h,children:ae}),L):/* @__PURE__ */ H(`span`,{"data-support-capture":`exclude`,className:[t?`position-fixed m-3`:`d-inline-block`,m].filter(Boolean).join(` `),style:t?{...qe,...h}:h,children:ae}),S&&/* @__PURE__ */ U(`div`,{"data-support-capture":`exclude`,role:`status`,className:`position-fixed top-0 start-50 translate-middle-x mt-3 d-flex align-items-center gap-2 px-3 py-2 bg-body border rounded-pill shadow-sm wui-text-sm`,style:Je,children:[/* @__PURE__ */ H(`span`,{className:`spinner-border spinner-border-sm`,"aria-hidden":`true`}),`Taking a screenshot`]}),/* @__PURE__ */ H(D,{open:b,size:`lg`,title:`Report an issue`,subtitle:`Tell us what went wrong. You can add a screenshot of this page if it helps.`,headerIcon:`bug`,confirmDiscard:`Discard this report?`,dirty:ie&&!A,onClose:ne,footer:G,"data-support-capture":`exclude`,children:M?/* @__PURE__ */ H(u,{tone:`success`,role:`status`,title:`Ticket ${M.number} is with the support team`,children:`We reply by email. You can follow the ticket on your support page.`}):_?/* @__PURE__ */ H(Ge,{id:y,config:_,defaultCategory:r,initialValues:P,onValuesChange:I,extraFiles:T?[T]:[],onSubmit:re,onBusyChange:j,children:/* @__PURE__ */ H($e,{file:T,failed:O,disabled:A||S,hintId:`${y}-screenshot-hint`,controlRef:z,onAdd:te,onRemove:()=>E(null)})}):/* @__PURE__ */ H(u,{tone:v?`danger`:`info`,children:v?Z(v,`We could not load the support settings.`):`Loading the form.`})})]})}function tt({open:e,onClose:t,onCreated:n,config:r,defaultCategory:i,appVersion:o}){let s=Y(),l=`support-new-${a().replace(/[^a-zA-Z0-9-]/g,``)}`,[u,d]=c(!1),[f,m]=c(null),h=!!f&&(f.subject.trim()!==``||f.body.trim()!==``||f.files.length>0);async function g(e){n(await s.createTicket({...e,userAgent:typeof navigator>`u`?void 0:navigator.userAgent,appVersion:o}))}return/* @__PURE__ */ H(D,{open:e,size:`lg`,title:`New ticket`,subtitle:`Tell us what you need. We reply by email and on this page.`,headerIcon:`message-square`,confirmDiscard:`Discard this ticket?`,dirty:h&&!u,onClose:()=>{u||t()},footer:/* @__PURE__ */ U(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[/* @__PURE__ */ H(p,{variant:`secondary`,onClick:t,disabled:u,children:`Cancel`}),/* @__PURE__ */ H(p,{type:`submit`,form:l,loading:u,children:`Send ticket`})]}),children:e&&/* @__PURE__ */ H(Ge,{id:l,config:r,defaultCategory:i,onSubmit:g,onBusyChange:d,onValuesChange:m})})}var nt={Open:`warning`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`neutral`,Cancelled:`neutral`};function rt(e){return nt[e]??`neutral`}var it=6e4,at=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`application/pdf`];function ot({attachment:e}){let t=Y(),[n,r]=c(!1),[i,a]=c(!1);async function o(){r(!0),a(!1);let n=at.includes(e.contentType)?window.open(``,`_blank`):null;n&&(n.opener=null);try{let r=await t.fetchAttachment(e.id),i=URL.createObjectURL(r);if(setTimeout(()=>URL.revokeObjectURL(i),it),n)n.location.href=i;else{let t=document.createElement(`a`);t.href=i,t.download=e.fileName,t.click()}}catch{n?.close(),a(!0)}finally{r(!1)}}let s=Number.isFinite(e.sizeBytes)?ee(e.sizeBytes):`-`;return/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(h,{leadingIcon:i?`x-circle`:`paperclip`,label:n?/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(j,{size:`sm`,label:`Loading ${e.fileName}`}),` `,e.fileName]}):e.fileName,onClick:o,disabled:n,"aria-busy":n||void 0,title:`${e.fileName}, ${s}`}),i&&/* @__PURE__ */ H(`span`,{role:`status`,className:`wui-text-xs text-danger align-self-center`,children:`Could not load this file. Click to try again.`})]})}function $({iso:e,className:t}){let n=Ee(),r=Te();return n?n(e):/* @__PURE__ */ H(`time`,{dateTime:e,className:t,children:B(e,{timeZone:r})})}var st={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`};function ct({messages:e}){return/* @__PURE__ */ H(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:e.map(e=>{let t=/* @__PURE__ */ H($,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return/* @__PURE__ */ U(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[/* @__PURE__ */ H(`span`,{className:`d-block`,children:e.body}),t]},e.id);let n=e.authorKind===`Customer`,r=e.authorName||(n?`You`:`Support team`);return/* @__PURE__ */ U(`li`,{className:`d-flex align-items-start gap-2${n?` flex-row-reverse`:``}`,"data-author":n?`customer`:`agent`,children:[/* @__PURE__ */ H(d,{name:r,size:32,tone:n?`neutral`:`primary`}),/* @__PURE__ */ U(m,{className:`flex-grow-1 border`,padding:`sm`,variant:n?`default`:`accent`,style:{minWidth:0},children:[/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2 mb-2`,children:[/* @__PURE__ */ U(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2 fw-semibold wui-text-sm text-break`,children:[r,!n&&/* @__PURE__ */ H(f,{tone:`primary`,children:`Support`})]}),t]}),/* @__PURE__ */ H(`div`,{className:`wui-text-sm`,style:st,children:e.body}),e.attachments?.length>0&&/* @__PURE__ */ H(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.attachments.map(e=>/* @__PURE__ */ H(ot,{attachment:e},e.id))})]})]},e.id)})})}function lt({satisfaction:e,comment:t,canRate:n=!1,commentMaxLength:r,onRate:i}){let o=a(),[s,l]=c(``),[d,f]=c(null),[h,g]=c(``);if(e)return/* @__PURE__ */ U(u,{tone:e===`Satisfied`?`success`:`info`,role:`status`,children:[e===`Satisfied`?`You told us this solved your problem.`:`You told us this did not solve your problem.`,t?/* @__PURE__ */ U(`span`,{className:`d-block mt-1`,children:[`Your comment: `,t]}):null]});if(!n)return null;async function _(e){g(``),f(e);try{await i({satisfaction:e,comment:s})}catch(e){g(Z(e,`Your rating did not send. Please try again.`))}finally{f(null)}}return/* @__PURE__ */ H(m,{padding:`sm`,className:`border`,title:`Did this solve your problem?`,children:/* @__PURE__ */ U(`div`,{className:`d-flex flex-column gap-2`,children:[h&&/* @__PURE__ */ H(u,{tone:`danger`,children:h}),/* @__PURE__ */ H(P,{id:`${o}-comment`,label:`Anything to add?`,rows:2,maxLength:r,value:s,onChange:e=>l(e.target.value),hint:`Optional. Your comment goes to the support team.`}),/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ H(p,{variant:`outline`,leftIcon:`check-circle`,loading:d===`Satisfied`,disabled:d!==null,onClick:()=>_(`Satisfied`),children:`Yes, it is solved`}),/* @__PURE__ */ H(p,{variant:`outline`,leftIcon:`x-circle`,loading:d===`Unsatisfied`,disabled:d!==null,onClick:()=>_(`Unsatisfied`),children:`No, it is not`})]})]})})}function ut({onSend:e,config:t,reopens:n=!1}){let r=a(),[i,o]=c(``),[s,d]=c([]),[f,m]=c(``),[_,v]=c(``),[y,b]=c(!1),x=e=>{let n=Ie(s,e,t);d(n.files),m(n.notice)},S=e=>{let n=s.filter((t,n)=>n!==e);d(n),m(Q(n,t)??``)},C=e=>{let t=Le(e);t.length>0&&x(t)};async function w(n){n.preventDefault();let r=i.trim();if(!r){v(`Write a message before you send it.`);return}let a=Q(s,t);if(a)m(a);else{v(``),b(!0);try{await e({body:r,files:s}),o(``),d([]),m(``)}catch(e){v(Z(e,`Your reply did not send. Please try again.`))}finally{b(!1)}}}let T=_||f;return/* @__PURE__ */ U(`form`,{onSubmit:w,noValidate:!0,className:`d-flex flex-column gap-2`,"aria-label":`Reply to this ticket`,children:[T&&/* @__PURE__ */ H(u,{tone:`danger`,children:T}),/* @__PURE__ */ H(P,{id:`${r}-body`,label:`Your reply`,rows:4,autoGrow:!0,maxLength:t?.bodyMaxLength,value:i,onChange:e=>o(e.target.value),onPaste:C,hint:n?`Sending a reply reopens this ticket. You can paste an image into the message.`:`You can paste an image into the message.`,required:!0}),s.length>0&&/* @__PURE__ */ H(g,{label:`Attached files`,children:s.map((e,t)=>/* @__PURE__ */ H(h,{leadingIcon:`paperclip`,label:e.name,removeLabel:`Remove ${e.name}`,onRemove:()=>S(t)},Fe(e)))}),/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[/* @__PURE__ */ H(l,{iconVariant:`bulk`,icon:`paperclip`,label:`Attach a file`,multiple:t?.maxAttachmentsPerMessage!==1,accept:Me(t),onFiles:x}),/* @__PURE__ */ H(p,{type:`submit`,leftIcon:`send`,loading:y,children:`Send reply`})]})]})}function dt({ticketId:e,onBack:t,onChanged:n,onOpenTicket:r}){let{config:i}=X(),a=Te(),o=Ee(),{ticket:s,loading:l,error:d,reload:f,reply:h,reopen:g,cancel:v,rate:y}=Ae(e),[x,S]=c(!1),[C,T]=c(!1),[E,D]=c(!1),[O,k]=c(``),j=async e=>{let t=await e();return n?.(),t};async function N(){k(``),S(!0);try{await j(g)}catch(e){k(Z(e,`The ticket did not reopen. Please try again.`))}finally{S(!1)}}async function P(){k(``),D(!0);try{await j(v)}catch(e){k(Z(e,`The request was not withdrawn. Please try again.`))}finally{D(!1),T(!1)}}let F=/* @__PURE__ */ H(p,{variant:`ghost`,size:`sm`,leftIcon:`arrow-left`,onClick:t,className:`align-self-start`,children:`Back to tickets`});if(!s)return/* @__PURE__ */ U(`section`,{className:`d-flex flex-column gap-3`,"aria-busy":l||void 0,children:[F,d?/* @__PURE__ */ U(u,{tone:`danger`,children:[Z(d,`We could not load this ticket.`),` `,/* @__PURE__ */ H(p,{variant:`ghost`,size:`sm`,onClick:f,children:`Try again`})]}):/* @__PURE__ */ H(A,{height:160})]});let I=rt(s.status),L=[{key:`status`,label:`Status`,value:s.statusLabel?/* @__PURE__ */ H(M,{label:s.statusLabel,tone:I}):`-`},{key:`category`,label:`Category`,value:s.category||`-`},{key:`ticket`,label:`Ticket`,value:s.number},{key:`opened`,label:`Opened`,value:/* @__PURE__ */ H($,{iso:s.createdDateTimeUtc})},{key:`updated`,label:`Last update`,value:/* @__PURE__ */ H($,{iso:s.updatedDateTimeUtc})}];return/* @__PURE__ */ U(`section`,{className:`d-flex flex-column gap-3`,"aria-labelledby":`support-ticket-${s.id}`,children:[F,/* @__PURE__ */ U(`div`,{className:`row g-3`,children:[/* @__PURE__ */ U(`div`,{className:`col-12 col-lg-8 d-flex flex-column gap-3`,children:[/* @__PURE__ */ U(`header`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap align-items-center gap-2`,children:[/* @__PURE__ */ H(`h2`,{id:`support-ticket-${s.id}`,className:`h5 mb-0 text-break`,children:s.subject}),s.statusLabel&&/* @__PURE__ */ H(M,{label:s.statusLabel,tone:I})]}),/* @__PURE__ */ U(`ul`,{className:`list-unstyled d-flex flex-wrap gap-3 mb-0 wui-text-sm text-body-secondary`,"aria-label":`Ticket summary`,children:[s.number&&/* @__PURE__ */ U(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ H(w,{variant:`bulk`,name:`receipt-text`,size:16}),s.number]}),s.category&&/* @__PURE__ */ U(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ H(w,{variant:`bulk`,name:`folder-2`,size:16}),s.category]}),/* @__PURE__ */ U(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ H(w,{variant:`bulk`,name:`calendar-1`,size:16}),`Opened `,/* @__PURE__ */ H($,{iso:s.createdDateTimeUtc})]})]}),o===null&&/* @__PURE__ */ U(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:[`Times are shown in `,te(a),`.`]})]}),O&&/* @__PURE__ */ H(u,{tone:`danger`,children:O}),s.mergedInto&&/* @__PURE__ */ U(u,{tone:`info`,role:`status`,children:[`This ticket was merged into `,s.mergedInto.number,`. The conversation carries on there.`,` `,r&&/* @__PURE__ */ U(p,{variant:`ghost`,size:`sm`,onClick:()=>r(s.mergedInto.id),children:[`Open `,s.mergedInto.number]})]}),s.canReopen&&/* @__PURE__ */ H(u,{tone:`success`,role:`status`,children:`If you still need help, reopen the ticket or send a reply.`}),s.status===`WaitingOnCustomer`&&/* @__PURE__ */ H(u,{tone:`warning`,role:`status`,children:`We need your answer to carry on. Reply below and the ticket goes back to our team.`}),!s.canReopen&&/* @__PURE__ */ H(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:`Our team marks this resolved once your question is answered. Replying reopens it.`}),s.canReopen&&/* @__PURE__ */ H(p,{variant:`secondary`,leftIcon:`history`,loading:x,onClick:N,className:`align-self-start`,children:`Reopen ticket`}),s.canCancel&&/* @__PURE__ */ H(p,{variant:`secondary`,onClick:()=>T(!0),className:`align-self-start`,children:`Withdraw request`}),/* @__PURE__ */ H(_,{open:C,title:`Withdraw this request?`,message:`Our team will stop working on this ticket. You can open a new ticket later if you still need help.`,confirmLabel:`Withdraw request`,danger:!0,loading:E,onConfirm:P,onClose:()=>T(!1)}),/* @__PURE__ */ H(lt,{satisfaction:s.satisfaction,comment:s.satisfactionComment,canRate:s.canRate,commentMaxLength:i?.satisfactionCommentMaxLength,onRate:e=>j(()=>y(e))}),/* @__PURE__ */ H(ct,{messages:s.messages??[]}),s.mergedTickets?.length>0&&/* @__PURE__ */ U(`section`,{"aria-labelledby":`support-merged-${s.id}`,className:`d-flex flex-column gap-1`,children:[/* @__PURE__ */ H(`h3`,{id:`support-merged-${s.id}`,className:`h6 mb-0`,children:`Merged into this ticket`}),/* @__PURE__ */ H(`ul`,{className:`list-unstyled d-flex flex-column gap-1 mb-0 wui-text-sm`,children:s.mergedTickets.map(e=>/* @__PURE__ */ H(`li`,{children:r?/* @__PURE__ */ U(p,{variant:`ghost`,size:`sm`,onClick:()=>r(e.id),children:[e.number,`: `,e.subject]}):`${e.number}: ${e.subject}`},e.id))})]}),!s.mergedInto&&/* @__PURE__ */ H(ut,{config:i,reopens:s.canReopen,onSend:e=>j(()=>h(e))})]}),/* @__PURE__ */ H(`aside`,{"aria-label":`Ticket details`,className:`col-12 col-lg-4`,children:/* @__PURE__ */ U(m,{padding:`sm`,className:`border`,children:[/* @__PURE__ */ H(`h3`,{className:`h6`,children:`Ticket details`}),/* @__PURE__ */ H(b,{columns:1,items:L})]})})]})]})}var ft=`ticket`;function pt(){return typeof window>`u`?null:new URLSearchParams(window.location.search).get(ft)}function mt(e){if(typeof window>`u`)return e?`?${ft}=${encodeURIComponent(e)}`:`?`;let t=new URL(window.location.href);return e?t.searchParams.set(ft,e):t.searchParams.delete(ft),`${t.pathname}${t.search}${t.hash}`}function ht(e){if(typeof window>`u`)return;let t=mt(e);t!==`${window.location.pathname}${window.location.search}${window.location.hash}`&&window.history.replaceState(window.history.state,``,t)}var gt=[{key:`all`,label:`All`,countKey:`total`},{key:`Open`,label:`Open`,countKey:`open`},{key:`InProgress`,label:`In progress`,countKey:`inProgress`},{key:`WaitingOnCustomer`,label:`Waiting on you`,countKey:`waitingOnCustomer`},{key:`Resolved`,label:`Resolved`,countKey:`resolved`},{key:`Closed`,label:`Closed`,countKey:`closed`},{key:`Cancelled`,label:`Cancelled`,countKey:null}],_t=[`tabs`,`select`,`none`];function vt({tickets:e,loading:t,error:n,onRetry:r,onOpen:i,status:a,onStatusChange:o,statusFilter:s=`tabs`,counts:c,search:d,onSearchChange:f,pagination:m}){I(`SupportCenter`,`statusFilter`,s,_t);let h=gt.map(({key:e,label:t,countKey:n})=>{let r=c?.[n];return{value:e,label:r==null?t:`${t} (${r})`}}),g=(e,t)=>{e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),i(t))};return/* @__PURE__ */ U(`div`,{className:`d-flex flex-column gap-3`,children:[n&&/* @__PURE__ */ U(u,{tone:`danger`,children:[Z(n,`We could not load your tickets.`),` `,/* @__PURE__ */ H(p,{variant:`ghost`,size:`sm`,onClick:r,children:`Try again`})]}),/* @__PURE__ */ U(`div`,{className:`d-flex flex-column flex-md-row gap-2 align-items-md-center justify-content-between`,children:[s===`none`?null:s===`select`?/* @__PURE__ */ H(k,{label:`Status`,value:a,onChange:o,options:h}):/* @__PURE__ */ H(N,{tabs:gt.map(({key:e,label:t,countKey:n})=>({key:e,label:t,count:c?.[n]})),value:a,onChange:o,ariaLabel:`Filter tickets by status`,className:`flex-grow-1`}),/* @__PURE__ */ H(O,{value:d,onChange:f,placeholder:`Search tickets`,ariaLabel:`Search tickets`})]}),/* @__PURE__ */ H(y,{columns:[{key:`subject`,label:`Subject`,render:e=>/* @__PURE__ */ U(`div`,{className:`d-flex flex-column`,style:{minWidth:0},children:[/* @__PURE__ */ H(E,{href:mt(e.id),animation:`none`,className:`fw-semibold text-break`,onClick:t=>g(t,e.id),children:e.subject}),/* @__PURE__ */ U(`span`,{className:`wui-text-xs text-body-secondary`,children:[e.number,`, `,e.category,e.awaitingCustomer?`. Waiting for your reply`:``]})]})},{key:`status`,label:`Status`,render:e=>e.statusLabel?/* @__PURE__ */ H(M,{label:e.statusLabel,tone:rt(e.status)}):`-`},{key:`messageCount`,label:`Messages`,cellClassName:`wui-text-sm text-body-secondary`,render:e=>e.messageCount},{key:`updatedDateTimeUtc`,label:`Last update`,cellClassName:`wui-text-sm text-body-secondary text-nowrap`,render:e=>/* @__PURE__ */ H($,{iso:e.updatedDateTimeUtc})}],rows:e,loading:t,skeletonRows:4,ariaLabel:`Support tickets`,rowActionsLabel:`Actions`,rowActions:e=>/* @__PURE__ */ H(l,{icon:`eye`,label:`Open ticket ${e.subject}`,href:mt(e.id),onClick:t=>g(t,e.id)}),stickyActions:!0,stackOnMobile:!0,sourceCount:c?.total??0,pagination:m,empty:/* @__PURE__ */ H(S,{variant:`table`,icon:`message-square`,title:`No tickets yet`,text:`When you raise a ticket, it shows here with its status.`}),emptyFiltered:/* @__PURE__ */ H(S,{variant:`table`,icon:`search`,title:`No tickets match`,text:`Try another search or status.`})})]})}var yt=300,bt=10;function xt({initialTicketId:e,defaultCategory:t,appVersion:n,status:r,defaultStatus:a=`all`,onStatusChange:o,statusFilter:s=`tabs`}){let{config:l,error:d,reload:f}=X(),[m,h]=c(a),g=r!==void 0,_=g?r:m,v=e=>{g||h(e),o?.(e)},[y,b]=c(``),x=Re(y.trim(),yt),[S,C]=c(bt),w=`${_}|${x}|${S}`,[T,E]=c({key:w,page:1}),D=T.key===w?T.page:1,O=e=>E({key:w,page:e}),k=Oe({status:_===`all`?void 0:_,search:x||void 0,page:D,pageSize:S}),{counts:A,reload:j}=ke(),[M,N]=c(()=>e||pt()),[P,F]=c(!1),I=k.totalPages;i(()=>{I>0&&D>I&&E({key:w,page:I})},[I,D,w]);let L=()=>{k.reload(),j()},R=e=>{N(e),ht(e)};if(M)return/* @__PURE__ */ H(dt,{ticketId:M,onBack:()=>R(null),onChanged:L,onOpenTicket:R},M);let z={page:D,totalPages:Math.max(1,k.totalPages),pageSize:S,total:k.totalCount,setPage:O,setPageSize:C};return/* @__PURE__ */ U(`section`,{className:`d-flex flex-column gap-3 min-w-0`,"aria-labelledby":`support-center-title`,children:[/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[/* @__PURE__ */ H(`h2`,{id:`support-center-title`,className:`h5 mb-0`,children:`Your tickets`}),/* @__PURE__ */ H(p,{leftIcon:`plus`,onClick:()=>F(!0),disabled:!l,children:`New ticket`})]}),d&&/* @__PURE__ */ U(u,{tone:`warning`,children:[Z(d,`We could not load the support settings.`),` `,/* @__PURE__ */ H(p,{variant:`ghost`,size:`sm`,onClick:f,children:`Try again`})]}),/* @__PURE__ */ H(vt,{tickets:k.tickets,loading:k.loading,error:k.error,onRetry:L,onOpen:R,status:_,onStatusChange:v,statusFilter:s,counts:A,search:y,onSearchChange:b,pagination:z}),l&&/* @__PURE__ */ H(tt,{open:P,onClose:()=>F(!1),config:l,defaultCategory:t,appVersion:n,onCreated:e=>{F(!1),L(),R(e.id)}})]})}function St(e){return e===0?`You are next in the queue.`:e===1?`1 person is ahead of you.`:`${e} people are ahead of you.`}function Ct({position:e}){return/* @__PURE__ */ U(`div`,{className:`d-flex flex-column gap-1`,children:[/* @__PURE__ */ U(`div`,{className:`d-flex align-items-center gap-2`,children:[/* @__PURE__ */ H(j,{size:`sm`,label:`Waiting for a person`}),/* @__PURE__ */ H(`span`,{className:`wui-text-sm`,children:`Waiting for a person to join.`})]}),typeof e==`number`&&/* @__PURE__ */ H(`span`,{className:`wui-text-sm text-body-secondary`,children:St(e)}),/* @__PURE__ */ H(`span`,{className:`wui-text-sm text-body-secondary`,children:`If no one is free, we will reply here and by email.`})]})}var wt={CustomerEnded:`You ended this chat.`,AgentEnded:`Our team ended this chat.`,NoAgentAvailable:`No one was free to join. We will reply to you here and by email.`,Idle:`This chat ended because it was quiet for a while.`};function Tt({state:e,closeReason:t,agentName:n,ticketNumber:r,ticketId:i,waitingPosition:a,canRequestAgent:o=!1,requesting:s=!1,onRequestAgent:c,onOpenTicket:l,onRestart:u}){return/* @__PURE__ */ U(`div`,{role:`status`,className:`d-flex flex-column gap-2 pb-3 mb-3 border-bottom`,children:[e===`Assistant`&&/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(`div`,{children:/* @__PURE__ */ H(f,{tone:`neutral`,children:`AI assistant`})}),/* @__PURE__ */ H(`p`,{className:`wui-text-sm mb-0`,children:`You are chatting with our AI assistant.`}),o&&/* @__PURE__ */ H(`div`,{children:/* @__PURE__ */ H(p,{variant:`outline`,size:`sm`,leftIcon:`user`,loading:s,onClick:c,children:`Talk to a person`})})]}),e===`WaitingForAgent`&&/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(`div`,{children:/* @__PURE__ */ H(f,{tone:`info`,children:`In the queue`})}),/* @__PURE__ */ H(Ct,{position:a??null})]}),e===`WithAgent`&&/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(`div`,{children:/* @__PURE__ */ H(f,{tone:`success`,children:`Live agent`})}),/* @__PURE__ */ H(`p`,{className:`wui-text-sm mb-0`,children:n?`${n} from our team is chatting with you.`:`A member of our team is chatting with you.`})]}),e===`Closed`&&/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(`div`,{children:/* @__PURE__ */ H(f,{tone:`neutral`,children:`Chat ended`})}),/* @__PURE__ */ H(`p`,{className:`wui-text-sm mb-0`,children:wt[t]??`This chat has ended.`}),r&&/* @__PURE__ */ H(`p`,{className:`wui-text-sm mb-0`,children:`Your ticket number is ${r}.`}),/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap gap-2`,children:[l&&i&&/* @__PURE__ */ H(p,{variant:`outline`,size:`sm`,onClick:()=>l({id:i,number:r}),children:`View ticket`}),/* @__PURE__ */ H(p,{size:`sm`,leftIcon:`plus`,onClick:u,children:`Start a new chat`})]})]})]})}var Et={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},Dt={...Et,maxWidth:`85%`};function Ot(e){for(let t=e?.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e}=getComputedStyle(t);if((e===`auto`||e===`scroll`)&&t.scrollHeight>t.clientHeight)return t}return null}function kt(e){if(!e?.parentElement)return;let t=()=>{let t=Ot(e);t&&(t.scrollTop=t.scrollHeight)};t();let n=new MutationObserver(t);return n.observe(e.parentElement,{childList:!0,subtree:!0,characterData:!0}),()=>n.disconnect()}function At({attachments:e}){return e?.length?/* @__PURE__ */ H(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.map(e=>/* @__PURE__ */ H(ot,{attachment:e},e.id))}):null}function jt({message:e,resolveLink:t,linkComponent:n}){let r=/* @__PURE__ */ H($,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return/* @__PURE__ */ U(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[/* @__PURE__ */ H(`span`,{className:`d-block`,children:e.body}),r]});if(e.authorKind===`Customer`)return/* @__PURE__ */ H(`li`,{className:`d-flex justify-content-end`,"data-author":`customer`,children:/* @__PURE__ */ U(m,{padding:`sm`,variant:`muted`,style:Dt,children:[/* @__PURE__ */ H(`span`,{className:`visually-hidden`,children:`You: `}),/* @__PURE__ */ H(`div`,{className:`wui-text-sm`,style:Et,children:e.body}),/* @__PURE__ */ H(At,{attachments:e.attachments}),/* @__PURE__ */ H(`div`,{className:`mt-1`,children:r})]})});if(e.authorKind===`Assistant`)return/* @__PURE__ */ U(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,children:[/* @__PURE__ */ H(d,{name:`Assistant`,size:32,tone:`primary`}),/* @__PURE__ */ U(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap align-items-center gap-2 mb-1`,children:[/* @__PURE__ */ H(`span`,{className:`fw-semibold`,children:`Assistant`}),/* @__PURE__ */ H(f,{tone:`neutral`,children:`AI`})]}),/* @__PURE__ */ H(`span`,{className:`visually-hidden`,children:`Assistant: `}),/* @__PURE__ */ H(re,{text:e.body,resolveLink:t,linkComponent:n}),/* @__PURE__ */ H(At,{attachments:e.attachments}),/* @__PURE__ */ H(`div`,{className:`mt-1`,children:r})]})]});let i=e.authorName||`Support team`;return/* @__PURE__ */ U(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`agent`,children:[/* @__PURE__ */ H(d,{name:i,size:32,tone:`primary`}),/* @__PURE__ */ U(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap align-items-center gap-2 mb-1`,children:[/* @__PURE__ */ H(`span`,{className:`fw-semibold`,children:i}),/* @__PURE__ */ H(f,{tone:`primary`,children:`Support`})]}),/* @__PURE__ */ H(`div`,{style:Et,children:e.body}),/* @__PURE__ */ H(At,{attachments:e.attachments}),/* @__PURE__ */ H(`div`,{className:`mt-1`,children:r})]})]})}function Mt({item:e,onRetry:t,onDiscard:n}){return/* @__PURE__ */ U(`li`,{className:`d-flex flex-column align-items-end gap-1`,"data-author":`customer`,children:[/* @__PURE__ */ H(m,{padding:`sm`,variant:`muted`,style:Dt,children:/* @__PURE__ */ H(`div`,{className:`wui-text-sm`,style:Et,children:e.body})}),e.status===`sending`&&/* @__PURE__ */ H(`span`,{className:`wui-text-xs text-body-secondary`,children:`Sending`}),e.status===`failed`&&/* @__PURE__ */ U(u,{tone:`danger`,size:`sm`,children:[/* @__PURE__ */ H(`div`,{children:e.error}),/* @__PURE__ */ U(`div`,{className:`d-flex gap-2 mt-2`,children:[/* @__PURE__ */ H(p,{size:`sm`,variant:`outline`,onClick:()=>t(e.localId),children:`Try again`}),/* @__PURE__ */ H(p,{size:`sm`,variant:`ghost`,onClick:()=>n(e.localId),children:`Discard`})]})]})]})}function Nt({messages:e,pending:t,assistantText:n,assistantWriting:r,agentName:i,agentTyping:a,onRetry:o,onDiscard:s,resolveLink:c,linkComponent:l}){return e.length===0&&t.length===0&&!n&&!r&&!a?/* @__PURE__ */ H(S,{icon:`sparkles`,size:`sm`,title:`How can we help?`,text:`Ask a question and our AI assistant will answer it. You can ask to talk to a person once you have sent a message.`}):/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ U(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:[e.map(e=>/* @__PURE__ */ H(jt,{message:e,resolveLink:c,linkComponent:l},e.id)),t.map(e=>/* @__PURE__ */ H(Mt,{item:e,onRetry:o,onDiscard:s},e.localId)),n?/* @__PURE__ */ U(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,"aria-busy":`true`,children:[/* @__PURE__ */ H(d,{name:`Assistant`,size:32,tone:`primary`}),/* @__PURE__ */ U(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[/* @__PURE__ */ H(`span`,{className:`fw-semibold`,children:`Assistant`}),/* @__PURE__ */ H(re,{text:n,resolveLink:c,linkComponent:l})]})]}):r&&/* @__PURE__ */ U(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,children:[/* @__PURE__ */ H(d,{name:`Assistant`,size:32,tone:`primary`}),/* @__PURE__ */ U(`div`,{className:`d-flex align-items-center gap-2 wui-text-sm`,children:[/* @__PURE__ */ H(j,{size:`sm`,label:`The assistant is writing`}),/* @__PURE__ */ H(`span`,{children:`The assistant is writing`})]})]}),a&&/* @__PURE__ */ H(`li`,{className:`wui-text-sm text-body-secondary`,"aria-live":`polite`,children:`${i||`Our team`} is typing`})]}),/* @__PURE__ */ H(`div`,{ref:kt})]})}var Pt=3e3,Ft=`This chat is no longer available.`,It=(e,t)=>e.sequence-t.sequence;function Lt(e,t){return e.some(e=>e.id===t.id)?e:[...e,t].sort(It)}function Rt(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.has(n.id)||t.set(n.id,n);return[...t.values()].sort(It)}function zt(e,t){if(!e)return;let n=Date.parse(e)-Date.now();if(!(n>0))return;let r=setTimeout(t,n);return()=>clearTimeout(r)}function Bt({chatClient:e,connection:t,open:r,appVersion:a}){let[o,l]=c(`idle`),[u,d]=c(``),[f,p]=c(null),[m,h]=c([]),[g,_]=c([]),[v,y]=c(``),[b,x]=c(null),[S,C]=c(null),[w,T]=c(``),[E,D]=c(!1),[,O]=c(0),k=s(null),A=s(null),j=s(0),M=n(e=>{let t=A.current;A.current=e.id;let{messages:n,...r}=e;p(r),h(Rt(n??[])),t!==e.id&&_([])},[]);i(()=>zt(b,()=>O(e=>e+1)),[b]),i(()=>zt(S,()=>O(e=>e+1)),[S]);let N=n(()=>{let n=!0,r=()=>{},i=e=>({onSnapshot(t){t.id===e&&(M(t),y(``))},onMessage(t){t.chatId===e&&(h(e=>Lt(e,t.message)),t.message.authorKind===`Assistant`&&y(``))},onState(t){t.chatId===e&&(p(e=>e&&{...e,state:t.state,closeReason:t.closeReason,ticketId:t.ticketId,ticketNumber:t.ticketNumber,agentName:t.agentName,waitingPosition:t.state===`WaitingForAgent`?t.waitingPosition:null}),y(``))},onTyping(t){t.chatId===e&&(t.who===`Agent`?x(t.untilDateTimeUtc):t.who===`Assistant`&&C(t.untilDateTimeUtc))},onDelta(t){t.chatId===e&&y(e=>e+t.text)},onError(e){e.code===`chat_not_found`?(p(e=>e&&{...e,state:`Closed`,closeReason:null}),T(Ft)):T(typeof e.message==`string`&&e.message?e.message:`The chat connection had a problem. We are reconnecting.`)}});return l(`loading`),e.start({pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:a}).then(e=>{n&&(M(e),d(``),l(`ready`),r=t.watch(e.id,e.sequence,i(e.id)))}).catch(e=>{n&&(d(Z(e,`We could not start the chat. Please try again.`)),l(`error`))}),()=>{n=!1,r()}},[e,t,M,a]);i(()=>{if(!r)return;let e=N();return k.current=()=>{e(),e=N()},()=>{k.current=null,e()}},[r,N]);let P=(t,n)=>e.get(t).then(M).catch(e=>T(Z(e,n)));async function F(t){let n=f.id;try{let r=await e.send(n,{body:t.body,files:t.files,idempotencyKey:t.key});return A.current===n&&(h(e=>{let t=Lt(e,r.message);return r.reply?Lt(t,r.reply):t}),_(e=>e.filter(e=>e.localId!==t.localId)),r.reply&&y(``),!0)}catch(e){return A.current===n?e?.code===`chat_closed`?(_(e=>e.filter(e=>e.localId!==t.localId)),await P(n,Ft),!1):(_(n=>n.map(n=>n.localId===t.localId?{...n,status:`failed`,error:Z(e,`Your message did not send. Please try again.`)}:n)),!1):!1}}return{phase:o,startError:u,chat:f,messages:m,pending:g,assistantText:v,agentTypingUntil:b,assistantTypingUntil:S,notice:w,requesting:E,send:(e,t=[])=>{let n={localId:crypto.randomUUID(),key:crypto.randomUUID(),body:e,files:t,status:`sending`,error:``};return _(e=>[...e,n]),F(n)},retry:e=>{let t=g.find(t=>t.localId===e);if(!t)return;let n={...t,status:`sending`,error:``};_(t=>t.map(t=>t.localId===e?n:t)),F(n)},discard:e=>{_(t=>t.filter(t=>t.localId!==e))},requestAgent:async()=>{let t=f.id;D(!0);try{M(await e.requestAgent(t))}catch(e){let n=`We could not reach the team. Please try again.`;e?.code===`chat_not_with_assistant`?await P(t,n):T(Z(e,n))}finally{D(!1)}},end:async()=>{try{M(await e.close(f.id))}catch(e){T(Z(e,`We could not end the chat. Please try again.`))}},restart:()=>{A.current=null,p(null),h([]),_([]),y(``),T(``),x(null),C(null),l(`loading`),k.current?.()},retryStart:()=>{k.current?.()},notifyTyping:()=>{if(o!==`ready`||f?.state!==`WithAgent`)return;let t=Date.now();t-j.current<Pt||(j.current=t,e.typing(f.id).catch(()=>{}))}}}var Vt={composer:`Your message`,placeholder:`Type your message`},Ht=e=>!!e&&Date.now()<Date.parse(e);function Ut({chatClient:e,connection:t,open:r,onClose:a,appVersion:o,onOpenTicket:d,resolveLink:f,linkComponent:m,title:h=`Chat with us`,width:g=`440px`}){let{config:v}=X(),y=Bt({chatClient:e,connection:t,open:r,appVersion:o}),[b,S]=c(!1),[C,T]=c([]),[E,D]=c(``),O=s(0),k=s(null),A=s(y.notifyTyping);i(()=>{A.current=y.notifyTyping});let M=e=>{let t=Ie(C.map(e=>e.file),e,v);T(t.files.map(e=>C.find(t=>t.file===e)||(O.current+=1,{key:`attachment-${O.current}`,fileName:e.name,contentType:e.type,length:e.size,status:`Ready`,progress:null,error:null,file:e}))),D(t.notice)},N=e=>{T(t=>t.filter(t=>t.key!==e)),D(``)},P=async e=>{let t=C;await y.send(e,t.map(e=>e.file))&&T(e=>e.filter(e=>!t.includes(e)))},F=()=>{T([]),D(``),y.restart()},I=n(()=>A.current(),[]),L=n(e=>{k.current?.removeEventListener(`input`,I),k.current=e,e?.addEventListener(`input`,I)},[I]),R=y.phase===`ready`&&y.chat!==null,z=y.chat?.state,B=R&&z!==`Closed`,ee=Ht(y.assistantTypingUntil)||z===`Assistant`&&y.pending.some(e=>e.status===`sending`),te=Ht(y.agentTypingUntil),re=y.messages.some(e=>e.authorKind===`Customer`)&&!!y.chat?.assistantAvailable;i(()=>{r&&R&&k.current?.focus()},[r,R]);let W=/* @__PURE__ */ U(`div`,{className:`drawer-header`,children:[/* @__PURE__ */ U(`div`,{className:`drawer-title`,children:[/* @__PURE__ */ H(`span`,{className:`drawer-title-ic`,children:/* @__PURE__ */ H(w,{name:`message-circle`,size:18})}),h]}),/* @__PURE__ */ U(`div`,{className:`d-flex align-items-center gap-1`,children:[B&&/* @__PURE__ */ H(p,{variant:`ghost`,size:`sm`,onClick:()=>S(!0),children:`End chat`}),/* @__PURE__ */ H(l,{icon:`x`,label:`Close`,onClick:a})]})]}),G;G=y.phase===`error`?/* @__PURE__ */ U(u,{tone:`danger`,children:[y.startError,/* @__PURE__ */ H(`div`,{className:`mt-2`,children:/* @__PURE__ */ H(p,{size:`sm`,variant:`outline`,onClick:y.retryStart,children:`Try again`})})]}):R?/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(Tt,{state:z,closeReason:y.chat.closeReason,agentName:y.chat.agentName,ticketNumber:y.chat.ticketNumber,ticketId:y.chat.ticketId,waitingPosition:y.chat.waitingPosition,canRequestAgent:re,requesting:y.requesting,onRequestAgent:y.requestAgent,onOpenTicket:d,onRestart:F}),/* @__PURE__ */ H(Nt,{messages:y.messages,pending:y.pending,assistantText:y.assistantText,assistantWriting:ee,agentName:y.chat.agentName,agentTyping:te,onRetry:y.retry,onDiscard:y.discard,resolveLink:f,linkComponent:m}),y.notice&&/* @__PURE__ */ H(u,{tone:`danger`,size:`sm`,children:y.notice})]}):/* @__PURE__ */ H(`div`,{className:`d-flex justify-content-center py-4`,children:/* @__PURE__ */ H(j,{label:`Starting your chat`})});let ae=B?/* @__PURE__ */ U(`div`,{className:`d-flex flex-column gap-2`,children:[E&&/* @__PURE__ */ H(u,{tone:`danger`,size:`sm`,children:E}),/* @__PURE__ */ H(ne,{onSubmit:P,busy:y.pending.length>0||!!y.assistantText,maxLength:v?.bodyMaxLength??4e3,inputRef:L,attachments:C,onAttach:M,onRemoveAttachment:N,accept:Me(v),labels:Vt}),z===`Assistant`&&/* @__PURE__ */ H(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:ie.disclaimer})]}):void 0;return/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(x,{open:r,onClose:a,sheet:!1,width:g,header:W,footer:ae,ariaLabel:h,onOpened:()=>k.current?.focus(),children:G}),/* @__PURE__ */ H(_,{open:b,title:`End this chat?`,message:z===`Assistant`?`You can start a new chat whenever you like.`:`Our team can still see this conversation on your ticket.`,confirmLabel:`End chat`,cancelLabel:`Keep chatting`,onConfirm:()=>{S(!1),y.end()},onClose:()=>S(!1)})]})}var Wt={zIndex:`var(--wui-z-fixed)`,bottom:`var(--wui-consent-banner-block, 0px)`},Gt={end:{insetInlineEnd:0},start:{insetInlineStart:0}};function Kt({onClick:e,open:t=!1,label:n=`Chat with us`,position:r=`end`,icon:i=`message-circle`,compact:a=!1,className:o,style:s}){return a?/* @__PURE__ */ H(qt,{onClick:e,open:t,label:n,position:r,icon:i,className:o,style:s}):/* @__PURE__ */ H(`span`,{"data-support-capture":`exclude`,className:[`position-fixed m-3`,o].filter(Boolean).join(` `),style:{...Wt,...Gt[r],...s},children:/* @__PURE__ */ H(p,{leftIcon:i,className:`rounded-pill`,onClick:e,"aria-haspopup":`dialog`,"aria-expanded":t,children:n})})}function qt({onClick:e,open:t,label:n,position:r,icon:i,className:a,style:o}){let s=F(r);return s?R(/* @__PURE__ */ H(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--primary`,a].filter(Boolean).join(` `),style:o,children:/* @__PURE__ */ H(p,{className:`wui-floating-btn`,onClick:e,"aria-label":n,"aria-haspopup":`dialog`,"aria-expanded":t,tooltip:n,tooltipPlacement:r===`start`?`end`:`start`,children:/* @__PURE__ */ H(w,{name:i,size:24})})}),s):null}var Jt=e=>typeof e==`string`&&e.trim()!==``;function Yt({className:e}){let{config:t}=X();if(!t)return null;let n=[];return Jt(t.supportEmail)&&n.push({key:`email`,icon:`mail`,label:`Email`,value:/* @__PURE__ */ U(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2`,children:[/* @__PURE__ */ H(`a`,{href:`mailto:${t.supportEmail}`,className:`text-break`,children:t.supportEmail}),/* @__PURE__ */ H(v,{text:t.supportEmail,size:`sm`,label:`Copy email`,copiedLabel:`Email copied`})]})}),Jt(t.supportPhone)&&n.push({key:`phone`,icon:`phone`,label:`Phone`,value:t.supportPhone,href:`tel:${t.supportPhone.replace(/[^\d+]/g,``)}`}),Jt(t.supportHours)&&n.push({key:`hours`,icon:`clock`,label:`Hours`,value:t.supportHours}),n.length===0?null:/* @__PURE__ */ U(`section`,{className:e,"aria-label":Jt(t.supportName)?`Contact ${t.supportName}`:`Contact support`,children:[Jt(t.supportName)&&/* @__PURE__ */ H(`p`,{className:`fw-semibold mb-2`,children:t.supportName}),/* @__PURE__ */ H(b,{items:n,layout:`list`,columns:1})]})}function Xt({client:e,timeZone:t=z,renderTime:r,children:i}){let a=s(null),c=n((t=!1)=>{let n=a.current;if(t||!n||n.client!==e){let t=e.getConfig(),n={client:e,pending:t};return a.current=n,t.catch(()=>{a.current===n&&(a.current=null)}),t}return n.pending},[e]),l=o(()=>({client:e,loadConfig:c,timeZone:t,renderTime:r}),[e,c,t,r]);return/* @__PURE__ */ H(Ce.Provider,{value:l,children:i})}export{et as ReportIssue,G as SupportApiError,xt as SupportCenter,Ut as SupportChat,Kt as SupportChatLauncher,Yt as SupportContact,Xt as SupportProvider,Se as createSseChatConnection,he as createSupportChatClient,de as createSupportClient,Y as useSupportClient,X as useSupportConfig,Ae as useSupportTicket,ke as useSupportTicketCounts,Oe as useSupportTickets};
|
|
@@ -24,7 +24,7 @@ export declare function useSupportChatSession({ chatClient, connection, open, ap
|
|
|
24
24
|
assistantTypingUntil: null;
|
|
25
25
|
notice: string;
|
|
26
26
|
requesting: boolean;
|
|
27
|
-
send: (body: any) =>
|
|
27
|
+
send: (body: any, files?: any[]) => Promise<boolean>;
|
|
28
28
|
retry: (localId: any) => void;
|
|
29
29
|
discard: (localId: any) => void;
|
|
30
30
|
requestAgent: () => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/support-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.124.0",
|
|
4
4
|
"description": "Webority customer support for React portals: ticket centre, report-an-issue with an optional page screenshot, and support contact details, built on @webority/ui-react.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
},
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@webority/chat-react": "0.
|
|
31
|
-
"@webority/ui-elements": "0.
|
|
32
|
-
"@webority/ui-react": "0.
|
|
30
|
+
"@webority/chat-react": "0.124.0",
|
|
31
|
+
"@webority/ui-elements": "0.124.0",
|
|
32
|
+
"@webority/ui-react": "0.124.0",
|
|
33
33
|
"bootstrap": "5.3.3",
|
|
34
34
|
"react": "^19.0.0",
|
|
35
35
|
"react-bootstrap": "^2.10.0",
|
|
@@ -43,10 +43,10 @@
|
|
|
43
43
|
"@types/react": "^19.2.17",
|
|
44
44
|
"@vitejs/plugin-react": "^6.0.1",
|
|
45
45
|
"@vitest/coverage-v8": "5.0.1",
|
|
46
|
-
"@webority/canvas-kit": "0.
|
|
47
|
-
"@webority/chat-react": "0.
|
|
48
|
-
"@webority/ui-elements": "0.
|
|
49
|
-
"@webority/ui-react": "0.
|
|
46
|
+
"@webority/canvas-kit": "0.124.0",
|
|
47
|
+
"@webority/chat-react": "0.124.0",
|
|
48
|
+
"@webority/ui-elements": "0.124.0",
|
|
49
|
+
"@webority/ui-react": "0.124.0",
|
|
50
50
|
"bootstrap": "5.3.3",
|
|
51
51
|
"jsdom": "30.1.1",
|
|
52
52
|
"react": "^19.2.6",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"vitest": "5.0.1"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
+
"@webority/chat-core": "0.124.0",
|
|
60
61
|
"html-to-image": "^1.11.13"
|
|
61
62
|
},
|
|
62
63
|
"scripts": {
|