@webority/support-react 0.126.2 → 0.128.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/README.md CHANGED
@@ -74,9 +74,9 @@ entry repeats. `stallTimeoutMs` is how long the stream may go quiet before it is
74
74
 
75
75
  `listTickets` returns one page, most recently updated first, in the shape
76
76
  `{ items, page, pageSize, totalCount, totalPages }`. Every query part is optional: `status` is one
77
- of `Open`, `InProgress`, `Resolved` or `Closed`, `search` matches the subject or the ticket
77
+ of `Open`, `NeedsReply`, `Resolved` or `Withdrawn`, `search` matches the subject or the ticket
78
78
  number, `page` starts at 1, and the API caps `pageSize` at 100. `getTicketCounts` returns
79
- `{ open, inProgress, resolved, closed, total }`. A ticket's `accountId` and `realm` are `null` on
79
+ `{ open, needsReply, resolved, withdrawn, total }`. A ticket's `accountId` and `realm` are `null` on
80
80
  the customer side, and its `version` is for support staff only; the components use none of them.
81
81
 
82
82
  | Method | Request |
@@ -103,8 +103,8 @@ acted on (with `id` and `number`), and an expired or unknown token rejects with
103
103
 
104
104
  The support page: the customer's tickets with status tabs and a search box, one ticket's
105
105
  conversation, and a New ticket dialog. The server filters, searches and pages the list, so it
106
- stays quick however many tickets a customer has. The tabs are All, Open, In progress, Resolved
107
- and Closed, each labelled with its count from `getTicketCounts`. All is chosen first. The search
106
+ stays quick however many tickets a customer has. The tabs are All, Open, Needs your reply, Resolved
107
+ and Withdrawn, each labelled with its count from `getTicketCounts`. All is chosen first. The search
108
108
  asks the server once typing pauses, and a new tab or search starts again at page 1.
109
109
 
