@whoa-chat/react 0.3.1 → 0.3.2
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/LICENSE +14 -0
- package/dist/locales/bg.json +4 -3
- package/dist/locales/da.json +4 -3
- package/dist/locales/de.json +4 -3
- package/dist/locales/en.json +4 -3
- package/dist/locales/es.json +4 -3
- package/dist/locales/fr.json +4 -3
- package/dist/locales/index.d.ts +15 -0
- package/dist/locales/it.json +4 -3
- package/dist/locales/ja.json +4 -3
- package/dist/locales/nl.json +4 -3
- package/dist/locales/pl.json +4 -3
- package/dist/locales/pt-BR.json +4 -3
- package/dist/locales/pt-PT.json +4 -3
- package/dist/locales/sv.json +4 -3
- package/dist/locales/zh-CN.json +4 -3
- package/dist/locales/zh-TW.json +4 -3
- package/dist/src/Attachments.d.ts +0 -3
- package/dist/src/AvailabilityCard.d.ts +0 -4
- package/dist/src/ChatThread.d.ts +0 -5
- package/dist/src/ChatThread.js +7 -7
- package/dist/src/DraftCard.js +1 -1
- package/dist/src/FormattedText.d.ts +0 -4
- package/dist/src/HelpOfferCard.js +1 -1
- package/dist/src/InboxTools.d.ts +0 -3
- package/dist/src/MessagePreview.js +1 -1
- package/dist/src/PasswordCard.js +1 -1
- package/dist/src/ReviewCard.d.ts +0 -2
- package/dist/src/ReviewCard.js +1 -1
- package/dist/src/RichCards.d.ts +0 -3
- package/dist/src/RichCards.js +1 -1
- package/dist/src/RichInput.d.ts +0 -8
- package/dist/src/StoreAvatar.d.ts +0 -1
- package/dist/src/appearance.d.ts +0 -3
- package/dist/src/chatApi.d.ts +0 -4
- package/dist/src/chatEnv.d.ts +0 -1
- package/dist/src/chime.d.ts +0 -1
- package/dist/src/clock.d.ts +0 -1
- package/dist/src/copyToClipboard.d.ts +0 -9
- package/dist/src/host.d.ts +1 -7
- package/dist/src/refLinks.d.ts +0 -1
- package/dist/src/supportChat.css +1 -2521
- package/dist/src/useLive.d.ts +0 -2
- package/package.json +8 -8
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
|
|
2
|
-
`)&&
|
|
3
|
-
`]})})(),
|
|
1
|
+
import{Fragment as k,jsx as s,jsxs as o}from"react/jsx-runtime";import{Fragment as ze,useEffect as T,useLayoutEffect as zn,useRef as y,useState as f}from"react";import{mentionsIn as Is,noteTarget as Bs,splitMentions as Wn,typingMention as Fs}from"@whoa-chat/core/mentions";import{ALLOWED_TYPES as We,fileTypeOf as js,maxBytesFor as Hs,maxLabelFor as zs}from"@whoa-chat/core/fileTypes";import{InlineImage as Ws,MediaProvider as Vs,MessageFiles as Vn,PendingFiles as qs}from"./Attachments.js";import{AvailabilityCard as _s,AwayBar as qn,OnlineBar as Ks}from"./AvailabilityCard.js";import{HelpOfferCard as Gs,VerifiedIcon as Zs}from"./HelpOfferCard.js";import{PasswordCard as Qs}from"./PasswordCard.js";import{FeatureRequestCard as Us,TicketCard as Ys}from"./RequestCards.js";import{CardOutcome as Js}from"./CardOutcome.js";import{EmojiPicker as Xs,LinkPicker as ta}from"./ComposerTools.js";import{useTranslation as ea}from"./i18n.js";import{TEAM_FLAG as Ve,languageFlag as _n,languageName as Kn}from"./flags.js";import{FILE_IMG as na,FormattedText as qe,inlineFileIds as sa}from"./FormattedText.js";import{isUrl as aa,linkToken as _e}from"@whoa-chat/core/links";import{splitRefs as ra}from"./refLinks.js";import{RichInput as oa}from"./RichInput.js";import{AiSteps as ia}from"./AssistantNote.js";import{AiChoices as la,AiProgress as ca}from"./AiChoices.js";import{MessageActions as Ke}from"./MessageActions.js";import{ActionGroup as da}from"./ActionGroup.js";import{EventRow as ua}from"./EventRow.js";import{DraftCard as pa}from"./DraftCard.js";import{StoreAvatar as ga}from"./StoreAvatar.js";import{AgentAvatar as Ct}from"./agents.js";import{ReviewCard as ma}from"./ReviewCard.js";import{CustomCard as ha}from"./CustomCard.js";import{ChatEnvProvider as Gn,DeepLinkCard as fa,Mention as ka,MessageWithReferences as ba,PricingCard as ya,ReferenceCard as Zn}from"./RichCards.js";import{timeOpts as va}from"./clock.js";import{LinkNamesContext as Ca,OpenedLinksContext as $a}from"./chatEnv.js";import{useAppearance as Na}from"./appearance.js";import{brandVars as Qn,chatHost as $t}from"./host.js";const Bt=({viewer:p,message:c,children:it})=>p==="agent"?s(Js,{message:c,children:it}):s(k,{children:it}),Y=p=>new Date(p).toDateString(),ee=({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([],va()),wa=30*6e4,Un=(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,Ge=(p,c,it)=>{const Nt=Un(p,c);return Nt?it?Nt.alt:Nt.main:p.body},ar=({messages:p,viewer:c,shopOwnerName:it,listing:Nt,onSend:Ze,onReviewState:Yn,sending:Jn,previewUrl:ne,open:Xn,agents:K=[],onSendNote:Ft,onDraft:wt,uploadUrl:Qe,uploadFields:Ue,fileUrl:z,uploadFile:jt,pickGif:se,fetchFile:Ht,availability:G,shortcuts:lt=[],onSendCard:ae,composerTop:re=null,composerAside:ts=null,composerFill:xt=null,onComposerEscape:Ye,composerSend:M=null,shortcutVars:es={},gifSearchUrl:oe,gifPickUrl:ie,otherReadAt:Mt=null,otherDeliveredAt:Je=null,emailedAt:Xe=null,email:le=null,menu:zt,plusOnDesktop:ns,me:W=null,merchantCountry:tn=null,rich:S=!1,onDraftChange:en,typingNow:C=null,onEdit:ct,onDelete:J,onRestore:nn,onSaveReply:xa,onSlash:sn,onReact:dt,visitorCta:ss=!1,onResendEmail:an,searchRefs:ut,linkShortcuts:pt,onTrack:Lt,onAddFeature:rn,actions:ce=null,store:X,onActionsBefore:de,actionsStatus:on=null,refLink:ln,linkNames:as})=>{const{t:r,i18n:ue}=ea("home"),rs=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},cn=Na(ue,c==="merchant"),dn=(t,n)=>ln?ra(t,ln).map((a,i)=>a.href?s("a",{href:a.href,target:"_blank",rel:"noopener noreferrer",children:a.text},`${n}-r${i}`):s(ze,{children:a.text},`${n}-r${i}`)):t,[g,A]=f(""),[D,Wt]=f(null),[L,pe]=f(null),[Rt,ge]=f(null),[un,me]=f([]),Vt=t=>{me(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&&ae?ae(t.card):t.note&&Ft?Ft(t.body,t.files,t.replyTo):Ze(t.body,t.files,t.refs,t.replyTo),a=()=>me(i=>i.filter(e=>e.key!==t.key));if(!n)return a();n.then(a,()=>me(i=>i.map(e=>e.key===t.key?{...e,status:"failed"}:e)))},os=t=>Number(t.key.split("-")[0])||0,is=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)>=os(t)-12e4),[Tt,ls]=f(()=>new Set),cs=t=>ls(n=>{const a=new Set(n);return a.delete(t)||a.add(t),a}),qt=y(null),[he,ds]=f(!1),fe=y(null),_t=t=>{const n=qt.current;n&&t!==he&&(fe.current=new Map([n,...Array.from(n.children)].map(a=>[a,a.getBoundingClientRect()]))),ds(t)},pn=y(_t);pn.current=_t,T(()=>{g?g.includes(`
|
|
2
|
+
`)&&_t(!0):_t(!1)},[g]),T(()=>{const t=qt.current;if(!t||typeof ResizeObserver>"u")return;const n=new ResizeObserver(()=>{const a=t.querySelector(".sc-rich-input, textarea");a&&a.scrollHeight>44&&pn.current(!0)});return n.observe(t),()=>n.disconnect()},[]),zn(()=>{const t=fe.current;fe.current=null;const n=qt.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)}},[he]);const gn=y(!1),ke=y(en);ke.current=en,T(()=>{D||ke.current?.(g,gn.current)},[g,D]);const w=y(null),mn=y(g);mn.current=g,T(()=>{if(!xt)return;if(xt.replace){j(xt.text);return}if(g.trim())return;let t=0,n;const a=()=>{j(xt.text),n=setTimeout(()=>{!mn.current.trim()&&++t<30&&a()},100)};return a(),()=>clearTimeout(n)},[xt?.key]);const[us,ps]=f(""),$=S?us:g,j=(t,n)=>{S&&(t?w.current?.setText(t,n):w.current?.clear()),A(t)},be=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"&&ce?ce.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 ye=t=>t?.message&&(!t.message.kind||t.message.kind==="text")?`${t.message.from}:${t.message.agentName??""}`:null,hn=(t,n)=>!!(t&&n&&ye(t)&&ye(t)===ye(n)&&Y(t.at)===Y(n.at)&&Date.parse(n.at)-Date.parse(t.at)<5*6e4),gs=y(null),tt=y(null),fn=y(null),gt=y(!0),kn=()=>{const t=tt.current;if(!t||!de)return;if(t.scrollTop<60)return de(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&&de(i.dataset.at)},Kt=y(0),ms=ce?.length??0;zn(()=>{const t=tt.current;t&&(!gt.current&&Kt.current&&(t.scrollTop+=t.scrollHeight-Kt.current),Kt.current=t.scrollHeight,kn())},[ms]),T(()=>{const t=tt.current,n=fn.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],[bn,ve]=f(!1),yn=y(null),vn=()=>{gt.current=!0,ve(!1),tt.current&&(tt.current.scrollTop=tt.current.scrollHeight)};T(()=>{const t=yn.current===null;if(yn.current=mt?.id??"",!mt)return;const n=mt.from===c||c==="agent"&&mt.from==="agent"&&mt.agentName===W;t||n||gt.current?vn():ve(!0)},[mt?.id]);const[Gt,et]=f(!1),[St,At]=f(!1),O=y(null),q=c==="agent"&&!!Ft&&K.length>0,ht=q?Bs(g,K):null,Zt=q&&/^\s*@/.test(g),x=q&&(St||(!!ht||Zt)&&!Gt);gn.current=x,T(()=>{!D&&g.trim()&&ke.current?.(g,x)},[x]);const Qt=y(!1);T(()=>{q&&!St&&!Gt&&(Zt||ht)&&(Qt.current=!0,At(!0))},[q,St,Gt,Zt,ht]),T(()=>{c==="agent"&&sn&&g==="/"&&(j(""),sn())},[g]);const Cn=x?Is(g,K):[],Ce=q?Fs($):null,_=Ce===null?[]:K.filter(t=>t.toLowerCase().startsWith(Ce.toLowerCase())),[hs,$e]=f(0);T(()=>$e(0),[Ce]);const Ne=_[Math.min(hs,_.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 we=lt.length?$.match(/(?:^|\s)!([a-z0-9-]*)$/i)?.[1]??null:null,ft=we===null?[]:lt.filter(t=>t.key.startsWith(we.toLowerCase())||t.title.toLowerCase().includes(we.toLowerCase())).slice(0,6),xe=t=>t.replace(/\{\{\s*(\w+)\s*\}\}/g,(n,a)=>es[a]??n),$n=t=>{const n=t.body;t.card&&ae&&ge(t.card),S?w.current?.replaceBefore($.match(/![a-z0-9-]*$/i)?.[0].length??0,xe(n)):A(a=>a.replace(/![a-z0-9-]*$/i,xe(n))),O.current?.focus()},[Me,Nn]=f(null),[Le,fs]=f(null),wn=c==="agent"&&pt?$.match(/(?:^|\s)\[([^[\]\n]{0,40})$/)?.[1]??null:null,Z=wn!==null&&Le!==null&&$.startsWith(Le)&&$.lastIndexOf("[")===Le.lastIndexOf("[")?null:wn;T(()=>{Z!==null&&Me===null&&pt&&pt().then(Nn,()=>Nn([]))},[Z!==null]);const ks=(Z??"").toLowerCase().split(/\s+/).filter(Boolean),P=Z===null||!Me?[]:Me.filter(t=>ks.every(n=>`${t.label} ${t.url}`.toLowerCase().includes(n))).slice(0,6),[Re,Te]=f(0);T(()=>Te(0),[Z]);const xn=t=>{const n=$.match(/\[[^[\]\n]*$/)?.[0].length??0;S?w.current?.insertLink(t.url,void 0,n):(A(a=>a.replace(/\[[^[\]\n]*$/,`${_e(t.url,"")} `)),O.current?.focus())},[Se,bs]=f(null),ys=ut?$.match(/(?:^|\s)#((?:[^\s#\d][^#\n]{0,39})?|\d[^\s#]{0,19})$/)?.[1]??null:null,H=Se!==null&&$.startsWith(Se)&&$.lastIndexOf("#")===Se.lastIndexOf("#")?null:ys,[nt,Mn]=f({q:"",data:null}),[Q,Dt]=f(null),[Ae,Ut]=f([]);T(()=>{if(H===null||!ut)return Dt(null);let t=!0;const n=window.setTimeout(()=>{ut(H.trim()).then(a=>t&&Mn({q:H,data:a}),()=>t&&Mn({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(/^#/,"")}),Dt(null);return}A(a=>a.replace(/#[^#\n]*$/,`${t} `)),n&&Ut(a=>[...a.filter(i=>i.text!==t),{text:t,ref:n}]),Dt(null),O.current?.focus()},Yt=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?Dt(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)}))],De=y(null),vs=(()=>{const t=Ae.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?Wn(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
|
+
`]})})(),Jt=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))})},Ln=t=>{if(t.key==="Escape"&&St&&!D&&!L&&!ft.length&&Z===null)return Qt.current=!1,At(!1),et(!0),!0;if(t.key==="Escape"&&M&&Ye&&H===null&&Z===null&&!ft.length)return Ye(),!0;if((t.key==="Tab"||t.key==="Enter")&&H!==null&&Yt.length&&!t.metaKey&&!t.ctrlKey)return Yt[0].pick(),!0;if(t.key==="Escape"&&H!==null)return bs($),!0;if((t.key==="ArrowDown"||t.key==="ArrowUp")&&P.length>1){const a=t.key==="ArrowDown"?1:-1;return Te(i=>(Math.min(i,P.length-1)+a+P.length)%P.length),!0}if((t.key==="Tab"||t.key==="Enter")&&P.length)return xn(P[Math.min(Re,P.length-1)]),!0;if(t.key==="Escape"&&Z!==null)return fs($),!0;if((t.key==="Tab"||t.key==="Enter")&&ft.length)return $n(ft[0]),!0;if((t.key==="ArrowDown"||t.key==="ArrowUp")&&_.length>1){const a=t.key==="ArrowDown"?1:-1;return $e(i=>(Math.min(i,_.length-1)+a+_.length)%_.length),!0}if((t.key==="Tab"||t.key==="Enter")&&Ne)return An(Ne),!0;if(t.key==="ArrowUp"&&!g&&ct&&W){const a=xs();return a?(Wt(a.id),j(a.body,a.refs),!0):!1}return t.key==="Escape"&&D?(Fe(),!0):t.key==="Escape"&&L?(Xt(),!0):t.key!=="Enter"||t.isComposing?!1:(c==="agent"?t.metaKey||t.ctrlKey:!t.shiftKey)?(Fn(),!0):!1},Cs=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),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"&&
|
|
8
|
-
`))return;t.preventDefault();const e=
|
|
5
|
+
${d}${g.slice(a)}`,h=l?i:a+1+d.length;A(m),requestAnimationFrame(()=>n.setSelectionRange(h,h))},[at,kt]=f(null),[Rn,Oe]=f(!1),Tn=y(null),Sn=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)})},An=t=>{S?w.current?.replaceBefore($.match(/@[\p{L}]*$/u)?.[0].length??0,`@${t} `):A(n=>n.replace(/@[\p{L}]*$/u,`@${t} `)),O.current?.focus()},[Ot,E]=f([]),[Dn,Pe]=f(!1),Ee=y(null),On=Ot.some(t=>!t.ref&&!t.error),$s=Ot.filter(t=>t.ref).map(t=>t.ref.id),Ns=t=>Ot.filter(n=>n.ref&&(!n.inline||t.includes(`file:${n.ref.id}`))).map(n=>n.ref.id),U=!!(Qe||jt),Pt=(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=js(a.name,a.type),l=e===a.type?a:new File([a],a.name,{type:e}),d=We[l.type]?l.size>Hs(l.type)?r("supportChat.files.tooBig",{max:zs(l.type)}):void 0:r("supportChat.files.notAllowed"),m=!d&&l.type.startsWith("image/")?URL.createObjectURL(l):null,h=!!(n&&S&&m&&jt&&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(jt){jt(l).then(b=>I(b),()=>I());continue}const B=new FormData;for(const[b,R]of Object.entries(Ue??{}))B.append(b,R);B.append("file",l,l.name||"screenshot.png"),fetch(Qe,{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)))}},ws=t=>{if(!ie&&!se)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}]),se){se(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(!ie)return;const a=new FormData;for(const[i,e]of Object.entries(Ue??{}))a.append(i,e);a.append("id",t.id),fetch(ie,{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)))},xs=()=>[...p].reverse().find(t=>t.from==="agent"&&t.agentName===W&&(t.kind==="text"||t.kind==="note")&&t.id!=="pending")??null,[Et,Ie]=f(null),[Ms,Pn]=f(!1),Be=t=>{Ie(t),S?w.current?.focus?.():O.current?.focus()},rt=(t,n)=>c==="agent"&&t.from==="agent"?s(Ke,{inline:!0,side:n,onReply:()=>Be(t),onDelete:J?()=>J(t.id):void 0}):null,En=t=>t.from==="merchant"?c==="merchant"?r("supportChat.msg.you"):X?.name??r("supportChat.msg.merchant"):t.bot?$t().brand.bot:t.author??t.agentName??$t().brand.team,In=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:En({from:t.replyTo.from,author:t.replyTo.author==="merchant"?void 0:t.replyTo.author})}),s("span",{children:t.replyTo.excerpt})]}):null,Bn=t=>{pe(null),Wt(t.id),j(t.body,t.refs),O.current?.focus()},Fe=()=>{Wt(null),j("")},Xt=()=>{pe(null),j("")},Fn=()=>{const t=g.trim();if(M){if(M.blocked)return;M.send(t),j("");return}if(D){t&&ct&&ct(D,t),Fe();return}if(L){t&&wt&&wt(L.id,"send",t),Xt();return}const n=Ns(t);if(!t&&!n.length&&!Rt||On)return;const a=Rt;ge(null),(t||n.length)&&Vt({key:`${Date.now()}-${Math.random()}`,body:t,files:n,refs:Ae.filter(i=>t.includes(i.text)),note:!!(x&&Ft),...Et?{replyTo:Et.id}:{},status:"sending"}),Ie(null),a&&Vt({key:`${Date.now()}-card`,body:"",files:[],note:!1,card:a,status:"sending"}),Ut([]),j(""),et(!1),Qt.current&&(Qt.current=!1,At(!1)),E([])},Ls=p.find(t=>t.from==="agent"&&!t.bot&&!t.deletedAt&&t.kind!=="note"&&t.kind!=="draft"&&t.kind!=="event")?.id??null,te=z?(t,n,a)=>s(Ws,{id:t,name:n,url:z(t),load:Ht},a):void 0,It=t=>{const n=sa(t.body);return(t.files??[]).filter(a=>!n.has(a.id))},je=[];if(z){for(const t of p)if(!(t.deletedAt||t.kind==="event")){for(const n of(t.body??"").matchAll(na))je.push({id:n[2],name:n[1]||"Image",type:"image/png",url:z(n[2])});for(const n of It(t))(n.type.startsWith("image/")||n.type.startsWith("video/"))&&je.push({id:n.id,name:n.name,type:n.type,url:z(n.id)})}}const Rs=t=>t==="system"?"system":t===c?"merchant":"agent",ot=ne?{previewUrl:ne,open:Xn}:null,bt=p.filter(t=>t.kind!=="note").filter(t=>t.kind!=="event"&&t.kind!=="draft"),Ts=bt[bt.length-1]?.id??null,Ss=t=>{const n=bt.findIndex(a=>a.id===t);return bt.slice(n+1).find(a=>a.from==="merchant")?.body??null},As=t=>Vt({key:`${Date.now()}-choice`,body:t,files:[],note:!1,status:"sending"}),jn=c==="merchant"?"merchant":"agent",Hn=[...bt].reverse().find(t=>t.from===jn)?.id??null,Ds=Mt?Date.parse(Mt):NaN,Os=[...bt].reverse().find(t=>t.from===jn&&t.id!=="pending"&&Date.parse(t.at)<=Ds)?.id??null,Ps=t=>{if(t.id===Os&&t.id!==Hn){const B=r("supportChat.receipts.seen");return o("span",{className:"sc-receipt sc-receipt--seen","data-tip":`${B} ${F(Mt)}`,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!==Hn||t.id==="pending")return null;const n=B=>!!(B&&Date.parse(B)>=Date.parse(t.at)),a=c==="agent"&&le&&n(le.at)?le:null,i=a?a.clickedAt??a.openedAt??null:null,e=c==="agent"&&!a&&n(Xe)?Xe:null,l=n(Mt)?{kind:"seen",at:Mt}:i?{kind:"emailOpened",at:i}:n(Je)?{kind:"delivered",at:Je}: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&&an&&s("button",{type:"button",className:"sc-resend",disabled:Ms,onClick:()=>{Pn(!0),an().finally(()=>Pn(!1))},children:r("supportChat.receipts.resend")})]})},He=t=>{const n=Ps(t);return n?o(k,{children:[n," \xB7 "]}):null},yt=(t,n)=>o("div",{className:"sc-meta",style:{textAlign:n==="merchant"?"right":"left"},children:[He(t),t.from==="agent"&&t.agentName?`${t.agentName} \xB7 `:"",F(t.at)]}),Es=t=>{if(!ot)return null;const n=ot.open;return{...ot,open:n?a=>{Lt?.(t,"open"),n(a)}:void 0}};return s(Vs,{items:je,load:Ht,children:s(Ca.Provider,{value:as,children:s(Gn,{value:ot,children:o("div",{className:`sc-shell sc-shell--${c}${Dn?" sc-shell--drop":""}${cn.className}`,style:cn.style,onDragOver:t=>{!U||!t.dataTransfer.types.includes("Files")||(t.preventDefault(),Pe(!0))},onDragLeave:t=>{t.currentTarget.contains(t.relatedTarget)||Pe(!1)},onDrop:t=>{U&&(t.preventDefault(),Pe(!1),Pt(t.dataTransfer.files,!0))},children:[Dn&&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&&bn&&ve(!1),Kt.current=n.scrollHeight,kn()},children:[s("div",{className:"sc-newbelow-wrap",children:bn&&o("button",{type:"button",className:"sc-newbelow",onClick:vn,children:[r("supportChat.msg.newBelow")," \u2193"]})}),o("div",{className:"sc-content",ref:fn,children:[c==="merchant"&&G&&p.length>0&&s(qn,{availability:G}),c==="merchant"&&G&&p.length>0&&s(Ks,{availability:G,recentReply:p.some(t=>t.from==="agent"&&!t.bot&&Date.now()-Date.parse(t.at)<30*6e4)}),on&&s("div",{className:"sc-actions-status",children:on}),p.length===0&&o("div",{className:"sc-empty",children:[s("strong",{children:r("supportChat.emptyTitle")}),G?r("supportChat.emptyBodyShort"):r("supportChat.emptyBody",Qn()),G&&o("div",{className:"sc-empty-card",children:[s(qn,{availability:G}),s(_s,{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(da,{actions:t.group,store:X})]},`a-${t.group[0].id}`);const e=t.message,l=Rs(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)&&Lt?.(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??""})}),nn&&s("button",{type:"button",className:"sc-deleted-undo",onClick:()=>{nn(e.id)},children:r("supportChat.msg.undoDelete")})]}):null:e.kind==="draft"?c==="agent"?s(pa,{message:e,time:F(e.at),onDraft:wt,editing:L?.id===e.id,onEdit:()=>{Wt(null),pe({id:e.id,name:e.agentName??"Claude"}),j(e.body)}}):null:e.kind==="event"?c==="agent"?s(ua,{message:e,time:F(e.at)}):null:e.kind==="note"?c==="agent"?o("div",{className:`sc-note${e.reminder?" sc-note--reminder":""}${e.from==="system"?" sc-note--system":""}`,"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(Ke,{inline:!0,side:"agent",onReply:()=>Be(e),onEdit:ct&&e.agentName===W?()=>Bn(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(qe,{text:e.body,image:te,inline:(d,m)=>Wn(d,K.length?K:e.mentions??[]).map((h,v)=>h.agent?o("span",{className:"sc-mention",children:["@",h.agent]},`${m}-${v}`):s(ze,{children:dn(h.text,`${m}-${v}`)},`${m}-${v}`))})}),It(e).length&&z?s(Vn,{files:It(e),fileUrl:z,fetchFile:Ht}):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(Bt,{viewer:c,message:e,children:s(Qs,{message:e,onOpen:c==="merchant"?()=>Lt?.(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(Bt,{viewer:c,message:e,children:s(Us,{message:e,onAdd:c==="merchant"&&rn?()=>rn(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(Ys,{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(ha,{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(Bt,{viewer:c,message:e,children:s(Gs,{message:e,answered:p.slice(p.indexOf(e)+1).some(d=>d.from==="merchant"),onAnswer:c==="merchant"?d=>{Lt?.(e.id,d===r("supportChat.helpOffer.yesMessage")?"help_yes":"help_no"),Ze(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(Bt,{viewer:c,message:e,children:s(ma,{message:e,shopOwnerName:it,listing:Nt,preview:c==="agent",onState:(d,m)=>Yn?.(e.id,d,m),onAway:c==="merchant"?d=>Lt?.(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??$t().brand.team,size:28}),c==="agent"&&e.from==="agent"&&s("span",{className:"sc-own-avatar",children:s(Ct,{name:e.agentName??$t().brand.team,size:28})}),s(Bt,{viewer:c,message:e,children:s(Gn,{value:Es(e.id),children:e.kind==="link"&&e.link?s(fa,{link:e.link}):e.kind==="pricing"&&e.pricing?s(ya,{pricing:e.pricing}):e.kind==="offer"&&e.offerId?s(Zn,{refId:`offer-${e.offerId}`}):s(Zn,{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:[He(e),e.from==="agent"&&e.agentName?`${e.agentName} \xB7 `:"",F(e.at)]})]}):(()=>{const d=hn(V[n-1],t),m=hn(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??$t().brand.team,size:30}),o("div",{children:[o("strong",{children:[e.agentName??$t().brand.team,e.bot&&s("em",{className:"sc-ai-label",children:"AI"})]}),s("span",{children:r(e.bot?"supportChat.ai.byline":"supportChat.preview.fromTeam",Qn())})]})]}):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(ia,{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(ga,{shop:X.shop,name:X.name,look:X.look,size:28})}):null,o("div",{className:"sc-msg-stack",children:[(()=>{const u=Un(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"?`${_n(N,tn)} \u203A ${Ve}`:u?.kind==="to"?`${Ve} \u203A ${_n(N,tn)}`:Ve}),u?u.kind==="from"?r("supportChat.translate.from",{language:Kn(u.lang,ue.language)}):u.kind==="to"?r("supportChat.translate.sentIn",{language:Kn(u.lang,ue.language)}):r("supportChat.translate.translated"):r("supportChat.translate.translating"),u&&s("button",{type:"button",onClick:()=>cs(e.id),"aria-pressed":Tt.has(e.id),children:r(u.kind==="to"!==Tt.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(Ke,{side:l,onReply:()=>Be(e),onReact:dt?u=>dt(e.id,u):void 0,onEdit:c==="agent"&&ct&&e.from==="agent"&&e.agentName===W?()=>Bn(e):void 0,onDelete:c==="agent"&&J&&e.from==="agent"?()=>J(e.id):void 0,copyText:Ge(e,c,Tt.has(e.id)),reacted:e.reactions?.filter(u=>c==="merchant"?u.by.includes("merchant"):W&&u.by.includes(W)).map(u=>u.emoji)}),s($a.Provider,{value:c==="agent"?rs(e):null,children:ot?s(ba,{text:Ge(e,c,Tt.has(e.id)),bubbleClass:v,head:o(k,{children:[vt,In(e)]}),links:e.refs,image:te}):o("div",{className:v,children:[vt,In(e),s(qe,{text:Ge(e,c,Tt.has(e.id)),inline:dn,image:te})]})})]}),e.id===Ls&&o("div",{className:"sc-human",children:[s(Zs,{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(ca,{steps:e.progress}):null,ss&&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(la,{choices:e.choices,active:c==="merchant"&&e.id===Ts&&un.length===0,picked:Ss(e.id),onPick:As}):null,It(e).length&&z?s(Vn,{files:It(e),fileUrl:z,fetchFile:Ht}):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:[He(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)}),un.filter(t=>!(t.status==="sending"&&is(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(qe,{image:te,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:()=>Vt(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:gs})]})]}),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:be})}),s("button",{type:"button",onClick:Fe,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:be})}),o("span",{className:"sc-draft-bar-actions",children:[s("button",{type:"button",onClick:Xt,children:r("supportChat.draft.cancelEdits")}),s("button",{type:"button",className:"sc-draft-update",disabled:!g.trim(),onClick:()=>{const t=g.trim();t&&wt&&L&&wt(L.id,"update",t),Xt()},children:r("supportChat.draft.update")})]})]}),Et&&!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:En(Et)})}),s("span",{children:Et.body.replace(/\s+/g," ").slice(0,140)})]}),s("button",{type:"button","aria-label":r("supportChat.msg.cancelReply"),onClick:()=>Ie(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:()=>{At(!1),et(!0)},children:r("supportChat.note.tabReply")}),s("button",{type:"button",role:"tab","aria-selected":x,className:"sc-mode-note",onClick:()=>{At(!0),et(!1)},children:r("supportChat.note.tabNote")})]}),ts]}),!D&&!L&&!St&&(x||(ht||Zt)&&Gt)&&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:Cn.length||ht?r("supportChat.note.mode",{names:Cn.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:()=>Dt(null),children:r("supportChat.refPick.back")}),nt.data?Yt.length===0?s("p",{className:"sc-refpick-note",children:r("supportChat.refPick.none")}):Yt.map(t=>o(ze,{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(Re,P.length-1),className:n===Math.min(Re,P.length-1)?"sc-shortcut--on":void 0,onMouseDown:a=>a.preventDefault(),onMouseEnter:()=>Te(n),onClick:()=>xn(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:()=>$n(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:xe(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===Ne,onMouseDown:n=>n.preventDefault(),onMouseEnter:()=>$e(_.indexOf(t)),onClick:()=>An(t),children:[s(Ct,{name:t,size:22}),t]},t))}),(()=>{const t=[...Ae.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&&ne&&!S?s("div",{className:"sc-draft-refs",children:t.map(n=>o("span",{className:"sc-draft-ref",children:[s(ka,{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," ")),Ut(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})(),Ot.some(t=>!t.inline||t.error)&&s(qs,{files:Ot.filter(t=>!t.inline||t.error),removeLabel:r("supportChat.files.remove"),onRemove:t=>E(n=>n.filter(a=>a.key!==t))}),Rt&&o("div",{className:"sc-attached-card",children:[s("span",{children:r("supportChat.outbox.card",{card:r(`supportChat.inbox.tabs.${Rt.kind}`)})}),s("button",{type:"button","aria-label":r("supportChat.outbox.removeCard"),onClick:()=>ge(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:qt,className:`sc-composer${re?" sc-composer--top":""}${M?M.text?" sc-composer--cardtext":" sc-composer--card":""}${x&&!L?" sc-composer--note":""}${L?" sc-composer--draft":""}${zt?" sc-composer--menu":""}${zt&&ns?" sc-composer--plus":""}${he&&!M?" sc-composer--multi":""}`,children:[re&&s("div",{className:"sc-composer-top",children:re}),M&&!M.text&&M.label&&s("span",{className:"sc-composer-cardnote",children:M.label}),zt&&o(k,{children:[s("button",{type:"button",className:"sc-plus","aria-label":r("supportChat.menu.open"),"aria-expanded":Rn,onClick:()=>Oe(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"})})}),Rn&&o(k,{children:[s("div",{className:"sc-menu-scrim",onClick:()=>Oe(!1),"aria-hidden":!0}),s("div",{className:"sc-menu",role:"menu",children:[...U?[{key:"camera",label:r("supportChat.menu.camera"),icon:s(ee,{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:()=>Tn.current?.click()},{key:"files",label:r("supportChat.menu.files"),icon:s(ee,{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:()=>Ee.current?.click()}]:[],...ut?[{key:"hash",label:r("supportChat.tools.hash"),icon:s(ee,{d:"M8 3.5 6.5 16.5M13.5 3.5 12 16.5M4 7.5h12.5M3.5 12.5H16"}),onSelect:()=>Jt("#")}]:[],...lt.length?[{key:"slash",label:r("supportChat.tools.slash"),icon:s(ee,{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:()=>Jt("!")}]:[],...zt].map(t=>o("button",{type:"button",role:"menuitem","data-key":t.key,onClick:()=>{Oe(!1),t.onSelect()},children:[s("span",{className:"sc-menu-icon",children:t.icon}),t.label]},t.key))})]}),U&&s("input",{ref:Tn,type:"file",accept:"image/*",capture:"environment",hidden:!0,onChange:t=>{t.target.files&&Pt(t.target.files),t.target.value=""}})]}),at==="link"&&pt&&s(ta,{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):"";Sn(`${_e(t.url,a.includes(`
|
|
7
|
+
`)?"":a)} `)}}}),(at==="emoji"||at==="gif"&&oe)&&s(Xs,{onPick:t=>Sn(t),onClose:()=>kt(null),gif:oe?{searchUrl:oe,onPick:ws}: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:()=>Jt("#"),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:()=>Jt("!"),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:()=>Ee.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:Ee,type:"file",multiple:!0,hidden:!0,accept:[...Object.keys(We),...Object.values(We).map(t=>`.${t}`)].join(","),onChange:t=>{t.target.files&&Pt(t.target.files),t.target.value=""}})]}),S?s(oa,{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),Ut(n),ps(a)},onKey:Ln,onPasteFiles:U?t=>Pt(t,!0):void 0,mentions:x?K:[]}):s(k,{children:o("div",{className:"sc-input",children:[s("div",{className:"sc-mirror",ref:De,"aria-hidden":!0,children:vs}),s("textarea",{onPaste:t=>{if(U&&t.clipboardData.files.length){t.preventDefault(),Pt(t.clipboardData.files);return}const n=t.currentTarget,a=t.clipboardData.getData("text/plain").trim(),i=n.value.slice(n.selectionStart,n.selectionEnd);if(!aa(a)||!i.trim()||i.includes(`
|
|
8
|
+
`))return;t.preventDefault();const e=_e(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=>De.current&&(De.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=>{Ln(t.nativeEvent)?t.preventDefault():t.key==="Enter"&&!t.nativeEvent.isComposing&&Cs(t)}})]})}),s("button",{type:"button",className:"sc-send",title:c==="agent"?r("supportChat.sendWith",{key:be}):void 0,onClick:Fn,disabled:M?M.blocked:!g.trim()&&!$s.length&&!Rt||Jn||On,"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,ee as MenuIcon};
|
package/dist/src/DraftCard.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as t,jsxs as
|
|
1
|
+
import{Fragment as L,jsx as t,jsxs as s}from"react/jsx-runtime";import{useState as i}from"react";import{useTranslation as F}from"./i18n.js";import{FormattedText as M}from"./FormattedText.js";import{EditIcon as S}from"./MessageActions.js";import{asksForReview as T,withoutReviewLink as g}from"@whoa-chat/core/reviewLink";import{ReviewCard as R}from"./ReviewCard.js";import{TEAM_FLAG as V,languageFlag as A,languageName as B}from"./flags.js";const W=({message:r,time:u,onDraft:o,onEdit:f,editing:l=!1})=>{const{t:a,i18n:k}=F("home"),e=r.translation?.to==="en"?r.translation:null,[n,x]=i(!1),m=T(r.body),[b,O]=i(!0),d=m&&b,h=d&&g(r.body)||r.body,[p,C]=i(!1),[v,y]=i(null),w=r.draft?.state??"open",N=async c=>{if(o){C(!0),y(null);try{await o(r.id,c,c==="send"?r.body:void 0,c==="send"?{card:d}:void 0)}catch(E){y(E.message)}finally{C(!1)}}};return w!=="open"?s("div",{className:"sc-draft sc-draft--done",children:[a(w==="sent"?"supportChat.draft.sent":"supportChat.draft.discarded",{name:r.draft?.by??""}),t("time",{children:u})]}):s("div",{className:"sc-draft","aria-label":a("supportChat.draft.label"),children:[s("div",{className:"sc-draft-head",children:[t(S,{size:13}),a("supportChat.draft.title",{name:r.agentName??"Claude"}),t("time",{children:u})]}),l?t("p",{className:"sc-draft-editing",children:a("supportChat.draft.editingBelow")}):s(L,{children:[e&&s("div",{className:"sc-translated sc-draft-lang",children:[t("span",{className:"sc-translated-flags","aria-hidden":!0,children:`${A(e.from)} \u203A ${V}`}),a("supportChat.translate.from",{language:B(e.from,k.language)}),t("button",{type:"button",onClick:()=>x(!n),"aria-pressed":n,children:a(n?"supportChat.translate.showTranslation":"supportChat.translate.showOriginal")})]}),t("div",{className:"sc-draft-body",children:t(M,{text:e&&!n?d&&g(e.text)||e.text:h})})]}),m&&s("div",{className:"sc-draft-cardrow",children:[d&&t("div",{className:"sc-draft-peek","aria-label":a("supportChat.draft.withCard"),children:t(R,{message:{...r,kind:"review_request",body:"",review:{fixed:"",state:"sent"}},shopOwnerName:null,listing:null,preview:!0})}),s("p",{className:"sc-draft-card",children:[a(d?"supportChat.draft.linkOut":"supportChat.draft.noCard")," ",t("button",{type:"button",onClick:()=>O(!b),children:a(d?"supportChat.draft.cardOff":"supportChat.draft.cardOn")})]})]}),r.draft?.note&&s("div",{className:"sc-draft-before",children:[t("strong",{children:a("supportChat.draft.before")}),r.draft.note]}),v&&t("p",{className:"sc-draft-error",children:v}),s("div",{className:"sc-draft-actions",children:[t("button",{type:"button",className:"sc-draft-send",disabled:p||l||!h.trim()||!o,onClick:()=>{N("send")},children:a("supportChat.draft.send")}),!l&&f&&t("button",{type:"button",disabled:p,onClick:f,children:a("supportChat.draft.edit")}),t("button",{type:"button",className:"sc-draft-discard",disabled:p||!o,onClick:()=>{N("discard")},children:a("supportChat.draft.discard")})]})]})};export{W as DraftCard};
|
|
@@ -8,10 +8,7 @@ export declare const appPage: (url: string) => {
|
|
|
8
8
|
logo?: string;
|
|
9
9
|
};
|
|
10
10
|
} | null;
|
|
11
|
-
/** Whether a link shows as a badge (a page in the Shopify admin or in the app) rather than as plain words. */
|
|
12
11
|
export declare const isBadgeLink: (url: string) => boolean;
|
|
13
|
-
/** A link as the chat shows it: a badge for admin and app pages, else its label (or address) underlined.
|
|
14
|
-
* asText draws it without a working link (the composer). */
|
|
15
12
|
export declare const LinkBadge: ({ url, label, asText }: {
|
|
16
13
|
url: string;
|
|
17
14
|
label?: string;
|
|
@@ -31,7 +28,6 @@ export declare const CODE_LANGUAGES: readonly [{
|
|
|
31
28
|
readonly aliases: readonly ["css", "scss"];
|
|
32
29
|
}];
|
|
33
30
|
export declare const codeLanguage: (raw: string) => "javascript" | "liquid" | "css" | null;
|
|
34
|
-
/** Our three languages, guessed from the code itself: Liquid's tags, then JavaScript's words, then CSS rules. */
|
|
35
31
|
export declare const detectLanguage: (code: string) => string | null;
|
|
36
32
|
export declare const LanguageIcon: ({ lang }: {
|
|
37
33
|
lang: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as a}from"react/jsx-runtime";import{useTranslation as n}from"./i18n.js";import{AgentAvatar as i}from"./agents.js";import{brandVars as d}from"./host.js";const
|
|
1
|
+
import{jsx as e,jsxs as a}from"react/jsx-runtime";import{useTranslation as n}from"./i18n.js";import{AgentAvatar as i}from"./agents.js";import{brandVars as d,chatHost as h}from"./host.js";const l=({size:o=16,check:s="#fff"})=>a("svg",{viewBox:"0 0 24 24",width:o,height:o,"aria-hidden":!0,children:[e("path",{d:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76Z",fill:"currentColor"}),e("path",{d:"m9 12 2 2 4-4",fill:"none",stroke:s,strokeWidth:"2.2",strokeLinecap:"round",strokeLinejoin:"round"})]}),b=({message:o,answered:s,onAnswer:r})=>{const{t}=n("home"),p=o.agentName??h().brand.team;return a("article",{className:"ho-card","aria-label":t("supportChat.helpOffer.label"),children:[a("header",{className:"ho-head",children:[e(i,{name:p,size:30}),a("div",{children:[e("strong",{children:p}),e("span",{children:t("supportChat.preview.fromTeam",d())})]})]}),e("p",{className:"ho-body",children:o.body}),a("div",{className:"ho-perk",children:[e(l,{size:17}),t("supportChat.preview.helpPerks")]}),!s&&a("div",{className:"ho-actions",children:[e("button",{type:"button",className:"mp-btn mp-btn--brand","data-card-action":"help_yes",disabled:!r,onClick:()=>r?.(t("supportChat.helpOffer.yesMessage")),children:t("supportChat.helpOffer.yes")}),e("button",{type:"button",className:"mp-btn mp-btn--plain","data-card-action":"help_no",disabled:!r,onClick:()=>r?.(t("supportChat.helpOffer.noMessage")),children:t("supportChat.helpOffer.no")})]})]})};export{b as HelpOfferCard,l as VerifiedIcon};
|
package/dist/src/InboxTools.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ export type Reminder = {
|
|
|
5
5
|
note: string;
|
|
6
6
|
by: string;
|
|
7
7
|
};
|
|
8
|
-
/** The instant a wall-clock time in a time zone falls on (two passes cover a DST change). */
|
|
9
8
|
export declare const zonedTime: (y: number, mo: number, d: number, h: number, mi: number, timeZone?: string | null) => Date;
|
|
10
9
|
export declare const formatWhen: (iso: string, lang?: string) => string;
|
|
11
10
|
export declare const ReminderControl: ({ reminders, error, busy, onAdd, onRemove, open: openProp, onOpenChange, hideButton, timeZone, }: {
|
|
@@ -42,12 +41,10 @@ export declare const ShortcutsPanel: ({ shortcuts, error, onSave, onDelete, onCl
|
|
|
42
41
|
onDelete: (id: string) => void;
|
|
43
42
|
onClose: () => void;
|
|
44
43
|
inline?: boolean;
|
|
45
|
-
/** The workspace's apps ("-" the first app's key); with two or more, a saved reply can be for some of them. */
|
|
46
44
|
apps?: {
|
|
47
45
|
key: string;
|
|
48
46
|
name: string;
|
|
49
47
|
}[];
|
|
50
|
-
/** A new saved reply starts as this app's (Settings with one app picked). */
|
|
51
48
|
newFor?: string;
|
|
52
49
|
}) => import("react").JSX.Element;
|
|
53
50
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as r,jsxs as a}from"react/jsx-runtime";import{CustomCard as N}from"./CustomCard.js";import{useState as x}from"react";import{PASSWORD_PAGE as M}from"./PasswordCard.js";import{useTranslation as I}from"./i18n.js";import{AgentAvatar as S}from"./agents.js";import{VerifiedIcon as L}from"./HelpOfferCard.js";import{brandVars as
|
|
1
|
+
import{jsx as r,jsxs as a}from"react/jsx-runtime";import{CustomCard as N}from"./CustomCard.js";import{useState as x}from"react";import{PASSWORD_PAGE as M}from"./PasswordCard.js";import{useTranslation as I}from"./i18n.js";import{AgentAvatar as S}from"./agents.js";import{VerifiedIcon as L}from"./HelpOfferCard.js";import{brandVars as k,chatHost as v}from"./host.js";import{ReferenceMini as w,referencesIn as A}from"./RichCards.js";import{FILE_IMG as B,FormattedText as P}from"./FormattedText.js";import{linkLabels as R}from"@whoa-chat/core/links";const $=({label:e,placeholder:p,onOpen:s,onSend:h})=>{const[t,u]=x("");return a("form",{className:"mp-reply",onSubmit:c=>{c.preventDefault();const d=t.trim();d?h(d):s()},children:[r("input",{value:t,onChange:c=>u(c.target.value),placeholder:p,"aria-label":p,maxLength:4e3}),r("button",{type:"submit","aria-label":e,className:t.trim()?"mp-reply-send--on":void 0,children:r("svg",{viewBox:"0 0 20 20",width:"15",height:"15","aria-hidden":!0,children:r("path",{d:"M10 15.5v-11M5 9l5-5 5 5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},g=(e,p=180)=>e.includes("```")||e.length<=p?e:`${e.slice(0,p-3).trimEnd()}...`,O="M11.128 4.123c-.453-.95-1.803-.95-2.256 0l-1.39 2.912-3.199.421c-1.042.138-1.46 1.422-.697 2.146l2.34 2.222-.587 3.172c-.192 1.034.901 1.828 1.825 1.327l2.836-1.54 2.836 1.54c.924.501 2.017-.293 1.825-1.327l-.587-3.172 2.34-2.222c.762-.724.345-2.008-.697-2.146l-3.2-.421-1.389-2.912Z",D=(e,p)=>{const s=Math.round((Date.now()-Date.parse(e))/6e4);if(s<1)return p("supportChat.preview.justNow");if(s<60)return p("supportChat.preview.minutesAgo",{count:s});const h=Math.round(s/60);return h<24?p("supportChat.preview.hoursAgo",{count:h}):new Date(e).toLocaleDateString(void 0,{day:"numeric",month:"short"})},G=({message:e,listing:p,onAction:s,onDismiss:h})=>{const{t}=I("home"),u=e.agentName??v().brand.team,c=e.files?.length??0,d=(i,b=!1)=>({kind:"reply",text:i,open:b}),m=R((e.body??"").replace(B," ")).replace(/[ \t]{2,}/g," ").trim();let n=m?g(m):"",l=null,o=[];switch(e.kind){case"review_request":{n=e.review?.fixed?t("supportChat.preview.fixed",{fixed:e.review.fixed}):t("supportChat.preview.howItWent"),l=a("div",{className:"mp-rich mp-rich--review",children:[r("img",{src:v().brand.logo,alt:"",width:34,height:34}),a("div",{children:[r("strong",{children:t("supportChat.review.appName",k())}),p?a("span",{className:"mp-stars",children:[[1,2,3,4,5].map(i=>r("svg",{viewBox:"0 0 20 20",width:"12",height:"12","aria-hidden":!0,children:r("path",{d:O,fill:"#ffb21e"})},i)),r("b",{children:p.rating.toFixed(1)}),r("span",{children:t("supportChat.review.reviewCount",{count:p.reviewCount})})]}):r("span",{className:"mp-stars",children:t("supportChat.review.onAppStore")})]})]}),o=[{label:t("supportChat.preview.writeReview"),action:{kind:"review",messageId:e.id},tone:"brand"}];break}case"password_request":l=a("div",{className:"mp-rich mp-rich--help",children:[r("span",{className:"mp-help-icon","aria-hidden":!0,children:r("svg",{viewBox:"0 0 20 20",width:"18",height:"18",children:r("path",{d:"M5.5 9V6.8a4.5 4.5 0 0 1 9 0V9M4.5 9h11v8h-11zM10 12v2",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round"})})}),r("span",{children:t("supportChat.password.where")})]}),o=[{label:t("supportChat.password.open"),action:{kind:"go",path:M},tone:"brand"},{label:t("supportChat.preview.reply"),action:d(""),tone:"plain"}];break;case"feature_request":n=t("supportChat.featureCard.preview",{title:e.feature?.title??e.body}),o=[{label:t("supportChat.preview.openChat"),action:{kind:"open"},tone:"brand"}];break;case"ticket":n=t("supportChat.ticketCard.opened",{title:e.ticket?.title??e.body}),o=[{label:t("supportChat.preview.openChat"),action:{kind:"open"},tone:"dark"}];break;case"help_offer":l=a("div",{className:"mp-rich mp-rich--help",children:[r("span",{className:"mp-help-icon","aria-hidden":!0,children:r(L,{size:18,check:"#1a73e8"})}),r("span",{children:t("supportChat.preview.helpPerks")})]}),o=[{label:t("supportChat.helpOffer.yes"),action:d(t("supportChat.helpOffer.yesMessage"),!0),tone:"brand"},{label:t("supportChat.helpOffer.no"),action:d(t("supportChat.helpOffer.noMessage")),tone:"plain"}];break;case"link":e.link&&(l=r("div",{className:"mp-mini mp-mini--link",children:a("span",{className:"mp-mini-text",children:[r("strong",{children:e.link.title}),r("span",{children:e.link.crumb.join(" \u203A ")})]})})),n=n&&n!==e.link?.title?n:"",e.link&&(o=[{label:t("supportChat.preview.takeMe"),action:{kind:"go",path:e.link.path},tone:"brand"}]),o.push({label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"plain"});break;case"offer":n="",e.offerId&&(l=r(w,{refId:`offer-${e.offerId}`})),o=[...e.offerId?[{label:t("supportChat.preview.openOffer"),action:{kind:"go",path:`/app/offers/${e.offerId}`},tone:"dark"}]:[],{label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"plain"}];break;case"subscription":n="",e.subscriptionId&&(l=r(w,{refId:e.subscriptionId})),o=[{label:t("supportChat.preview.openChat"),action:{kind:"open"},tone:"dark"}];break;case"custom":n="",e.card&&(l=r("div",{className:"mp-rich mp-rich--custom",children:r(N,{tree:e.card.tree,name:e.card.name})})),o=[{label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"dark"}];break;case"pricing":if(n="",e.pricing){const i=v().priceBook(e.pricing.priceBookId).tiers.find(b=>b.key===e.pricing.tierKey);l=a("div",{className:"mp-mini mp-mini--pricing",children:[r("span",{className:"mp-mini-pic",children:r("img",{src:v().brand.logo,alt:""})}),a("span",{className:"mp-mini-text",children:[r("strong",{children:t("supportChat.mini.pricing",k())}),r("span",{children:t("supportChat.mini.revenue",{revenue:`$${Math.round(e.pricing.revenueUsd).toLocaleString("en-US")}`,price:i?.custom?t("supportChat.pricing.custom"):i&&i.priceUsd?`$${i.priceUsd}/mo`:t("supportChat.mini.noCharge")})})]})]})}o=[{label:t("supportChat.preview.seePlan"),action:{kind:"go",path:"/app/plan"},tone:"dark"},{label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"plain"}];break;default:{!n&&c&&(n=t("supportChat.preview.files",{count:c}));const i=e.refs?.[0]?.ref??(e.body?A(e.body)[0]:void 0);i&&(l=r(w,{refId:i})),o=[{label:t("supportChat.preview.reply"),action:{kind:"open"},tone:"dark"}]}}const f=t("supportChat.preview.reply"),y=o.some(i=>i.label===f),C=o.filter(i=>i.label!==f);return a("article",{className:`mp-card mp-card--${e.kind}`,"aria-label":t("supportChat.preview.label",{name:u}),children:[a("header",{className:"mp-head",children:[r(S,{name:u,size:26}),a("span",{className:"mp-who",children:[r("strong",{children:u}),a("span",{children:["\xB7 ",t("supportChat.preview.fromTeam",k())]})]}),r("time",{children:D(e.at,t)}),r("button",{type:"button",className:"mp-close","aria-label":t("supportChat.preview.dismiss"),onClick:h,children:r("svg",{viewBox:"0 0 20 20",width:"12",height:"12","aria-hidden":!0,children:r("path",{d:"M5 5l10 10M15 5L5 15",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})})]}),(n||c>0)&&a("button",{type:"button",className:"mp-bubble",onClick:()=>s({kind:"open"}),children:[n&&m&&n===g(m)?r(P,{text:n}):n,c>0&&m&&r("span",{className:"mp-files",children:t("supportChat.preview.files",{count:c})})]}),l,C.length>0&&r("div",{className:"mp-actions",children:C.map(i=>r("button",{type:"button",className:`mp-btn mp-btn--${i.tone}`,onClick:()=>s(i.action),children:i.label},i.label))}),y&&r($,{label:f,placeholder:t("supportChat.preview.writeReply"),onOpen:()=>s({kind:"open"}),onSend:i=>s(d(i,!0))})]})};export{G as MessagePreview};
|
package/dist/src/PasswordCard.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as a}from"react/jsx-runtime";import{useTranslation as p}from"./i18n.js";import{AgentAvatar as i}from"./agents.js";import{useChatEnv as d}from"./chatEnv.js";import{brandVars as h}from"./host.js";const
|
|
1
|
+
import{jsx as e,jsxs as a}from"react/jsx-runtime";import{useTranslation as p}from"./i18n.js";import{AgentAvatar as i}from"./agents.js";import{useChatEnv as d}from"./chatEnv.js";import{brandVars as h,chatHost as c}from"./host.js";const m="shopify://admin/online_store/preferences",b=({message:t,onOpen:n})=>{const{t:o}=p("home"),r=d(),s=t.agentName??c().brand.team;return a("article",{className:"ho-card pw-card","aria-label":o("supportChat.password.label"),children:[a("header",{className:"ho-head",children:[e(i,{name:s,size:30}),a("div",{children:[e("strong",{children:s}),e("span",{children:o("supportChat.preview.fromTeam",h())})]})]}),e("p",{className:"ho-body",children:t.body}),a("div",{className:"ho-perk pw-where",children:[e("svg",{viewBox:"0 0 20 20",width:"16",height:"16","aria-hidden":!0,children:e("path",{d:"M5.5 9V6.8a4.5 4.5 0 0 1 9 0V9M4.5 9h11v8h-11zM10 12v2",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round"})}),o("supportChat.password.where")]}),e("div",{className:"ho-actions",children:e("button",{type:"button",className:"mp-btn mp-btn--brand","data-card-action":"open",disabled:!r?.open,onClick:()=>{n?.(),r?.open?.(m)},children:o("supportChat.password.open")})})]})};export{m as PASSWORD_PAGE,b as PasswordCard};
|
package/dist/src/ReviewCard.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { type ListingStats, type ReviewState, type SupportMessageView } from "@whoa-chat/core/types";
|
|
2
|
-
/** Shopify's review dialog, else the listing in a new tab. Null while a dialog is already on its way. */
|
|
3
2
|
export declare const requestReview: () => Promise<string | null>;
|
|
4
|
-
/** requestReview, then times how long they stay in the dialog or on the listing tab (reported once, as a card detail). */
|
|
5
3
|
export declare const requestReviewTimed: (onAway?: (detail: string) => void) => Promise<string | null>;
|
|
6
4
|
type Props = {
|
|
7
5
|
message: SupportMessageView;
|
package/dist/src/ReviewCard.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e,jsxs as i}from"react/jsx-runtime";import{useEffect as
|
|
1
|
+
import{jsx as e,jsxs as i}from"react/jsx-runtime";import{useEffect as C,useRef as I,useState as d,useMemo as O}from"react";import{useTranslation as q}from"./i18n.js";import{copyToClipboard as E}from"./copyToClipboard.js";import{APP_STORE_REVIEW_URL as u}from"@whoa-chat/core/types";import{awayDetail as U,watchReviewAway as B}from"@whoa-chat/core/reviewAway";import{AgentAvatar as F}from"./agents.js";import{brandVars as V,chatHost as h}from"./host.js";const W=new Set(["already-open","open-in-progress"]),k="M11.128 4.123c-.453-.95-1.803-.95-2.256 0l-1.39 2.912-3.199.421c-1.042.138-1.46 1.422-.697 2.146l2.34 2.222-.587 3.172c-.192 1.034.901 1.828 1.825 1.327l2.836-1.54 2.836 1.54c.924.501 2.017-.293 1.825-1.327l-.587-3.172 2.34-2.222c.762-.724.345-2.008-.697-2.146l-3.2-.421-1.389-2.912Z",j=async()=>{let r="error";try{r=(await shopify.reviews.request()).code}catch{}return W.has(r)?null:r!=="success"&&r!=="cancelled"?(window.open(u,"_blank","noopener"),"app-store"):r},z=async r=>{const a=Date.now(),s=await j();return r&&(s==="success"||s==="app-store")&&B(s==="app-store"?"tab":"dialog",c=>r(U(c)),{startedAt:a,answerMs:Date.now()-a}),s},H=()=>e("svg",{viewBox:"0 0 24 24",width:"10",height:"10","aria-hidden":!0,children:e("path",{className:"srv-check-path",d:"M5 12.5l4.2 4.2L19 7",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round"})}),G=({rating:r})=>e("span",{className:"srv-stars","aria-hidden":!0,children:[1,2,3,4,5].map(a=>i("svg",{viewBox:"0 0 20 20",width:"15",height:"15",style:{animationDelay:`${.25+a*.07}s`},children:[e("defs",{children:e("clipPath",{id:`srv-star-${a}`,children:e("rect",{x:"0",y:"0",width:20*Math.max(0,Math.min(1,r-a+1)),height:"20"})})}),e("path",{d:k,fill:"#e3e3e3",transform:"translate(-0.5 -0.6) scale(1.1)"}),e("path",{d:k,fill:"#ffb21e",clipPath:`url(#srv-star-${a})`,transform:"translate(-0.5 -0.6) scale(1.1)"})]},a))}),y=["#7c5cff","#29b6f6","#f5a623","#22c55e","#ff5c8a","#ffd23f"],Z=()=>{const r=O(()=>Array.from({length:70},(a,s)=>({left:Math.random()*100,drift:(Math.random()-.5)*140,spin:(Math.random()-.5)*900,delay:Math.random()*.35,duration:1.6+Math.random()*1.1,colour:y[s%y.length],round:s%3===0})),[]);return e("div",{className:"srv-confetti","aria-hidden":!0,children:r.map((a,s)=>e("i",{className:a.round?"srv-confetti-dot":void 0,style:{left:`${a.left}%`,background:a.colour,animationDelay:`${a.delay}s`,animationDuration:`${a.duration}s`,"--drift":`${a.drift}px`,"--spin":`${a.spin}deg`}},s))})},ae=({message:r,shopOwnerName:a,listing:s,preview:c,onState:v,onAway:S})=>{const{t,i18n:L}=q("home"),o=r.review,l=r.agentName??h().brand.team,[m,f]=d(o.state),[x,w]=d(!1),[M,R]=d(!1),[A,P]=d(!1),g=I(!1);C(()=>f(o.state),[o.state]),C(()=>{c||g.current||o.state!=="sent"||(g.current=!0,v?.("seen"))},[c,o.state,v]);const N=(n,p)=>{f(n),v?.(n,p)},_=async()=>{if(c)return;const n=await z(S);n!==null&&(n==="app-store"&&R(!0),P(!0),N("clicked",n))},D=async()=>{c||(await E(u),w(!0),window.setTimeout(()=>w(!1),2500))},b=a?.split(" ")[0],T=s?new Intl.NumberFormat(L.language,{minimumFractionDigits:1,maximumFractionDigits:1}).format(s.rating):null;return m==="clicked"?i("div",{className:"srv-card srv-card--thanks",role:"status",children:[A&&e(Z,{}),e("img",{className:"srv-thanks-logo",src:h().brand.logo,alt:"",width:52,height:52}),e("p",{className:"srv-thanks-title",children:b?t("supportChat.review.thanksNamed",{name:b}):t("supportChat.review.thanks")}),e("p",{className:"srv-thanks-copy",children:t("supportChat.review.thanksCopy",{agent:l})}),e("a",{className:"srv-link",href:u,target:"_blank",rel:"noopener noreferrer",children:t(M?"supportChat.review.openListing":"supportChat.review.openAgain")})]}):m==="issue"?e("div",{className:"srv-card srv-card--quiet",role:"status",children:e("p",{className:"srv-quiet",children:t("supportChat.review.issueAck",{agent:l})})}):m==="dismissed"?e("div",{className:"srv-card srv-card--quiet",children:i("p",{className:"srv-quiet",children:[t("supportChat.review.dismissedAck")," ",e("button",{type:"button",className:"srv-link",onClick:()=>N("seen"),children:t("supportChat.review.showAgain")})]})}):i("article",{className:`srv-card${c?" srv-card--preview":""}`,"aria-label":t("supportChat.review.label"),children:[i("div",{className:"srv-hero",children:[e("span",{className:"srv-blob srv-blob--a","aria-hidden":!0}),e("span",{className:"srv-blob srv-blob--b","aria-hidden":!0}),e("img",{className:"srv-logo",src:h().brand.logo,alt:"",width:56,height:56}),i("div",{className:"srv-app",children:[e("strong",{children:t("supportChat.review.appName",V())}),s?i("span",{className:"srv-rating",children:[e(G,{rating:s.rating}),e("b",{children:T}),e("span",{children:t("supportChat.review.reviewCount",{count:s.reviewCount})})]}):e("span",{className:"srv-rating",children:t("supportChat.review.onAppStore")})]})]}),i("div",{className:"srv-body",children:[o.fixed&&i("div",{className:"srv-fixed",children:[i("span",{className:"srv-agent-ring",children:[e(F,{name:l,size:36}),e("span",{className:"srv-check",children:e(H,{})})]}),i("div",{className:"srv-fixed-main",children:[e("span",{className:"srv-eyebrow",children:t("supportChat.review.fixedBy",{agent:l})}),e("p",{className:"srv-fixed-text",children:o.fixed})]})]}),o.beforeImageUrl&&o.afterImageUrl&&e("div",{className:"srv-ba",children:[[o.beforeImageUrl,t("supportChat.review.before")],[o.afterImageUrl,t("supportChat.review.after")]].map(([n,p],$)=>i("a",{className:`srv-shot${$?" srv-shot--after":""}`,href:n,target:"_blank",rel:"noopener noreferrer",children:[e("img",{src:n,alt:p,loading:"lazy"}),e("span",{children:p})]},p))}),e("h3",{className:"srv-title",children:o?.title||t("supportChat.review.title")}),e("p",{className:"srv-copy",children:o?.ask||t("supportChat.review.body")}),i("button",{type:"button",className:"srv-primary","data-card-action":"review_clicked",onClick:_,disabled:c,children:[e("span",{children:t("supportChat.review.cta")}),e("span",{className:"srv-primary-icon","aria-hidden":!0,children:e("svg",{viewBox:"0 0 20 20",width:"12",height:"12",children:e("path",{d:"M7 13l6-6M8 7h5v5",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round"})})})]}),e("p",{className:"srv-time",children:s?t("supportChat.review.joinOthers",{count:s.reviewCount}):t("supportChat.review.time")})]}),i("footer",{className:"srv-owner",children:[e("span",{children:t("supportChat.review.ownerOnly")}),e("button",{type:"button",className:"srv-link",onClick:D,children:t(x?"supportChat.review.copied":"supportChat.review.copyLink")})]})]})};export{ae as ReviewCard,j as requestReview,z as requestReviewTimed};
|
package/dist/src/RichCards.d.ts
CHANGED
|
@@ -2,12 +2,10 @@ import { type ReactNode } from "react";
|
|
|
2
2
|
import type { DeepLink, MessageRef, PricingSnapshot } from "@whoa-chat/core/types";
|
|
3
3
|
import { ChatEnvProvider } from "./chatEnv";
|
|
4
4
|
export { ChatEnvProvider };
|
|
5
|
-
/** An order, subscription, offer, product or customer, full in the thread or compact in a hover card. */
|
|
6
5
|
export declare const ReferenceCard: ({ refId, compact }: {
|
|
7
6
|
refId: string;
|
|
8
7
|
compact?: boolean;
|
|
9
8
|
}) => import("react").JSX.Element;
|
|
10
|
-
/** Kept for subscription cards already sent. */
|
|
11
9
|
export declare const SubscriptionCard: ({ id }: {
|
|
12
10
|
id: string;
|
|
13
11
|
}) => import("react").JSX.Element;
|
|
@@ -31,7 +29,6 @@ export declare const PricingCard: ({ pricing }: {
|
|
|
31
29
|
export declare const DeepLinkCard: ({ link }: {
|
|
32
30
|
link: DeepLink;
|
|
33
31
|
}) => import("react").JSX.Element;
|
|
34
|
-
/** One row for the closed chat's preview: an icon or picture, the name, and the one fact that matters. */
|
|
35
32
|
export declare const ReferenceMini: ({ refId }: {
|
|
36
33
|
refId: string;
|
|
37
34
|
}) => import("react").JSX.Element | null;
|