1var Q=Object.defineProperty,X=Object.defineProperties;var Z=Object.getOwnPropertyDescriptors;var M=Object.getOwnPropertySymbols;var ee=Object.prototype.hasOwnProperty,se=Object.prototype.propertyIsEnumerable;var K=(e,s,n)=>s in e?Q(e,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[s]=n,W=(e,s)=>{for(var n in s||(s={}))ee.call(s,n)&&K(e,n,s[n]);if(M)for(var n of M(s))se.call(s,n)&&K(e,n,s[n]);return e},Y=(e,s)=>X(e,Z(s));var A=(e,s,n)=>new Promise((r,o)=>{var a=i=>{try{d(n.next(i))}catch(f){o(f)}},u=i=>{try{d(n.throw(i))}catch(f){o(f)}},d=i=>i.done?r(i.value):Promise.resolve(i.value).then(a,u);d((n=n.apply(e,s)).next())});import{j as t}from"./vendor-mui-BGS3mHwM.js";import{r as l}from"./vendor-redux-FtDGt7Mz.js";/* empty css */import{oi as D,gc as te,kv as ne,kx as re,I as ae,K as ie,ge as ce}from"./index-D5apbUK-.js";import{a as oe,u as le,c as ue}from"./chat-keys-BLUTcyLG.js";import{c as de,u as pe}from"./vendor-react-CUpnpRPD.js";import{o as H,r as fe}from"./service-buckets-YGgJR-rm.js";import{W as he}from"./WarningIcon-DbaJxr2G.js";import"./vendor-stream-CynyArsg.js";import"./vendor-pdf-Ddbn4B6C.js";import"./vendor-graphql-CuoeCPzn.js";import"./vendor-media-BEZy7yMd.js";import"./vendor-radix-NiTG7895.js";import"./vendor-mui-pickers-BdXKbjEa.js";import"./vendor-forms-BcpGzS3-.js";const me=e=>{if(!e)return null;const s=e==null?void 0:e.status;return s===400?"unusable-request":s===404?"order-unavailable":"retryable"},ge=()=>{const{orderSource:e="",orderLocator:s=""}=de(),n=D(e)&&te(s),r=D(e)?e:null,{data:o,error:a,isFetching:u,refetch:d}=oe({orderSource:r,orderLocator:s},{skip:!n});return{orderSource:r,orderLocator:s,context:o!=null?o:null,isLoading:n&&u,failure:n?me(a):"unusable-request",refetch:d}},ye=(e,s)=>{const{context:n}=e;return n?n.id===s.orderLocator&&n.subtype===s.subtype:!1},be=(e,s=!0,n)=>{const r=ne(),[o,a]=l.useState({isChecking:s,existingConversationId:null,existingLabel:null,failedOpen:!1}),u=JSON.stringify(e),d=n?JSON.stringify(n):"",i=l.useRef(0);return l.useEffect(()=>{if(!s){a({isChecking:!1,existingConversationId:null,existingLabel:null,failedOpen:!1});return}i.current+=1;const f=i.current,m=JSON.parse(u),b=d?JSON.parse(d):null;return a({isChecking:!0,existingConversationId:null,existingLabel:null,failedOpen:!1}),A(void 0,null,function*(){var C,O,v,N;try{const R=m.properties&&Object.keys(m.properties).length>0?m.properties:void 0,S=yield r.fetchInAppChatConversations(Y(W({identityId:re,limit:b?20:1,page:1},m),{properties:R,statuses:["DRAFT","ACTIVE"]}));if(f!==i.current)return;const c=b?S.find(I=>ye(I,b)):S[0],k=((C=c==null?void 0:c.context)==null?void 0:C.name)||((O=c==null?void 0:c.context)==null?void 0:O.reference)||((v=c==null?void 0:c.topic)==null?void 0:v.label)||(c==null?void 0:c.title)||null;a({isChecking:!1,existingConversationId:(N=c==null?void 0:c.conversationId)!=null?N:null,existingLabel:c!=null&&c.conversationId?k:null,failedOpen:!1})}catch(R){if(f!==i.current)return;a({isChecking:!1,existingConversationId:null,existingLabel:null,failedOpen:!0})}}).catch(()=>{}),()=>{i.current+=1}},[r,u,d,s]),o},xe=ae.injectEndpoints({endpoints:e=>({getIssueCreationReasons:e.query({query:({serviceType:s,appointmentType:n})=>({url:`${ie}/content-provider/api/v1/reasons`,params:{reasonType:"ISSUE_CREATION",serviceType:s,appointmentType:n,consumerType:"USER",page:0,size:100}}),transformResponse:s=>{var o;const n=(o=s==null?void 0:s.data)==null?void 0:o.content;return Array.isArray(n)?{reasons:n.filter(a=>{var u;return typeof(a==null?void 0:a.id)=="number"&&!!((u=a==null?void 0:a.name)!=null&&u.trim())}).map(a=>({id:a.id,name:a.name.trim()})),malformed:!1}:{reasons:[],malformed:!0}}})})}),{useGetIssueCreationReasonsQuery:ve}=xe,je=e=>{const s=H(e.orderType),n=e.reference?`Order #${e.reference}`:`my ${s.toLowerCase()}`;return e.name?`${n} â ${e.name}`:n},J=e=>`I need help with ${je(e)}`,B={reasonId:null,label:"My issue isnât listed",initialMessage:J},Ce=(e,s)=>({reasonId:e,label:s,initialMessage:n=>`${J(n)}: ${s}`}),Ne=(e,s)=>{const n=l.useMemo(()=>fe(e),[e]),{data:r,isFetching:o,isError:a,refetch:u}=ve({serviceType:n.serviceType,appointmentType:n.appointmentType},{skip:!s}),d=l.useMemo(()=>{const f=r==null?void 0:r.reasons;return!f||f.length===0?[]:[...f.map(m=>Ce(m.id,m.name)),B]},[r]);let i="loading";return o?i="loading":a||r!=null&&r.malformed?i="error":r&&(i="ready"),{status:i,topics:d,isEmpty:i==="ready"&&d.length===0,refresh:()=>{u()}}},Se=({open:e,contextLabel:s,onContinue:n,onStartNew:r,onCancel:o})=>e?t.jsx("div",{className:"cnh-chat",children:t.jsx("div",{className:"sc-modal-overlay",onClick:a=>{a.target===a.currentTarget&&o()},role:"presentation",children:t.jsxs("div",{className:"sc-modal sc-modal-center",role:"dialog","aria-modal":"true","aria-labelledby":"sc-nudge-title",children:[t.jsx(he,{}),t.jsxs("div",{className:"sc-modal-copy",children:[t.jsx("div",{className:"sc-modal-title",id:"sc-nudge-title",children:"You already have an active chat"}),t.jsx("p",{className:"sc-modal-desc",children:s?t.jsxs(t.Fragment,{children:["You have an ongoing conversation about ",t.jsx("b",{children:s}),". You can continue that one, or start a new chat anyway."]}):"You have an ongoing conversation. You can continue that one, or start a new chat anyway."})]}),t.jsxs("div",{className:"sc-modal-actions-center",children:[t.jsx("button",{type:"button",className:"sc-btn sc-btn-primary",onClick:n,children:"Continue"}),t.jsx("button",{type:"button",className:"sc-btn sc-btn-secondary",onClick:r,children:"Start New Chat"})]})]})})}):null,ke=e=>{const s=e==null?void 0:e.trim();return s?{"order-id":s}:{}},Ke=()=>{const e=pe(),{orderSource:s,orderLocator:n,context:r,isLoading:o,failure:a,refetch:u}=ge(),{startChat:d,isStarting:i}=le(),[f,m]=l.useState(!1),[b,C]=l.useState(null),[O,v]=l.useState(!1),[N,R]=l.useState(!1),S=l.useRef(!1),c=l.useRef(null),[k,I]=l.useState(null),w=l.useRef(!1),T=(r==null?void 0:r.subtype)||"",y=be({properties:ke(n)},!!r&&!f,{orderLocator:n,subtype:T}),h=Ne(T,!!r),E=y.isChecking,$=!f&&!y.isChecking&&!!y.existingConversationId,L=l.useCallback(p=>A(void 0,null,function*(){var q,z;if(w.current||E||i||!r||!s)return;w.current=!0,C(null),v(!1);const j=String((q=p.reasonId)!=null?q:"other");I(j);const x=((z=c.current)==null?void 0:z.intentId)===j?c.current.key:yield ue(s,n,j);c.current={intentId:j,key:x};const g=yield d({clientIdempotencyKey:x,text:p.initialMessage({orderType:T,orderId:n,reference:r.reference,name:r.name}),orderSource:s,orderLocator:n,reasonId:p.reasonId});if(!g){w.current=!1,I(null);return}if(g.failure){if(w.current=!1,I(null),g.failure.kind==="order-unavailable"){u();return}C(g.failure.message),v(g.failure.kind==="attempt-rejected");return}c.current=null,e(`/support/chat/c/${g.conversationId}`,{replace:!0})}),[T,r,i,e,n,s,u,E,d]),G=l.useCallback(()=>{R(!0),v(!1),h.refresh()},[h]),F=h.isEmpty&&!N&&!S.current&&!!r&&!y.isChecking&&!$&&!i;l.useEffect(()=>{F&&(S.current=!0,L(B))},[F,L]);const P=l.useCallback(p=>{ce(),L(p)},[L]);if(o)return t.jsx("div",{className:"cnh-chat sc-screen",children:t.jsx("div",{className:"sc-empty",style:{flex:1},children:t.jsx("p",{style:{fontSize:14,color:"var(--sc-fg-2)"},children:"Loading your orderâ¦"})})});if(a==="unusable-request"||a==="order-unavailable"){const p=a==="unusable-request"?"This order canât be used for chat.":"We couldnât find that order.";return t.jsx("div",{className:"cnh-chat sc-screen",children:t.jsxs("div",{className:"sc-empty",style:{flex:1},children:[t.jsx("p",{style:{fontSize:14,color:"var(--sc-fg-2)"},children:p}),t.jsx("button",{type:"button",className:"sc-btn sc-btn-primary sc-btn-sm",onClick:()=>e("/support/chat/new/general"),children:"Start a general chat"}),t.jsx("button",{type:"button",className:"sc-btn sc-btn-secondary sc-btn-sm",onClick:()=>e("/support/chat"),children:"Back to chats"})]})})}if(a==="retryable"||!r)return t.jsx("div",{className:"cnh-chat sc-screen",children:t.jsxs("div",{className:"sc-empty",style:{flex:1},children:[t.jsx("p",{style:{fontSize:14,color:"var(--sc-fg-2)"},children:"We couldnât load your order just now."}),t.jsx("button",{type:"button",className:"sc-btn sc-btn-primary sc-btn-sm",onClick:()=>u(),children:"Try again"})]})});const U=r.name||r.reference||H(T),_=p=>{var g;const j=String((g=p.reasonId)!=null?g:"other"),x=k===j;return p.reasonId===null?t.jsxs("button",{type:"button",className:"sc-other","aria-busy":x,disabled:E||i||k!==null,onClick:()=>P(p),children:[p.label,x&&t.jsx("span",{className:"sc-spinner","aria-hidden":!0})]},"other"):t.jsxs("button",{type:"button",className:"sc-scenario","aria-busy":x,disabled:E||i||k!==null,onClick:()=>P(p),children:[t.jsx("span",{children:p.label}),x?t.jsx("span",{className:"sc-spinner","aria-hidden":!0}):t.jsx("span",{className:"sc-scenario-chevron",children:"âº"})]},p.reasonId)},V=()=>h.status==="error"?t.jsxs(t.Fragment,{children:[t.jsx("p",{style:{fontSize:14,color:"var(--sc-fg-2)"},children:"We couldnât load the list of topics just now."}),t.jsx("button",{type:"button",className:"sc-btn sc-btn-primary sc-btn-sm",onClick:()=>h.refresh(),children:"Try again"})]}):h.status==="loading"||h.isEmpty&&!N&&!b?t.jsx("p",{style:{fontSize:14,color:"var(--sc-fg-2)"},children:h.isEmpty?"Starting your chatâ¦":"Loading topicsâ¦"}):h.isEmpty?t.jsxs(t.Fragment,{children:[t.jsx("p",{style:{fontSize:14,color:"var(--sc-fg-2)"},children:"There are no topics to pick for this order."}),_(B)]}):h.topics.map(_);return t.jsxs("div",{className:"cnh-chat sc-screen",children:[t.jsxs("div",{className:"sc-hdr-plain",children:[t.jsx("button",{type:"button",className:"sc-hdr-back",onClick:()=>e(-1),"aria-label":"Back",children:"â"}),t.jsx("div",{className:"sc-hdr-plain-title",children:U})]}),t.jsx("div",{className:"sc-scroll",children:t.jsxs("div",{className:"sc-container",children:[y.failedOpen&&t.jsx("div",{className:"sc-error-note",style:{background:"var(--sc-warn-bg)",borderRadius:"var(--sc-radius-md)",padding:"8px 11px",marginBottom:12},children:"We couldnât check for an existing chat, but you can still start one."}),b&&t.jsxs("div",{className:"sc-error-note",children:[b,O&&t.jsx("button",{type:"button",className:"sc-btn sc-btn-secondary sc-btn-sm",style:{marginTop:8},onClick:G,children:"Refresh topics"})]}),t.jsx("div",{className:"sc-section-label",children:"How can we help?"}),V()]})}),t.jsx(Se,{open:$,contextLabel:y.existingLabel,onContinue:()=>y.existingConversationId&&e(`/support/chat/c/${y.existingConversationId}`,{replace:!0}),onStartNew:()=>m(!0),onCancel:()=>e(-1)})]})};export{Ke as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.