110
110
  ```jsx
@@ -2,7 +2,7 @@
2
2
  "format": "webority-guidance/1",
3
3
  "package": {
4
4
  "name": "@webority/support-react",
5
- "version": "0.126.2"
5
+ "version": "0.128.0"
6
6
  },
7
7
  "components": [
8
8
  {
@@ -83,7 +83,7 @@
83
83
  "usage": {
84
84
  "when": [
85
85
  "A page or footer shows how to reach support.",
86
- "It lists the email address with a copy button, the phone number as a call link and the opening hours.",
86
+ "It shows the email address with a copy button, the phone number as a call link and the opening hours on one line.",
87
87
  "A field the product has not set is left out, and nothing renders when none is set."
88
88
  ],
89
89
  "whenNot": [],
@@ -1,12 +1,12 @@
1
- import{createContext as e,useCallback as t,useContext as n,useEffect as r,useId as i,useMemo as a,useRef as o,useState as s}from"react";import{AppActionIcon as c,AppAlert as l,AppAvatar as u,AppBadge as d,AppButton as f,AppCard as p,AppChip as m,AppChipGroup as h,AppConfirmDialog as g,AppCopyButton as _,AppDataTable as v,AppDescriptions as y,AppDrawer as b,AppEmptyState as x,AppFileAttachment as S,AppIcon as C,AppInput as w,AppLink as T,AppModal as E,AppSearch as D,AppSelect as O,AppSkeleton as k,AppSpinner as A,AppStatusBadge as j,AppTabs as M,AppTextarea as N,useFloatingStack as P,warnInvalidValue as F}from"@webority/ui-react";import{toBlob as I}from"html-to-image";import{createPortal as L}from"react-dom";import{IST_TIME_ZONE as R,formatDateTime as z,formatFileSize as B,timeZoneLabel as ee}from"@webority/ui-elements/helpers";import{Fragment as V,jsx as H,jsxs as U}from"react/jsx-runtime";import{ChatComposer as te,ChatMarkdown as W,DEFAULT_CHAT_LABELS as ne}from"@webority/chat-react";var re=`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 ie(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 K(e){if(e instanceof G)return e;let t=e?.response;if(!t)return new G(`network`,re);let n=await ie(t.data);return new G(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.detail==`string`&&n.detail.trim()?n.detail:re,t.status)}async function q(e){try{return(await e()).data}catch(e){throw await K(e)}}function J(e,t,n){n!=null&&String(n).trim()!==``&&e.append(t,String(n))}function ae(e,t,n,r){(n??[]).forEach((n,i)=>{let a=n?.name||`${r}-${i+1}.png`;e.append(t,n,a)})}var oe=20;function se(e,t){return(e??[]).map((e,n)=>e?.name||`${t}-${n+1}.png`).join(`|`)}function ce(e){return e instanceof G&&typeof e.status==`number`&&e.status>=400&&e.status<=499&&e.status!==408&&e.status!==429}function le(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<=oe)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 ce(t)&&i.delete(e),t}finally{let t=a.get(e)-1;t>0?a.set(e,t):a.delete(e)}}return{getConfig:()=>q(()=>e.get(`${n}/settings`)),listTickets:({status:t,search:r,page:i,pageSize:a}={})=>{let o=new URLSearchParams;J(o,`status`,t),J(o,`search`,r?.trim()),J(o,`page`,i),J(o,`pageSize`,a);let s=o.toString();return q(()=>e.get(`${n}/tickets${s?`?${s}`:``}`))},getTicketCounts:()=>q(()=>e.get(`${n}/tickets/counts`)),getTicket:t=>q(()=>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??``),J(d,`pageUrl`,a),J(d,`userAgent`,o),J(d,`appVersion`,c),ae(d,`files`,l,`file`),ae(d,`screenshots`,u,`screenshot`),s([`ticket`,t,r,i,se(l,`file`),se(u,`screenshot`)].join(`\0`),t=>q(()=>e.post(`${n}/tickets`,d,{headers:{"Idempotency-Key":t}})))},getSuggestions:async(t,{signal:r}={})=>{try{return await q(()=>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??``),ae(o,`files`,i,`file`),ae(o,`screenshots`,a,`screenshot`),s([`reply`,t,n,se(i,`file`),se(a,`screenshot`)].join(`\0`),n=>q(()=>e.post(`${r(t)}/replies`,o,{headers:{"Idempotency-Key":n}})))},reopen:t=>q(()=>e.post(`${r(t)}/reopen`)),cancel:t=>q(()=>e.post(`${r(t)}/cancel`)),rate:(t,{satisfaction:n,comment:i})=>{let a={satisfaction:n};return i!=null&&i.trim()!==``&&(a.comment=i.trim()),q(()=>e.post(`${r(t)}/rating`,a))},fetchAttachment:t=>q(()=>e.get(`${n}/attachments/${encodeURIComponent(t)}`,{responseType:`blob`})),confirmAction:t=>q(()=>e.post(`${n}/actions/confirm`,{token:t}))}}var ue=`Something went wrong. Please try again.`;async function de(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 fe(e){if(e instanceof G)return e;let t=e?.response;if(!t)return new G(`network`,ue);let n=await de(t.data);return new G(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.message==`string`&&n.message?n.message:ue,t.status)}async function Y(e){try{return(await e()).data}catch(e){throw await fe(e)}}function pe({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`,`chatConversationReference`,`openingLine`]){let n=t?.[e];typeof n==`string`&&n.trim()!==``&&(r[e]=n)}return t?.wantsPerson===!0&&(r.wantsPerson=!0),Y(()=>e.post(`${n}/chats`,r))},current:()=>Y(()=>e.get(`${n}/chats/current`)),get:t=>Y(()=>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`)}),Y(()=>e.post(`${r(t)}/messages`,o,{headers:{"Idempotency-Key":a}}))},requestAgent:t=>Y(()=>e.post(`${r(t)}/agent`)),typing:async t=>{await Y(()=>e.post(`${r(t)}/typing`))},close:t=>Y(()=>e.post(`${r(t)}/close`))}}var me=e=>{let t=``,n=t=>{let n=`message`,r=[];for(let e of t.split(`
1
+ import{createContext as e,useCallback as t,useContext as n,useEffect as r,useId as i,useMemo as a,useRef as o,useState as s}from"react";import{AppActionIcon as c,AppAlert as l,AppAvatar as u,AppBadge as d,AppButton as f,AppCard as p,AppChip as m,AppChipGroup as h,AppConfirmDialog as g,AppCopyButton as _,AppDataTable as v,AppDescriptions as y,AppDrawer as b,AppEmptyState as x,AppFileAttachment as S,AppFormActions 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 V,timeZoneLabel as ee}from"@webority/ui-elements/helpers";import{Fragment as H,jsx as U,jsxs as W}from"react/jsx-runtime";import{ChatComposer as te,ChatMarkdown as ne,DEFAULT_CHAT_LABELS as re}from"@webority/chat-react";var G=`Something went wrong. Please try again.`,K=class extends Error{constructor(e,t,n){super(t),this.name=`SupportApiError`,this.code=e,this.status=n}};async function ie(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 ae(e){if(e instanceof K)return e;let t=e?.response;if(!t)return new K(`network`,G);let n=await ie(t.data);return new K(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.detail==`string`&&n.detail.trim()?n.detail:G,t.status)}async function q(e){try{return(await e()).data}catch(e){throw await ae(e)}}function J(e,t,n){n!=null&&String(n).trim()!==``&&e.append(t,String(n))}function oe(e,t,n,r){(n??[]).forEach((n,i)=>{let a=n?.name||`${r}-${i+1}.png`;e.append(t,n,a)})}var se=20;function ce(e,t){return(e??[]).map((e,n)=>e?.name||`${t}-${n+1}.png`).join(`|`)}function le(e){return e instanceof K&&typeof e.status==`number`&&e.status>=400&&e.status<=499&&e.status!==408&&e.status!==429}function ue(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<=se)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 le(t)&&i.delete(e),t}finally{let t=a.get(e)-1;t>0?a.set(e,t):a.delete(e)}}return{getConfig:()=>q(()=>e.get(`${n}/settings`)),listTickets:({status:t,search:r,page:i,pageSize:a}={})=>{let o=new URLSearchParams;J(o,`status`,t),J(o,`search`,r?.trim()),J(o,`page`,i),J(o,`pageSize`,a);let s=o.toString();return q(()=>e.get(`${n}/tickets${s?`?${s}`:``}`))},getTicketCounts:()=>q(()=>e.get(`${n}/tickets/counts`)),getTicket:t=>q(()=>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??``),J(d,`pageUrl`,a),J(d,`userAgent`,o),J(d,`appVersion`,c),oe(d,`files`,l,`file`),oe(d,`screenshots`,u,`screenshot`),s([`ticket`,t,r,i,ce(l,`file`),ce(u,`screenshot`)].join(`\0`),t=>q(()=>e.post(`${n}/tickets`,d,{headers:{"Idempotency-Key":t}})))},getSuggestions:async(t,{signal:r}={})=>{try{return await q(()=>e.get(`${n}/suggestions`,{params:{subject:t},signal:r}))}catch(e){if(e instanceof K&&e.status===404)return[];throw e}},reply:(t,{body:n,files:i,screenshots:a})=>{let o=new FormData;return o.append(`body`,n??``),oe(o,`files`,i,`file`),oe(o,`screenshots`,a,`screenshot`),s([`reply`,t,n,ce(i,`file`),ce(a,`screenshot`)].join(`\0`),n=>q(()=>e.post(`${r(t)}/replies`,o,{headers:{"Idempotency-Key":n}})))},reopen:t=>q(()=>e.post(`${r(t)}/reopen`)),cancel:t=>q(()=>e.post(`${r(t)}/cancel`)),rate:(t,{satisfaction:n,comment:i})=>{let a={satisfaction:n};return i!=null&&i.trim()!==``&&(a.comment=i.trim()),q(()=>e.post(`${r(t)}/rating`,a))},fetchAttachment:t=>q(()=>e.get(`${n}/attachments/${encodeURIComponent(t)}`,{responseType:`blob`})),confirmAction:t=>q(()=>e.post(`${n}/actions/confirm`,{token:t}))}}var de=`Something went wrong. Please try again.`;async function fe(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 pe(e){if(e instanceof K)return e;let t=e?.response;if(!t)return new K(`network`,de);let n=await fe(t.data);return new K(typeof n?.code==`string`&&n.code?n.code:`unknown`,typeof n?.message==`string`&&n.message?n.message:de,t.status)}async function Y(e){try{return(await e()).data}catch(e){throw await pe(e)}}function me({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`,`chatConversationReference`,`openingLine`]){let n=t?.[e];typeof n==`string`&&n.trim()!==``&&(r[e]=n)}return t?.wantsPerson===!0&&(r.wantsPerson=!0),Y(()=>e.post(`${n}/chats`,r))},current:()=>Y(()=>e.get(`${n}/chats/current`)),get:t=>Y(()=>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`)}),Y(()=>e.post(`${r(t)}/messages`,o,{headers:{"Idempotency-Key":a}}))},requestAgent:t=>Y(()=>e.post(`${r(t)}/agent`)),typing:async t=>{await Y(()=>e.post(`${r(t)}/typing`))},close:t=>Y(()=>e.post(`${r(t)}/close`))}}var he=e=>{let t=``,n=t=>{let n=`message`,r=[];for(let e of t.split(`
2
2
  `)){if(e===``||e.startsWith(`:`))continue;let t=e.indexOf(`:`),i=t===-1?e:e.slice(0,t),a=t===-1?``:e.slice(t+1);a.startsWith(` `)&&(a=a.slice(1)),i===`event`?n=a:i===`data`&&r.push(a)}if(r.length===0)return;let i;try{i=JSON.parse(r.join(`
3
3
  `))}catch{e({name:`error`,data:{code:`invalid-response`,message:null}});return}e({name:n,data:i})};return{push(e){if(!e)return;t=(t+e).replace(/\r\n/g,`
4
4
  `).replace(/\r(?!$)/g,`
5
5
  `);let r=t.split(`
6
6
 
7
- `);t=r.pop()??``;for(let e of r)n(e)},end(){let e=t.replace(/\r$/,``);t=``,e.trim()&&n(e)}}},he=`Something went wrong. Please try again.`;function ge(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 _e(e){if(typeof e==`string`)try{return JSON.parse(e)}catch{return null}return e??null}function ve(e){let t=e?.response,n=_e(t?.data),r=typeof n?.code==`string`&&n.code?n.code:`unknown`,i=typeof n?.message==`string`&&n.message?n.message:he;return{status:t?.status,code:r,message:i}}var ye=e=>e===void 0||e===408||e===429||e>=500;function be(){let e=``,t=null;return{push(n){e=(e+n).replace(/\r\n/g,`
7
+ `);t=r.pop()??``;for(let e of r)n(e)},end(){let e=t.replace(/\r$/,``);t=``,e.trim()&&n(e)}}},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,`
8
8
  `).replace(/\r(?!$)/g,`
9
9
  `);let r=e.split(`
10
10
 
11
11
  `);e=r.pop();for(let e of r)for(let n of e.split(`
12
- `)){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 xe({http:e,baseUrl:t=`/api/support`,retryDelaysMs:n,stallTimeoutMs:r=9e4}){let i=t.replace(/\/+$/,``),a=Array.isArray(n)&&n.length>0?n:[1e3];return{watch(t,n,o){let s=Number.isFinite(n)?n:null,c=!1,l=null,u=null,d=null,f=null,p=!1,m=!1,h=!1,g=null,_=0,v=e=>{Number.isFinite(e)&&(s=Math.max(s??0,e))};function y(e,t){if(!c){m=!0;try{e===`snapshot`?(v(t?.sequence),o.onSnapshot?.(t)):e===`message`?(v(t?.message?.sequence),o.onMessage?.(t)):e===`state`?o.onState?.(t):e===`typing`?o.onTyping?.(t):e===`delta`&&o.onDelta?.(t)}catch{o.onError?.(new G(`handler_failed`,he))}}}function b(){clearTimeout(u),u=setTimeout(()=>{h=!0,l.abort()},r)}async function x(){l=new AbortController,p=!1,m=!1,h=!1,g=null;let n=0,r=be(),a=me(({name:e,data:t})=>{c||g||(e===`error`?t?.code===`invalid-response`||t?.code===`stream_ended`?g=`retry`:t?.code===`chat_not_found`?(o.onError?.(t),g=`stop`):(o.onError?.(t),g=`retry`):y(e,t))}),d=e=>{if(c||typeof e!=`string`||e.length<=n)return;let t=e.slice(n);n=e.length,a.push(t),r.push(t),r.last!==null&&(s=Math.max(s??0,r.last)),p=!0,b()},f=`${i}/chats/${encodeURIComponent(t)}/events${s===null?``:`?after=${s}`}`;b();let _;try{_=await e.get(f,{responseType:`text`,headers:{Accept:`text/event-stream`},signal:l.signal,timeout:0,onDownloadProgress:e=>d(ge(e))})}catch(e){if(c)return`stop`;if(h)return`retry`;let t=ve(e);return ye(t.status)?`retry`:(o.onError?.({code:t.code,message:t.message}),`stop`)}finally{clearTimeout(u)}return d(_.data),clearTimeout(u),a.end(),g??`retry`}function S(e){return new Promise(t=>{f=t,d=setTimeout(t,e)})}async function C(){let e=0;for(;!c;){let t=await x();if(c||t===`stop`)return;if(p&&(e=0),_=m?0:_+1,_>=10){o.onError?.(new G(`connection_lost`,`We lost the connection to support. Check your internet and try again.`));return}let n=a[Math.min(e,a.length-1)];e+=1,await S(n)}}function w(){c=!0,l?.abort(),clearTimeout(u),clearTimeout(d),f?.()}return C(),w}}}var Se=e(null);function Ce(){let e=n(Se);if(!e)throw Error(`Support components and hooks must be used inside <SupportProvider>.`);return e}function X(){return Ce().client}function we(){return Ce().timeZone}function Te(){return Ce().renderTime??null}function Ee(e,n,i=!0){let[a,c]=s({data:null,loading:i,error:null}),[l,u]=s(0),d=o(e);d.current=e;let f=o(n);r(()=>{let e=f.current!==n;if(f.current=n,!i){c({data:null,loading:!1,error:null});return}let t=!0;return c(t=>({data:e?null:t.data,loading:!0,error:null})),d.current(l>0).then(e=>t&&c({data:e,loading:!1,error:null}),e=>t&&c(t=>({...t,loading:!1,error:e}))),()=>{t=!1}},[n,i,l]);let p=t(()=>u(e=>e+1),[]),m=t(e=>c(t=>({...t,data:e})),[]);return{...a,reload:p,setData:m}}function Z(){let{loadConfig:e}=Ce(),{data:t,loading:n,error:r,reload:i}=Ee(e,`config`);return{config:t,loading:n,error:r,reload:i}}function De(e={}){let t=X(),{status:n,search:r,page:i,pageSize:a}=e,{data:o,loading:s,error:c,reload:l}=Ee(()=>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 Oe(){let e=X(),{data:t,loading:n,error:r,reload:i}=Ee(()=>e.getTicketCounts(),`ticket-counts`);return{counts:t,loading:n,error:r,reload:i}}function ke(e){let n=X(),{data:r,loading:i,error:a,reload:o,setData:s}=Ee(()=>n.getTicket(e),e??``,!!e),c=t(async e=>{let t=await e();return s(t),t},[s]);return{ticket:r,loading:i,error:a,reload:o,reply:t(t=>c(()=>n.reply(e,t)),[c,n,e]),reopen:t(()=>c(()=>n.reopen(e)),[c,n,e]),cancel:t(()=>c(()=>n.cancel(e)),[c,n,e]),rate:t(t=>c(()=>n.rate(e,t)),[c,n,e])}}var Ae=`We could not reach support. Check your connection and try again.`;function Q(e,t){if(e instanceof G){if(e.code===`network`)return Ae;if(e.code!==`unknown`)return e.message}return t}function je(e){return(e?.allowedContentTypes??[]).join(`,`)}function Me(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 Ne(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(!Me(e.type,a))return`${t} is a file type we cannot accept.`;if(i>0&&e.size>i)return`${t} is larger than ${B(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)??Ne(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,i]=s(e);return r(()=>{let n=setTimeout(()=>i(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(S,{id:e,label:t,optional:!0,multiple:!0,value:n,onChange:r,accept:je(i),maxSizeMb:s,validate:!1,error:a||void 0})}function Be({items:e}){return e.length===0?null:/* @__PURE__ */ H(p,{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:i,onValuesChange:a,extraFiles:o=[],onSubmit:c,onBusyChange:u,children:d}){let f=t?.categories??[],[p,m]=s(()=>i?.category??We(f,n)),[h,g]=s(i?.subject??``),[_,v]=s(i?.body??``),[y,b]=s(i?.files??[]),[x,S]=s({}),[C,T]=s(``),E=X(),[D,k]=s(``),[A,j]=s([]),M=Re(h.trim(),Ve);r(()=>{a?.({category:p,subject:h,body:_,files:y})},[p,h,_,y,a]),r(()=>{k(M)},[M]),r(()=>{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 P=e=>{b(e),S(n=>({...n,files:Ne([...o,...e],t)??void 0}))},F=e=>{let t=Le(e);t.length>0&&P([...y,...t])};function I(){let e={};h.trim()||(e.subject=`Enter a subject.`),_.trim()||(e.body=`Enter what happened.`);let n=Ne([...o,...y],t);return n&&(e.files=n),S(e),Object.keys(e).length===0}async function L(e){if(e.preventDefault(),T(``),I()){u?.(!0);try{await c({category:p,subject:h.trim(),body:_.trim(),files:y})}catch(e){T(Q(e,`Your ticket did not send. Please try again.`))}finally{u?.(!1)}}}return/* @__PURE__ */ U(`form`,{id:e,onSubmit:L,noValidate:!0,className:`d-flex flex-column gap-3`,children:[C&&/* @__PURE__ */ H(l,{tone:`danger`,children:C}),/* @__PURE__ */ H(O,{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(w,{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:()=>k(h.trim()),error:x.subject}),/* @__PURE__ */ H(Be,{items:A}),/* @__PURE__ */ H(N,{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:P,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 I(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:i,controlRef:a,onAdd:o,onRemove:c}){let[u,d]=s(null);return r(()=>{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&&u&&/* @__PURE__ */ H(`img`,{src:u,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(f,{variant:`outline`,size:`sm`,leftIcon:`refresh-cw`,onClick:o,disabled:n,"aria-describedby":i,children:`Retake`}),/* @__PURE__ */ H(f,{variant:`ghost`,size:`sm`,leftIcon:`x`,onClick:c,disabled:n,children:`Remove screenshot`})]}):/* @__PURE__ */ H(f,{variant:`outline`,size:`sm`,leftIcon:`camera`,onClick:o,disabled:n,"aria-describedby":i,children:`Add a screenshot`})}),/* @__PURE__ */ H(`span`,{id:i,className:`wui-text-sm text-body-secondary`,children:`Only what is on your screen now. You can remove it before sending.`}),t&&/* @__PURE__ */ H(l,{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:a=`Bug report`,appVersion:c,getTicketHref:u,onOpenTicket:d,onCreated:p,className:m,style:h}){let g=X(),{config:_,error:v}=Z(),y=`support-report-${i().replace(/[^a-zA-Z0-9-]/g,``)}`,[b,x]=s(!1),[S,w]=s(!1),[T,D]=s(null),[O,k]=s(!1),[A,j]=s(!1),[M,N]=s(null),[F,I]=s(null),R=P(`end`,t&&n),z=o(null),B=o(!1);r(()=>{!S&&B.current&&(B.current=!1,z.current?.querySelector(`button`)?.focus())},[S]);function ee(){N(null),D(null),k(!1),I(null),x(!0)}async function te(){w(!0),k(!1),await Ze(),await Ze();try{D(await Qe())}catch{D(null),k(!0)}finally{B.current=!0,w(!1)}}let W=()=>{A||(x(!1),D(null),k(!1),N(null),I(null))};async function ne(e){let t=await g.createTicket({...e,pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:c,screenshots:T?[T]:[]});N(t),D(null),p?.(t)}let re=!M&&(!!T||!!F&&(F.subject.trim()!==``||F.body.trim()!==``||F.files.length>0)),G=M&&u?u(M.id):void 0,ie=M?/* @__PURE__ */ U(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[/* @__PURE__ */ H(f,{variant:`secondary`,onClick:W,children:`Close`}),M&&(G||d)?/* @__PURE__ */ H(f,{href:G,onClick:G?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(f,{variant:`secondary`,onClick:W,disabled:A,children:`Cancel`}),/* @__PURE__ */ H(f,{type:`submit`,form:y,loading:A,disabled:!_,children:`Submit`})]}),K=n?/* @__PURE__ */ H(f,{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(C,{name:`bug`,size:22})}):/* @__PURE__ */ H(f,{leftIcon:`bug`,variant:t?`primary`:`outline`,disabled:S,onClick:ee,"aria-haspopup":`dialog`,children:e});return/* @__PURE__ */ U(V,{children:[t&&n?R&&L(/* @__PURE__ */ H(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--secondary`,m].filter(Boolean).join(` `),style:h,children:K}),R):/* @__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:K}),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(E,{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:re&&!A,onClose:W,footer:ie,"data-support-capture":`exclude`,children:M?/* @__PURE__ */ H(l,{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:a,initialValues:F,onValuesChange:I,extraFiles:T?[T]:[],onSubmit:ne,onBusyChange:j,children:/* @__PURE__ */ H($e,{file:T,failed:O,disabled:A||S,hintId:`${y}-screenshot-hint`,controlRef:z,onAdd:te,onRemove:()=>D(null)})}):/* @__PURE__ */ H(l,{tone:v?`danger`:`info`,children:v?Q(v,`We could not load the support settings.`):`Loading the form.`})})]})}function tt({open:e,onClose:t,onCreated:n,config:r,defaultCategory:a,appVersion:o}){let c=X(),l=`support-new-${i().replace(/[^a-zA-Z0-9-]/g,``)}`,[u,d]=s(!1),[p,m]=s(null),h=!!p&&(p.subject.trim()!==``||p.body.trim()!==``||p.files.length>0);async function g(e){n(await c.createTicket({...e,userAgent:typeof navigator>`u`?void 0:navigator.userAgent,appVersion:o}))}return/* @__PURE__ */ H(E,{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(f,{variant:`secondary`,onClick:t,disabled:u,children:`Cancel`}),/* @__PURE__ */ H(f,{type:`submit`,form:l,loading:u,children:`Send ticket`})]}),children:e&&/* @__PURE__ */ H(Ge,{id:l,config:r,defaultCategory:a,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=X(),[n,r]=s(!1),[i,a]=s(!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 c=Number.isFinite(e.sizeBytes)?B(e.sizeBytes):`-`;return/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(m,{leadingIcon:i?`x-circle`:`paperclip`,label:n?/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(A,{size:`sm`,label:`Loading ${e.fileName}`}),` `,e.fileName]}):e.fileName,onClick:o,disabled:n,"aria-busy":n||void 0,title:`${e.fileName}, ${c}`}),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=Te(),r=we();return n?n(e):/* @__PURE__ */ H(`time`,{dateTime:e,className:t,children:z(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(u,{name:r,size:32,tone:n?`neutral`:`primary`}),/* @__PURE__ */ U(p,{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(d,{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:a}){let o=i(),[c,u]=s(``),[d,m]=s(null),[h,g]=s(``);if(e)return/* @__PURE__ */ U(l,{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(``),m(e);try{await a({satisfaction:e,comment:c})}catch(e){g(Q(e,`Your rating did not send. Please try again.`))}finally{m(null)}}return/* @__PURE__ */ H(p,{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(l,{tone:`danger`,children:h}),/* @__PURE__ */ H(N,{id:`${o}-comment`,label:`Anything to add?`,rows:2,maxLength:r,value:c,onChange:e=>u(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(f,{variant:`outline`,leftIcon:`check-circle`,loading:d===`Satisfied`,disabled:d!==null,onClick:()=>_(`Satisfied`),children:`Yes, it is solved`}),/* @__PURE__ */ H(f,{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=i(),[a,o]=s(``),[u,d]=s([]),[p,g]=s(``),[_,v]=s(``),[y,b]=s(!1),x=e=>{let n=Ie(u,e,t);d(n.files),g(n.notice)},S=e=>{let n=u.filter((t,n)=>n!==e);d(n),g(Ne(n,t)??``)},C=e=>{let t=Le(e);t.length>0&&x(t)};async function w(n){n.preventDefault();let r=a.trim();if(!r){v(`Write a message before you send it.`);return}let i=Ne(u,t);if(i)g(i);else{v(``),b(!0);try{await e({body:r,files:u}),o(``),d([]),g(``)}catch(e){v(Q(e,`Your reply did not send. Please try again.`))}finally{b(!1)}}}let T=_||p;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(l,{tone:`danger`,children:T}),/* @__PURE__ */ H(N,{id:`${r}-body`,label:`Your reply`,rows:4,autoGrow:!0,maxLength:t?.bodyMaxLength,value:a,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}),u.length>0&&/* @__PURE__ */ H(h,{label:`Attached files`,children:u.map((e,t)=>/* @__PURE__ */ H(m,{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(c,{iconVariant:`bulk`,icon:`paperclip`,label:`Attach a file`,multiple:t?.maxAttachmentsPerMessage!==1,accept:je(t),onFiles:x}),/* @__PURE__ */ H(f,{type:`submit`,leftIcon:`send`,loading:y,children:`Send reply`})]})]})}function dt({ticketId:e,onBack:t,onChanged:n,onOpenTicket:r}){let{config:i}=Z(),a=we(),o=Te(),{ticket:c,loading:u,error:d,reload:m,reply:h,reopen:_,cancel:v,rate:b}=ke(e),[x,S]=s(!1),[w,T]=s(!1),[E,D]=s(!1),[O,A]=s(``),M=async e=>{let t=await e();return n?.(),t};async function N(){A(``),S(!0);try{await M(_)}catch(e){A(Q(e,`The ticket did not reopen. Please try again.`))}finally{S(!1)}}async function P(){A(``),D(!0);try{await M(v)}catch(e){A(Q(e,`The request was not withdrawn. Please try again.`))}finally{D(!1),T(!1)}}let F=/* @__PURE__ */ H(f,{variant:`ghost`,size:`sm`,leftIcon:`arrow-left`,onClick:t,className:`align-self-start`,children:`Back to tickets`});if(!c)return/* @__PURE__ */ U(`section`,{className:`d-flex flex-column gap-3`,"aria-busy":u||void 0,children:[F,d?/* @__PURE__ */ U(l,{tone:`danger`,children:[Q(d,`We could not load this ticket.`),` `,/* @__PURE__ */ H(f,{variant:`ghost`,size:`sm`,onClick:m,children:`Try again`})]}):/* @__PURE__ */ H(k,{height:160})]});let I=rt(c.status),L=[{key:`status`,label:`Status`,value:c.statusLabel?/* @__PURE__ */ H(j,{label:c.statusLabel,tone:I}):`-`},{key:`category`,label:`Category`,value:c.category||`-`},{key:`ticket`,label:`Ticket`,value:c.number},{key:`opened`,label:`Opened`,value:/* @__PURE__ */ H($,{iso:c.createdDateTimeUtc})},{key:`updated`,label:`Last update`,value:/* @__PURE__ */ H($,{iso:c.updatedDateTimeUtc})}];return/* @__PURE__ */ U(`section`,{className:`d-flex flex-column gap-3`,"aria-labelledby":`support-ticket-${c.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-${c.id}`,className:`h5 mb-0 text-break`,children:c.subject}),c.statusLabel&&/* @__PURE__ */ H(j,{label:c.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:[c.number&&/* @__PURE__ */ U(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ H(C,{variant:`bulk`,name:`receipt-text`,size:16}),c.number]}),c.category&&/* @__PURE__ */ U(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ H(C,{variant:`bulk`,name:`folder-2`,size:16}),c.category]}),/* @__PURE__ */ U(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ H(C,{variant:`bulk`,name:`calendar-1`,size:16}),`Opened `,/* @__PURE__ */ H($,{iso:c.createdDateTimeUtc})]})]}),o===null&&/* @__PURE__ */ U(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:[`Times are shown in `,ee(a),`.`]})]}),O&&/* @__PURE__ */ H(l,{tone:`danger`,children:O}),c.mergedInto&&/* @__PURE__ */ U(l,{tone:`info`,role:`status`,children:[`This ticket was merged into `,c.mergedInto.number,`. The conversation carries on there.`,` `,r&&/* @__PURE__ */ U(f,{variant:`ghost`,size:`sm`,onClick:()=>r(c.mergedInto.id),children:[`Open `,c.mergedInto.number]})]}),c.canReopen&&/* @__PURE__ */ H(l,{tone:`success`,role:`status`,children:`If you still need help, reopen the ticket or send a reply.`}),c.status===`WaitingOnCustomer`&&/* @__PURE__ */ H(l,{tone:`warning`,role:`status`,children:`We need your answer to carry on. Reply below and the ticket goes back to our team.`}),!c.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.`}),c.canReopen&&/* @__PURE__ */ H(f,{variant:`secondary`,leftIcon:`history`,loading:x,onClick:N,className:`align-self-start`,children:`Reopen ticket`}),c.canCancel&&/* @__PURE__ */ H(f,{variant:`secondary`,onClick:()=>T(!0),className:`align-self-start`,children:`Withdraw request`}),/* @__PURE__ */ H(g,{open:w,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:c.satisfaction,comment:c.satisfactionComment,canRate:c.canRate,commentMaxLength:i?.satisfactionCommentMaxLength,onRate:e=>M(()=>b(e))}),/* @__PURE__ */ H(ct,{messages:c.messages??[]}),c.mergedTickets?.length>0&&/* @__PURE__ */ U(`section`,{"aria-labelledby":`support-merged-${c.id}`,className:`d-flex flex-column gap-1`,children:[/* @__PURE__ */ H(`h3`,{id:`support-merged-${c.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:c.mergedTickets.map(e=>/* @__PURE__ */ H(`li`,{children:r?/* @__PURE__ */ U(f,{variant:`ghost`,size:`sm`,onClick:()=>r(e.id),children:[e.number,`: `,e.subject]}):`${e.number}: ${e.subject}`},e.id))})]}),!c.mergedInto&&/* @__PURE__ */ H(ut,{config:i,reopens:c.canReopen,onSend:e=>M(()=>h(e))})]}),/* @__PURE__ */ H(`aside`,{"aria-label":`Ticket details`,className:`col-12 col-lg-4`,children:/* @__PURE__ */ U(p,{padding:`sm`,className:`border`,children:[/* @__PURE__ */ H(`h3`,{className:`h6`,children:`Ticket details`}),/* @__PURE__ */ H(y,{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:u,search:d,onSearchChange:p,pagination:m}){F(`SupportCenter`,`statusFilter`,s,_t);let h=gt.map(({key:e,label:t,countKey:n})=>{let r=u?.[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(l,{tone:`danger`,children:[Q(n,`We could not load your tickets.`),` `,/* @__PURE__ */ H(f,{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(O,{label:`Status`,value:a,onChange:o,options:h}):/* @__PURE__ */ H(M,{tabs:gt.map(({key:e,label:t,countKey:n})=>({key:e,label:t,count:u?.[n]})),value:a,onChange:o,ariaLabel:`Filter tickets by status`,className:`flex-grow-1`}),/* @__PURE__ */ H(D,{value:d,onChange:p,placeholder:`Search tickets`,ariaLabel:`Search tickets`})]}),/* @__PURE__ */ H(v,{columns:[{key:`subject`,label:`Subject`,render:e=>/* @__PURE__ */ U(`div`,{className:`d-flex flex-column`,style:{minWidth:0},children:[/* @__PURE__ */ H(T,{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(j,{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(c,{icon:`eye`,label:`Open ticket ${e.subject}`,href:mt(e.id),onClick:t=>g(t,e.id)}),stickyActions:!0,stackOnMobile:!0,sourceCount:u?.total??0,pagination:m,empty:/* @__PURE__ */ H(x,{variant:`table`,icon:`message-square`,title:`No tickets yet`,text:`When you raise a ticket, it shows here with its status.`}),emptyFiltered:/* @__PURE__ */ H(x,{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:i,defaultStatus:a=`all`,onStatusChange:o,statusFilter:c=`tabs`}){let{config:u,error:d,reload:p}=Z(),[m,h]=s(a),g=i!==void 0,_=g?i:m,v=e=>{g||h(e),o?.(e)},[y,b]=s(``),x=Re(y.trim(),yt),[S,C]=s(bt),w=`${_}|${x}|${S}`,[T,E]=s({key:w,page:1}),D=T.key===w?T.page:1,O=e=>E({key:w,page:e}),k=De({status:_===`all`?void 0:_,search:x||void 0,page:D,pageSize:S}),{counts:A,reload:j}=Oe(),[M,N]=s(()=>e||pt()),[P,F]=s(!1),I=k.totalPages;r(()=>{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(f,{leftIcon:`plus`,onClick:()=>F(!0),disabled:!u,children:`New ticket`})]}),d&&/* @__PURE__ */ U(l,{tone:`warning`,children:[Q(d,`We could not load the support settings.`),` `,/* @__PURE__ */ H(f,{variant:`ghost`,size:`sm`,onClick:p,children:`Try again`})]}),/* @__PURE__ */ H(vt,{tickets:k.tickets,loading:k.loading,error:k.error,onRetry:L,onOpen:R,status:_,onStatusChange:v,statusFilter:c,counts:A,search:y,onSearchChange:b,pagination:z}),u&&/* @__PURE__ */ H(tt,{open:P,onClose:()=>F(!1),config:u,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(A,{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(d,{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(f,{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(d,{tone:`info`,children:`In the queue`})}),/* @__PURE__ */ H(Ct,{position:a??null})]}),e===`WithAgent`&&/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(`div`,{children:/* @__PURE__ */ H(d,{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(d,{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(f,{variant:`outline`,size:`sm`,onClick:()=>l({id:i,number:r}),children:`View ticket`}),/* @__PURE__ */ H(f,{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(p,{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(u,{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(d,{tone:`neutral`,children:`AI`})]}),/* @__PURE__ */ H(`span`,{className:`visually-hidden`,children:`Assistant: `}),/* @__PURE__ */ H(W,{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(u,{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(d,{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(p,{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(l,{tone:`danger`,size:`sm`,children:[/* @__PURE__ */ H(`div`,{children:e.error}),/* @__PURE__ */ U(`div`,{className:`d-flex gap-2 mt-2`,children:[/* @__PURE__ */ H(f,{size:`sm`,variant:`outline`,onClick:()=>t(e.localId),children:`Try again`}),/* @__PURE__ */ H(f,{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(x,{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(u,{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(W,{text:n,resolveLink:c,linkComponent:l})]})]}):r&&/* @__PURE__ */ U(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,children:[/* @__PURE__ */ H(u,{name:`Assistant`,size:32,tone:`primary`}),/* @__PURE__ */ U(`div`,{className:`d-flex align-items-center gap-2 wui-text-sm`,children:[/* @__PURE__ */ H(A,{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:n,open:i,appVersion:a,start:c}){let[l,u]=s(`idle`),[d,f]=s(``),[p,m]=s(null),[h,g]=s([]),[_,v]=s([]),[y,b]=s(``),[x,S]=s(null),[C,w]=s(null),[T,E]=s(``),[D,O]=s(!1),[,k]=s(0),A=o(null),j=o(null),M=o(0),N=t(e=>{let t=j.current;j.current=e.id;let{messages:n,...r}=e;m(r),g(Rt(n??[])),t!==e.id&&v([])},[]);r(()=>zt(x,()=>k(e=>e+1)),[x]),r(()=>zt(C,()=>k(e=>e+1)),[C]);let P=t(()=>{let t=!0,r=()=>{},i=e=>({onSnapshot(t){t.id===e&&(N(t),b(``))},onMessage(t){t.chatId===e&&(g(e=>Lt(e,t.message)),t.message.authorKind===`Assistant`&&b(``))},onState(t){t.chatId===e&&(m(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}),b(``))},onTyping(t){t.chatId===e&&(t.who===`Agent`?S(t.untilDateTimeUtc):t.who===`Assistant`&&w(t.untilDateTimeUtc))},onDelta(t){t.chatId===e&&b(e=>e+t.text)},onError(e){e.code===`chat_not_found`?(m(e=>e&&{...e,state:`Closed`,closeReason:null}),E(Ft)):E(typeof e.message==`string`&&e.message?e.message:`The chat connection had a problem. We are reconnecting.`)}});return u(`loading`),e.start({pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:a,...c}).then(e=>{t&&(N(e),f(``),u(`ready`),r=n.watch(e.id,e.sequence,i(e.id)))}).catch(e=>{t&&(f(Q(e,`We could not start the chat. Please try again.`)),u(`error`))}),()=>{t=!1,r()}},[e,n,N,a,c]);r(()=>{if(!i)return;let e=P();return A.current=()=>{e(),e=P()},()=>{A.current=null,e()}},[i,P]);let F=(t,n)=>e.get(t).then(N).catch(e=>E(Q(e,n)));async function I(t){let n=p.id;try{let r=await e.send(n,{body:t.body,files:t.files,idempotencyKey:t.key});return j.current===n&&(g(e=>{let t=Lt(e,r.message);return r.reply?Lt(t,r.reply):t}),v(e=>e.filter(e=>e.localId!==t.localId)),r.reply&&b(``),!0)}catch(e){return j.current===n?e?.code===`chat_closed`?(v(e=>e.filter(e=>e.localId!==t.localId)),await F(n,Ft),!1):(v(n=>n.map(n=>n.localId===t.localId?{...n,status:`failed`,error:Q(e,`Your message did not send. Please try again.`)}:n)),!1):!1}}return{phase:l,startError:d,chat:p,messages:h,pending:_,assistantText:y,agentTypingUntil:x,assistantTypingUntil:C,notice:T,requesting:D,send:(e,t=[])=>{let n={localId:crypto.randomUUID(),key:crypto.randomUUID(),body:e,files:t,status:`sending`,error:``};return v(e=>[...e,n]),I(n)},retry:e=>{let t=_.find(t=>t.localId===e);if(!t)return;let n={...t,status:`sending`,error:``};v(t=>t.map(t=>t.localId===e?n:t)),I(n)},discard:e=>{v(t=>t.filter(t=>t.localId!==e))},requestAgent:async()=>{let t=p.id;O(!0);try{N(await e.requestAgent(t))}catch(e){let n=`We could not reach the team. Please try again.`;e?.code===`chat_not_with_assistant`?await F(t,n):E(Q(e,n))}finally{O(!1)}},end:async()=>{try{N(await e.close(p.id))}catch(e){E(Q(e,`We could not end the chat. Please try again.`))}},restart:()=>{j.current=null,m(null),g([]),v([]),b(``),E(``),S(null),w(null),u(`loading`),A.current?.()},retryStart:()=>{A.current?.()},notifyTyping:()=>{if(l!==`ready`||p?.state!==`WithAgent`)return;let t=Date.now();t-M.current<Pt||(M.current=t,e.typing(p.id).catch(()=>{}))}}}var Vt={composer:`Your message`,placeholder:`Type your message`},Ht=e=>!!e&&Date.now()<Date.parse(e);function Ut({chatClient:e,connection:n,open:i,onClose:a,appVersion:u,start:d,onOpenTicket:p,resolveLink:m,linkComponent:h,title:_=`Chat with us`,width:v=`440px`}){let{config:y}=Z(),x=Bt({chatClient:e,connection:n,open:i,appVersion:u,start:d}),[S,w]=s(!1),[T,E]=s([]),[D,O]=s(``),k=o(0),j=o(null),M=o(x.notifyTyping);r(()=>{M.current=x.notifyTyping});let N=e=>{let t=Ie(T.map(e=>e.file),e,y);E(t.files.map(e=>T.find(t=>t.file===e)||(k.current+=1,{key:`attachment-${k.current}`,fileName:e.name,contentType:e.type,length:e.size,status:`Ready`,progress:null,error:null,file:e}))),O(t.notice)},P=e=>{E(t=>t.filter(t=>t.key!==e)),O(``)},F=async e=>{let t=T;await x.send(e,t.map(e=>e.file))&&E(e=>e.filter(e=>!t.includes(e)))},I=()=>{E([]),O(``),x.restart()},L=t(()=>M.current(),[]),R=t(e=>{j.current?.removeEventListener(`input`,L),j.current=e,e?.addEventListener(`input`,L)},[L]),z=x.phase===`ready`&&x.chat!==null,B=x.chat?.state,ee=z&&B!==`Closed`,W=Ht(x.assistantTypingUntil)||B===`Assistant`&&x.pending.some(e=>e.status===`sending`),re=Ht(x.agentTypingUntil),G=x.messages.some(e=>e.authorKind===`Customer`)&&!!x.chat?.assistantAvailable;r(()=>{i&&z&&j.current?.focus()},[i,z]);let ie=/* @__PURE__ */ U(`div`,{className:`drawer-header`,children:[/* @__PURE__ */ U(`div`,{className:`drawer-title`,children:[/* @__PURE__ */ H(`span`,{className:`drawer-title-ic`,children:/* @__PURE__ */ H(C,{name:`message-circle`,size:18})}),_]}),/* @__PURE__ */ U(`div`,{className:`d-flex align-items-center gap-1`,children:[ee&&/* @__PURE__ */ H(f,{variant:`ghost`,size:`sm`,onClick:()=>w(!0),children:`End chat`}),/* @__PURE__ */ H(c,{icon:`x`,label:`Close`,onClick:a})]})]}),K;K=x.phase===`error`?/* @__PURE__ */ U(l,{tone:`danger`,children:[x.startError,/* @__PURE__ */ H(`div`,{className:`mt-2`,children:/* @__PURE__ */ H(f,{size:`sm`,variant:`outline`,onClick:x.retryStart,children:`Try again`})})]}):z?/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(Tt,{state:B,closeReason:x.chat.closeReason,agentName:x.chat.agentName,ticketNumber:x.chat.ticketNumber,ticketId:x.chat.ticketId,waitingPosition:x.chat.waitingPosition,canRequestAgent:G,requesting:x.requesting,onRequestAgent:x.requestAgent,onOpenTicket:p,onRestart:I}),/* @__PURE__ */ H(Nt,{messages:x.messages,pending:x.pending,assistantText:x.assistantText,assistantWriting:W,agentName:x.chat.agentName,agentTyping:re,onRetry:x.retry,onDiscard:x.discard,resolveLink:m,linkComponent:h}),x.notice&&/* @__PURE__ */ H(l,{tone:`danger`,size:`sm`,children:x.notice})]}):/* @__PURE__ */ H(`div`,{className:`d-flex justify-content-center py-4`,children:/* @__PURE__ */ H(A,{label:`Starting your chat`})});let q=ee?/* @__PURE__ */ U(`div`,{className:`d-flex flex-column gap-2`,children:[D&&/* @__PURE__ */ H(l,{tone:`danger`,size:`sm`,children:D}),/* @__PURE__ */ H(te,{onSubmit:F,busy:x.pending.length>0||!!x.assistantText,maxLength:y?.bodyMaxLength??4e3,inputRef:R,attachments:T,onAttach:N,onRemoveAttachment:P,accept:je(y),labels:Vt}),B===`Assistant`&&/* @__PURE__ */ H(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:ne.disclaimer})]}):void 0;return/* @__PURE__ */ U(V,{children:[/* @__PURE__ */ H(b,{open:i,onClose:a,sheet:!1,width:v,header:ie,footer:q,ariaLabel:_,onOpened:()=>j.current?.focus(),children:K}),/* @__PURE__ */ H(g,{open:S,title:`End this chat?`,message:B===`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:()=>{w(!1),x.end()},onClose:()=>w(!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(f,{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=P(r);return s?L(/* @__PURE__ */ H(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--primary`,a].filter(Boolean).join(` `),style:o,children:/* @__PURE__ */ H(f,{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(C,{name:i,size:24})})}),s):null}var Jt=e=>typeof e==`string`&&e.trim()!==``;function Yt({className:e}){let{config:t}=Z();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(_,{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(y,{items:n,layout:`list`,columns:1})]})}function Xt({client:e,timeZone:n=R,renderTime:r,children:i}){let s=o(null),c=t((t=!1)=>{let n=s.current;if(t||!n||n.client!==e){let t=e.getConfig(),n={client:e,pending:t};return s.current=n,t.catch(()=>{s.current===n&&(s.current=null)}),t}return n.pending},[e]),l=a(()=>({client:e,loadConfig:c,timeZone:n,renderTime:r}),[e,c,n,r]);return/* @__PURE__ */ H(Se.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,xe as createSseChatConnection,pe as createSupportChatClient,le as createSupportClient,X as useSupportClient,Z as useSupportConfig,ke as useSupportTicket,Oe as useSupportTicketCounts,De as useSupportTickets};
12
+ `)){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:e,baseUrl:t=`/api/support`,retryDelaysMs:n,stallTimeoutMs:r=9e4}){let i=t.replace(/\/+$/,``),a=Array.isArray(n)&&n.length>0?n:[1e3];return{watch(t,n,o){let s=Number.isFinite(n)?n:null,c=!1,l=null,u=null,d=null,f=null,p=!1,m=!1,h=!1,g=null,_=0,v=e=>{Number.isFinite(e)&&(s=Math.max(s??0,e))};function y(e,t){if(!c){m=!0;try{e===`snapshot`?(v(t?.sequence),o.onSnapshot?.(t)):e===`message`?(v(t?.message?.sequence),o.onMessage?.(t)):e===`state`?o.onState?.(t):e===`typing`?o.onTyping?.(t):e===`delta`&&o.onDelta?.(t)}catch{o.onError?.(new K(`handler_failed`,ge))}}}function b(){clearTimeout(u),u=setTimeout(()=>{h=!0,l.abort()},r)}async function x(){l=new AbortController,p=!1,m=!1,h=!1,g=null;let n=0,r=xe(),a=he(({name:e,data:t})=>{c||g||(e===`error`?t?.code===`invalid-response`||t?.code===`stream_ended`?g=`retry`:t?.code===`chat_not_found`?(o.onError?.(t),g=`stop`):(o.onError?.(t),g=`retry`):y(e,t))}),d=e=>{if(c||typeof e!=`string`||e.length<=n)return;let t=e.slice(n);n=e.length,a.push(t),r.push(t),r.last!==null&&(s=Math.max(s??0,r.last)),p=!0,b()},f=`${i}/chats/${encodeURIComponent(t)}/events${s===null?``:`?after=${s}`}`;b();let _;try{_=await e.get(f,{responseType:`text`,headers:{Accept:`text/event-stream`},signal:l.signal,timeout:0,onDownloadProgress:e=>d(_e(e))})}catch(e){if(c)return`stop`;if(h)return`retry`;let t=ye(e);return be(t.status)?`retry`:(o.onError?.({code:t.code,message:t.message}),`stop`)}finally{clearTimeout(u)}return d(_.data),clearTimeout(u),a.end(),g??`retry`}function S(e){return new Promise(t=>{f=t,d=setTimeout(t,e)})}async function C(){let e=0;for(;!c;){let t=await x();if(c||t===`stop`)return;if(p&&(e=0),_=m?0:_+1,_>=10){o.onError?.(new K(`connection_lost`,`We lost the connection to support. Check your internet and try again.`));return}let n=a[Math.min(e,a.length-1)];e+=1,await S(n)}}function w(){c=!0,l?.abort(),clearTimeout(u),clearTimeout(d),f?.()}return C(),w}}}var Ce=3e4,we=e(null);function Te(){let e=n(we);if(!e)throw Error(`Support components and hooks must be used inside <SupportProvider>.`);return e}function X(){return Te().client}function Ee(){return Te().timeZone}function De(){return Te().renderTime??null}function Oe(e,n,i=!0){let[a,c]=s({data:null,loading:i,error:null}),[l,u]=s(0),d=o(e);d.current=e;let f=o(n);r(()=>{let e=f.current!==n;if(f.current=n,!i){c({data:null,loading:!1,error:null});return}let t=!0;return c(t=>({data:e?null:t.data,loading:!0,error:null})),d.current(l>0).then(e=>t&&c({data:e,loading:!1,error:null}),e=>t&&c(t=>({...t,loading:!1,error:e}))),()=>{t=!1}},[n,i,l]);let p=t(()=>u(e=>e+1),[]),m=t(e=>c(t=>({...t,data:typeof e==`function`?e(t.data):e})),[]);return{...a,reload:p,setData:m}}function Z(){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=X(),{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=X(),{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 n=X(),{data:i,loading:a,error:s,reload:c,setData:l}=Oe(()=>n.getTicket(e),e??``,!!e),u=o(0),d=o(e);d.current=e;let f=t(async e=>{u.current+=1;try{let t=await e();return l(t),t}finally{--u.current}},[l]),p=t(async()=>{if(u.current>0)return;let t=e;try{let e=await n.getTicket(t);if(d.current!==t)return;l(t=>t?Date.parse(e.updatedDateTimeUtc)>=Date.parse(t.updatedDateTimeUtc)?e:t:e)}catch{}},[n,e,l]);return r(()=>{if(!e)return;let t=null,n=()=>{t===null&&(t=setInterval(p,Ce))},r=()=>{t!==null&&clearInterval(t),t=null},i=()=>{document.hidden?r():(p(),n())};return document.addEventListener(`visibilitychange`,i),document.hidden||n(),()=>{r(),document.removeEventListener(`visibilitychange`,i)}},[e,p]),{ticket:i,loading:a,error:s,reload:c,reply:t(t=>f(()=>n.reply(e,t)),[f,n,e]),reopen:t(()=>f(()=>n.reopen(e)),[f,n,e]),cancel:t(()=>f(()=>n.cancel(e)),[f,n,e]),rate:t(t=>f(()=>n.rate(e,t)),[f,n,e])}}var Me=`We could not reach support. Check your connection and try again.`;function Q(e,t){if(e instanceof K){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 Fe(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 ${V(i)}.`}return null}var Ie=e=>e===1?`You can attach one file.`:`You can attach up to ${e} files.`;function Le(e){return`${e.name}|${e.size}|${e.lastModified}`}function Re(e,t,n){let r=n?.maxAttachmentsPerMessage??0,i=new Set(e.map(Le)),a=[],o=null;for(let e of t){let t=Le(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?Ie(r):null)??Fe(c,n)??(o?`${o} is already attached.`:``)}}function ze(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})})}var Be=80;function Ve(e,t){let n=Math.min(t,Be),r=(e??``).split(/\r?\n/).find(e=>e.trim()!==``);if(r===void 0)return``;let i=r.replace(/\s+/g,` `).trim();if(i.length<=n)return i;let a=i.slice(0,n+1).lastIndexOf(` `);return(a>0?i.slice(0,a):i.slice(0,n)).replace(/[ ,;:.-]+$/,``)}function He(e,t){let[n,i]=s(e);return r(()=>{let n=setTimeout(()=>i(e),t);return()=>clearTimeout(n)},[e,t]),n}function Ue({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__ */ U(S,{id:e,label:t,optional:!0,multiple:!0,value:n,onChange:r,accept:Ne(i),maxSizeMb:s,validate:!1,error:a||void 0})}function We({items:e}){return e.length===0?null:/* @__PURE__ */ U(p,{variant:`muted`,padding:`sm`,title:`These may already answer your question`,children:/* @__PURE__ */ U(`ul`,{className:`list-unstyled mb-0 d-flex flex-column gap-2`,children:e.map(e=>/* @__PURE__ */ W(`li`,{children:[/* @__PURE__ */ U(`div`,{className:`fw-semibold`,children:e.title}),/* @__PURE__ */ U(`div`,{className:`small text-body-secondary`,children:e.summary})]},e.title))})})}var Ge=500,Ke=3,qe=5;function Je(e,t){return t&&e.includes(t)?t:``}function Ye({id:e,config:t,defaultCategory:n,initialValues:i,onValuesChange:a,extraFiles:o=[],onSubmit:c,onBusyChange:u,children:d}){let f=t?.categories??[],p=t?.subjectMaxLength??1/0,[m,h]=s(()=>i?.category??Je(f,n)),[g,_]=s(i?.body??``),[v,y]=s(()=>i?.subject||Ve(i?.body??``,p)),[b,x]=s(()=>{let e=(i?.subject??``).trim();return e!==``&&e!==Ve(i?.body??``,p)}),[S,C]=s(i?.files??[]),[w,E]=s({}),[D,O]=s(``),A=X(),[j,M]=s(``),[N,F]=s([]),I=He(v.trim(),Ge);r(()=>{a?.({category:m,subject:v,body:g,files:S})},[m,v,g,S,a]),r(()=>{M(I)},[I]),r(()=>{if(j.length<Ke){F([]);return}let e=!0,t=new AbortController;return F([]),A.getSuggestions(j,{signal:t.signal}).then(t=>{e&&F(Array.isArray(t)?t.slice(0,qe):[])},()=>{e&&F([])}),()=>{e=!1,t.abort()}},[A,j]);let L=e=>{C(e),E(n=>({...n,files:Fe([...o,...e],t)??void 0}))},R=e=>{let t=ze(e);t.length>0&&L([...S,...t])},z=e=>{let t=e.target.value;_(t),b||y(Ve(t,p)),w.body&&E(e=>({...e,body:t.trim()?void 0:`Enter what happened.`}))},B=e=>{let t=e.target.value;y(t),x(t.trim()!==``)};function V(){let e={};g.trim()||(e.body=`Enter what happened.`);let n=Fe([...o,...S],t);return n&&(e.files=n),E(e),Object.keys(e).length===0}async function ee(e){if(e.preventDefault(),O(``),V()){u?.(!0);try{await c({category:m,subject:v.trim()||Ve(g,p),body:g.trim(),files:S})}catch(e){O(Q(e,`Your ticket did not send. Please try again.`))}finally{u?.(!1)}}}return/* @__PURE__ */ W(`form`,{id:e,onSubmit:ee,noValidate:!0,className:`d-flex flex-column gap-3`,children:[D&&/* @__PURE__ */ U(l,{tone:`danger`,children:D}),/* @__PURE__ */ U(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:g,onChange:z,onPaste:R,hint:`You can paste an image into the message.`,error:w.body}),/* @__PURE__ */ U(T,{id:`${e}-subject`,label:`Subject`,maxLength:t?.subjectMaxLength,showCount:!0,placeholder:`A short summary`,hint:`Filled in from your message. You can change it.`,value:v,onChange:B,onBlur:()=>M(v.trim())}),/* @__PURE__ */ U(We,{items:N}),/* @__PURE__ */ U(k,{id:`${e}-category`,label:`Category (optional)`,value:m,onChange:h,options:f.map(e=>({value:e,label:e})),placeholder:`Choose a category`,hint:`Not sure? Leave it empty and we will sort it.`,error:w.category}),d,/* @__PURE__ */ U(Ue,{id:`${e}-files`,files:S,onChange:L,config:t,error:w.files})]})}var Xe=`supportCapture`,Ze={zIndex:`var(--wui-z-fixed)`,bottom:0,insetInlineEnd:0},Qe={zIndex:`var(--wui-z-fixed)`},$e={maxWidth:`20rem`},et=e=>e.dataset?.[Xe]===`exclude`||e.matches?.(`.modal-backdrop`)?!1:!(e.matches?.(`.modal`)&&e.querySelector?.(`[data-support-capture="exclude"]`)),tt=()=>new Promise(e=>requestAnimationFrame(()=>e()));async function nt(){let e=await L(document.body,{filter:et,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 rt({file:e,failed:t,disabled:n,hintId:i,controlRef:a,onAdd:o,onRemove:c}){let[u,d]=s(null);return r(()=>{if(!e)return;let t=URL.createObjectURL(e);return d(t),()=>URL.revokeObjectURL(t)},[e]),/* @__PURE__ */ W(`div`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ U(`span`,{className:`wui-text-sm fw-semibold`,children:`Screenshot`}),e&&u&&/* @__PURE__ */ U(`img`,{src:u,alt:`Screenshot of the page you were on`,className:`d-block w-100 border rounded`,style:$e}),/* @__PURE__ */ U(`div`,{ref:a,className:`d-flex flex-wrap gap-2`,children:e?/* @__PURE__ */ W(H,{children:[/* @__PURE__ */ U(f,{variant:`outline`,size:`sm`,leftIcon:`refresh-cw`,onClick:o,disabled:n,"aria-describedby":i,children:`Retake`}),/* @__PURE__ */ U(f,{variant:`ghost`,size:`sm`,leftIcon:`x`,onClick:c,disabled:n,children:`Remove screenshot`})]}):/* @__PURE__ */ U(f,{variant:`outline`,size:`sm`,leftIcon:`camera`,onClick:o,disabled:n,"aria-describedby":i,children:`Add a screenshot`})}),/* @__PURE__ */ U(`span`,{id:i,className:`wui-text-sm text-body-secondary`,children:`Only what is on your screen now. You can remove it before sending.`}),t&&/* @__PURE__ */ U(l,{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 it({label:e=`Report an issue`,floating:t=!1,compact:n=!1,defaultCategory:a=`Bug report`,appVersion:c,getTicketHref:u,onOpenTicket:d,onCreated:p,className:m,style:h}){let g=X(),{config:_,error:v}=Z(),y=`support-report-${i().replace(/[^a-zA-Z0-9-]/g,``)}`,[b,x]=s(!1),[S,C]=s(!1),[T,E]=s(null),[O,k]=s(!1),[A,j]=s(!1),[M,N]=s(null),[P,I]=s(null),L=F(`end`,t&&n),z=o(null),B=o(!1);r(()=>{!S&&B.current&&(B.current=!1,z.current?.querySelector(`button`)?.focus())},[S]);function V(){N(null),E(null),k(!1),I(null),x(!0)}async function ee(){C(!0),k(!1),await tt(),await tt();try{E(await nt())}catch{E(null),k(!0)}finally{B.current=!0,C(!1)}}let te=()=>{A||(x(!1),E(null),k(!1),N(null),I(null))};async function ne(e){let t=await g.createTicket({...e,pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:c,screenshots:T?[T]:[]});N(t),E(null),p?.(t)}let re=!M&&(!!T||!!P&&(P.subject.trim()!==``||P.body.trim()!==``||P.files.length>0)),G=M&&u?u(M.id):void 0,K=M?/* @__PURE__ */ W(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[/* @__PURE__ */ U(f,{variant:`secondary`,onClick:te,children:`Close`}),M&&(G||d)?/* @__PURE__ */ U(f,{href:G,onClick:G?void 0:()=>{x(!1),N(null),d(M)},children:`View ticket`}):null]}):/* @__PURE__ */ W(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[/* @__PURE__ */ U(f,{variant:`secondary`,onClick:te,disabled:A,children:`Cancel`}),/* @__PURE__ */ U(f,{type:`submit`,form:y,loading:A,disabled:!_,children:`Submit`})]}),ie=n?/* @__PURE__ */ U(f,{variant:`secondary`,className:`wui-floating-btn wui-floating-btn--secondary`,disabled:S,onClick:V,"aria-haspopup":`dialog`,"aria-label":e,tooltip:e,tooltipPlacement:`start`,children:/* @__PURE__ */ U(w,{name:`bug`,size:22})}):/* @__PURE__ */ U(f,{leftIcon:`bug`,variant:t?`primary`:`outline`,disabled:S,onClick:V,"aria-haspopup":`dialog`,children:e});return/* @__PURE__ */ W(H,{children:[t&&n?L&&R(/* @__PURE__ */ U(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--secondary`,m].filter(Boolean).join(` `),style:h,children:ie}),L):/* @__PURE__ */ U(`span`,{"data-support-capture":`exclude`,className:[t?`position-fixed m-3`:`d-inline-block`,m].filter(Boolean).join(` `),style:t?{...Ze,...h}:h,children:ie}),S&&/* @__PURE__ */ W(`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:Qe,children:[/* @__PURE__ */ U(`span`,{className:`spinner-border spinner-border-sm`,"aria-hidden":`true`}),`Taking a screenshot`]}),/* @__PURE__ */ U(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:re&&!A,onClose:te,footer:K,"data-support-capture":`exclude`,children:M?/* @__PURE__ */ U(l,{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__ */ U(Ye,{id:y,config:_,defaultCategory:a,initialValues:P,onValuesChange:I,extraFiles:T?[T]:[],onSubmit:ne,onBusyChange:j,children:/* @__PURE__ */ U(rt,{file:T,failed:O,disabled:A||S,hintId:`${y}-screenshot-hint`,controlRef:z,onAdd:ee,onRemove:()=>E(null)})}):/* @__PURE__ */ U(l,{tone:v?`danger`:`info`,children:v?Q(v,`We could not load the support settings.`):`Loading the form.`})})]})}function at({open:e,onClose:t,onCreated:n,config:r,defaultCategory:a,appVersion:o}){let c=X(),l=`support-new-${i().replace(/[^a-zA-Z0-9-]/g,``)}`,[u,d]=s(!1),[p,m]=s(null),h=!!p&&(p.subject.trim()!==``||p.body.trim()!==``||p.files.length>0);async function g(e){n(await c.createTicket({...e,userAgent:typeof navigator>`u`?void 0:navigator.userAgent,appVersion:o}))}return/* @__PURE__ */ U(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__ */ W(`div`,{className:`d-flex justify-content-end gap-2 w-100`,children:[/* @__PURE__ */ U(f,{variant:`secondary`,onClick:t,disabled:u,children:`Cancel`}),/* @__PURE__ */ U(f,{type:`submit`,form:l,loading:u,children:`Send ticket`})]}),children:e&&/* @__PURE__ */ U(Ye,{id:l,config:r,defaultCategory:a,onSubmit:g,onBusyChange:d,onValuesChange:m})})}var ot={Open:`info`,InProgress:`info`,WaitingOnCustomer:`warning`,Resolved:`success`,Closed:`success`,Cancelled:`neutral`};function st(e){return ot[e]??`neutral`}var ct=6e4,lt=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`,`application/pdf`];function ut({attachment:e}){let t=X(),[n,r]=s(!1),[i,a]=s(!1);async function o(){r(!0),a(!1);let n=lt.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),ct),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 c=Number.isFinite(e.sizeBytes)?V(e.sizeBytes):`-`;return/* @__PURE__ */ W(H,{children:[/* @__PURE__ */ U(m,{leadingIcon:i?`x-circle`:`paperclip`,label:n?/* @__PURE__ */ W(H,{children:[/* @__PURE__ */ U(j,{size:`sm`,label:`Loading ${e.fileName}`}),` `,e.fileName]}):e.fileName,onClick:o,disabled:n,"aria-busy":n||void 0,title:`${e.fileName}, ${c}`}),i&&/* @__PURE__ */ U(`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=De(),r=Ee();return n?n(e):/* @__PURE__ */ U(`time`,{dateTime:e,className:t,children:B(e,{timeZone:r})})}var dt={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`};function ft({messages:e}){return/* @__PURE__ */ U(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:e.map(e=>{let t=/* @__PURE__ */ U($,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return/* @__PURE__ */ W(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[/* @__PURE__ */ U(`span`,{className:`d-block`,children:e.body}),t]},e.id);let n=e.authorKind===`Customer`,r=e.authorName||(n?`You`:`Support team`);return/* @__PURE__ */ W(`li`,{className:`d-flex align-items-start gap-2${n?` flex-row-reverse`:``}`,"data-author":n?`customer`:`agent`,children:[/* @__PURE__ */ U(u,{name:r,size:32,tone:n?`neutral`:`primary`}),/* @__PURE__ */ W(p,{className:`flex-grow-1 border`,padding:`sm`,variant:n?`default`:`accent`,style:{minWidth:0},children:[/* @__PURE__ */ W(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2 mb-2`,children:[/* @__PURE__ */ W(`span`,{className:`d-inline-flex flex-wrap align-items-center gap-2 fw-semibold wui-text-sm text-break`,children:[r,!n&&/* @__PURE__ */ U(d,{tone:`primary`,children:`Support`})]}),t]}),/* @__PURE__ */ U(`div`,{className:`wui-text-sm`,style:dt,children:e.body}),e.attachments?.length>0&&/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.attachments.map(e=>/* @__PURE__ */ U(ut,{attachment:e},e.id))})]})]},e.id)})})}function pt({satisfaction:e,comment:t,canRate:n=!1,commentMaxLength:r,onRate:a}){let o=i(),[c,u]=s(``),[d,m]=s(null),[h,g]=s(``);if(e)return/* @__PURE__ */ W(l,{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__ */ W(`span`,{className:`d-block mt-1`,children:[`Your comment: `,t]}):null]});if(!n)return null;async function _(e){g(``),m(e);try{await a({satisfaction:e,comment:c})}catch(e){g(Q(e,`Your rating did not send. Please try again.`))}finally{m(null)}}return/* @__PURE__ */ U(p,{padding:`sm`,className:`border`,title:`Did this solve your problem?`,children:/* @__PURE__ */ W(`div`,{className:`d-flex flex-column gap-2`,children:[h&&/* @__PURE__ */ U(l,{tone:`danger`,children:h}),/* @__PURE__ */ U(P,{id:`${o}-comment`,label:`Anything to add?`,rows:2,maxLength:r,value:c,onChange:e=>u(e.target.value),hint:`Optional. Your comment goes to the support team.`}),/* @__PURE__ */ W(`div`,{className:`d-flex flex-wrap gap-2`,children:[/* @__PURE__ */ U(f,{variant:`outline`,leftIcon:`check-circle`,loading:d===`Satisfied`,disabled:d!==null,onClick:()=>_(`Satisfied`),children:`Yes, it is solved`}),/* @__PURE__ */ U(f,{variant:`outline`,leftIcon:`x-circle`,loading:d===`Unsatisfied`,disabled:d!==null,onClick:()=>_(`Unsatisfied`),children:`No, it is not`})]})]})})}function mt({onSend:e,config:t,reopens:n=!1}){let r=i(),[a,o]=s(``),[u,d]=s([]),[p,g]=s(``),[_,v]=s(``),[y,b]=s(!1),x=e=>{let n=Re(u,e,t);d(n.files),g(n.notice)},S=e=>{let n=u.filter((t,n)=>n!==e);d(n),g(Fe(n,t)??``)},C=e=>{let t=ze(e);t.length>0&&x(t)};async function w(n){n.preventDefault();let r=a.trim();if(!r){v(`Write a message before you send it.`);return}let i=Fe(u,t);if(i)g(i);else{v(``),b(!0);try{await e({body:r,files:u}),o(``),d([]),g(``)}catch(e){v(Q(e,`Your reply did not send. Please try again.`))}finally{b(!1)}}}let T=_||p;return/* @__PURE__ */ W(`form`,{onSubmit:w,noValidate:!0,className:`d-flex flex-column gap-2 flex-grow-1 min-w-0`,"aria-label":`Reply to this ticket`,children:[T&&/* @__PURE__ */ U(l,{tone:`danger`,children:T}),/* @__PURE__ */ U(P,{id:`${r}-body`,label:`Your reply`,rows:2,autoGrow:!0,maxLength:t?.bodyMaxLength,value:a,onChange:e=>{o(e.target.value),v(``)},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}),u.length>0&&/* @__PURE__ */ U(h,{label:`Attached files`,children:u.map((e,t)=>/* @__PURE__ */ U(m,{leadingIcon:`paperclip`,label:e.name,removeLabel:`Remove ${e.name}`,onRemove:()=>S(t)},Le(e)))}),/* @__PURE__ */ W(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[/* @__PURE__ */ U(c,{iconVariant:`bulk`,icon:`paperclip`,label:`Attach a file`,multiple:t?.maxAttachmentsPerMessage!==1,accept:Ne(t),onFiles:x}),/* @__PURE__ */ U(f,{type:`submit`,leftIcon:`send`,loading:y,children:`Send reply`})]})]})}function ht({ticketId:e,onBack:t,onChanged:n,onOpenTicket:r}){let{config:i}=Z(),a=Ee(),o=De(),{ticket:c,loading:u,error:d,reload:m,reply:h,reopen:_,cancel:v,rate:b}=je(e),[x,S]=s(!1),[T,E]=s(!1),[D,O]=s(!1),[k,j]=s(``),N=async e=>{let t=await e();return n?.(),t};async function P(){j(``),S(!0);try{await N(_)}catch(e){j(Q(e,`The ticket did not reopen. Please try again.`))}finally{S(!1)}}async function F(){j(``),O(!0);try{await N(v)}catch(e){j(Q(e,`The request was not withdrawn. Please try again.`))}finally{O(!1),E(!1)}}let I=/* @__PURE__ */ U(f,{variant:`ghost`,size:`sm`,leftIcon:`arrow-left`,onClick:t,className:`align-self-start`,children:`Back to tickets`});if(!c)return/* @__PURE__ */ W(`section`,{className:`d-flex flex-column gap-3`,"aria-busy":u||void 0,children:[I,d?/* @__PURE__ */ W(l,{tone:`danger`,children:[Q(d,`We could not load this ticket.`),` `,/* @__PURE__ */ U(f,{variant:`ghost`,size:`sm`,onClick:m,children:`Try again`})]}):/* @__PURE__ */ U(A,{height:160})]});let L=st(c.status),R=[{key:`status`,label:`Status`,value:c.statusLabel?/* @__PURE__ */ U(M,{label:c.statusLabel,tone:L}):`-`},{key:`category`,label:`Category`,value:c.category||`-`},{key:`ticket`,label:`Ticket`,value:c.number},{key:`opened`,label:`Opened`,value:/* @__PURE__ */ U($,{iso:c.createdDateTimeUtc})},{key:`updated`,label:`Last update`,value:/* @__PURE__ */ U($,{iso:c.updatedDateTimeUtc})}];return/* @__PURE__ */ W(`section`,{className:`d-flex flex-column gap-3`,"aria-labelledby":`support-ticket-${c.id}`,children:[I,/* @__PURE__ */ W(`div`,{className:`row g-3`,children:[/* @__PURE__ */ W(`div`,{className:`col-12 col-lg-8 d-flex flex-column gap-3`,children:[/* @__PURE__ */ W(`header`,{className:`d-flex flex-column gap-2`,children:[/* @__PURE__ */ W(`div`,{className:`d-flex flex-wrap align-items-center gap-2`,children:[/* @__PURE__ */ U(`h2`,{id:`support-ticket-${c.id}`,className:`h5 mb-0 text-break`,children:c.subject}),c.statusLabel&&/* @__PURE__ */ U(M,{label:c.statusLabel,tone:L})]}),/* @__PURE__ */ W(`ul`,{className:`list-unstyled d-flex flex-wrap gap-3 mb-0 wui-text-sm text-body-secondary`,"aria-label":`Ticket summary`,children:[c.number&&/* @__PURE__ */ W(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ U(w,{variant:`bulk`,name:`receipt-text`,size:16}),c.number]}),c.category&&/* @__PURE__ */ W(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ U(w,{variant:`bulk`,name:`folder-2`,size:16}),c.category]}),/* @__PURE__ */ W(`li`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ U(w,{variant:`bulk`,name:`calendar-1`,size:16}),`Opened `,/* @__PURE__ */ U($,{iso:c.createdDateTimeUtc})]})]}),o===null&&/* @__PURE__ */ W(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:[`Times are shown in `,ee(a),`.`]})]}),k&&/* @__PURE__ */ U(l,{tone:`danger`,children:k}),c.mergedInto&&/* @__PURE__ */ W(l,{tone:`info`,role:`status`,children:[`This ticket was merged into `,c.mergedInto.number,`. The conversation carries on there.`,` `,r&&/* @__PURE__ */ W(f,{variant:`ghost`,size:`sm`,onClick:()=>r(c.mergedInto.id),children:[`Open `,c.mergedInto.number]})]}),c.canReopen&&/* @__PURE__ */ U(l,{tone:`success`,role:`status`,children:`If you still need help, reopen the ticket or send a reply.`}),c.status===`WaitingOnCustomer`&&/* @__PURE__ */ U(l,{tone:`warning`,role:`status`,children:`We need your answer to carry on. Reply below and the ticket goes back to our team.`}),!c.canReopen&&/* @__PURE__ */ U(`p`,{className:`wui-text-sm text-body-secondary mb-0`,children:`Our team marks this resolved once your question is answered. Replying reopens it.`}),c.canReopen&&/* @__PURE__ */ U(f,{variant:`secondary`,leftIcon:`history`,loading:x,onClick:P,className:`align-self-start`,children:`Reopen ticket`}),c.canCancel&&/* @__PURE__ */ U(f,{variant:`secondary`,onClick:()=>E(!0),className:`align-self-start`,children:`Withdraw request`}),/* @__PURE__ */ U(g,{open:T,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`,cancelLabel:`Keep request`,danger:!0,loading:D,onConfirm:F,onClose:()=>E(!1)}),/* @__PURE__ */ U(pt,{satisfaction:c.satisfaction,comment:c.satisfactionComment,canRate:c.canRate,commentMaxLength:i?.satisfactionCommentMaxLength,onRate:e=>N(()=>b(e))}),/* @__PURE__ */ U(ft,{messages:c.messages??[]}),c.mergedTickets?.length>0&&/* @__PURE__ */ W(`section`,{"aria-labelledby":`support-merged-${c.id}`,className:`d-flex flex-column gap-1`,children:[/* @__PURE__ */ U(`h3`,{id:`support-merged-${c.id}`,className:`h6 mb-0`,children:`Merged into this ticket`}),/* @__PURE__ */ U(`ul`,{className:`list-unstyled d-flex flex-column gap-1 mb-0 wui-text-sm`,children:c.mergedTickets.map(e=>/* @__PURE__ */ U(`li`,{children:r?/* @__PURE__ */ W(f,{variant:`ghost`,size:`sm`,onClick:()=>r(e.id),children:[e.number,`: `,e.subject]}):`${e.number}: ${e.subject}`},e.id))})]}),!c.mergedInto&&/* @__PURE__ */ U(C,{sticky:!0,align:`start`,children:/* @__PURE__ */ U(mt,{config:i,reopens:c.canReopen,onSend:e=>N(()=>h(e))})})]}),/* @__PURE__ */ U(`aside`,{"aria-label":`Ticket details`,className:`col-12 col-lg-4`,children:/* @__PURE__ */ W(p,{padding:`sm`,className:`border`,children:[/* @__PURE__ */ U(`h3`,{className:`h6`,children:`Ticket details`}),/* @__PURE__ */ U(y,{columns:1,items:R})]})})]})]})}var gt=`ticket`;function _t(){return typeof window>`u`?null:new URLSearchParams(window.location.search).get(gt)}function vt(e){if(typeof window>`u`)return e?`?${gt}=${encodeURIComponent(e)}`:`?`;let t=new URL(window.location.href);return e?t.searchParams.set(gt,e):t.searchParams.delete(gt),`${t.pathname}${t.search}${t.hash}`}function yt(e){if(typeof window>`u`)return;let t=vt(e);t!==`${window.location.pathname}${window.location.search}${window.location.hash}`&&window.history.replaceState(window.history.state,``,t)}var bt=[{key:`all`,label:`All`,countKey:`total`},{key:`Open`,label:`Open`,countKey:`open`},{key:`NeedsReply`,label:`Needs your reply`,countKey:`needsReply`},{key:`Resolved`,label:`Resolved`,countKey:`resolved`},{key:`Withdrawn`,label:`Withdrawn`,countKey:`withdrawn`}],xt=[`tabs`,`select`,`none`];function St({tickets:e,loading:t,error:n,onRetry:r,onOpen:i,status:a,onStatusChange:o,statusFilter:s=`tabs`,counts:u,search:d,onSearchChange:p,pagination:m}){I(`SupportCenter`,`statusFilter`,s,xt);let h=bt.map(({key:e,label:t,countKey:n})=>{let r=u?.[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__ */ W(`div`,{className:`d-flex flex-column gap-3`,children:[n&&/* @__PURE__ */ W(l,{tone:`danger`,children:[Q(n,`We could not load your tickets.`),` `,/* @__PURE__ */ U(f,{variant:`ghost`,size:`sm`,onClick:r,children:`Try again`})]}),/* @__PURE__ */ W(`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__ */ U(k,{label:`Status`,value:a,onChange:o,options:h}):/* @__PURE__ */ U(N,{tabs:bt.map(({key:e,label:t,countKey:n})=>({key:e,label:t,count:u?.[n]})),value:a,onChange:o,ariaLabel:`Filter tickets by status`,className:`flex-grow-1`}),/* @__PURE__ */ U(O,{value:d,onChange:p,placeholder:`Search tickets`,ariaLabel:`Search tickets`})]}),/* @__PURE__ */ U(v,{columns:[{key:`subject`,label:`Subject`,render:e=>/* @__PURE__ */ W(`div`,{className:`d-flex flex-column`,style:{minWidth:0},children:[/* @__PURE__ */ U(E,{href:vt(e.id),animation:`none`,className:`fw-semibold text-break`,onClick:t=>g(t,e.id),children:e.subject}),/* @__PURE__ */ W(`span`,{className:`wui-text-xs text-body-secondary`,children:[e.number,`, `,e.category]})]})},{key:`status`,label:`Status`,render:e=>e.statusLabel?/* @__PURE__ */ U(M,{label:e.statusLabel,tone:st(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__ */ U($,{iso:e.updatedDateTimeUtc})}],rows:e,loading:t,skeletonRows:4,ariaLabel:`Support tickets`,rowActionsLabel:`Actions`,rowActions:e=>/* @__PURE__ */ U(c,{icon:`eye`,label:`Open ticket ${e.subject}`,href:vt(e.id),onClick:t=>g(t,e.id)}),stickyActions:!0,stackOnMobile:!0,sourceCount:u?.total??0,pagination:m,empty:/* @__PURE__ */ U(x,{variant:`table`,icon:`message-square`,title:`No tickets yet`,text:`When you raise a ticket, it shows here with its status.`}),emptyFiltered:/* @__PURE__ */ U(x,{variant:`table`,icon:`search`,title:`No tickets match`,text:`Try another search or status.`})})]})}var Ct=300,wt=10;function Tt({initialTicketId:e,defaultCategory:t,appVersion:n,status:i,defaultStatus:a=`all`,onStatusChange:o,statusFilter:c=`tabs`}){let{config:u,error:d,reload:p}=Z(),[m,h]=s(a),g=i!==void 0,_=g?i:m,v=e=>{g||h(e),o?.(e)},[y,b]=s(``),x=He(y.trim(),Ct),[S,C]=s(wt),w=`${_}|${x}|${S}`,[T,E]=s({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]=s(()=>e||_t()),[P,F]=s(!1),I=k.totalPages;r(()=>{I>0&&D>I&&E({key:w,page:I})},[I,D,w]);let L=()=>{k.reload(),j()},R=e=>{N(e),yt(e)};if(M)return/* @__PURE__ */ U(ht,{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__ */ W(`section`,{className:`d-flex flex-column gap-3 min-w-0`,"aria-labelledby":`support-center-title`,children:[/* @__PURE__ */ W(`div`,{className:`d-flex flex-wrap align-items-center justify-content-between gap-2`,children:[/* @__PURE__ */ U(`h2`,{id:`support-center-title`,className:`h5 mb-0`,children:`Your tickets`}),/* @__PURE__ */ U(f,{leftIcon:`plus`,onClick:()=>F(!0),disabled:!u,children:`New ticket`})]}),d&&/* @__PURE__ */ W(l,{tone:`warning`,children:[Q(d,`We could not load the support settings.`),` `,/* @__PURE__ */ U(f,{variant:`ghost`,size:`sm`,onClick:p,children:`Try again`})]}),/* @__PURE__ */ U(St,{tickets:k.tickets,loading:k.loading,error:k.error,onRetry:L,onOpen:R,status:_,onStatusChange:v,statusFilter:c,counts:A,search:y,onSearchChange:b,pagination:z}),u&&/* @__PURE__ */ U(at,{open:P,onClose:()=>F(!1),config:u,defaultCategory:t,appVersion:n,onCreated:e=>{F(!1),L(),R(e.id)}})]})}function Et(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 Dt({position:e}){return/* @__PURE__ */ W(`div`,{className:`d-flex flex-column gap-1`,children:[/* @__PURE__ */ W(`div`,{className:`d-flex align-items-center gap-2`,children:[/* @__PURE__ */ U(j,{size:`sm`,label:`Waiting for a person`}),/* @__PURE__ */ U(`span`,{className:`wui-text-sm`,children:`Waiting for a person to join.`})]}),typeof e==`number`&&/* @__PURE__ */ U(`span`,{className:`wui-text-sm text-body-secondary`,children:Et(e)}),/* @__PURE__ */ U(`span`,{className:`wui-text-sm text-body-secondary`,children:`If no one is free, we will reply here and by email.`})]})}var Ot={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 kt({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__ */ W(`div`,{role:`status`,className:`d-flex flex-column gap-2 pb-3 mb-3 border-bottom`,children:[e===`Assistant`&&/* @__PURE__ */ W(H,{children:[/* @__PURE__ */ U(`div`,{children:/* @__PURE__ */ U(d,{tone:`neutral`,children:`AI assistant`})}),/* @__PURE__ */ U(`p`,{className:`wui-text-sm mb-0`,children:`You are chatting with our AI assistant.`}),o&&/* @__PURE__ */ U(`div`,{children:/* @__PURE__ */ U(f,{variant:`outline`,size:`sm`,leftIcon:`user`,loading:s,onClick:c,children:`Talk to a person`})})]}),e===`WaitingForAgent`&&/* @__PURE__ */ W(H,{children:[/* @__PURE__ */ U(`div`,{children:/* @__PURE__ */ U(d,{tone:`info`,children:`In the queue`})}),/* @__PURE__ */ U(Dt,{position:a??null})]}),e===`WithAgent`&&/* @__PURE__ */ W(H,{children:[/* @__PURE__ */ U(`div`,{children:/* @__PURE__ */ U(d,{tone:`success`,children:`Live agent`})}),/* @__PURE__ */ U(`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__ */ W(H,{children:[/* @__PURE__ */ U(`div`,{children:/* @__PURE__ */ U(d,{tone:`neutral`,children:`Chat ended`})}),/* @__PURE__ */ U(`p`,{className:`wui-text-sm mb-0`,children:Ot[t]??`This chat has ended.`}),r&&/* @__PURE__ */ U(`p`,{className:`wui-text-sm mb-0`,children:`Your ticket number is ${r}.`}),/* @__PURE__ */ W(`div`,{className:`d-flex flex-wrap gap-2`,children:[l&&i&&/* @__PURE__ */ U(f,{variant:`outline`,size:`sm`,onClick:()=>l({id:i,number:r}),children:`View ticket`}),/* @__PURE__ */ U(f,{size:`sm`,leftIcon:`plus`,onClick:u,children:`Start a new chat`})]})]})]})}var At={whiteSpace:`pre-wrap`,overflowWrap:`anywhere`},jt={...At,maxWidth:`85%`};function Mt(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 Nt(e){if(!e?.parentElement)return;let t=()=>{let t=Mt(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 Pt({attachments:e}){return e?.length?/* @__PURE__ */ U(`div`,{className:`d-flex flex-wrap gap-2 mt-2`,children:e.map(e=>/* @__PURE__ */ U(ut,{attachment:e},e.id))}):null}function Ft({message:e,resolveLink:t,linkComponent:n}){let r=/* @__PURE__ */ U($,{iso:e.createdDateTimeUtc,className:`wui-text-xs text-body-secondary text-nowrap`});if(e.authorKind===`System`)return/* @__PURE__ */ W(`li`,{className:`text-center wui-text-xs text-body-secondary`,"data-author":`system`,children:[/* @__PURE__ */ U(`span`,{className:`d-block`,children:e.body}),r]});if(e.authorKind===`Customer`)return/* @__PURE__ */ U(`li`,{className:`d-flex justify-content-end`,"data-author":`customer`,children:/* @__PURE__ */ W(p,{padding:`sm`,variant:`muted`,style:jt,children:[/* @__PURE__ */ U(`span`,{className:`visually-hidden`,children:`You: `}),/* @__PURE__ */ U(`div`,{className:`wui-text-sm`,style:At,children:e.body}),/* @__PURE__ */ U(Pt,{attachments:e.attachments}),/* @__PURE__ */ U(`div`,{className:`mt-1`,children:r})]})});if(e.authorKind===`Assistant`)return/* @__PURE__ */ W(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,children:[/* @__PURE__ */ U(u,{name:`Assistant`,size:32,tone:`primary`}),/* @__PURE__ */ W(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[/* @__PURE__ */ W(`div`,{className:`d-flex flex-wrap align-items-center gap-2 mb-1`,children:[/* @__PURE__ */ U(`span`,{className:`fw-semibold`,children:`Assistant`}),/* @__PURE__ */ U(d,{tone:`neutral`,children:`AI`})]}),/* @__PURE__ */ U(`span`,{className:`visually-hidden`,children:`Assistant: `}),/* @__PURE__ */ U(ne,{text:e.body,resolveLink:t,linkComponent:n}),/* @__PURE__ */ U(Pt,{attachments:e.attachments}),/* @__PURE__ */ U(`div`,{className:`mt-1`,children:r})]})]});let i=e.authorName||`Support team`;return/* @__PURE__ */ W(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`agent`,children:[/* @__PURE__ */ U(u,{name:i,size:32,tone:`primary`}),/* @__PURE__ */ W(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[/* @__PURE__ */ W(`div`,{className:`d-flex flex-wrap align-items-center gap-2 mb-1`,children:[/* @__PURE__ */ U(`span`,{className:`fw-semibold`,children:i}),/* @__PURE__ */ U(d,{tone:`primary`,children:`Support`})]}),/* @__PURE__ */ U(`div`,{style:At,children:e.body}),/* @__PURE__ */ U(Pt,{attachments:e.attachments}),/* @__PURE__ */ U(`div`,{className:`mt-1`,children:r})]})]})}function It({item:e,onRetry:t,onDiscard:n}){return/* @__PURE__ */ W(`li`,{className:`d-flex flex-column align-items-end gap-1`,"data-author":`customer`,children:[/* @__PURE__ */ U(p,{padding:`sm`,variant:`muted`,style:jt,children:/* @__PURE__ */ U(`div`,{className:`wui-text-sm`,style:At,children:e.body})}),e.status===`sending`&&/* @__PURE__ */ U(`span`,{className:`wui-text-xs text-body-secondary`,children:`Sending`}),e.status===`failed`&&/* @__PURE__ */ W(l,{tone:`danger`,size:`sm`,children:[/* @__PURE__ */ U(`div`,{children:e.error}),/* @__PURE__ */ W(`div`,{className:`d-flex gap-2 mt-2`,children:[/* @__PURE__ */ U(f,{size:`sm`,variant:`outline`,onClick:()=>t(e.localId),children:`Try again`}),/* @__PURE__ */ U(f,{size:`sm`,variant:`ghost`,onClick:()=>n(e.localId),children:`Discard`})]})]})]})}function Lt({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__ */ U(x,{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__ */ W(H,{children:[/* @__PURE__ */ W(`ol`,{className:`list-unstyled d-flex flex-column gap-3 mb-0`,"aria-label":`Conversation`,children:[e.map(e=>/* @__PURE__ */ U(Ft,{message:e,resolveLink:c,linkComponent:l},e.id)),t.map(e=>/* @__PURE__ */ U(It,{item:e,onRetry:o,onDiscard:s},e.localId)),n?/* @__PURE__ */ W(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,"aria-busy":`true`,children:[/* @__PURE__ */ U(u,{name:`Assistant`,size:32,tone:`primary`}),/* @__PURE__ */ W(`div`,{className:`flex-grow-1 wui-text-sm min-w-0`,children:[/* @__PURE__ */ U(`span`,{className:`fw-semibold`,children:`Assistant`}),/* @__PURE__ */ U(ne,{text:n,resolveLink:c,linkComponent:l})]})]}):r&&/* @__PURE__ */ W(`li`,{className:`d-flex align-items-start gap-2`,"data-author":`assistant`,children:[/* @__PURE__ */ U(u,{name:`Assistant`,size:32,tone:`primary`}),/* @__PURE__ */ W(`div`,{className:`d-flex align-items-center gap-2 wui-text-sm`,children:[/* @__PURE__ */ U(j,{size:`sm`,label:`The assistant is writing`}),/* @__PURE__ */ U(`span`,{children:`The assistant is writing`})]})]}),a&&/* @__PURE__ */ U(`li`,{className:`wui-text-sm text-body-secondary`,"aria-live":`polite`,children:`${i||`Our team`} is typing`})]}),/* @__PURE__ */ U(`div`,{ref:Nt})]})}var Rt=3e3,zt=`This chat is no longer available.`,Bt=(e,t)=>e.sequence-t.sequence;function Vt(e,t){return e.some(e=>e.id===t.id)?e:[...e,t].sort(Bt)}function Ht(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.has(n.id)||t.set(n.id,n);return[...t.values()].sort(Bt)}function Ut(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 Wt({chatClient:e,connection:n,open:i,appVersion:a,start:c}){let[l,u]=s(`idle`),[d,f]=s(``),[p,m]=s(null),[h,g]=s([]),[_,v]=s([]),[y,b]=s(``),[x,S]=s(null),[C,w]=s(null),[T,E]=s(``),[D,O]=s(!1),[,k]=s(0),A=o(null),j=o(null),M=o(0),N=t(e=>{let t=j.current;j.current=e.id;let{messages:n,...r}=e;m(r),g(Ht(n??[])),t!==e.id&&v([])},[]);r(()=>Ut(x,()=>k(e=>e+1)),[x]),r(()=>Ut(C,()=>k(e=>e+1)),[C]);let P=t(()=>{let t=!0,r=()=>{},i=e=>({onSnapshot(t){t.id===e&&(N(t),b(``))},onMessage(t){t.chatId===e&&(g(e=>Vt(e,t.message)),t.message.authorKind===`Assistant`&&b(``))},onState(t){t.chatId===e&&(m(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}),b(``))},onTyping(t){t.chatId===e&&(t.who===`Agent`?S(t.untilDateTimeUtc):t.who===`Assistant`&&w(t.untilDateTimeUtc))},onDelta(t){t.chatId===e&&b(e=>e+t.text)},onError(e){e.code===`chat_not_found`?(m(e=>e&&{...e,state:`Closed`,closeReason:null}),E(zt)):E(typeof e.message==`string`&&e.message?e.message:`The chat connection had a problem. We are reconnecting.`)}});return u(`loading`),e.start({pageUrl:window.location.href,userAgent:navigator.userAgent,appVersion:a,...c}).then(e=>{t&&(N(e),f(``),u(`ready`),r=n.watch(e.id,e.sequence,i(e.id)))}).catch(e=>{t&&(f(Q(e,`We could not start the chat. Please try again.`)),u(`error`))}),()=>{t=!1,r()}},[e,n,N,a,c]);r(()=>{if(!i)return;let e=P();return A.current=()=>{e(),e=P()},()=>{A.current=null,e()}},[i,P]);let F=(t,n)=>e.get(t).then(N).catch(e=>E(Q(e,n)));async function I(t){let n=p.id;try{let r=await e.send(n,{body:t.body,files:t.files,idempotencyKey:t.key});return j.current===n&&(g(e=>{let t=Vt(e,r.message);return r.reply?Vt(t,r.reply):t}),v(e=>e.filter(e=>e.localId!==t.localId)),r.reply&&b(``),!0)}catch(e){return j.current===n?e?.code===`chat_closed`?(v(e=>e.filter(e=>e.localId!==t.localId)),await F(n,zt),!1):(v(n=>n.map(n=>n.localId===t.localId?{...n,status:`failed`,error:Q(e,`Your message did not send. Please try again.`)}:n)),!1):!1}}return{phase:l,startError:d,chat:p,messages:h,pending:_,assistantText:y,agentTypingUntil:x,assistantTypingUntil:C,notice:T,requesting:D,send:(e,t=[])=>{let n={localId:crypto.randomUUID(),key:crypto.randomUUID(),body:e,files:t,status:`sending`,error:``};return v(e=>[...e,n]),I(n)},retry:e=>{let t=_.find(t=>t.localId===e);if(!t)return;let n={...t,status:`sending`,error:``};v(t=>t.map(t=>t.localId===e?n:t)),I(n)},discard:e=>{v(t=>t.filter(t=>t.localId!==e))},requestAgent:async()=>{let t=p.id;O(!0);try{N(await e.requestAgent(t))}catch(e){let n=`We could not reach the team. Please try again.`;e?.code===`chat_not_with_assistant`?await F(t,n):E(Q(e,n))}finally{O(!1)}},end:async()=>{try{N(await e.close(p.id))}catch(e){E(Q(e,`We could not end the chat. Please try again.`))}},restart:()=>{j.current=null,m(null),g([]),v([]),b(``),E(``),S(null),w(null),u(`loading`),A.current?.()},retryStart:()=>{A.current?.()},notifyTyping:()=>{if(l!==`ready`||p?.state!==`WithAgent`)return;let t=Date.now();t-M.current<Rt||(M.current=t,e.typing(p.id).catch(()=>{}))}}}var Gt={composer:`Your message`,placeholder:`Type your message`},Kt=e=>!!e&&Date.now()<Date.parse(e);function qt({chatClient:e,connection:n,open:i,onClose:a,appVersion:u,start:d,onOpenTicket:p,resolveLink:m,linkComponent:h,title:_=`Chat with us`,width:v=`440px`}){let{config:y}=Z(),x=Wt({chatClient:e,connection:n,open:i,appVersion:u,start:d}),[S,C]=s(!1),[T,E]=s([]),[D,O]=s(``),k=o(0),A=o(null),M=o(x.notifyTyping);r(()=>{M.current=x.notifyTyping});let N=e=>{let t=Re(T.map(e=>e.file),e,y);E(t.files.map(e=>T.find(t=>t.file===e)||(k.current+=1,{key:`attachment-${k.current}`,fileName:e.name,contentType:e.type,length:e.size,status:`Ready`,progress:null,error:null,file:e}))),O(t.notice)},P=e=>{E(t=>t.filter(t=>t.key!==e)),O(``)},F=async e=>{let t=T;await x.send(e,t.map(e=>e.file))&&E(e=>e.filter(e=>!t.includes(e)))},I=()=>{E([]),O(``),x.restart()},L=t(()=>M.current(),[]),R=t(e=>{A.current?.removeEventListener(`input`,L),A.current=e,e?.addEventListener(`input`,L)},[L]),z=x.phase===`ready`&&x.chat!==null,B=x.chat?.state,V=z&&B!==`Closed`,ee=Kt(x.assistantTypingUntil)||B===`Assistant`&&x.pending.some(e=>e.status===`sending`),ne=Kt(x.agentTypingUntil),G=x.messages.some(e=>e.authorKind===`Customer`)&&!!x.chat?.assistantAvailable;r(()=>{i&&z&&A.current?.focus()},[i,z]);let K=/* @__PURE__ */ W(`div`,{className:`drawer-header`,children:[/* @__PURE__ */ W(`div`,{className:`drawer-title`,children:[/* @__PURE__ */ U(`span`,{className:`drawer-title-ic`,children:/* @__PURE__ */ U(w,{name:`message-circle`,size:18})}),_]}),/* @__PURE__ */ W(`div`,{className:`d-flex align-items-center gap-1`,children:[V&&/* @__PURE__ */ U(f,{variant:`ghost`,size:`sm`,onClick:()=>C(!0),children:`End chat`}),/* @__PURE__ */ U(c,{icon:`x`,label:`Close`,onClick:a})]})]}),ie;ie=x.phase===`error`?/* @__PURE__ */ W(l,{tone:`danger`,children:[x.startError,/* @__PURE__ */ U(`div`,{className:`mt-2`,children:/* @__PURE__ */ U(f,{size:`sm`,variant:`outline`,onClick:x.retryStart,children:`Try again`})})]}):z?/* @__PURE__ */ W(H,{children:[/* @__PURE__ */ U(kt,{state:B,closeReason:x.chat.closeReason,agentName:x.chat.agentName,ticketNumber:x.chat.ticketNumber,ticketId:x.chat.ticketId,waitingPosition:x.chat.waitingPosition,canRequestAgent:G,requesting:x.requesting,onRequestAgent:x.requestAgent,onOpenTicket:p,onRestart:I}),/* @__PURE__ */ U(Lt,{messages:x.messages,pending:x.pending,assistantText:x.assistantText,assistantWriting:ee,agentName:x.chat.agentName,agentTyping:ne,onRetry:x.retry,onDiscard:x.discard,resolveLink:m,linkComponent:h}),x.notice&&/* @__PURE__ */ U(l,{tone:`danger`,size:`sm`,children:x.notice})]}):/* @__PURE__ */ U(`div`,{className:`d-flex justify-content-center py-4`,children:/* @__PURE__ */ U(j,{label:`Starting your chat`})});let ae=V?/* @__PURE__ */ W(`div`,{className:`d-flex flex-column gap-2`,children:[D&&/* @__PURE__ */ U(l,{tone:`danger`,size:`sm`,children:D}),/* @__PURE__ */ U(te,{onSubmit:F,busy:x.pending.length>0||!!x.assistantText,maxLength:y?.bodyMaxLength??4e3,inputRef:R,attachments:T,onAttach:N,onRemoveAttachment:P,accept:Ne(y),labels:Gt}),B===`Assistant`&&/* @__PURE__ */ U(`p`,{className:`wui-text-xs text-body-secondary mb-0`,children:re.disclaimer})]}):void 0;return/* @__PURE__ */ W(H,{children:[/* @__PURE__ */ U(b,{open:i,onClose:a,sheet:!1,width:v,header:K,footer:ae,ariaLabel:_,onOpened:()=>A.current?.focus(),children:ie}),/* @__PURE__ */ U(g,{open:S,title:`End this chat?`,message:B===`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:()=>{C(!1),x.end()},onClose:()=>C(!1)})]})}var Jt={zIndex:`var(--wui-z-fixed)`,bottom:`var(--wui-consent-banner-block, 0px)`},Yt={end:{insetInlineEnd:0},start:{insetInlineStart:0}};function Xt({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__ */ U(Zt,{onClick:e,open:t,label:n,position:r,icon:i,className:o,style:s}):/* @__PURE__ */ U(`span`,{"data-support-capture":`exclude`,className:[`position-fixed m-3`,o].filter(Boolean).join(` `),style:{...Jt,...Yt[r],...s},children:/* @__PURE__ */ U(f,{leftIcon:i,className:`rounded-pill`,onClick:e,"aria-haspopup":`dialog`,"aria-expanded":t,children:n})})}function Zt({onClick:e,open:t,label:n,position:r,icon:i,className:a,style:o}){let s=F(r);return s?R(/* @__PURE__ */ U(`span`,{className:[`wui-floating-stack-item wui-floating-stack-item--primary`,a].filter(Boolean).join(` `),style:o,children:/* @__PURE__ */ U(f,{className:`wui-floating-btn`,onClick:e,"aria-label":n,"aria-haspopup":`dialog`,"aria-expanded":t,tooltip:n,tooltipPlacement:r===`start`?`end`:`start`,children:/* @__PURE__ */ U(w,{name:i,size:24})})}),s):null}var Qt=e=>typeof e==`string`&&e.trim()!==``;function $t({className:e}){let{config:t}=Z();if(!t)return null;let n=Qt(t.supportEmail),r=Qt(t.supportPhone),i=Qt(t.supportHours);if(!n&&!r&&!i)return null;let a=[`d-flex flex-wrap align-items-center gap-2 wui-text-sm`,e].filter(Boolean).join(` `);return/* @__PURE__ */ W(`section`,{className:a,"aria-label":Qt(t.supportName)?`Contact ${t.supportName}`:`Contact support`,children:[/* @__PURE__ */ U(`span`,{className:`fw-semibold`,children:Qt(t.supportName)?t.supportName:`Contact support`}),n&&/* @__PURE__ */ W(`span`,{className:`d-inline-flex align-items-center gap-1`,children:[/* @__PURE__ */ U(`a`,{href:`mailto:${t.supportEmail}`,className:`text-break`,children:t.supportEmail}),/* @__PURE__ */ U(_,{text:t.supportEmail,iconOnly:!0,label:`Copy email`,copiedLabel:`Email copied`})]}),r&&/* @__PURE__ */ U(`a`,{href:`tel:${t.supportPhone.replace(/[^\d+]/g,``)}`,children:t.supportPhone}),i&&/* @__PURE__ */ U(`span`,{className:`text-body-secondary`,children:t.supportHours})]})}function en({client:e,timeZone:n=z,renderTime:r,children:i}){let s=o(null),c=t((t=!1)=>{let n=s.current;if(t||!n||n.client!==e){let t=e.getConfig(),n={client:e,pending:t};return s.current=n,t.catch(()=>{s.current===n&&(s.current=null)}),t}return n.pending},[e]),l=a(()=>({client:e,loadConfig:c,timeZone:n,renderTime:r}),[e,c,n,r]);return/* @__PURE__ */ U(we.Provider,{value:l,children:i})}export{it as ReportIssue,K as SupportApiError,Tt as SupportCenter,qt as SupportChat,Xt as SupportChatLauncher,$t as SupportContact,en as SupportProvider,Se as createSseChatConnection,me as createSupportChatClient,ue as createSupportClient,X as useSupportClient,Z as useSupportConfig,je as useSupportTicket,Ae as useSupportTicketCounts,ke as useSupportTickets};
@@ -8,8 +8,8 @@
8
8
  * @param {string} [props.initialTicketId]
9
9
  * @param {string} [props.defaultCategory]
10
10
  * @param {string} [props.appVersion]
11
- * @param {"all"|"Open"|"InProgress"|"WaitingOnCustomer"|"Resolved"|"Closed"|"Cancelled"} [props.status] The status shown; when passed, the product drives it.
12
- * @param {"all"|"Open"|"InProgress"|"WaitingOnCustomer"|"Resolved"|"Closed"|"Cancelled"} [props.defaultStatus="all"] The status to start on when `status` is not passed.
11
+ * @param {"all"|"Open"|"NeedsReply"|"Resolved"|"Withdrawn"} [props.status] The status shown; when passed, the product drives it.
12
+ * @param {"all"|"Open"|"NeedsReply"|"Resolved"|"Withdrawn"} [props.defaultStatus="all"] The status to start on when `status` is not passed.
13
13
  * @param {(status: string) => void} [props.onStatusChange] Called with the status the person picks.
14
14
  * @param {"tabs"|"select"|"none"} [props.statusFilter="tabs"] The status control: tabs, a Status select, or none.
15
15
  */
@@ -17,8 +17,8 @@ export default function SupportCenter({ initialTicketId, defaultCategory, appVer
17
17
  initialTicketId?: string;
18
18
  defaultCategory?: string;
19
19
  appVersion?: string;
20
- status?: "all" | "Open" | "InProgress" | "WaitingOnCustomer" | "Resolved" | "Closed" | "Cancelled";
21
- defaultStatus?: "all" | "Open" | "InProgress" | "WaitingOnCustomer" | "Resolved" | "Closed" | "Cancelled";
20
+ status?: "all" | "Open" | "NeedsReply" | "Resolved" | "Withdrawn";
21
+ defaultStatus?: "all" | "Open" | "NeedsReply" | "Resolved" | "Withdrawn";
22
22
  onStatusChange?: (status: string) => void;
23
23
  statusFilter?: "tabs" | "select" | "none";
24
24
  }): import("react").JSX.Element;
@@ -18,7 +18,7 @@ export declare const meta: {
18
18
  };
19
19
  readonly defaultStatus: {
20
20
  readonly type: "enum";
21
- readonly values: readonly ["all", "Open", "InProgress", "WaitingOnCustomer", "Resolved", "Closed", "Cancelled"];
21
+ readonly values: readonly ["all", "Open", "NeedsReply", "Resolved", "Withdrawn"];
22
22
  readonly default: "all";
23
23
  readonly description: "The status to start on when the product does not drive it.";
24
24
  };
@@ -1,6 +1,7 @@
1
1
  /**
2
- * How to reach support: the email address with a copy button, the phone number as a call link,
3
- * and the hours. A field the product has not set is left out; nothing renders when none is set.
2
+ * How to reach support on one line: the name, the email address with a copy button, the phone
3
+ * number as a call link and the hours. A field the product has not set is left out; nothing
4
+ * renders when none is set.
4
5
  *
5
6
  * @param {object} props
6
7
  * @param {string} [props.className]
@@ -16,7 +16,7 @@ export declare const meta: {
16
16
  readonly props: {};
17
17
  }];
18
18
  readonly usage: {
19
- readonly when: readonly ["A page or footer shows how to reach support.", "It lists the email address with a copy button, the phone number as a call link and the opening hours.", "A field the product has not set is left out, and nothing renders when none is set."];
19
+ readonly when: readonly ["A page or footer shows how to reach support.", "It shows the email address with a copy button, the phone number as a call link and the opening hours on one line.", "A field the product has not set is left out, and nothing renders when none is set."];
20
20
  readonly whenNot: readonly [];
21
21
  readonly do: readonly [];
22
22
  readonly dont: readonly [];
@@ -45,11 +45,12 @@ export type RatingInput = {
45
45
  comment?: string;
46
46
  };
47
47
  export type TicketStatus = "Open" | "InProgress" | "WaitingOnCustomer" | "Resolved" | "Closed" | "Cancelled";
48
+ export type SupportCustomerStatus = "Open" | "NeedsReply" | "Resolved" | "Withdrawn";
48
49
  export type TicketListQuery = {
49
50
  /**
50
- * Only tickets in this status; every status when left out.
51
+ * Only tickets in this customer status; every status when left out.
51
52
  */
52
- status?: TicketStatus;
53
+ status?: SupportCustomerStatus;
53
54
  /**
54
55
  * Matches the subject or the ticket number.
55
56
  */
@@ -72,10 +73,9 @@ export type TicketPage = {
72
73
  };
73
74
  export type TicketCounts = {
74
75
  open: number;
75
- inProgress: number;
76
- waitingOnCustomer: number;
76
+ needsReply: number;
77
77
  resolved: number;
78
- closed: number;
78
+ withdrawn: number;
79
79
  total: number;
80
80
  };
81
81
  export type SupportSuggestedArticle = {
@@ -144,9 +144,12 @@ export type SupportClient = {
144
144
  /**
145
145
  * @typedef {"Open"|"InProgress"|"WaitingOnCustomer"|"Resolved"|"Closed"|"Cancelled"} TicketStatus
146
146
  */
147
+ /**
148
+ * @typedef {"Open"|"NeedsReply"|"Resolved"|"Withdrawn"} SupportCustomerStatus A ticket's status as the customer reads it.
149
+ */
147
150
  /**
148
151
  * @typedef {object} TicketListQuery
149
- * @property {TicketStatus} [status] Only tickets in this status; every status when left out.
152
+ * @property {SupportCustomerStatus} [status] Only tickets in this customer status; every status when left out.
150
153
  * @property {string} [search] Matches the subject or the ticket number.
151
154
  * @property {number} [page] 1-based. The API defaults to 1.
152
155
  * @property {number} [pageSize] The API defaults to 20 and allows up to 100.
@@ -160,12 +163,11 @@ export type SupportClient = {
160
163
  * @property {number} totalPages
161
164
  */
162
165
  /**
163
- * @typedef {object} TicketCounts How many of the customer's tickets are in each status.
166
+ * @typedef {object} TicketCounts How many of the customer's tickets are in each customer status.
164
167
  * @property {number} open
165
- * @property {number} inProgress
166
- * @property {number} waitingOnCustomer
168
+ * @property {number} needsReply
167
169
  * @property {number} resolved
168
- * @property {number} closed
170
+ * @property {number} withdrawn
169
171
  * @property {number} total
170
172
  */
171
173
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
- * The fields of a new ticket: category, subject, message and attachments. Validates against the
3
- * support config before anything uploads. The submit button lives outside (a modal footer), tied
4
- * to this form by `id`.
2
+ * The fields of a new ticket: message, subject, category and attachments. The subject follows the
3
+ * message until the person types in it. Validates against the support config before anything
4
+ * uploads. The submit button lives outside (a modal footer), tied to this form by `id`.
5
5
  *
6
6
  * @param {object} props
7
7
  * @param {string} props.id The form's id, for a submit button outside it.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The subject a new ticket starts with: the first non-blank line of the message, whitespace collapsed.
3
+ * A line longer than the limit is cut at the last space at or before it, or hard at the limit when it
4
+ * has no space, and the cut end loses trailing spaces and the characters `,;:.-`. The limit is the
5
+ * smaller of `maxLength` and 80.
6
+ *
7
+ * @param {string} message
8
+ * @param {number} maxLength
9
+ * @returns {string} The subject, or "" when the message has no text.
10
+ */
11
+ export declare function subjectFromMessage(message: string, maxLength: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webority/support-react",
3
- "version": "0.126.2",
3
+ "version": "0.128.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.126.2",
31
- "@webority/ui-elements": "0.126.2",
32
- "@webority/ui-react": "0.126.2",
30
+ "@webority/chat-react": "0.128.0",
31
+ "@webority/ui-elements": "0.128.0",
32
+ "@webority/ui-react": "0.128.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.126.2",
47
- "@webority/chat-react": "0.126.2",
48
- "@webority/ui-elements": "0.126.2",
49
- "@webority/ui-react": "0.126.2",
46
+ "@webority/canvas-kit": "0.128.0",
47
+ "@webority/chat-react": "0.128.0",
48
+ "@webority/ui-elements": "0.128.0",
49
+ "@webority/ui-react": "0.128.0",
50
50
  "bootstrap": "5.3.3",
51
51
  "jsdom": "30.1.1",
52
52
  "react": "^19.2.6",
@@ -57,7 +57,7 @@
57
57
  "vitest": "5.0.1"
58
58
  },
59
59
  "dependencies": {
60
- "@webority/markdown-core": "0.126.2",
60
+ "@webority/markdown-core": "0.128.0",
61
61
  "html-to-image": "^1.11.13"
62
62
  },
63
63
  "scripts": {