@whoa-chat/react 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/src/ChatThread.d.ts
CHANGED
|
@@ -73,6 +73,8 @@ type Props = {
|
|
|
73
73
|
card?: ShortcutCard;
|
|
74
74
|
}[];
|
|
75
75
|
composerTop?: ReactNode;
|
|
76
|
+
/** Beside the Reply and Note tabs, on the right: one action for this conversation (the inbox: ask for a review). */
|
|
77
|
+
composerAside?: ReactNode;
|
|
76
78
|
composerFill?: {
|
|
77
79
|
text: string;
|
|
78
80
|
key: number;
|
|
@@ -145,5 +147,5 @@ type Props = {
|
|
|
145
147
|
export declare const MenuIcon: ({ d }: {
|
|
146
148
|
d: string;
|
|
147
149
|
}) => import("react").JSX.Element;
|
|
148
|
-
export declare const ChatThread: ({ messages, viewer, shopOwnerName, listing, onSend, onReviewState, sending, previewUrl, open, agents, onSendNote, onDraft, uploadUrl, uploadFields, fileUrl, uploadFile, pickGif, fetchFile, availability, shortcuts, onSendCard, composerTop, composerFill, onComposerEscape, composerSend, shortcutVars, gifSearchUrl, gifPickUrl, otherReadAt, otherDeliveredAt, emailedAt, email, menu, plusOnDesktop, me, merchantCountry, rich, onDraftChange, typingNow, onEdit, onDelete, onRestore, onSaveReply: _onSaveReply, onSlash, onReact, visitorCta, onResendEmail, searchRefs, linkShortcuts, onTrack, onAddFeature, actions, store, onActionsBefore, actionsStatus, refLink, linkNames, }: Props) => import("react").JSX.Element;
|
|
150
|
+
export declare const ChatThread: ({ messages, viewer, shopOwnerName, listing, onSend, onReviewState, sending, previewUrl, open, agents, onSendNote, onDraft, uploadUrl, uploadFields, fileUrl, uploadFile, pickGif, fetchFile, availability, shortcuts, onSendCard, composerTop, composerAside, composerFill, onComposerEscape, composerSend, shortcutVars, gifSearchUrl, gifPickUrl, otherReadAt, otherDeliveredAt, emailedAt, email, menu, plusOnDesktop, me, merchantCountry, rich, onDraftChange, typingNow, onEdit, onDelete, onRestore, onSaveReply: _onSaveReply, onSlash, onReact, visitorCta, onResendEmail, searchRefs, linkShortcuts, onTrack, onAddFeature, actions, store, onActionsBefore, actionsStatus, refLink, linkNames, }: Props) => import("react").JSX.Element;
|
|
149
151
|
export {};
|
package/dist/src/ChatThread.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{Fragment as k,jsx as s,jsxs as o}from"react/jsx-runtime";import{Fragment as He,useEffect as T,useLayoutEffect as Hn,useRef as y,useState as f}from"react";import{mentionsIn as
|
|
2
|
-
`)&&qt(!0):qt(!1)},[g]),T(()=>{const t=Vt.current;if(!t||typeof ResizeObserver>"u")return;const n=new ResizeObserver(()=>{const a=t.querySelector(".sc-rich-input, textarea");a&&a.scrollHeight>44&&un.current(!0)});return n.observe(t),()=>n.disconnect()},[]),Hn(()=>{const t=he.current;he.current=null;const n=Vt.current;if(!t||!n||window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;const a={duration:220,easing:"cubic-bezier(0.2, 0.8, 0.2, 1)"};for(const[i,e]of t){if(!i.isConnected)continue;const l=i.getBoundingClientRect();if(i===n){Math.abs(e.height-l.height)>1&&n.animate([{height:`${e.height}px`},{height:`${l.height}px`}],a);continue}const d=e.left-l.left,m=e.top-l.top;(Math.abs(d)>1||Math.abs(m)>1)&&i.animate([{transform:`translate(${d}px, ${m}px)`},{transform:"none"}],a)}},[me]);const pn=y(!1),fe=y(tn);fe.current=tn,T(()=>{D||fe.current?.(g,pn.current)},[g,D]);const w=y(null),gn=y(g);gn.current=g,T(()=>{if(!wt)return;if(wt.replace){j(wt.text);return}if(g.trim())return;let t=0,n;const a=()=>{j(wt.text),n=setTimeout(()=>{!gn.current.trim()&&++t<30&&a()},100)};return a(),()=>clearTimeout(n)},[wt?.key]);const[
|
|
3
|
-
`]})})(),Yt=t=>{if(S)return w.current?.insertText(`${$&&!/\s$/.test($)?" ":""}${t}`);A(n=>`${n}${n&&!/\s$/.test(n)?" ":""}${t}`),window.requestAnimationFrame(()=>{const n=O.current;n&&(n.focus(),n.setSelectionRange(n.value.length,n.value.length))})},Mn=t=>{if(t.key==="Escape"&&Tt&&!D&&!L&&!ft.length&&Z===null)return Zt.current=!1,St(!1),et(!0),!0;if(t.key==="Escape"&&M&&Ue&&H===null&&Z===null&&!ft.length)return Ue(),!0;if((t.key==="Tab"||t.key==="Enter")&&H!==null&&Ut.length&&!t.metaKey&&!t.ctrlKey)return Ut[0].pick(),!0;if(t.key==="Escape"&&H!==null)return
|
|
1
|
+
import{Fragment as k,jsx as s,jsxs as o}from"react/jsx-runtime";import{Fragment as He,useEffect as T,useLayoutEffect as Hn,useRef as y,useState as f}from"react";import{mentionsIn as Es,noteTarget as Is,splitMentions as zn,typingMention as Bs}from"@whoa-chat/core/mentions";import{ALLOWED_TYPES as ze,fileTypeOf as Fs,maxBytesFor as js,maxLabelFor as Hs}from"@whoa-chat/core/fileTypes";import{InlineImage as zs,MediaProvider as Ws,MessageFiles as Wn,PendingFiles as Vs}from"./Attachments.js";import{AvailabilityCard as qs,AwayBar as Vn,OnlineBar as _s}from"./AvailabilityCard.js";import{HelpOfferCard as Ks,VerifiedIcon as Gs}from"./HelpOfferCard.js";import{PasswordCard as Zs}from"./PasswordCard.js";import{FeatureRequestCard as Qs,TicketCard as Us}from"./RequestCards.js";import{CardOutcome as Ys}from"./CardOutcome.js";import{EmojiPicker as Js,LinkPicker as Xs}from"./ComposerTools.js";import{useTranslation as ta}from"./i18n.js";import{TEAM_FLAG as We,languageFlag as qn,languageName as _n}from"./flags.js";import{FILE_IMG as ea,FormattedText as Ve,inlineFileIds as na}from"./FormattedText.js";import{isUrl as sa,linkToken as qe}from"@whoa-chat/core/links";import{splitRefs as aa}from"./refLinks.js";import{RichInput as ra}from"./RichInput.js";import{AiSteps as oa}from"./AssistantNote.js";import{AiChoices as ia,AiProgress as la}from"./AiChoices.js";import{MessageActions as _e}from"./MessageActions.js";import{ActionGroup as ca}from"./ActionGroup.js";import{EventRow as da}from"./EventRow.js";import{DraftCard as ua}from"./DraftCard.js";import{StoreAvatar as pa}from"./StoreAvatar.js";import{AgentAvatar as Ct}from"./agents.js";import{ReviewCard as ga}from"./ReviewCard.js";import{CustomCard as ma}from"./CustomCard.js";import{ChatEnvProvider as Kn,DeepLinkCard as ha,Mention as fa,MessageWithReferences as ka,PricingCard as ba,ReferenceCard as Gn}from"./RichCards.js";import{timeOpts as ya}from"./clock.js";import{LinkNamesContext as va,OpenedLinksContext as Ca}from"./chatEnv.js";import{useAppearance as $a}from"./appearance.js";import{brandVars as Na,chatHost as Zn}from"./host.js";const It=({viewer:p,message:c,children:it})=>p==="agent"?s(Ys,{message:c,children:it}):s(k,{children:it}),Y=p=>new Date(p).toDateString(),te=({d:p})=>s("svg",{viewBox:"0 0 20 20",width:"20",height:"20","aria-hidden":!0,children:s("path",{d:p,fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),F=p=>new Date(p).toLocaleTimeString([],ya()),wa=30*6e4,Qn=(p,c)=>c==="agent"&&p.translation&&p.from==="merchant"?{kind:"from",lang:p.translation.from,main:p.translation.text,alt:p.body}:c==="agent"&&p.translation&&p.from==="agent"?{kind:"to",lang:p.translation.to,main:p.body,alt:p.translation.text}:c==="merchant"&&p.original?{kind:"merchant",lang:p.original.lang,main:p.body,alt:p.original.body}:null,Ke=(p,c,it)=>{const $t=Qn(p,c);return $t?it?$t.alt:$t.main:p.body},ar=({messages:p,viewer:c,shopOwnerName:it,listing:$t,onSend:Ge,onReviewState:Un,sending:Yn,previewUrl:ee,open:Jn,agents:K=[],onSendNote:Bt,onDraft:Nt,uploadUrl:Ze,uploadFields:Qe,fileUrl:z,uploadFile:Ft,pickGif:ne,fetchFile:jt,availability:G,shortcuts:lt=[],onSendCard:se,composerTop:ae=null,composerAside:Xn=null,composerFill:wt=null,onComposerEscape:Ue,composerSend:M=null,shortcutVars:ts={},gifSearchUrl:re,gifPickUrl:oe,otherReadAt:xt=null,otherDeliveredAt:Ye=null,emailedAt:Je=null,email:ie=null,menu:Ht,plusOnDesktop:es,me:W=null,merchantCountry:Xe=null,rich:S=!1,onDraftChange:tn,typingNow:C=null,onEdit:ct,onDelete:J,onRestore:en,onSaveReply:xa,onSlash:nn,onReact:dt,visitorCta:ns=!1,onResendEmail:sn,searchRefs:ut,linkShortcuts:pt,onTrack:Mt,onAddFeature:an,actions:le=null,store:X,onActionsBefore:ce,actionsStatus:rn=null,refLink:on,linkNames:ss})=>{const{t:r,i18n:de}=ta("home"),as=t=>{const n=new Map,a=(t.clicks??[]).filter(i=>i.action==="link"&&/^https?:/.test(i.detail??""));for(const i of a){const e=a.filter(l=>l.detail===i.detail);n.has(i.detail)||n.set(i.detail,r("supportChat.msg.linkClicked",{time:F(e[0].at),count:e.length}))}return n},ln=$a(de,c==="merchant"),cn=(t,n)=>on?aa(t,on).map((a,i)=>a.href?s("a",{href:a.href,target:"_blank",rel:"noopener noreferrer",children:a.text},`${n}-r${i}`):s(He,{children:a.text},`${n}-r${i}`)):t,[g,A]=f(""),[D,zt]=f(null),[L,ue]=f(null),[Lt,pe]=f(null),[dn,ge]=f([]),Wt=t=>{ge(i=>i.some(e=>e.key===t.key)?i.map(e=>e.key===t.key?{...t,status:"sending"}:e):[...i,t]);const n=t.card&&se?se(t.card):t.note&&Bt?Bt(t.body,t.files,t.replyTo):Ge(t.body,t.files,t.refs,t.replyTo),a=()=>ge(i=>i.filter(e=>e.key!==t.key));if(!n)return a();n.then(a,()=>ge(i=>i.map(e=>e.key===t.key?{...e,status:"failed"}:e)))},rs=t=>Number(t.key.split("-")[0])||0,os=t=>!t.card&&!!t.body&&p.some(n=>n.from===c&&n.kind==="note"===t.note&&n.body?.trim()===t.body.trim()&&Date.parse(n.at)>=rs(t)-12e4),[Rt,is]=f(()=>new Set),ls=t=>is(n=>{const a=new Set(n);return a.delete(t)||a.add(t),a}),Vt=y(null),[me,cs]=f(!1),he=y(null),qt=t=>{const n=Vt.current;n&&t!==me&&(he.current=new Map([n,...Array.from(n.children)].map(a=>[a,a.getBoundingClientRect()]))),cs(t)},un=y(qt);un.current=qt,T(()=>{g?g.includes(`
|
|
2
|
+
`)&&qt(!0):qt(!1)},[g]),T(()=>{const t=Vt.current;if(!t||typeof ResizeObserver>"u")return;const n=new ResizeObserver(()=>{const a=t.querySelector(".sc-rich-input, textarea");a&&a.scrollHeight>44&&un.current(!0)});return n.observe(t),()=>n.disconnect()},[]),Hn(()=>{const t=he.current;he.current=null;const n=Vt.current;if(!t||!n||window.matchMedia("(prefers-reduced-motion: reduce)").matches)return;const a={duration:220,easing:"cubic-bezier(0.2, 0.8, 0.2, 1)"};for(const[i,e]of t){if(!i.isConnected)continue;const l=i.getBoundingClientRect();if(i===n){Math.abs(e.height-l.height)>1&&n.animate([{height:`${e.height}px`},{height:`${l.height}px`}],a);continue}const d=e.left-l.left,m=e.top-l.top;(Math.abs(d)>1||Math.abs(m)>1)&&i.animate([{transform:`translate(${d}px, ${m}px)`},{transform:"none"}],a)}},[me]);const pn=y(!1),fe=y(tn);fe.current=tn,T(()=>{D||fe.current?.(g,pn.current)},[g,D]);const w=y(null),gn=y(g);gn.current=g,T(()=>{if(!wt)return;if(wt.replace){j(wt.text);return}if(g.trim())return;let t=0,n;const a=()=>{j(wt.text),n=setTimeout(()=>{!gn.current.trim()&&++t<30&&a()},100)};return a(),()=>clearTimeout(n)},[wt?.key]);const[ds,us]=f(""),$=S?ds:g,j=(t,n)=>{S&&(t?w.current?.setText(t,n):w.current?.clear()),A(t)},ke=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.platform)?"\u2318 Enter":"Ctrl Enter",V=[];for(const t of[...p.map(n=>({at:n.at,message:n})),...c==="agent"&&le?le.map(n=>({at:n.at,action:n})):[]].sort((n,a)=>Date.parse(n.at)-Date.parse(a.at))){const n=V[V.length-1];"action"in t&&t.action?n?.group&&Y(n.at)===Y(t.at)?n.group.push(t.action):V.push({at:t.at,group:[t.action]}):"message"in t&&t.message&&V.push({at:t.at,message:t.message})}const be=t=>t?.message&&(!t.message.kind||t.message.kind==="text")?`${t.message.from}:${t.message.agentName??""}`:null,mn=(t,n)=>!!(t&&n&&be(t)&&be(t)===be(n)&&Y(t.at)===Y(n.at)&&Date.parse(n.at)-Date.parse(t.at)<5*6e4),ps=y(null),tt=y(null),hn=y(null),gt=y(!0),fn=()=>{const t=tt.current;if(!t||!ce)return;if(t.scrollTop<60)return ce(new Date(0).toISOString());const n=t.getBoundingClientRect().top,a=t.querySelectorAll("[data-at]"),i=[...a].find(e=>e.getBoundingClientRect().bottom>=n)??a[0];i?.dataset.at&&ce(i.dataset.at)},_t=y(0),gs=le?.length??0;Hn(()=>{const t=tt.current;t&&(!gt.current&&_t.current&&(t.scrollTop+=t.scrollHeight-_t.current),_t.current=t.scrollHeight,fn())},[gs]),T(()=>{const t=tt.current,n=hn.current;if(!t||!n)return;const a=()=>gt.current&&(t.scrollTop=t.scrollHeight),i=new ResizeObserver(a);return i.observe(n),i.observe(t),a(),()=>i.disconnect()},[]);const mt=p[p.length-1],[kn,ye]=f(!1),bn=y(null),yn=()=>{gt.current=!0,ye(!1),tt.current&&(tt.current.scrollTop=tt.current.scrollHeight)};T(()=>{const t=bn.current===null;if(bn.current=mt?.id??"",!mt)return;const n=mt.from===c||c==="agent"&&mt.from==="agent"&&mt.agentName===W;t||n||gt.current?yn():ye(!0)},[mt?.id]);const[Kt,et]=f(!1),[Tt,St]=f(!1),O=y(null),q=c==="agent"&&!!Bt&&K.length>0,ht=q?Is(g,K):null,Gt=q&&/^\s*@/.test(g),x=q&&(Tt||(!!ht||Gt)&&!Kt);pn.current=x,T(()=>{!D&&g.trim()&&fe.current?.(g,x)},[x]);const Zt=y(!1);T(()=>{q&&!Tt&&!Kt&&(Gt||ht)&&(Zt.current=!0,St(!0))},[q,Tt,Kt,Gt,ht]),T(()=>{c==="agent"&&nn&&g==="/"&&(j(""),nn())},[g]);const vn=x?Es(g,K):[],ve=q?Bs($):null,_=ve===null?[]:K.filter(t=>t.toLowerCase().startsWith(ve.toLowerCase())),[ms,Ce]=f(0);T(()=>Ce(0),[ve]);const $e=_[Math.min(ms,_.length-1)];T(()=>{g.trim()||et(!1);const t=O.current;t&&(t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,160)}px`)},[g]);const Ne=lt.length?$.match(/(?:^|\s)!([a-z0-9-]*)$/i)?.[1]??null:null,ft=Ne===null?[]:lt.filter(t=>t.key.startsWith(Ne.toLowerCase())||t.title.toLowerCase().includes(Ne.toLowerCase())).slice(0,6),we=t=>t.replace(/\{\{\s*(\w+)\s*\}\}/g,(n,a)=>ts[a]??n),Cn=t=>{const n=t.body;t.card&&se&&pe(t.card),S?w.current?.replaceBefore($.match(/![a-z0-9-]*$/i)?.[0].length??0,we(n)):A(a=>a.replace(/![a-z0-9-]*$/i,we(n))),O.current?.focus()},[xe,$n]=f(null),[Me,hs]=f(null),Nn=c==="agent"&&pt?$.match(/(?:^|\s)\[([^[\]\n]{0,40})$/)?.[1]??null:null,Z=Nn!==null&&Me!==null&&$.startsWith(Me)&&$.lastIndexOf("[")===Me.lastIndexOf("[")?null:Nn;T(()=>{Z!==null&&xe===null&&pt&&pt().then($n,()=>$n([]))},[Z!==null]);const fs=(Z??"").toLowerCase().split(/\s+/).filter(Boolean),P=Z===null||!xe?[]:xe.filter(t=>fs.every(n=>`${t.label} ${t.url}`.toLowerCase().includes(n))).slice(0,6),[Le,Re]=f(0);T(()=>Re(0),[Z]);const wn=t=>{const n=$.match(/\[[^[\]\n]*$/)?.[0].length??0;S?w.current?.insertLink(t.url,void 0,n):(A(a=>a.replace(/\[[^[\]\n]*$/,`${qe(t.url,"")} `)),O.current?.focus())},[Te,ks]=f(null),bs=ut?$.match(/(?:^|\s)#((?:[^\s#\d][^#\n]{0,39})?|\d[^\s#]{0,19})$/)?.[1]??null:null,H=Te!==null&&$.startsWith(Te)&&$.lastIndexOf("#")===Te.lastIndexOf("#")?null:bs,[nt,xn]=f({q:"",data:null}),[Q,At]=f(null),[Se,Qt]=f([]);T(()=>{if(H===null||!ut)return At(null);let t=!0;const n=window.setTimeout(()=>{ut(H.trim()).then(a=>t&&xn({q:H,data:a}),()=>t&&xn({q:H,data:{offers:[],products:[]}}))},350);return()=>{t=!1,window.clearTimeout(n)}},[H,ut]);const st=(t,n)=>{if(S){w.current?.replaceBefore($.match(/#[^#\n]*$/)?.[0].length??0,t,{text:t,ref:n??t.replace(/^#/,"")}),At(null);return}A(a=>a.replace(/#[^#\n]*$/,`${t} `)),n&&Qt(a=>[...a.filter(i=>i.text!==t),{text:t,ref:n}]),At(null),O.current?.focus()},Ut=H===null||!nt.data?[]:Q?[{key:"any",label:r("supportChat.refPick.anyVariant"),sub:Q.title,image:Q.image,pick:()=>st(Q.title,`product-${Q.id}`)},...Q.variants.map(t=>({key:t.id,label:t.title,sub:t.sku?`SKU ${t.sku}`:void 0,pick:()=>st(`${Q.title}, ${t.title}`,`variant-${t.id}`)}))]:[...nt.data.offers.slice(0,3).map((t,n)=>({key:`o${t.id}`,section:n===0?r("supportChat.refPick.offers"):void 0,label:t.name,sub:t.label,pick:()=>st(t.name,`offer-${t.id}`)})),...nt.data.products.slice(0,4).map((t,n)=>({key:`p${t.id}`,section:n===0?r("supportChat.refPick.products"):void 0,label:t.title,sub:t.variants.length>1?r("supportChat.product.variants",{count:t.variants.length}):t.status!=="active"?r(`supportChat.product.status.${t.status}`,{defaultValue:t.status}):void 0,image:t.image,pick:()=>t.variants.length>1?At(t):st(t.title,`product-${t.id}`)})),...(nt.data.customers??[]).slice(0,3).map((t,n)=>({key:`c${t.id}`,section:n===0?r("supportChat.refPick.customers"):void 0,label:t.name,sub:[t.email,t.active?r("supportChat.customer.active",{count:t.active}):t.subscriptions?r("supportChat.customer.noneActive",{count:t.subscriptions}):null].filter(Boolean).join(" \xB7 "),pick:()=>st(t.name,`customer-${t.id}`)})),...(nt.data.subscriptions??[]).slice(0,3).map((t,n)=>({key:`s${t.id}`,section:n===0?r("supportChat.refPick.subscriptions"):void 0,label:t.customer,sub:[`#${t.id}`,t.product,t.status].filter(Boolean).join(" \xB7 "),pick:()=>st(`#${t.id}`,null)})),...(nt.data.orders??[]).slice(0,3).map((t,n)=>({key:`r${t.name}`,section:n===0?r("supportChat.refPick.orders"):void 0,label:t.name,sub:[t.customer,new Date(t.createdAt).toLocaleDateString(void 0,{day:"numeric",month:"short"})].filter(Boolean).join(" \xB7 "),pick:()=>st(t.name.startsWith("#")?t.name:`#${t.name}`,null)}))],Ae=y(null),ys=(()=>{const t=Se.filter(d=>g.includes(d.text)).sort((d,m)=>m.text.length-d.text.length),n=new Map(t.map(d=>[d.text,d.ref.startsWith("offer-")?"offer":d.ref.startsWith("customer-")?"customer":"product"])),a=[...t.map(d=>d.text.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")),"#[A-Za-z]{0,6}\\d{3,20}[A-Za-z]{0,6}\\b","`[^`\\n]+`"],i=new RegExp(`(${a.join("|")})`,"g"),e=(d,m)=>x?zn(d,K).map((h,v)=>h.agent?s("mark",{className:"sc-hl sc-hl--mention",children:h.text},`${m}-m${v}`):h.text):d,l=(d,m)=>d.split(i).map((h,v)=>v%2===1?s("mark",{className:`sc-hl sc-hl--${h.startsWith("`")?"code":n.get(h)??"order"}`,children:h},`${m}-${v}`):e(h,`${m}-${v}`));return o(k,{children:[g.split(/(```[\s\S]*?(?:```|$))/).map((d,m)=>m%2===1?s("mark",{className:"sc-hl sc-hl--block",children:d},`f${m}`):l(d,`t${m}`)),`
|
|
3
|
+
`]})})(),Yt=t=>{if(S)return w.current?.insertText(`${$&&!/\s$/.test($)?" ":""}${t}`);A(n=>`${n}${n&&!/\s$/.test(n)?" ":""}${t}`),window.requestAnimationFrame(()=>{const n=O.current;n&&(n.focus(),n.setSelectionRange(n.value.length,n.value.length))})},Mn=t=>{if(t.key==="Escape"&&Tt&&!D&&!L&&!ft.length&&Z===null)return Zt.current=!1,St(!1),et(!0),!0;if(t.key==="Escape"&&M&&Ue&&H===null&&Z===null&&!ft.length)return Ue(),!0;if((t.key==="Tab"||t.key==="Enter")&&H!==null&&Ut.length&&!t.metaKey&&!t.ctrlKey)return Ut[0].pick(),!0;if(t.key==="Escape"&&H!==null)return ks($),!0;if((t.key==="ArrowDown"||t.key==="ArrowUp")&&P.length>1){const a=t.key==="ArrowDown"?1:-1;return Re(i=>(Math.min(i,P.length-1)+a+P.length)%P.length),!0}if((t.key==="Tab"||t.key==="Enter")&&P.length)return wn(P[Math.min(Le,P.length-1)]),!0;if(t.key==="Escape"&&Z!==null)return hs($),!0;if((t.key==="Tab"||t.key==="Enter")&&ft.length)return Cn(ft[0]),!0;if((t.key==="ArrowDown"||t.key==="ArrowUp")&&_.length>1){const a=t.key==="ArrowDown"?1:-1;return Ce(i=>(Math.min(i,_.length-1)+a+_.length)%_.length),!0}if((t.key==="Tab"||t.key==="Enter")&&$e)return Sn($e),!0;if(t.key==="ArrowUp"&&!g&&ct&&W){const a=ws();return a?(zt(a.id),j(a.body,a.refs),!0):!1}return t.key==="Escape"&&D?(Be(),!0):t.key==="Escape"&&L?(Jt(),!0):t.key!=="Enter"||t.isComposing?!1:(c==="agent"?t.metaKey||t.ctrlKey:!t.shiftKey)?(Bn(),!0):!1},vs=t=>{const n=t.currentTarget;if(n.selectionStart!==n.selectionEnd)return;const a=n.selectionStart,i=g.lastIndexOf(`
|
|
4
4
|
`,a-1)+1,e=/^(\s*)(?:([-*•])|(\d{1,3})([.)]))\s+/.exec(g.slice(i,a));if(!e)return;t.preventDefault();const l=g.slice(i,a).trim()===e[0].trim(),d=e[3]?`${e[1]}${Number(e[3])+1}${e[4]} `:`${e[1]}${e[2]} `,m=l?g.slice(0,i)+g.slice(a):`${g.slice(0,a)}
|
|
5
|
-
${d}${g.slice(a)}`,h=l?i:a+1+d.length;A(m),requestAnimationFrame(()=>n.setSelectionRange(h,h))},[at,kt]=f(null),[Ln,De]=f(!1),Rn=y(null),Tn=t=>{if(S)return w.current?.insertText(t);const n=O.current,a=n?.selectionStart??g.length,i=n?.selectionEnd??a;A(e=>e.slice(0,a)+t+e.slice(i)),window.requestAnimationFrame(()=>{n?.focus(),n?.setSelectionRange(a+t.length,a+t.length)})},Sn=t=>{S?w.current?.replaceBefore($.match(/@[\p{L}]*$/u)?.[0].length??0,`@${t} `):A(n=>n.replace(/@[\p{L}]*$/u,`@${t} `)),O.current?.focus()},[Dt,E]=f([]),[An,Oe]=f(!1),Pe=y(null),Dn=Dt.some(t=>!t.ref&&!t.error),vs=Dt.filter(t=>t.ref).map(t=>t.ref.id),Cs=t=>Dt.filter(n=>n.ref&&(!n.inline||t.includes(`file:${n.ref.id}`))).map(n=>n.ref.id),U=!!(Ze||Ft),Ot=(t,n=!1)=>{if(U)for(const a of Array.from(t).slice(0,10)){const i=`${Date.now()}-${Math.random().toString(36).slice(2)}`,e=Bs(a.name,a.type),l=e===a.type?a:new File([a],a.name,{type:e}),d=ze[l.type]?l.size>Fs(l.type)?r("supportChat.files.tooBig",{max:js(l.type)}):void 0:r("supportChat.files.notAllowed"),m=!d&&l.type.startsWith("image/")?URL.createObjectURL(l):null,h=!!(n&&S&&m&&Ft&&w.current),v=l.name||"screenshot.png";if(E(b=>[...b,{key:i,name:v,size:l.size,type:l.type,preview:m,error:d,...h?{inline:!0}:{}}]),d)continue;h&&w.current.insertImage(i,v,m);const I=(b,R)=>{h&&(b?w.current?.setImageId(i,b.id):w.current?.removeImage(i)),E(vt=>vt.map(u=>u.key===i?b?{...u,ref:b}:{...u,error:R??r("supportChat.files.failed")}:u))};if(Ft){Ft(l).then(b=>I(b),()=>I());continue}const B=new FormData;for(const[b,R]of Object.entries(Qe??{}))B.append(b,R);B.append("file",l,l.name||"screenshot.png"),fetch(Ze,{method:"POST",body:B}).then(async b=>({ok:b.ok,body:await b.json().catch(()=>({}))})).then(({ok:b,body:R})=>E(vt=>vt.map(u=>u.key===i?b&&R.file?{...u,ref:R.file}:{...u,error:R.error??r("supportChat.files.failed")}:u))).catch(()=>E(b=>b.map(R=>R.key===i?{...R,error:r("supportChat.files.failed")}:R)))}},$s=t=>{if(!oe&&!ne)return;kt(null);const n=`gif-${t.id}-${Date.now()}`;if(E(i=>[...i,{key:n,name:t.title||"GIF",size:0,type:"image/gif",preview:t.preview}]),ne){ne(t.id).then(i=>E(e=>e.map(l=>l.key===n?{...l,ref:i,size:i.size}:l)),()=>E(i=>i.map(e=>e.key===n?{...e,error:r("supportChat.files.failed")}:e)));return}if(!oe)return;const a=new FormData;for(const[i,e]of Object.entries(Qe??{}))a.append(i,e);a.append("id",t.id),fetch(oe,{method:"POST",body:a}).then(async i=>({ok:i.ok,body:await i.json().catch(()=>({}))})).then(({ok:i,body:e})=>E(l=>l.map(d=>d.key===n?i&&e.file?{...d,ref:e.file,size:e.file.size}:{...d,error:e.error??r("supportChat.files.failed")}:d))).catch(()=>E(i=>i.map(e=>e.key===n?{...e,error:r("supportChat.files.failed")}:e)))},Ns=()=>[...p].reverse().find(t=>t.from==="agent"&&t.agentName===W&&(t.kind==="text"||t.kind==="note")&&t.id!=="pending")??null,[Pt,Ee]=f(null),[ws,On]=f(!1),Ie=t=>{Ee(t),S?w.current?.focus?.():O.current?.focus()},rt=(t,n)=>c==="agent"&&t.from==="agent"?s(_e,{inline:!0,side:n,onReply:()=>Ie(t),onDelete:J?()=>J(t.id):void 0}):null,Pn=t=>t.from==="merchant"?c==="merchant"?r("supportChat.msg.you"):X?.name??r("supportChat.msg.merchant"):t.bot?Zn().brand.bot:t.author??t.agentName??Zn().brand.team,En=t=>t.replyTo?o("button",{type:"button",className:"sc-quote",onClick:()=>document.querySelector(`[data-msg="${CSS.escape(t.replyTo.id)}"]`)?.nextElementSibling?.scrollIntoView({behavior:"smooth",block:"center"}),children:[s("strong",{children:Pn({from:t.replyTo.from,author:t.replyTo.author==="merchant"?void 0:t.replyTo.author})}),s("span",{children:t.replyTo.excerpt})]}):null,In=t=>{ue(null),zt(t.id),j(t.body,t.refs),O.current?.focus()},Be=()=>{zt(null),j("")},Jt=()=>{ue(null),j("")},Bn=()=>{const t=g.trim();if(M){if(M.blocked)return;M.send(t),j("");return}if(D){t&&ct&&ct(D,t),Be();return}if(L){t&&Nt&&Nt(L.id,"send",t),Jt();return}const n=Cs(t);if(!t&&!n.length&&!Lt||Dn)return;const a=Lt;pe(null),(t||n.length)&&Wt({key:`${Date.now()}-${Math.random()}`,body:t,files:n,refs:Se.filter(i=>t.includes(i.text)),note:!!(x&&Bt),...Pt?{replyTo:Pt.id}:{},status:"sending"}),Ee(null),a&&Wt({key:`${Date.now()}-card`,body:"",files:[],note:!1,card:a,status:"sending"}),Qt([]),j(""),et(!1),Zt.current&&(Zt.current=!1,St(!1)),E([])},xs=p.find(t=>t.from==="agent"&&!t.bot&&!t.deletedAt&&t.kind!=="note"&&t.kind!=="draft"&&t.kind!=="event")?.id??null,Xt=z?(t,n,a)=>s(Hs,{id:t,name:n,url:z(t),load:jt},a):void 0,Et=t=>{const n=ea(t.body);return(t.files??[]).filter(a=>!n.has(a.id))},Fe=[];if(z){for(const t of p)if(!(t.deletedAt||t.kind==="event")){for(const n of(t.body??"").matchAll(ta))Fe.push({id:n[2],name:n[1]||"Image",type:"image/png",url:z(n[2])});for(const n of Et(t))(n.type.startsWith("image/")||n.type.startsWith("video/"))&&Fe.push({id:n.id,name:n.name,type:n.type,url:z(n.id)})}}const Ms=t=>t==="system"?"system":t===c?"merchant":"agent",ot=ee?{previewUrl:ee,open:Jn}:null,bt=p.filter(t=>t.kind!=="note").filter(t=>t.kind!=="event"&&t.kind!=="draft"),Ls=bt[bt.length-1]?.id??null,Rs=t=>{const n=bt.findIndex(a=>a.id===t);return bt.slice(n+1).find(a=>a.from==="merchant")?.body??null},Ts=t=>Wt({key:`${Date.now()}-choice`,body:t,files:[],note:!1,status:"sending"}),Fn=c==="merchant"?"merchant":"agent",jn=[...bt].reverse().find(t=>t.from===Fn)?.id??null,Ss=xt?Date.parse(xt):NaN,As=[...bt].reverse().find(t=>t.from===Fn&&t.id!=="pending"&&Date.parse(t.at)<=Ss)?.id??null,Ds=t=>{if(t.id===As&&t.id!==jn){const B=r("supportChat.receipts.seen");return o("span",{className:"sc-receipt sc-receipt--seen","data-tip":`${B} ${F(xt)}`,children:[o("svg",{viewBox:"0 0 18 14",width:"17",height:"13","aria-hidden":!0,children:[s("path",{d:"M1.5 7.5l3.2 3.2L11 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"}),s("path",{d:"M8.2 10.7L14.6 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})]}),s("span",{className:"sc-receipt-label",children:B})]})}if(t.id!==jn||t.id==="pending")return null;const n=B=>!!(B&&Date.parse(B)>=Date.parse(t.at)),a=c==="agent"&&ie&&n(ie.at)?ie:null,i=a?a.clickedAt??a.openedAt??null:null,e=c==="agent"&&!a&&n(Je)?Je:null,l=n(xt)?{kind:"seen",at:xt}:i?{kind:"emailOpened",at:i}:n(Ye)?{kind:"delivered",at:Ye}:a?.status==="sent"||e?{kind:"emailed",at:a?.at??e}:{kind:a?.status==="held"||a?.status==="failed"?"held":"sent",at:t.at},d=l.kind==="held"&&a?.status==="failed",m=r(`supportChat.receipts.${l.kind==="held"?a?.status==="failed"?"emailFailed":"emailHeld":l.kind}`),h=l.kind!=="sent"&&l.kind!=="held",v=o("svg",{viewBox:"0 0 18 14",width:"17",height:"13","aria-hidden":!0,children:[s("path",{d:h?"M1.5 7.5l3.2 3.2L11 4.2":"M3.5 7.5l3.2 3.2L13 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"}),h&&s("path",{d:"M8.2 10.7L14.6 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})]}),I=l.kind==="seen"||l.kind==="emailOpened"?`${m} ${F(l.at)}`:void 0;return o("span",{className:`sc-receipt sc-receipt--${l.kind}${d?" sc-receipt--failed":""}`,"data-tip":l.kind==="emailOpened"?`${I}. ${r("supportChat.receipts.openNote")}`:I,children:[v,s("span",{className:"sc-receipt-label",children:m}),d&&sn&&s("button",{type:"button",className:"sc-resend",disabled:ws,onClick:()=>{On(!0),sn().finally(()=>On(!1))},children:r("supportChat.receipts.resend")})]})},je=t=>{const n=Ds(t);return n?o(k,{children:[n," \xB7 "]}):null},yt=(t,n)=>o("div",{className:"sc-meta",style:{textAlign:n==="merchant"?"right":"left"},children:[je(t),t.from==="agent"&&t.agentName?`${t.agentName} \xB7 `:"",F(t.at)]}),Os=t=>{if(!ot)return null;const n=ot.open;return{...ot,open:n?a=>{Mt?.(t,"open"),n(a)}:void 0}};return s(zs,{items:Fe,load:jt,children:s(ya.Provider,{value:ns,children:s(Kn,{value:ot,children:o("div",{className:`sc-shell sc-shell--${c}${An?" sc-shell--drop":""}${ln.className}`,style:ln.style,onDragOver:t=>{!U||!t.dataTransfer.types.includes("Files")||(t.preventDefault(),Oe(!0))},onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)||Oe(!1)},onDrop:t=>{U&&(t.preventDefault(),Oe(!1),Ot(t.dataTransfer.files,!0))},children:[An&&s("div",{className:"sc-drop",children:r("supportChat.files.drop")}),o("div",{className:"sc-thread","aria-live":"polite",ref:tt,onScroll:t=>{const n=t.currentTarget;gt.current=n.scrollHeight-n.scrollTop-n.clientHeight<40,gt.current&&kn&&ye(!1),_t.current=n.scrollHeight,fn()},children:[s("div",{className:"sc-newbelow-wrap",children:kn&&o("button",{type:"button",className:"sc-newbelow",onClick:yn,children:[r("supportChat.msg.newBelow")," \u2193"]})}),o("div",{className:"sc-content",ref:hn,children:[c==="merchant"&&G&&p.length>0&&s(Vn,{availability:G}),c==="merchant"&&G&&p.length>0&&s(qs,{availability:G,recentReply:p.some(t=>t.from==="agent"&&!t.bot&&Date.now()-Date.parse(t.at)<30*6e4)}),rn&&s("div",{className:"sc-actions-status",children:rn}),p.length===0&&o("div",{className:"sc-empty",children:[s("strong",{children:r("supportChat.emptyTitle")}),r(G?"supportChat.emptyBodyShort":"supportChat.emptyBody"),G&&o("div",{className:"sc-empty-card",children:[s(Vn,{availability:G}),s(Vs,{availability:G})]})]}),V.map((t,n)=>{const a=V[n-1]?.at,i=(!a||Y(a)!==Y(t.at))&&s("div",{className:"sc-day",children:new Date(t.at).toLocaleDateString([],{weekday:"short",day:"numeric",month:"short"})});if(t.group)return o("div",{style:{display:"contents"},children:[i,s("i",{className:"sc-at","data-at":t.at}),s(la,{actions:t.group,store:X})]},`a-${t.group[0].id}`);const e=t.message,l=Ms(e.from);return o("div",{style:{display:"contents"},onClickCapture:c==="merchant"&&e.from==="agent"&&e.kind==="text"?d=>{const m=d.target.closest?.("a[href]");m&&/^https?:/.test(m.href)&&Mt?.(e.id,"link",m.href.slice(0,300))}:void 0,children:[i,s("i",{className:"sc-at","data-at":e.at,"data-msg":e.id}),e.deletedAt?c==="agent"?o("div",{className:`sc-deleted sc-deleted--${l}`,children:[s("s",{children:e.body.length>120?`${e.body.slice(0,117)}...`:e.body}),s("span",{children:r("supportChat.msg.deletedBy",{name:e.deletedBy??""})}),en&&s("button",{type:"button",className:"sc-deleted-undo",onClick:()=>{en(e.id)},children:r("supportChat.msg.undoDelete")})]}):null:e.kind==="draft"?c==="agent"?s(da,{message:e,time:F(e.at),onDraft:Nt,editing:L?.id===e.id,onEdit:()=>{zt(null),ue({id:e.id,name:e.agentName??"Claude"}),j(e.body)}}):null:e.kind==="event"?c==="agent"?s(ca,{message:e,time:F(e.at)}):null:e.kind==="note"?c==="agent"?o("div",{className:`sc-note${e.reminder?" sc-note--reminder":""}`,"aria-label":r(e.reminder?"supportChat.reminders.noteLabel":"supportChat.note.label"),children:[o("div",{className:"sc-note-head",children:[s("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:s("path",{d:"M4.5 3.5h11v8l-4 4.5h-7zM11.5 16v-4.5h4M7.5 7.5h5M7.5 10.5h2.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),r(e.reminder?"supportChat.reminders.noteTitle":"supportChat.note.title",{name:e.agentName??""}),e.from==="agent"&&!e.reminder&&(J||ct)?s(_e,{inline:!0,side:"agent",onReply:()=>Ie(e),onEdit:ct&&e.agentName===W?()=>In(e):void 0,onDelete:J?()=>J(e.id):void 0,copyText:e.body}):null,o("span",{children:[F(e.at),e.editedAt?` \xB7 ${r("supportChat.edit.edited")}`:""]})]}),s("div",{className:"sc-note-body",children:s(Ve,{text:e.body,image:Xt,inline:(d,m)=>zn(d,K.length?K:e.mentions??[]).map((h,v)=>h.agent?o("span",{className:"sc-mention",children:["@",h.agent]},`${m}-${v}`):s(He,{children:cn(h.text,`${m}-${v}`)},`${m}-${v}`))})}),Et(e).length&&z?s(Wn,{files:Et(e),fileUrl:z,fetchFile:jt}):null]}):null:l==="system"?s("div",{className:"sc-system",children:e.body}):e.kind==="password_request"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(Gs,{message:e,onOpen:c==="merchant"?()=>Mt?.(e.id,"open"):void 0})})]}),yt(e,l)]}):e.kind==="feature_request"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(Zs,{message:e,onAdd:c==="merchant"&&an?()=>an(e.id):void 0})})]}),yt(e,l)]}):e.kind==="ticket"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(Qs,{message:e})]}),yt(e,l)]}):e.kind==="custom"&&e.card?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(ga,{tree:e.card.tree,name:e.card.name})]}),yt(e,l)]}):e.kind==="help_offer"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(_s,{message:e,answered:p.slice(p.indexOf(e)+1).some(d=>d.from==="merchant"),onAnswer:c==="merchant"?d=>{Mt?.(e.id,d===r("supportChat.helpOffer.yesMessage")?"help_yes":"help_no"),Ge(d,[])}:void 0})})]}),yt(e,l)]}):e.kind==="review_request"&&e.review?o(k,{children:[o("div",{className:`sc-row sc-row--${l}`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(pa,{message:e,shopOwnerName:it,listing:$t,preview:c==="agent",onState:(d,m)=>Un?.(e.id,d,m),onAway:c==="merchant"?d=>Mt?.(e.id,"review_away",d):void 0})})]}),yt(e,l)]}):e.kind==="subscription"&&e.subscriptionId&&ot||e.kind==="link"&&e.link||e.kind==="pricing"&&e.pricing||e.kind==="offer"&&e.offerId&&ot?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),l==="agent"&&e.from==="agent"&&s(Ct,{name:e.agentName??"Stefan",size:28}),c==="agent"&&e.from==="agent"&&s("span",{className:"sc-own-avatar",children:s(Ct,{name:e.agentName??"Stefan",size:28})}),s(It,{viewer:c,message:e,children:s(Kn,{value:Os(e.id),children:e.kind==="link"&&e.link?s(ma,{link:e.link}):e.kind==="pricing"&&e.pricing?s(ka,{pricing:e.pricing}):e.kind==="offer"&&e.offerId?s(Gn,{refId:`offer-${e.offerId}`}):s(Gn,{refId:e.subscriptionId})})})]}),o("div",{className:"sc-meta",style:{textAlign:l==="merchant"?"right":"left",paddingLeft:l==="agent"&&e.from==="agent"?36:0,paddingRight:c==="agent"&&e.from==="agent"?36:0},children:[je(e),e.from==="agent"&&e.agentName?`${e.agentName} \xB7 `:"",F(e.at)]})]}):(()=>{const d=mn(V[n-1],t),m=mn(t,V[n+1]),h=e.from==="agent",v=`sc-bubble${h?" sc-bubble--card":""}${e.bot?" sc-bubble--ai":""}${d?" sc-bubble--after":""}${m?" sc-bubble--before":""}`,I=(()=>{for(let u=n-1;u>=0;u--){const N=V[u].message;if(N&&N.kind!=="note")return N}return null})(),B=!!(I&&I.from==="agent"&&I.agentName===e.agentName&&Date.parse(e.at)-Date.parse(I.at)<Na&&Y(I.at)===Y(e.at)),b=h&&!B?o("header",{className:"ho-head sc-card-head",children:[s(Ct,{name:e.agentName??"Stefan",size:30}),o("div",{children:[o("strong",{children:[e.agentName??"Stefan",e.bot&&s("em",{className:"sc-ai-label",children:"AI"})]}),s("span",{children:r(e.bot?"supportChat.ai.byline":"supportChat.preview.fromTeam",$a())})]})]}):null,R=c==="agent"&&e.bot&&e.verified?s("div",{className:"sc-verified",children:r("supportChat.verified.checked",{text:e.verified})}):null,vt=e.bot&&(e.ai||R)?o(k,{children:[b,e.ai?s(ra,{run:e.ai,detail:c==="agent",since:e.at}):null,R]}):b;return o(k,{children:[o("div",{className:`sc-row sc-row--${l}${d?" sc-row--cont":""}${e.bot?" sc-row--ai":""}`,children:[c==="agent"&&e.from==="merchant"&&X?s("span",{className:"sc-row-av","aria-hidden":!0,children:!m&&s(ua,{shop:X.shop,name:X.name,look:X.look,size:28})}):null,o("div",{className:"sc-msg-stack",children:[(()=>{const u=Qn(e,c);if(!u&&!(c==="agent"&&e.translating))return null;const N=u?.lang??null;return o("div",{className:`sc-translated sc-translated--${l}`,children:[N&&s("span",{className:"sc-translated-flags","aria-hidden":!0,children:u?.kind==="from"?`${qn(N,Xe)} \u203A ${We}`:u?.kind==="to"?`${We} \u203A ${qn(N,Xe)}`:We}),u?u.kind==="from"?r("supportChat.translate.from",{language:_n(u.lang,de.language)}):u.kind==="to"?r("supportChat.translate.sentIn",{language:_n(u.lang,de.language)}):r("supportChat.translate.translated"):r("supportChat.translate.translating"),u&&s("button",{type:"button",onClick:()=>is(e.id),"aria-pressed":Rt.has(e.id),children:r(u.kind==="to"!==Rt.has(e.id)?"supportChat.translate.showTranslation":"supportChat.translate.showOriginal")})]})})(),(e.body||e.bot&&e.ai)&&o("div",{className:"sc-bubble-anchor",children:[(c==="agent"||dt)&&e.kind==="text"&&e.body&&s(_e,{side:l,onReply:()=>Ie(e),onReact:dt?u=>dt(e.id,u):void 0,onEdit:c==="agent"&&ct&&e.from==="agent"&&e.agentName===W?()=>In(e):void 0,onDelete:c==="agent"&&J&&e.from==="agent"&&!e.bot?()=>J(e.id):void 0,copyText:Ke(e,c,Rt.has(e.id)),reacted:e.reactions?.filter(u=>c==="merchant"?u.by.includes("merchant"):W&&u.by.includes(W)).map(u=>u.emoji)}),s(va.Provider,{value:c==="agent"?ss(e):null,children:ot?s(fa,{text:Ke(e,c,Rt.has(e.id)),bubbleClass:v,head:o(k,{children:[vt,En(e)]}),links:e.refs,image:Xt}):o("div",{className:v,children:[vt,En(e),s(Ve,{text:Ke(e,c,Rt.has(e.id)),inline:cn,image:Xt})]})})]}),e.id===xs&&o("div",{className:"sc-human",children:[s(Ks,{size:15}),r("supportChat.preview.helpPerks")]}),e.reactions?.length?s("div",{className:"sc-reacts",children:e.reactions.map(u=>o("button",{type:"button",className:`sc-react${(c==="merchant"?u.by.includes("merchant"):W&&u.by.includes(W))?" sc-react--mine":""}`,title:u.by.map(N=>N==="merchant"?c==="merchant"?r("supportChat.msg.you"):X?.name??r("supportChat.msg.merchant"):N).join(", "),disabled:!dt,onClick:()=>dt&&void dt(e.id,u.emoji),children:[u.emoji,u.by.length>1&&s("span",{children:u.by.length})]},u.emoji))}):null,e.bot&&e.progress?.length?s(ia,{steps:e.progress}):null,es&&e.bot&&c==="agent"?s("div",{className:"sc-visitor-cta",children:s("span",{children:r("supportChat.visitor.ctaShown")})}):null,e.bot&&e.assigned?o("div",{className:"sc-assigned",children:[s(Ct,{name:e.assigned,size:20}),s("span",{children:r("supportChat.ai.assigned",{name:e.assigned})})]}):null,e.choices?.length?s(oa,{choices:e.choices,active:c==="merchant"&&e.id===Ls&&dn.length===0,picked:Rs(e.id),onPick:Ts}):null,Et(e).length&&z?s(Wn,{files:Et(e),fileUrl:z,fetchFile:jt}):null]})]}),c==="agent"&&e.clicks?.some(u=>u.action==="link"&&!/^https?:/.test(u.detail??""))&&(()=>{const u=e.clicks.filter(N=>N.action==="link"&&!/^https?:/.test(N.detail??""));return s("div",{className:"sc-link-opened",title:u.map(N=>`${F(N.at)} ${N.detail??""}`).join(`
|
|
6
|
-
`),children:r("supportChat.msg.linkOpened",{time:F(u[0].at),count:u.length})})})(),!m&&o("div",{className:"sc-meta",style:{textAlign:l==="merchant"?"right":"left"},children:[je(e),e.email?`${r("supportChat.email.via")} \xB7 `:"",F(e.at),e.editedAt?` \xB7 ${r("supportChat.edit.edited")}`:"",e.email&&!e.email.verified&&c==="agent"?s("span",{className:"sc-meta-warn",children:` \xB7 ${r("supportChat.email.unverified")}`}):null]})]})})()]},e.id)}),dn.filter(t=>!(t.status==="sending"&&rs(t))).map(t=>o("div",{className:`sc-out${t.status==="failed"?" sc-out--failed":""}`,children:[s("div",{className:"sc-row sc-row--merchant",children:s("div",{className:"sc-msg-stack",children:s("div",{className:t.note?"sc-note":"sc-bubble",children:s(Ve,{image:Xt,text:t.card?r("supportChat.outbox.card",{card:r(`supportChat.inbox.tabs.${t.card.kind}`)}):t.body||r("supportChat.outbox.files",{count:t.files.length})})})})}),s("div",{className:`sc-meta sc-out-meta${t.status==="sending"?" sc-out-meta--sending":""}`,role:t.status==="failed"?"alert":void 0,children:t.status==="sending"?r("supportChat.outbox.sending"):o(k,{children:[r("supportChat.outbox.failed"),s("button",{type:"button",onClick:()=>Wt(t),children:r("supportChat.outbox.resend")})]})})]},t.key)),C&&o("div",{className:"sc-row sc-row--agent sc-typing-row",role:"status","aria-live":"polite",children:[C.agent&&s(Ct,{name:C.name,size:28}),o("div",{className:`sc-typing${C.text?" sc-typing--peek":""}`,children:[C.text?o(k,{children:[o("span",{className:"sc-typing-label",children:[r("supportChat.typing.peek",{name:C.name}),C.agent&&s("em",{className:`sc-typing-kind${C.note?" sc-typing-kind--note":""}`,children:r(C.note?"supportChat.typing.note":"supportChat.typing.reply")})]}),s("span",{className:"sc-typing-text",children:C.text.length>400?`...${C.text.slice(-400)}`:C.text})]}):o("span",{className:"sc-typing-label",children:[r("supportChat.typing.dots",{name:C.name}),C.agent&&s("em",{className:`sc-typing-kind${C.note?" sc-typing-kind--note":""}`,children:r(C.note?"supportChat.typing.note":"supportChat.typing.reply")})]}),o("span",{className:"sc-dots","aria-hidden":!0,children:[s("i",{}),s("i",{}),s("i",{})]})]})]}),s("div",{ref:us})]})]}),D&&o("div",{className:"sc-note-bar sc-edit-bar",role:"status",children:[s("span",{children:r(c==="agent"?"supportChat.edit.modeAgent":"supportChat.edit.mode",{key:ke})}),s("button",{type:"button",onClick:Be,children:r("supportChat.edit.cancel")})]}),L&&o("div",{className:"sc-note-bar sc-edit-bar sc-draft-bar",role:"status",children:[s("span",{children:r("supportChat.draft.editing",{name:L.name,key:ke})}),o("span",{className:"sc-draft-bar-actions",children:[s("button",{type:"button",onClick:Jt,children:r("supportChat.draft.cancelEdits")}),s("button",{type:"button",className:"sc-draft-update",disabled:!g.trim(),onClick:()=>{const t=g.trim();t&&Nt&&L&&Nt(L.id,"update",t),Jt()},children:r("supportChat.draft.update")})]})]}),Pt&&!D&&!L&&o("div",{className:"sc-replying",role:"status",children:[s("span",{className:"sc-replying-bar","aria-hidden":!0}),o("span",{className:"sc-replying-text",children:[s("strong",{children:r("supportChat.msg.replyingTo",{name:Pn(Pt)})}),s("span",{children:Pt.body.replace(/\s+/g," ").slice(0,140)})]}),s("button",{type:"button","aria-label":r("supportChat.msg.cancelReply"),onClick:()=>Ee(null),children:"\xD7"})]}),q&&!D&&!L&&o("div",{className:"sc-mode",role:"tablist","aria-label":r("supportChat.note.label"),children:[s("button",{type:"button",role:"tab","aria-selected":!x,onClick:()=>{St(!1),et(!0)},children:r("supportChat.note.tabReply")}),s("button",{type:"button",role:"tab","aria-selected":x,className:"sc-mode-note",onClick:()=>{St(!0),et(!1)},children:r("supportChat.note.tabNote")})]}),!D&&!L&&!Tt&&(x||(ht||Gt)&&Kt)&&s("div",{className:`sc-note-bar${x?"":" sc-note-bar--reply"}`,role:"status",children:x?o(k,{children:[s("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:s("path",{d:"M6 9V7a4 4 0 1 1 8 0v2M5 9h10v8H5z",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinejoin:"round"})}),s("span",{children:vn.length||ht?r("supportChat.note.mode",{names:vn.join(` ${r("supportChat.note.and")} `)||ht}):r("supportChat.note.modeTeam")}),s("button",{type:"button",onClick:()=>et(!0),children:r("supportChat.note.sendAsReply")})]}):o(k,{children:[s("span",{children:r("supportChat.note.replyMode")}),s("button",{type:"button",onClick:()=>et(!1),children:r("supportChat.note.makeNote")})]})}),H!==null&&o("div",{className:"sc-shortcuts sc-refpick",role:"listbox","aria-label":r("supportChat.refPick.hint"),children:[Q&&s("button",{type:"button",className:"sc-refpick-back",onMouseDown:t=>t.preventDefault(),onClick:()=>At(null),children:r("supportChat.refPick.back")}),nt.data?Ut.length===0?s("p",{className:"sc-refpick-note",children:r("supportChat.refPick.none")}):Ut.map(t=>o(He,{children:[t.section&&s("span",{className:"sc-refpick-section",children:t.section}),o("button",{type:"button",role:"option","aria-selected":!1,onMouseDown:n=>n.preventDefault(),onClick:t.pick,children:[s("span",{className:"sc-refpick-thumb",children:t.image?s("img",{src:t.image,alt:""}):null}),o("span",{className:"sc-shortcut-text",children:[s("strong",{children:t.label}),t.sub&&s("span",{children:t.sub})]})]})]},t.key)):s("p",{className:"sc-refpick-note",children:r("supportChat.refPick.searching")})]}),P.length>0&&s("div",{className:"sc-shortcuts sc-link-suggest",role:"listbox","aria-label":r("supportChat.links.button"),children:P.map((t,n)=>s("button",{type:"button",role:"option","aria-selected":n===Math.min(Le,P.length-1),className:n===Math.min(Le,P.length-1)?"sc-shortcut--on":void 0,onMouseDown:a=>a.preventDefault(),onMouseEnter:()=>Re(n),onClick:()=>wn(t),children:o("span",{className:"sc-shortcut-text",children:[s("strong",{children:t.label}),s("span",{children:t.url.replace(/^https:\/\//,"")})]})},`${t.group}-${t.url}`))}),ft.length>0&&s("div",{className:"sc-shortcuts",role:"listbox","aria-label":r("supportChat.tools.shortcuts"),children:ft.map(t=>o("button",{type:"button",role:"option","aria-selected":!1,onMouseDown:n=>n.preventDefault(),onClick:()=>Cn(t),children:[o("span",{className:"sc-shortcut-key",children:["!",t.key]}),o("span",{className:"sc-shortcut-text",children:[o("strong",{children:[t.title,t.card&&s("em",{className:"sc-shortcut-card",children:r(`supportChat.inbox.tabs.${t.card.kind}`)})]}),s("span",{children:we(t.body)})]})]},t.key))}),_.length>0&&s("div",{className:"sc-suggest",role:"listbox","aria-label":r("supportChat.note.suggest"),children:_.map(t=>o("button",{type:"button",role:"option","aria-selected":t===$e,onMouseDown:n=>n.preventDefault(),onMouseEnter:()=>Ce(_.indexOf(t)),onClick:()=>Sn(t),children:[s(Ct,{name:t,size:22}),t]},t))}),(()=>{const t=[...Se.filter(n=>g.includes(n.text)).map(n=>({text:n.text,ref:n.ref})),...[...new Set(g.match(/#[A-Za-z]{0,6}\d{3,20}[A-Za-z]{0,6}\b/g)??[])].map(n=>({text:n,ref:n.slice(1)}))];return t.length&&ee&&!S?s("div",{className:"sc-draft-refs",children:t.map(n=>o("span",{className:"sc-draft-ref",children:[s(ha,{refId:n.ref,text:n.text}),s("button",{type:"button","aria-label":r("supportChat.files.remove"),onClick:()=>{A(a=>a.split(n.text).join("").replace(/ {2,}/g," ")),Qt(a=>a.filter(i=>i.ref!==n.ref))},children:s("svg",{viewBox:"0 0 20 20",width:"9",height:"9","aria-hidden":!0,children:s("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round"})})})]},n.ref))}):null})(),Dt.some(t=>!t.inline||t.error)&&s(Ws,{files:Dt.filter(t=>!t.inline||t.error),removeLabel:r("supportChat.files.remove"),onRemove:t=>E(n=>n.filter(a=>a.key!==t))}),Lt&&o("div",{className:"sc-attached-card",children:[s("span",{children:r("supportChat.outbox.card",{card:r(`supportChat.inbox.tabs.${Lt.kind}`)})}),s("button",{type:"button","aria-label":r("supportChat.outbox.removeCard"),onClick:()=>pe(null),children:s("svg",{viewBox:"0 0 20 20",width:"10",height:"10","aria-hidden":!0,children:s("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round"})})})]}),o("div",{ref:Vt,className:`sc-composer${ae?" sc-composer--top":""}${M?M.text?" sc-composer--cardtext":" sc-composer--card":""}${x&&!L?" sc-composer--note":""}${L?" sc-composer--draft":""}${Ht?" sc-composer--menu":""}${Ht&&ts?" sc-composer--plus":""}${me&&!M?" sc-composer--multi":""}`,children:[ae&&s("div",{className:"sc-composer-top",children:ae}),M&&!M.text&&M.label&&s("span",{className:"sc-composer-cardnote",children:M.label}),Ht&&o(k,{children:[s("button",{type:"button",className:"sc-plus","aria-label":r("supportChat.menu.open"),"aria-expanded":Ln,onClick:()=>De(t=>!t),children:s("svg",{viewBox:"0 0 20 20",width:"20",height:"20","aria-hidden":!0,children:s("path",{d:"M10 4v12M4 10h12",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round"})})}),Ln&&o(k,{children:[s("div",{className:"sc-menu-scrim",onClick:()=>De(!1),"aria-hidden":!0}),s("div",{className:"sc-menu",role:"menu",children:[...U?[{key:"camera",label:r("supportChat.menu.camera"),icon:s(te,{d:"M4 7.5h2.6l1.4-2h4l1.4 2H16a1 1 0 0 1 1 1V15a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V8.5a1 1 0 0 1 1-1z M10 13.6a2.6 2.6 0 1 0 0-5.2 2.6 2.6 0 0 0 0 5.2z"}),onSelect:()=>Rn.current?.click()},{key:"files",label:r("supportChat.menu.files"),icon:s(te,{d:"M13.5 6.5l-6 6a1.8 1.8 0 0 0 2.5 2.5l6.2-6.2a3.3 3.3 0 0 0-4.7-4.7L5.3 10.3a4.8 4.8 0 0 0 6.8 6.8l5.4-5.4"}),onSelect:()=>Pe.current?.click()}]:[],...ut?[{key:"hash",label:r("supportChat.tools.hash"),icon:s(te,{d:"M8 3.5 6.5 16.5M13.5 3.5 12 16.5M4 7.5h12.5M3.5 12.5H16"}),onSelect:()=>Yt("#")}]:[],...lt.length?[{key:"slash",label:r("supportChat.tools.slash"),icon:s(te,{d:"M11.8 6.5 8.2 13.5 M6.5 3h7a3.5 3.5 0 0 1 3.5 3.5v7a3.5 3.5 0 0 1-3.5 3.5h-7A3.5 3.5 0 0 1 3 13.5v-7A3.5 3.5 0 0 1 6.5 3z"}),onSelect:()=>Yt("!")}]:[],...Ht].map(t=>o("button",{type:"button",role:"menuitem","data-key":t.key,onClick:()=>{De(!1),t.onSelect()},children:[s("span",{className:"sc-menu-icon",children:t.icon}),t.label]},t.key))})]}),U&&s("input",{ref:Rn,type:"file",accept:"image/*",capture:"environment",hidden:!0,onChange:t=>{t.target.files&&Ot(t.target.files),t.target.value=""}})]}),at==="link"&&pt&&s(Js,{load:pt,onClose:()=>kt(null),onPick:t=>{if(kt(null),S)w.current?.insertLink(t.url);else{const n=O.current,a=n?g.slice(n.selectionStart,n.selectionEnd):"";Tn(`${qe(t.url,a.includes(`
|
|
7
|
-
`)?"":a)} `)}}}),(at==="emoji"||at==="gif"&&re)&&s(
|
|
8
|
-
`))return;t.preventDefault();const e=qe(a,i),l=n.selectionStart,d=`${n.value.slice(0,l)}${e}${n.value.slice(n.selectionEnd)}`;A(d.slice(0,4e3)),requestAnimationFrame(()=>n.setSelectionRange(l+e.length,l+e.length))},ref:O,onScroll:t=>Ae.current&&(Ae.current.scrollTop=t.currentTarget.scrollTop),rows:1,value:g,maxLength:4e3,placeholder:r(c==="merchant"?"supportChat.placeholder":x?"supportChat.note.notePlaceholder":lt.length?"supportChat.tools.placeholder":q?"supportChat.note.placeholder":"supportChat.agentPlaceholder"),onChange:t=>A(t.target.value),onKeyDown:t=>{Mn(t.nativeEvent)?t.preventDefault():t.key==="Enter"&&!t.nativeEvent.isComposing&&
|
|
5
|
+
${d}${g.slice(a)}`,h=l?i:a+1+d.length;A(m),requestAnimationFrame(()=>n.setSelectionRange(h,h))},[at,kt]=f(null),[Ln,De]=f(!1),Rn=y(null),Tn=t=>{if(S)return w.current?.insertText(t);const n=O.current,a=n?.selectionStart??g.length,i=n?.selectionEnd??a;A(e=>e.slice(0,a)+t+e.slice(i)),window.requestAnimationFrame(()=>{n?.focus(),n?.setSelectionRange(a+t.length,a+t.length)})},Sn=t=>{S?w.current?.replaceBefore($.match(/@[\p{L}]*$/u)?.[0].length??0,`@${t} `):A(n=>n.replace(/@[\p{L}]*$/u,`@${t} `)),O.current?.focus()},[Dt,E]=f([]),[An,Oe]=f(!1),Pe=y(null),Dn=Dt.some(t=>!t.ref&&!t.error),Cs=Dt.filter(t=>t.ref).map(t=>t.ref.id),$s=t=>Dt.filter(n=>n.ref&&(!n.inline||t.includes(`file:${n.ref.id}`))).map(n=>n.ref.id),U=!!(Ze||Ft),Ot=(t,n=!1)=>{if(U)for(const a of Array.from(t).slice(0,10)){const i=`${Date.now()}-${Math.random().toString(36).slice(2)}`,e=Fs(a.name,a.type),l=e===a.type?a:new File([a],a.name,{type:e}),d=ze[l.type]?l.size>js(l.type)?r("supportChat.files.tooBig",{max:Hs(l.type)}):void 0:r("supportChat.files.notAllowed"),m=!d&&l.type.startsWith("image/")?URL.createObjectURL(l):null,h=!!(n&&S&&m&&Ft&&w.current),v=l.name||"screenshot.png";if(E(b=>[...b,{key:i,name:v,size:l.size,type:l.type,preview:m,error:d,...h?{inline:!0}:{}}]),d)continue;h&&w.current.insertImage(i,v,m);const I=(b,R)=>{h&&(b?w.current?.setImageId(i,b.id):w.current?.removeImage(i)),E(vt=>vt.map(u=>u.key===i?b?{...u,ref:b}:{...u,error:R??r("supportChat.files.failed")}:u))};if(Ft){Ft(l).then(b=>I(b),()=>I());continue}const B=new FormData;for(const[b,R]of Object.entries(Qe??{}))B.append(b,R);B.append("file",l,l.name||"screenshot.png"),fetch(Ze,{method:"POST",body:B}).then(async b=>({ok:b.ok,body:await b.json().catch(()=>({}))})).then(({ok:b,body:R})=>E(vt=>vt.map(u=>u.key===i?b&&R.file?{...u,ref:R.file}:{...u,error:R.error??r("supportChat.files.failed")}:u))).catch(()=>E(b=>b.map(R=>R.key===i?{...R,error:r("supportChat.files.failed")}:R)))}},Ns=t=>{if(!oe&&!ne)return;kt(null);const n=`gif-${t.id}-${Date.now()}`;if(E(i=>[...i,{key:n,name:t.title||"GIF",size:0,type:"image/gif",preview:t.preview}]),ne){ne(t.id).then(i=>E(e=>e.map(l=>l.key===n?{...l,ref:i,size:i.size}:l)),()=>E(i=>i.map(e=>e.key===n?{...e,error:r("supportChat.files.failed")}:e)));return}if(!oe)return;const a=new FormData;for(const[i,e]of Object.entries(Qe??{}))a.append(i,e);a.append("id",t.id),fetch(oe,{method:"POST",body:a}).then(async i=>({ok:i.ok,body:await i.json().catch(()=>({}))})).then(({ok:i,body:e})=>E(l=>l.map(d=>d.key===n?i&&e.file?{...d,ref:e.file,size:e.file.size}:{...d,error:e.error??r("supportChat.files.failed")}:d))).catch(()=>E(i=>i.map(e=>e.key===n?{...e,error:r("supportChat.files.failed")}:e)))},ws=()=>[...p].reverse().find(t=>t.from==="agent"&&t.agentName===W&&(t.kind==="text"||t.kind==="note")&&t.id!=="pending")??null,[Pt,Ee]=f(null),[xs,On]=f(!1),Ie=t=>{Ee(t),S?w.current?.focus?.():O.current?.focus()},rt=(t,n)=>c==="agent"&&t.from==="agent"?s(_e,{inline:!0,side:n,onReply:()=>Ie(t),onDelete:J?()=>J(t.id):void 0}):null,Pn=t=>t.from==="merchant"?c==="merchant"?r("supportChat.msg.you"):X?.name??r("supportChat.msg.merchant"):t.bot?Zn().brand.bot:t.author??t.agentName??Zn().brand.team,En=t=>t.replyTo?o("button",{type:"button",className:"sc-quote",onClick:()=>document.querySelector(`[data-msg="${CSS.escape(t.replyTo.id)}"]`)?.nextElementSibling?.scrollIntoView({behavior:"smooth",block:"center"}),children:[s("strong",{children:Pn({from:t.replyTo.from,author:t.replyTo.author==="merchant"?void 0:t.replyTo.author})}),s("span",{children:t.replyTo.excerpt})]}):null,In=t=>{ue(null),zt(t.id),j(t.body,t.refs),O.current?.focus()},Be=()=>{zt(null),j("")},Jt=()=>{ue(null),j("")},Bn=()=>{const t=g.trim();if(M){if(M.blocked)return;M.send(t),j("");return}if(D){t&&ct&&ct(D,t),Be();return}if(L){t&&Nt&&Nt(L.id,"send",t),Jt();return}const n=$s(t);if(!t&&!n.length&&!Lt||Dn)return;const a=Lt;pe(null),(t||n.length)&&Wt({key:`${Date.now()}-${Math.random()}`,body:t,files:n,refs:Se.filter(i=>t.includes(i.text)),note:!!(x&&Bt),...Pt?{replyTo:Pt.id}:{},status:"sending"}),Ee(null),a&&Wt({key:`${Date.now()}-card`,body:"",files:[],note:!1,card:a,status:"sending"}),Qt([]),j(""),et(!1),Zt.current&&(Zt.current=!1,St(!1)),E([])},Ms=p.find(t=>t.from==="agent"&&!t.bot&&!t.deletedAt&&t.kind!=="note"&&t.kind!=="draft"&&t.kind!=="event")?.id??null,Xt=z?(t,n,a)=>s(zs,{id:t,name:n,url:z(t),load:jt},a):void 0,Et=t=>{const n=na(t.body);return(t.files??[]).filter(a=>!n.has(a.id))},Fe=[];if(z){for(const t of p)if(!(t.deletedAt||t.kind==="event")){for(const n of(t.body??"").matchAll(ea))Fe.push({id:n[2],name:n[1]||"Image",type:"image/png",url:z(n[2])});for(const n of Et(t))(n.type.startsWith("image/")||n.type.startsWith("video/"))&&Fe.push({id:n.id,name:n.name,type:n.type,url:z(n.id)})}}const Ls=t=>t==="system"?"system":t===c?"merchant":"agent",ot=ee?{previewUrl:ee,open:Jn}:null,bt=p.filter(t=>t.kind!=="note").filter(t=>t.kind!=="event"&&t.kind!=="draft"),Rs=bt[bt.length-1]?.id??null,Ts=t=>{const n=bt.findIndex(a=>a.id===t);return bt.slice(n+1).find(a=>a.from==="merchant")?.body??null},Ss=t=>Wt({key:`${Date.now()}-choice`,body:t,files:[],note:!1,status:"sending"}),Fn=c==="merchant"?"merchant":"agent",jn=[...bt].reverse().find(t=>t.from===Fn)?.id??null,As=xt?Date.parse(xt):NaN,Ds=[...bt].reverse().find(t=>t.from===Fn&&t.id!=="pending"&&Date.parse(t.at)<=As)?.id??null,Os=t=>{if(t.id===Ds&&t.id!==jn){const B=r("supportChat.receipts.seen");return o("span",{className:"sc-receipt sc-receipt--seen","data-tip":`${B} ${F(xt)}`,children:[o("svg",{viewBox:"0 0 18 14",width:"17",height:"13","aria-hidden":!0,children:[s("path",{d:"M1.5 7.5l3.2 3.2L11 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"}),s("path",{d:"M8.2 10.7L14.6 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})]}),s("span",{className:"sc-receipt-label",children:B})]})}if(t.id!==jn||t.id==="pending")return null;const n=B=>!!(B&&Date.parse(B)>=Date.parse(t.at)),a=c==="agent"&&ie&&n(ie.at)?ie:null,i=a?a.clickedAt??a.openedAt??null:null,e=c==="agent"&&!a&&n(Je)?Je:null,l=n(xt)?{kind:"seen",at:xt}:i?{kind:"emailOpened",at:i}:n(Ye)?{kind:"delivered",at:Ye}:a?.status==="sent"||e?{kind:"emailed",at:a?.at??e}:{kind:a?.status==="held"||a?.status==="failed"?"held":"sent",at:t.at},d=l.kind==="held"&&a?.status==="failed",m=r(`supportChat.receipts.${l.kind==="held"?a?.status==="failed"?"emailFailed":"emailHeld":l.kind}`),h=l.kind!=="sent"&&l.kind!=="held",v=o("svg",{viewBox:"0 0 18 14",width:"17",height:"13","aria-hidden":!0,children:[s("path",{d:h?"M1.5 7.5l3.2 3.2L11 4.2":"M3.5 7.5l3.2 3.2L13 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round"}),h&&s("path",{d:"M8.2 10.7L14.6 4.2",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round"})]}),I=l.kind==="seen"||l.kind==="emailOpened"?`${m} ${F(l.at)}`:void 0;return o("span",{className:`sc-receipt sc-receipt--${l.kind}${d?" sc-receipt--failed":""}`,"data-tip":l.kind==="emailOpened"?`${I}. ${r("supportChat.receipts.openNote")}`:I,children:[v,s("span",{className:"sc-receipt-label",children:m}),d&&sn&&s("button",{type:"button",className:"sc-resend",disabled:xs,onClick:()=>{On(!0),sn().finally(()=>On(!1))},children:r("supportChat.receipts.resend")})]})},je=t=>{const n=Os(t);return n?o(k,{children:[n," \xB7 "]}):null},yt=(t,n)=>o("div",{className:"sc-meta",style:{textAlign:n==="merchant"?"right":"left"},children:[je(t),t.from==="agent"&&t.agentName?`${t.agentName} \xB7 `:"",F(t.at)]}),Ps=t=>{if(!ot)return null;const n=ot.open;return{...ot,open:n?a=>{Mt?.(t,"open"),n(a)}:void 0}};return s(Ws,{items:Fe,load:jt,children:s(va.Provider,{value:ss,children:s(Kn,{value:ot,children:o("div",{className:`sc-shell sc-shell--${c}${An?" sc-shell--drop":""}${ln.className}`,style:ln.style,onDragOver:t=>{!U||!t.dataTransfer.types.includes("Files")||(t.preventDefault(),Oe(!0))},onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)||Oe(!1)},onDrop:t=>{U&&(t.preventDefault(),Oe(!1),Ot(t.dataTransfer.files,!0))},children:[An&&s("div",{className:"sc-drop",children:r("supportChat.files.drop")}),o("div",{className:"sc-thread","aria-live":"polite",ref:tt,onScroll:t=>{const n=t.currentTarget;gt.current=n.scrollHeight-n.scrollTop-n.clientHeight<40,gt.current&&kn&&ye(!1),_t.current=n.scrollHeight,fn()},children:[s("div",{className:"sc-newbelow-wrap",children:kn&&o("button",{type:"button",className:"sc-newbelow",onClick:yn,children:[r("supportChat.msg.newBelow")," \u2193"]})}),o("div",{className:"sc-content",ref:hn,children:[c==="merchant"&&G&&p.length>0&&s(Vn,{availability:G}),c==="merchant"&&G&&p.length>0&&s(_s,{availability:G,recentReply:p.some(t=>t.from==="agent"&&!t.bot&&Date.now()-Date.parse(t.at)<30*6e4)}),rn&&s("div",{className:"sc-actions-status",children:rn}),p.length===0&&o("div",{className:"sc-empty",children:[s("strong",{children:r("supportChat.emptyTitle")}),r(G?"supportChat.emptyBodyShort":"supportChat.emptyBody"),G&&o("div",{className:"sc-empty-card",children:[s(Vn,{availability:G}),s(qs,{availability:G})]})]}),V.map((t,n)=>{const a=V[n-1]?.at,i=(!a||Y(a)!==Y(t.at))&&s("div",{className:"sc-day",children:new Date(t.at).toLocaleDateString([],{weekday:"short",day:"numeric",month:"short"})});if(t.group)return o("div",{style:{display:"contents"},children:[i,s("i",{className:"sc-at","data-at":t.at}),s(ca,{actions:t.group,store:X})]},`a-${t.group[0].id}`);const e=t.message,l=Ls(e.from);return o("div",{style:{display:"contents"},onClickCapture:c==="merchant"&&e.from==="agent"&&e.kind==="text"?d=>{const m=d.target.closest?.("a[href]");m&&/^https?:/.test(m.href)&&Mt?.(e.id,"link",m.href.slice(0,300))}:void 0,children:[i,s("i",{className:"sc-at","data-at":e.at,"data-msg":e.id}),e.deletedAt?c==="agent"?o("div",{className:`sc-deleted sc-deleted--${l}`,children:[s("s",{children:e.body.length>120?`${e.body.slice(0,117)}...`:e.body}),s("span",{children:r("supportChat.msg.deletedBy",{name:e.deletedBy??""})}),en&&s("button",{type:"button",className:"sc-deleted-undo",onClick:()=>{en(e.id)},children:r("supportChat.msg.undoDelete")})]}):null:e.kind==="draft"?c==="agent"?s(ua,{message:e,time:F(e.at),onDraft:Nt,editing:L?.id===e.id,onEdit:()=>{zt(null),ue({id:e.id,name:e.agentName??"Claude"}),j(e.body)}}):null:e.kind==="event"?c==="agent"?s(da,{message:e,time:F(e.at)}):null:e.kind==="note"?c==="agent"?o("div",{className:`sc-note${e.reminder?" sc-note--reminder":""}`,"aria-label":r(e.reminder?"supportChat.reminders.noteLabel":"supportChat.note.label"),children:[o("div",{className:"sc-note-head",children:[s("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:s("path",{d:"M4.5 3.5h11v8l-4 4.5h-7zM11.5 16v-4.5h4M7.5 7.5h5M7.5 10.5h2.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),r(e.reminder?"supportChat.reminders.noteTitle":"supportChat.note.title",{name:e.agentName??""}),e.from==="agent"&&!e.reminder&&(J||ct)?s(_e,{inline:!0,side:"agent",onReply:()=>Ie(e),onEdit:ct&&e.agentName===W?()=>In(e):void 0,onDelete:J?()=>J(e.id):void 0,copyText:e.body}):null,o("span",{children:[F(e.at),e.editedAt?` \xB7 ${r("supportChat.edit.edited")}`:""]})]}),s("div",{className:"sc-note-body",children:s(Ve,{text:e.body,image:Xt,inline:(d,m)=>zn(d,K.length?K:e.mentions??[]).map((h,v)=>h.agent?o("span",{className:"sc-mention",children:["@",h.agent]},`${m}-${v}`):s(He,{children:cn(h.text,`${m}-${v}`)},`${m}-${v}`))})}),Et(e).length&&z?s(Wn,{files:Et(e),fileUrl:z,fetchFile:jt}):null]}):null:l==="system"?s("div",{className:"sc-system",children:e.body}):e.kind==="password_request"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(Zs,{message:e,onOpen:c==="merchant"?()=>Mt?.(e.id,"open"):void 0})})]}),yt(e,l)]}):e.kind==="feature_request"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(Qs,{message:e,onAdd:c==="merchant"&&an?()=>an(e.id):void 0})})]}),yt(e,l)]}):e.kind==="ticket"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(Us,{message:e})]}),yt(e,l)]}):e.kind==="custom"&&e.card?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(ma,{tree:e.card.tree,name:e.card.name})]}),yt(e,l)]}):e.kind==="help_offer"?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(Ks,{message:e,answered:p.slice(p.indexOf(e)+1).some(d=>d.from==="merchant"),onAnswer:c==="merchant"?d=>{Mt?.(e.id,d===r("supportChat.helpOffer.yesMessage")?"help_yes":"help_no"),Ge(d,[])}:void 0})})]}),yt(e,l)]}):e.kind==="review_request"&&e.review?o(k,{children:[o("div",{className:`sc-row sc-row--${l}`,children:[rt(e,l),s(It,{viewer:c,message:e,children:s(ga,{message:e,shopOwnerName:it,listing:$t,preview:c==="agent",onState:(d,m)=>Un?.(e.id,d,m),onAway:c==="merchant"?d=>Mt?.(e.id,"review_away",d):void 0})})]}),yt(e,l)]}):e.kind==="subscription"&&e.subscriptionId&&ot||e.kind==="link"&&e.link||e.kind==="pricing"&&e.pricing||e.kind==="offer"&&e.offerId&&ot?o(k,{children:[o("div",{className:`sc-row sc-row--${l} sc-row--card`,children:[rt(e,l),l==="agent"&&e.from==="agent"&&s(Ct,{name:e.agentName??"Stefan",size:28}),c==="agent"&&e.from==="agent"&&s("span",{className:"sc-own-avatar",children:s(Ct,{name:e.agentName??"Stefan",size:28})}),s(It,{viewer:c,message:e,children:s(Kn,{value:Ps(e.id),children:e.kind==="link"&&e.link?s(ha,{link:e.link}):e.kind==="pricing"&&e.pricing?s(ba,{pricing:e.pricing}):e.kind==="offer"&&e.offerId?s(Gn,{refId:`offer-${e.offerId}`}):s(Gn,{refId:e.subscriptionId})})})]}),o("div",{className:"sc-meta",style:{textAlign:l==="merchant"?"right":"left",paddingLeft:l==="agent"&&e.from==="agent"?36:0,paddingRight:c==="agent"&&e.from==="agent"?36:0},children:[je(e),e.from==="agent"&&e.agentName?`${e.agentName} \xB7 `:"",F(e.at)]})]}):(()=>{const d=mn(V[n-1],t),m=mn(t,V[n+1]),h=e.from==="agent",v=`sc-bubble${h?" sc-bubble--card":""}${e.bot?" sc-bubble--ai":""}${d?" sc-bubble--after":""}${m?" sc-bubble--before":""}`,I=(()=>{for(let u=n-1;u>=0;u--){const N=V[u].message;if(N&&N.kind!=="note")return N}return null})(),B=!!(I&&I.from==="agent"&&I.agentName===e.agentName&&Date.parse(e.at)-Date.parse(I.at)<wa&&Y(I.at)===Y(e.at)),b=h&&!B?o("header",{className:"ho-head sc-card-head",children:[s(Ct,{name:e.agentName??"Stefan",size:30}),o("div",{children:[o("strong",{children:[e.agentName??"Stefan",e.bot&&s("em",{className:"sc-ai-label",children:"AI"})]}),s("span",{children:r(e.bot?"supportChat.ai.byline":"supportChat.preview.fromTeam",Na())})]})]}):null,R=c==="agent"&&e.bot&&e.verified?s("div",{className:"sc-verified",children:r("supportChat.verified.checked",{text:e.verified})}):null,vt=e.bot&&(e.ai||R)?o(k,{children:[b,e.ai?s(oa,{run:e.ai,detail:c==="agent",since:e.at}):null,R]}):b;return o(k,{children:[o("div",{className:`sc-row sc-row--${l}${d?" sc-row--cont":""}${e.bot?" sc-row--ai":""}`,children:[c==="agent"&&e.from==="merchant"&&X?s("span",{className:"sc-row-av","aria-hidden":!0,children:!m&&s(pa,{shop:X.shop,name:X.name,look:X.look,size:28})}):null,o("div",{className:"sc-msg-stack",children:[(()=>{const u=Qn(e,c);if(!u&&!(c==="agent"&&e.translating))return null;const N=u?.lang??null;return o("div",{className:`sc-translated sc-translated--${l}`,children:[N&&s("span",{className:"sc-translated-flags","aria-hidden":!0,children:u?.kind==="from"?`${qn(N,Xe)} \u203A ${We}`:u?.kind==="to"?`${We} \u203A ${qn(N,Xe)}`:We}),u?u.kind==="from"?r("supportChat.translate.from",{language:_n(u.lang,de.language)}):u.kind==="to"?r("supportChat.translate.sentIn",{language:_n(u.lang,de.language)}):r("supportChat.translate.translated"):r("supportChat.translate.translating"),u&&s("button",{type:"button",onClick:()=>ls(e.id),"aria-pressed":Rt.has(e.id),children:r(u.kind==="to"!==Rt.has(e.id)?"supportChat.translate.showTranslation":"supportChat.translate.showOriginal")})]})})(),(e.body||e.bot&&e.ai)&&o("div",{className:"sc-bubble-anchor",children:[(c==="agent"||dt)&&e.kind==="text"&&e.body&&s(_e,{side:l,onReply:()=>Ie(e),onReact:dt?u=>dt(e.id,u):void 0,onEdit:c==="agent"&&ct&&e.from==="agent"&&e.agentName===W?()=>In(e):void 0,onDelete:c==="agent"&&J&&e.from==="agent"?()=>J(e.id):void 0,copyText:Ke(e,c,Rt.has(e.id)),reacted:e.reactions?.filter(u=>c==="merchant"?u.by.includes("merchant"):W&&u.by.includes(W)).map(u=>u.emoji)}),s(Ca.Provider,{value:c==="agent"?as(e):null,children:ot?s(ka,{text:Ke(e,c,Rt.has(e.id)),bubbleClass:v,head:o(k,{children:[vt,En(e)]}),links:e.refs,image:Xt}):o("div",{className:v,children:[vt,En(e),s(Ve,{text:Ke(e,c,Rt.has(e.id)),inline:cn,image:Xt})]})})]}),e.id===Ms&&o("div",{className:"sc-human",children:[s(Gs,{size:15}),r("supportChat.preview.helpPerks")]}),e.reactions?.length?s("div",{className:"sc-reacts",children:e.reactions.map(u=>o("button",{type:"button",className:`sc-react${(c==="merchant"?u.by.includes("merchant"):W&&u.by.includes(W))?" sc-react--mine":""}`,title:u.by.map(N=>N==="merchant"?c==="merchant"?r("supportChat.msg.you"):X?.name??r("supportChat.msg.merchant"):N).join(", "),disabled:!dt,onClick:()=>dt&&void dt(e.id,u.emoji),children:[u.emoji,u.by.length>1&&s("span",{children:u.by.length})]},u.emoji))}):null,e.bot&&e.progress?.length?s(la,{steps:e.progress}):null,ns&&e.bot&&c==="agent"?s("div",{className:"sc-visitor-cta",children:s("span",{children:r("supportChat.visitor.ctaShown")})}):null,e.bot&&e.assigned?o("div",{className:"sc-assigned",children:[s(Ct,{name:e.assigned,size:20}),s("span",{children:r("supportChat.ai.assigned",{name:e.assigned})})]}):null,e.choices?.length?s(ia,{choices:e.choices,active:c==="merchant"&&e.id===Rs&&dn.length===0,picked:Ts(e.id),onPick:Ss}):null,Et(e).length&&z?s(Wn,{files:Et(e),fileUrl:z,fetchFile:jt}):null]})]}),c==="agent"&&e.clicks?.some(u=>u.action==="link"&&!/^https?:/.test(u.detail??""))&&(()=>{const u=e.clicks.filter(N=>N.action==="link"&&!/^https?:/.test(N.detail??""));return s("div",{className:"sc-link-opened",title:u.map(N=>`${F(N.at)} ${N.detail??""}`).join(`
|
|
6
|
+
`),children:r("supportChat.msg.linkOpened",{time:F(u[0].at),count:u.length})})})(),!m&&o("div",{className:"sc-meta",style:{textAlign:l==="merchant"?"right":"left"},children:[je(e),e.email?`${r("supportChat.email.via")} \xB7 `:"",F(e.at),e.editedAt?` \xB7 ${r("supportChat.edit.edited")}`:"",e.email&&!e.email.verified&&c==="agent"?s("span",{className:"sc-meta-warn",children:` \xB7 ${r("supportChat.email.unverified")}`}):null]})]})})()]},e.id)}),dn.filter(t=>!(t.status==="sending"&&os(t))).map(t=>o("div",{className:`sc-out${t.status==="failed"?" sc-out--failed":""}`,children:[s("div",{className:"sc-row sc-row--merchant",children:s("div",{className:"sc-msg-stack",children:s("div",{className:t.note?"sc-note":"sc-bubble",children:s(Ve,{image:Xt,text:t.card?r("supportChat.outbox.card",{card:r(`supportChat.inbox.tabs.${t.card.kind}`)}):t.body||r("supportChat.outbox.files",{count:t.files.length})})})})}),s("div",{className:`sc-meta sc-out-meta${t.status==="sending"?" sc-out-meta--sending":""}`,role:t.status==="failed"?"alert":void 0,children:t.status==="sending"?r("supportChat.outbox.sending"):o(k,{children:[r("supportChat.outbox.failed"),s("button",{type:"button",onClick:()=>Wt(t),children:r("supportChat.outbox.resend")})]})})]},t.key)),C&&o("div",{className:"sc-row sc-row--agent sc-typing-row",role:"status","aria-live":"polite",children:[C.agent&&s(Ct,{name:C.name,size:28}),o("div",{className:`sc-typing${C.text?" sc-typing--peek":""}`,children:[C.text?o(k,{children:[o("span",{className:"sc-typing-label",children:[r("supportChat.typing.peek",{name:C.name}),C.agent&&s("em",{className:`sc-typing-kind${C.note?" sc-typing-kind--note":""}`,children:r(C.note?"supportChat.typing.note":"supportChat.typing.reply")})]}),s("span",{className:"sc-typing-text",children:C.text.length>400?`...${C.text.slice(-400)}`:C.text})]}):o("span",{className:"sc-typing-label",children:[r("supportChat.typing.dots",{name:C.name}),C.agent&&s("em",{className:`sc-typing-kind${C.note?" sc-typing-kind--note":""}`,children:r(C.note?"supportChat.typing.note":"supportChat.typing.reply")})]}),o("span",{className:"sc-dots","aria-hidden":!0,children:[s("i",{}),s("i",{}),s("i",{})]})]})]}),s("div",{ref:ps})]})]}),D&&o("div",{className:"sc-note-bar sc-edit-bar",role:"status",children:[s("span",{children:r(c==="agent"?"supportChat.edit.modeAgent":"supportChat.edit.mode",{key:ke})}),s("button",{type:"button",onClick:Be,children:r("supportChat.edit.cancel")})]}),L&&o("div",{className:"sc-note-bar sc-edit-bar sc-draft-bar",role:"status",children:[s("span",{children:r("supportChat.draft.editing",{name:L.name,key:ke})}),o("span",{className:"sc-draft-bar-actions",children:[s("button",{type:"button",onClick:Jt,children:r("supportChat.draft.cancelEdits")}),s("button",{type:"button",className:"sc-draft-update",disabled:!g.trim(),onClick:()=>{const t=g.trim();t&&Nt&&L&&Nt(L.id,"update",t),Jt()},children:r("supportChat.draft.update")})]})]}),Pt&&!D&&!L&&o("div",{className:"sc-replying",role:"status",children:[s("span",{className:"sc-replying-bar","aria-hidden":!0}),o("span",{className:"sc-replying-text",children:[s("strong",{children:r("supportChat.msg.replyingTo",{name:Pn(Pt)})}),s("span",{children:Pt.body.replace(/\s+/g," ").slice(0,140)})]}),s("button",{type:"button","aria-label":r("supportChat.msg.cancelReply"),onClick:()=>Ee(null),children:"\xD7"})]}),q&&!D&&!L&&o("div",{className:"sc-mode-row",children:[o("div",{className:"sc-mode",role:"tablist","aria-label":r("supportChat.note.label"),children:[s("button",{type:"button",role:"tab","aria-selected":!x,onClick:()=>{St(!1),et(!0)},children:r("supportChat.note.tabReply")}),s("button",{type:"button",role:"tab","aria-selected":x,className:"sc-mode-note",onClick:()=>{St(!0),et(!1)},children:r("supportChat.note.tabNote")})]}),Xn]}),!D&&!L&&!Tt&&(x||(ht||Gt)&&Kt)&&s("div",{className:`sc-note-bar${x?"":" sc-note-bar--reply"}`,role:"status",children:x?o(k,{children:[s("svg",{viewBox:"0 0 20 20",width:"13",height:"13","aria-hidden":!0,children:s("path",{d:"M6 9V7a4 4 0 1 1 8 0v2M5 9h10v8H5z",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinejoin:"round"})}),s("span",{children:vn.length||ht?r("supportChat.note.mode",{names:vn.join(` ${r("supportChat.note.and")} `)||ht}):r("supportChat.note.modeTeam")}),s("button",{type:"button",onClick:()=>et(!0),children:r("supportChat.note.sendAsReply")})]}):o(k,{children:[s("span",{children:r("supportChat.note.replyMode")}),s("button",{type:"button",onClick:()=>et(!1),children:r("supportChat.note.makeNote")})]})}),H!==null&&o("div",{className:"sc-shortcuts sc-refpick",role:"listbox","aria-label":r("supportChat.refPick.hint"),children:[Q&&s("button",{type:"button",className:"sc-refpick-back",onMouseDown:t=>t.preventDefault(),onClick:()=>At(null),children:r("supportChat.refPick.back")}),nt.data?Ut.length===0?s("p",{className:"sc-refpick-note",children:r("supportChat.refPick.none")}):Ut.map(t=>o(He,{children:[t.section&&s("span",{className:"sc-refpick-section",children:t.section}),o("button",{type:"button",role:"option","aria-selected":!1,onMouseDown:n=>n.preventDefault(),onClick:t.pick,children:[s("span",{className:"sc-refpick-thumb",children:t.image?s("img",{src:t.image,alt:""}):null}),o("span",{className:"sc-shortcut-text",children:[s("strong",{children:t.label}),t.sub&&s("span",{children:t.sub})]})]})]},t.key)):s("p",{className:"sc-refpick-note",children:r("supportChat.refPick.searching")})]}),P.length>0&&s("div",{className:"sc-shortcuts sc-link-suggest",role:"listbox","aria-label":r("supportChat.links.button"),children:P.map((t,n)=>s("button",{type:"button",role:"option","aria-selected":n===Math.min(Le,P.length-1),className:n===Math.min(Le,P.length-1)?"sc-shortcut--on":void 0,onMouseDown:a=>a.preventDefault(),onMouseEnter:()=>Re(n),onClick:()=>wn(t),children:o("span",{className:"sc-shortcut-text",children:[s("strong",{children:t.label}),s("span",{children:t.url.replace(/^https:\/\//,"")})]})},`${t.group}-${t.url}`))}),ft.length>0&&s("div",{className:"sc-shortcuts",role:"listbox","aria-label":r("supportChat.tools.shortcuts"),children:ft.map(t=>o("button",{type:"button",role:"option","aria-selected":!1,onMouseDown:n=>n.preventDefault(),onClick:()=>Cn(t),children:[o("span",{className:"sc-shortcut-key",children:["!",t.key]}),o("span",{className:"sc-shortcut-text",children:[o("strong",{children:[t.title,t.card&&s("em",{className:"sc-shortcut-card",children:r(`supportChat.inbox.tabs.${t.card.kind}`)})]}),s("span",{children:we(t.body)})]})]},t.key))}),_.length>0&&s("div",{className:"sc-suggest",role:"listbox","aria-label":r("supportChat.note.suggest"),children:_.map(t=>o("button",{type:"button",role:"option","aria-selected":t===$e,onMouseDown:n=>n.preventDefault(),onMouseEnter:()=>Ce(_.indexOf(t)),onClick:()=>Sn(t),children:[s(Ct,{name:t,size:22}),t]},t))}),(()=>{const t=[...Se.filter(n=>g.includes(n.text)).map(n=>({text:n.text,ref:n.ref})),...[...new Set(g.match(/#[A-Za-z]{0,6}\d{3,20}[A-Za-z]{0,6}\b/g)??[])].map(n=>({text:n,ref:n.slice(1)}))];return t.length&&ee&&!S?s("div",{className:"sc-draft-refs",children:t.map(n=>o("span",{className:"sc-draft-ref",children:[s(fa,{refId:n.ref,text:n.text}),s("button",{type:"button","aria-label":r("supportChat.files.remove"),onClick:()=>{A(a=>a.split(n.text).join("").replace(/ {2,}/g," ")),Qt(a=>a.filter(i=>i.ref!==n.ref))},children:s("svg",{viewBox:"0 0 20 20",width:"9",height:"9","aria-hidden":!0,children:s("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round"})})})]},n.ref))}):null})(),Dt.some(t=>!t.inline||t.error)&&s(Vs,{files:Dt.filter(t=>!t.inline||t.error),removeLabel:r("supportChat.files.remove"),onRemove:t=>E(n=>n.filter(a=>a.key!==t))}),Lt&&o("div",{className:"sc-attached-card",children:[s("span",{children:r("supportChat.outbox.card",{card:r(`supportChat.inbox.tabs.${Lt.kind}`)})}),s("button",{type:"button","aria-label":r("supportChat.outbox.removeCard"),onClick:()=>pe(null),children:s("svg",{viewBox:"0 0 20 20",width:"10",height:"10","aria-hidden":!0,children:s("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round"})})})]}),o("div",{ref:Vt,className:`sc-composer${ae?" sc-composer--top":""}${M?M.text?" sc-composer--cardtext":" sc-composer--card":""}${x&&!L?" sc-composer--note":""}${L?" sc-composer--draft":""}${Ht?" sc-composer--menu":""}${Ht&&es?" sc-composer--plus":""}${me&&!M?" sc-composer--multi":""}`,children:[ae&&s("div",{className:"sc-composer-top",children:ae}),M&&!M.text&&M.label&&s("span",{className:"sc-composer-cardnote",children:M.label}),Ht&&o(k,{children:[s("button",{type:"button",className:"sc-plus","aria-label":r("supportChat.menu.open"),"aria-expanded":Ln,onClick:()=>De(t=>!t),children:s("svg",{viewBox:"0 0 20 20",width:"20",height:"20","aria-hidden":!0,children:s("path",{d:"M10 4v12M4 10h12",fill:"none",stroke:"currentColor",strokeWidth:"1.9",strokeLinecap:"round"})})}),Ln&&o(k,{children:[s("div",{className:"sc-menu-scrim",onClick:()=>De(!1),"aria-hidden":!0}),s("div",{className:"sc-menu",role:"menu",children:[...U?[{key:"camera",label:r("supportChat.menu.camera"),icon:s(te,{d:"M4 7.5h2.6l1.4-2h4l1.4 2H16a1 1 0 0 1 1 1V15a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V8.5a1 1 0 0 1 1-1z M10 13.6a2.6 2.6 0 1 0 0-5.2 2.6 2.6 0 0 0 0 5.2z"}),onSelect:()=>Rn.current?.click()},{key:"files",label:r("supportChat.menu.files"),icon:s(te,{d:"M13.5 6.5l-6 6a1.8 1.8 0 0 0 2.5 2.5l6.2-6.2a3.3 3.3 0 0 0-4.7-4.7L5.3 10.3a4.8 4.8 0 0 0 6.8 6.8l5.4-5.4"}),onSelect:()=>Pe.current?.click()}]:[],...ut?[{key:"hash",label:r("supportChat.tools.hash"),icon:s(te,{d:"M8 3.5 6.5 16.5M13.5 3.5 12 16.5M4 7.5h12.5M3.5 12.5H16"}),onSelect:()=>Yt("#")}]:[],...lt.length?[{key:"slash",label:r("supportChat.tools.slash"),icon:s(te,{d:"M11.8 6.5 8.2 13.5 M6.5 3h7a3.5 3.5 0 0 1 3.5 3.5v7a3.5 3.5 0 0 1-3.5 3.5h-7A3.5 3.5 0 0 1 3 13.5v-7A3.5 3.5 0 0 1 6.5 3z"}),onSelect:()=>Yt("!")}]:[],...Ht].map(t=>o("button",{type:"button",role:"menuitem","data-key":t.key,onClick:()=>{De(!1),t.onSelect()},children:[s("span",{className:"sc-menu-icon",children:t.icon}),t.label]},t.key))})]}),U&&s("input",{ref:Rn,type:"file",accept:"image/*",capture:"environment",hidden:!0,onChange:t=>{t.target.files&&Ot(t.target.files),t.target.value=""}})]}),at==="link"&&pt&&s(Xs,{load:pt,onClose:()=>kt(null),onPick:t=>{if(kt(null),S)w.current?.insertLink(t.url);else{const n=O.current,a=n?g.slice(n.selectionStart,n.selectionEnd):"";Tn(`${qe(t.url,a.includes(`
|
|
7
|
+
`)?"":a)} `)}}}),(at==="emoji"||at==="gif"&&re)&&s(Js,{onPick:t=>Tn(t),onClose:()=>kt(null),gif:re?{searchUrl:re,onPick:Ns}:void 0,startOn:at==="gif"?"gif":"emoji"}),s("button",{type:"button","data-popover-toggle":!0,className:"sc-attach sc-emoji-btn","aria-label":r("supportChat.tools.emoji"),"aria-expanded":at==="emoji"||at==="gif",onClick:()=>kt(t=>t==="emoji"||t==="gif"?null:"emoji"),children:o("svg",{viewBox:"0 0 20 20",width:"18",height:"18","aria-hidden":!0,children:[s("circle",{cx:"10",cy:"10",r:"7.25",fill:"none",stroke:"currentColor",strokeWidth:"1.6"}),s("path",{d:"M7 11.5a3.6 3.6 0 0 0 6 0",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}),s("circle",{cx:"7.6",cy:"8.2",r:"1",fill:"currentColor"}),s("circle",{cx:"12.4",cy:"8.2",r:"1",fill:"currentColor"})]})}),c==="agent"&&pt&&s("button",{type:"button","data-popover-toggle":!0,className:"sc-attach sc-link-btn","aria-label":r("supportChat.links.button"),title:r("supportChat.links.button"),"aria-expanded":at==="link",onClick:()=>kt(t=>t==="link"?null:"link"),children:s("svg",{viewBox:"0 0 20 20",width:"17",height:"17","aria-hidden":!0,children:s("path",{d:"M8.6 11.4a3 3 0 0 0 4.2 0l2.6-2.6a3 3 0 0 0-4.2-4.2l-1 1M11.4 8.6a3 3 0 0 0-4.2 0l-2.6 2.6a3 3 0 0 0 4.2 4.2l1-1",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}),ut&&s("button",{type:"button",className:"sc-attach sc-tok-btn","aria-label":r("supportChat.tools.hash"),title:r("supportChat.tools.hash"),onClick:()=>Yt("#"),children:s("svg",{viewBox:"0 0 20 20",width:"17",height:"17","aria-hidden":!0,children:s("path",{d:"M8 3.5 6.5 16.5M13.5 3.5 12 16.5M4 7.5h12.5M3.5 12.5H16",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}),lt.length>0&&s("button",{type:"button",className:"sc-attach sc-tok-btn","aria-label":r("supportChat.tools.slash"),title:r("supportChat.tools.slash"),onClick:()=>Yt("!"),children:o("svg",{viewBox:"0 0 20 20",width:"17",height:"17","aria-hidden":!0,children:[s("rect",{x:"3",y:"3",width:"14",height:"14",rx:"3.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6"}),s("path",{d:"M11.8 6.5 8.2 13.5",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}),U&&o(k,{children:[s("button",{type:"button",className:"sc-attach","aria-label":r("supportChat.files.add"),onClick:()=>Pe.current?.click(),children:s("svg",{viewBox:"0 0 20 20",width:"18",height:"18","aria-hidden":!0,children:s("path",{d:"M13.5 6.5l-6 6a1.8 1.8 0 0 0 2.5 2.5l6.2-6.2a3.3 3.3 0 0 0-4.7-4.7L5.3 10.3a4.8 4.8 0 0 0 6.8 6.8l5.4-5.4",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})})}),s("input",{ref:Pe,type:"file",multiple:!0,hidden:!0,accept:[...Object.keys(ze),...Object.values(ze).map(t=>`.${t}`)].join(","),onChange:t=>{t.target.files&&Ot(t.target.files),t.target.value=""}})]}),S?s(ra,{ref:w,placeholder:M?.text?.placeholder??r(x?"supportChat.note.notePlaceholder":lt.length?"supportChat.tools.placeholder":q?"supportChat.note.placeholder":"supportChat.agentPlaceholder"),onChange:({text:t,refs:n,before:a})=>{A(t),Qt(n),us(a)},onKey:Mn,onPasteFiles:U?t=>Ot(t,!0):void 0,mentions:x?K:[]}):s(k,{children:o("div",{className:"sc-input",children:[s("div",{className:"sc-mirror",ref:Ae,"aria-hidden":!0,children:ys}),s("textarea",{onPaste:t=>{if(U&&t.clipboardData.files.length){t.preventDefault(),Ot(t.clipboardData.files);return}const n=t.currentTarget,a=t.clipboardData.getData("text/plain").trim(),i=n.value.slice(n.selectionStart,n.selectionEnd);if(!sa(a)||!i.trim()||i.includes(`
|
|
8
|
+
`))return;t.preventDefault();const e=qe(a,i),l=n.selectionStart,d=`${n.value.slice(0,l)}${e}${n.value.slice(n.selectionEnd)}`;A(d.slice(0,4e3)),requestAnimationFrame(()=>n.setSelectionRange(l+e.length,l+e.length))},ref:O,onScroll:t=>Ae.current&&(Ae.current.scrollTop=t.currentTarget.scrollTop),rows:1,value:g,maxLength:4e3,placeholder:r(c==="merchant"?"supportChat.placeholder":x?"supportChat.note.notePlaceholder":lt.length?"supportChat.tools.placeholder":q?"supportChat.note.placeholder":"supportChat.agentPlaceholder"),onChange:t=>A(t.target.value),onKeyDown:t=>{Mn(t.nativeEvent)?t.preventDefault():t.key==="Enter"&&!t.nativeEvent.isComposing&&vs(t)}})]})}),s("button",{type:"button",className:"sc-send",title:c==="agent"?r("supportChat.sendWith",{key:ke}):void 0,onClick:Bn,disabled:M?M.blocked:!g.trim()&&!Cs.length&&!Lt||Yn||Dn,"aria-label":r("supportChat.send"),children:s("svg",{viewBox:"0 0 20 20",width:"18",height:"18","aria-hidden":!0,children:s("path",{d:"M10 15.5v-11M5 9l5-5 5 5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})]})})})})};export{ar as ChatThread,te as MenuIcon};
|
package/dist/src/supportChat.css
CHANGED
|
@@ -1180,7 +1180,6 @@ textarea.rm-note { height: auto; padding: 8px 10px; resize: none; line-height: 1
|
|
|
1180
1180
|
.rail-item { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; width: 62px; padding: 8px 0 6px; border-radius: 14px; color: #a7a2b3; text-decoration: none; font-size: 10.5px; font-weight: 600; transition: background 0.15s, color 0.15s; }
|
|
1181
1181
|
.rail-item:hover { background: rgba(255, 255, 255, 0.06); background: color-mix(in srgb, var(--sc-surface) 6%, transparent); color: #fff; }
|
|
1182
1182
|
.rail-item--on { background: rgba(255, 255, 255, 0.1); background: color-mix(in srgb, var(--sc-surface) 10%, transparent); color: #fff; }
|
|
1183
|
-
.rail-item--on::before { content: ""; position: absolute; left: -7px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: linear-gradient(180deg, #1673e0, #6cbdf5); }
|
|
1184
1183
|
.rail-badge { position: absolute; top: 3px; right: 9px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: #1673e0; color: #fff; font-style: normal; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; box-sizing: border-box; }
|
|
1185
1184
|
.rail-badge--live { background: #12a150; }
|
|
1186
1185
|
@media (max-width: 700px) {
|
|
@@ -1241,7 +1240,6 @@ textarea.rm-note { height: auto; padding: 8px 10px; resize: none; line-height: 1
|
|
|
1241
1240
|
.rail-item { width: 58px; color: #8a8494; color: color-mix(in srgb, #8a8494 var(--sc-dk), #fff); }
|
|
1242
1241
|
.rail-item:hover { background: var(--sc-soft); color: var(--sc-ink); }
|
|
1243
1242
|
.rail-item--on { background: var(--sc-soft); color: var(--sc-ink); }
|
|
1244
|
-
.rail-item--on::before { left: -7px; }
|
|
1245
1243
|
.rail-badge { box-shadow: 0 0 0 2px #fff; box-shadow: 0 0 0 2px var(--sc-surface); }
|
|
1246
1244
|
@media (max-width: 700px) { .rail { border-right: 0; border-top: 1px solid var(--sc-line); } }
|
|
1247
1245
|
|
|
@@ -1325,7 +1323,6 @@ textarea.rm-note { height: auto; padding: 8px 10px; resize: none; line-height: 1
|
|
|
1325
1323
|
.rail-item:hover .rail-icon { background: #f0f0f3; background: color-mix(in srgb, #f0f0f3 var(--sc-tint), var(--sc-surface)); color: var(--sc-ink); }
|
|
1326
1324
|
.rail-item:active .rail-icon { transform: scale(0.96); }
|
|
1327
1325
|
.rail-item--on .rail-icon { background: #e6f3fe; background: color-mix(in srgb, #e6f3fe var(--sc-tint), var(--sc-surface)); color: #0f5fc4; color: color-mix(in srgb, #0f5fc4 var(--sc-dk), #fff); }
|
|
1328
|
-
.rail-item--on .rail-icon::before { content: ""; position: absolute; left: -13px; top: 11px; width: 4px; height: 20px; border-radius: 0 4px 4px 0; background: var(--sc-grad); }
|
|
1329
1326
|
.rail-label { display: none; }
|
|
1330
1327
|
.rail-badge { position: absolute; top: 3px; right: 2px; min-width: 15px; height: 15px; padding: 0 4px; border-radius: 999px; background: #1673e0; color: #fff; font-style: normal; font-size: 9.5px; font-weight: 700; line-height: 15px; text-align: center; box-sizing: border-box; box-shadow: 0 0 0 2px #fbfbfc; }
|
|
1331
1328
|
.rail-badge--live { background: #12a150; }
|
|
@@ -1723,7 +1720,7 @@ textarea.rm-note { height: auto; padding: 8px 10px; resize: none; line-height: 1
|
|
|
1723
1720
|
.ai-badge { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 7px; background: linear-gradient(135deg, #6366f1, #6cbdf5); color: #fff; align-self: center; }
|
|
1724
1721
|
.ai-head strong { font-size: 13.5px; }
|
|
1725
1722
|
.ai-asked { flex: 1 1 100%; color: var(--sc-ink-3); font-size: 12.5px; }
|
|
1726
|
-
.ai-steps { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px;
|
|
1723
|
+
.ai-steps { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
|
|
1727
1724
|
.ai-step-row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 8px; border: 0; background: none; font: inherit; font-size: 12.5px; color: var(--sc-ink-2); text-align: left; cursor: pointer; border-radius: 8px; }
|
|
1728
1725
|
.ai-step-row:hover { background: rgba(99, 102, 241, 0.06); }
|
|
1729
1726
|
.ai-step-icon { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; color: #4f46e5; }
|
|
@@ -1967,7 +1964,6 @@ button.ai-toggle:hover { background: var(--sc-soft); color: var(--sc-ink); }
|
|
|
1967
1964
|
.ibx-item--resolved, .ibx-item--resolved:hover { opacity: 1; }
|
|
1968
1965
|
.ibx-item--unread { background: #edf4ff; background: color-mix(in srgb, #edf4ff var(--sc-tint), var(--sc-surface)); }
|
|
1969
1966
|
.ibx-item--unread:hover { background: #e3eeff; background: color-mix(in srgb, #e3eeff var(--sc-tint), var(--sc-surface)); }
|
|
1970
|
-
.ibx-item--unread::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: #2f7fe0; }
|
|
1971
1967
|
.ibx-item--unread .ibx-item-text strong { color: #1f6fd1; color: color-mix(in srgb, #1f6fd1 var(--sc-dk), #fff); }
|
|
1972
1968
|
.ibx-item--unread .ibx-item-text > span:last-child { color: var(--sc-ink, #1a1a1a); color: var(--sc-ink, var(--sc-ink-strong, #1a1a1a)); font-weight: 650; }
|
|
1973
1969
|
.ibx-item--unread .ibx-item-meta time { color: #1f6fd1; color: color-mix(in srgb, #1f6fd1 var(--sc-dk), #fff); font-weight: 600; }
|
|
@@ -2138,7 +2134,7 @@ button.ai-toggle:hover { background: var(--sc-soft); color: var(--sc-ink); }
|
|
|
2138
2134
|
.sc-macts-emoji button:hover { transform: scale(1.25); background: none; }
|
|
2139
2135
|
@media (hover: none) { .sc-row:hover .sc-macts:not(.sc-macts--on) { display: none; } }
|
|
2140
2136
|
/* A reply's quote of the message it answers, and the "Replying to" bar over the composer. */
|
|
2141
|
-
.sc-quote { display: grid; gap: 1px; width: 100%; margin: 0 0 6px; padding: 5px 10px; border: 0; border-
|
|
2137
|
+
.sc-quote { display: grid; gap: 1px; width: 100%; margin: 0 0 6px; padding: 5px 10px; border: 0; border-radius: 8px; background: rgba(22, 115, 224, 0.08); font: inherit; text-align: left; cursor: pointer; }
|
|
2142
2138
|
.sc-quote strong { font-size: 12px; color: #0f5fc4; color: color-mix(in srgb, #0f5fc4 var(--sc-dk), #fff); }
|
|
2143
2139
|
.sc-quote span { font-size: 12.5px; color: var(--sc-ink-3, #616161); color: var(--sc-ink-3, color-mix(in srgb, #616161 var(--sc-dk), #fff)); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
|
|
2144
2140
|
.sc-replying { display: flex; align-items: center; gap: 10px; margin: 0 12px 6px; padding: 8px 10px; border-radius: 12px; background: var(--sc-soft); }
|
|
@@ -2520,3 +2516,6 @@ html[data-theme="dark"] .sc-ctx .sc-ctx-bar { box-shadow: 0 4px 14px rgba(0, 0,
|
|
|
2520
2516
|
.sc-tr-pop .sc-tr-done { color: var(--sc-ink); }
|
|
2521
2517
|
.sc-tr-send { align-self: flex-start; padding: 8px 16px; border: 0; border-radius: 999px; background: #1673e0; color: #fff; font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; }
|
|
2522
2518
|
.sc-tr-send:disabled { opacity: 0.6; cursor: default; }
|
|
2519
|
+
/* The Reply and Note tabs, with one action on the right (the inbox's Ask for a review). */
|
|
2520
|
+
.sc-mode-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
|
|
2521
|
+
.sc-mode-row > :last-child:not(.sc-mode) { margin: 0 14px 6px 0; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whoa-chat/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Whoa Chat's React components and styles: the merchant chat for your embedded Shopify app, its cards, files and live updates.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"homepage": "https://whoa.chat/docs/",
|