/*! For license information please see 923.801cb1c5c4253e5f.js.LICENSE.txt */ "use strict";(this.webpackChunk_gorgias_chat_client=this.webpackChunk_gorgias_chat_client||[]).push([[923],{893:(e,t,a)=>{a.d(t,{c:()=>_,h:()=>D});var n=a(68831),i=a(47420),o=a(32663),r=a(21253),s=a(57972),c=a(40637),d=a(45835),l=a(24758),u=a(71674),p=a(61042),g=a(59181),v=a(87978),A=a(67280),m=a(98698),h=a(36230),f=a(49195),y=a(11884),E=a(1568),b=a(76733),C=a(71207),x=a(90637),T=a(91066),w=a(47823),S=a(94177),_=(0,r.createContext)(null),k=b.N.SEND_CODE_SUBMIT_FAILED,I=b.N.SEND_CODE_SUBMIT_SUCCESS,O=b.N.CODE_VERIFICATION_SUBMIT_SUCCESS,R=b.N.CODE_VERIFICATION_SUBMIT_FAILED,M=b.N.NAVIGATE_TO,D=e=>{var t=e.children,a=(0,p.A)(),D=(0,s.useSelector)(g.Z0),U=(0,s.useSelector)(g.d8),N=(0,c.W6)(),H=(0,s.useDispatch)(),G=(0,r.useState)(),P=(0,o.A)(G,2),L=P[0],B=P[1],z=(0,r.useState)(T.y.PAGE),F=(0,o.A)(z,2),j=F[0],W=F[1],V=(0,r.useCallback)(function(){var e=(0,i.A)((0,n.A)().m(function e(t){var i,o,r,s,c,d;return(0,n.A)().w(function(e){for(;;)switch(e.n){case 0:return i=t.source,o=t.renderMode,r=void 0===o?T.y.PAGE:o,s=N.location.pathname,W(r),c=(0,l.c)(y.z,{input:{codeVerificationSource:i,chatTitle:a,language:D,themeColor:U}}),B(c),e.n=1,(0,u.fm)(c,e=>{var t=e.status;return["done","error"].includes(t)});case 1:if(d=e.v,c.stop(),r!==T.y.DRAWER&&N.replace(s),B(void 0),"error"!==d.status){e.n=2;break}throw d.error;case 2:if(d.output){e.n=3;break}throw new Error("No output from auth actor");case 3:return e.a(2,d.output)}},e)}));return function(t){return e.apply(this,arguments)}}(),[N,a,D,U]),q=(0,r.useCallback)((e,t)=>{if(e.type!==M){if(e.type===I)return[(0,d.V2)(e.codeRequestDetails),(0,d.An)(e.codeRequestDetails)];if(e.type===k)return[(0,d.F_)({codeRequestDetails:e.codeRequestDetails})];if(e.type===O){var a=e.channel===m.Q.EMAIL,n=[];if(n.push((0,d.dc)()),a&&n.push((0,A.K)(e.address),(0,v.r_)(e.address)),L&&j===T.y.DRAWER)L.getSnapshot().context.codeVerificationSource===w.W.SSP&&(0,h.O5)({accessToken:e.idToken}).then(e=>{H((0,d.rC)(e))}).catch(e=>{f.Ay.error(e)});return n}return e.type===R&&e.errorReason===x.R.MAX_VERIFICATION_ATTEMPTS_REACHED?[(0,d.jH)()]:e.type===b.N.ANOTHER_ACCOUNT_HAS_BEEN_USED?[(0,A.K)("")]:void 0}t!==T.y.DRAWER&&N.replace(E.Ei[e.route])},[N,L,j,H]);return(0,r.useEffect)(()=>{if(L){var e=L.on("*",e=>{var t=q(e,j);t&&t.forEach(H)}).unsubscribe;return L.start(),e}},[L,q,H,j]),(0,r.useEffect)(()=>{null===L||void 0===L||L.send({type:C.y.CONTEXT_UPDATE,context:{language:D,chatTitle:a,themeColor:U}})},[L,D,a,U]),(0,S.jsx)(_.Provider,{value:{actor:L,currentRenderMode:j,startAuth:V},children:t})}},18361:(e,t,a)=>{a.d(t,{BO:()=>U,Gf:()=>H,Hm:()=>D,Kh:()=>M,LS:()=>k,Qb:()=>I,Rx:()=>P,_v:()=>L,gq:()=>G,iz:()=>N});var n,i,o,r,s,c,d,l,u,p,g,v,A,m,h,f,y=a(27413),E=a(96859),b=a(62494),C=a(99165),x=a(26533),T=a(63168),w=e=>"".concat("xs"===e?T.Nr:T.J0,"px"),S={default:{desktop:"".concat(T.Sz,"px"),mobile:"".concat(T.e,"px")},chatRedesign:{desktop:"".concat(T.rB,"px"),mobile:"".concat(T.vI,"px")}},_=(e,t)=>S[null!==t&&void 0!==t?t:"default"]["xs"===e?"mobile":"desktop"],k=b.A.div(n||(n=(0,y.A)(["\n position: relative;\n\n width: ",";\n height: ",";\n\n ","\n"])),e=>e.isPartOfGrid?"initial":w(e.size),e=>e.isPartOfGrid?"initial":_(e.size,e.isChatRedesign?"chatRedesign":"default"),e=>!e.isChatRedesign&&(0,E.css)(i||(i=(0,y.A)(["\n background: linear-gradient(\n 180deg,\n rgba(255, 255, 255, 0) 0%,\n rgba(22, 22, 22, 0.1) 100%\n );\n border-radius: 16px;\n\n box-shadow: 4px 4px 16px rgba(22, 22, 22, 0.1);\n transition: box-shadow 350ms ease;\n list-style-type: none;\n\n cursor: pointer;\n\n &:hover {\n box-shadow: 4px 4px 16px rgba(22, 22, 22, 0.2);\n }\n "])))),I=b.A.div(o||(o=(0,y.A)(["\n height: ",";\n border-radius: var(--spacing-md) var(--spacing-md) 0 0;\n overflow: hidden;\n cursor: pointer;\n\n ","\n\n &.widget-xs {\n height: 158px;\n }\n"])),e=>e.isPartOfGrid?"180px":"220px",e=>e.isChatRedesign&&(0,E.css)(r||(r=(0,y.A)(["\n border-radius: var(--spacing-md);\n border: 1px solid var(--border-neutral-default);\n "])))),O=(0,E.css)(s||(s=(0,y.A)(["\n background-blend-mode: overlay;\n background-repeat: no-repeat;\n"]))),R=(0,E.css)(c||(c=(0,y.A)(["\n &:not(.widget-xs) {\n transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);\n &:hover {\n transform: scale(1.05);\n }\n }\n"]))),M=b.A.div(e=>{var t=e.position,a=e.isChatRedesign;return t?(0,E.css)(d||(d=(0,y.A)(["\n ","\n background-size: ","%;\n background-position: ","px ","px;\n\n // slight zoom effect on hover for non-xs widgets\n ","\n "])),O,t.size,t.x,t.y,a&&R):(0,E.css)(l||(l=(0,y.A)(["\n ","\n height: 220px;\n background-size: cover;\n background-position: center;\n\n &.widget-xs {\n height: 158px;\n }\n\n // slight zoom effect on hover for non-xs widgets\n ","\n "])),O,a&&R)}),D=b.A.div(u||(u=(0,y.A)(["\n position: ",";\n right: 0;\n bottom: ",";\n left: 0;\n\n padding: ",";\n border-radius: 0 0 var(--spacing-md) var(--spacing-md);\n\n background: ",";\n\n box-sizing: border-box;\n"])),e=>e.isChatRedesign?"initial":"absolute",e=>e.isChatRedesign?"unset":"0",e=>e.isChatRedesign?"var(--spacing-xs) var(--spacing-xxxs)":"var(--spacing-md)",C.nY.neutralGrey0),U=b.A.div(p||(p=(0,y.A)(["\n position: relative;\n display: flex;\n flex-direction: column;\n gap: var(--spacing-md);\n\n height: 100%;\n width: 100%;\n"]))),N=b.A.div(g||(g=(0,y.A)(["\n display: flex;\n flex-direction: ",";\n justify-content: space-between;\n user-select: none;\n gap: ",";\n"])),e=>e.isChatRedesign?"column":"row",e=>e.isChatRedesign?"var(--spacing-xxxs)":"0"),H=b.A.p(v||(v=(0,y.A)(["\n margin: 0;\n\n color: ",";\n\n font-weight: 500;\n font-size: 14px;\n line-height: 20px;\n letter-spacing: -0.01em;\n word-break: break-word;\n display: -webkit-box;\n -webkit-box-orient: vertical;\n overflow: hidden;\n line-clamp: ",";\n -webkit-line-clamp: ",";\n\n ","\n"])),C.nY.neutral10,e=>"xs"===e.size?1:2,e=>"xs"===e.size?1:2,e=>e.isChatRedesign&&(0,E.css)(A||(A=(0,y.A)(["\n font-size: 12px;\n line-height: 16px;\n color: var(--content-neutral-default);\n "])))),G=b.A.div(m||(m=(0,y.A)(["\n display: flex;\n\n width: ",";\n height: ",";\n\n align-items: center;\n justify-content: center;\n"])),e=>w(e.size),e=>_(e.size)),P=b.A.div(h||(h=(0,y.A)([""]))),L=(0,b.A)(x.A)(f||(f=(0,y.A)(["\n position: absolute;\n top: var(--spacing-xs);\n right: var(--spacing-xs);\n z-index: 10;\n\n border-radius: var(--spacing-lg);\n border: 0.5px solid var(--border-neutral-default);\n background: rgba(255, 255, 255, 0.4);\n box-shadow: 0 2px 3px 0 rgba(0, 0, 0, 0.05);\n\n /* Remove iOS blue tap highlight */\n -webkit-tap-highlight-color: transparent;\n -webkit-touch-callout: none;\n -webkit-user-select: none;\n user-select: none;\n\n /* Remove iOS button styling */\n -webkit-appearance: none;\n appearance: none;\n\n /* Override iOS system blue color */\n color: inherit;\n\n & svg path {\n fill: currentColor;\n }\n"])))},30702:(e,t,a)=>{a.d(t,{h:()=>n});var n=function(e){return e.SUCCESS="success",e.EXIT_BACK_BUTTON="exitBackButton",e.EXIT_UNABLE_TO_LOGIN="exitUnableToLogin",e}({})},42631:(e,t,a)=>{a.d(t,{A:()=>o});var n=a(21253),i=a(893);function o(){var e=(0,n.useContext)(i.c);if(!e){var t="".concat(o.name," must be used within a ").concat(i.h.name);throw new Error(t)}return e}},45579:(e,t,a)=>{a.d(t,{c:()=>o});var n=a(85002),i=a(68233),o=function(){for(var e=arguments.length,t=new Array(e),a=0;a{o.push(e),a!==t.length-1&&o.push("\n")})}}},47823:(e,t,a)=>{a.d(t,{W:()=>n});var n=function(e){return e.SSP="ssp",e.FLOWS="flows",e.AI_AGENT="ai_agent",e}({})},51105:(e,t,a)=>{a.d(t,{J:()=>u,k:()=>E});var n=a(21253),i=a(37680),o=a(16210),r=a(23977),s=a(81503),c=a(6840),d=a(38184),l=a(94177);const u=e=>{var t=e.campaign,a=e.products,u=e.onMove,p=(0,r.z)(),g="xs"===p,v=(0,d.j)(p,!1),A=Boolean(a.length>1),m=e=>{(0,i.$s)(i.TZ.CHAT_PRODUCT_ADD_TO_CART,(0,o.h)({product:e,campaign:t,origin:"campaign"}))},h=e=>{var a;(0,i.$s)(i.TZ.CHAT_PRODUCT_CLICKED,(0,o.h)({product:e,campaign:t,origin:"campaign"}));var n=null!==(a=e.tracking_url)&&void 0!==a?a:e.url;n&&window.open(n)};return(0,n.useEffect)(()=>{a.length&&(0,i.$s)(i.TZ.CHAT_PRODUCTS_DELIVERED,(0,o.h)({products:a,campaign:t,origin:"campaign"}))},[t,a]),A?(0,l.jsx)(c.Ay,{isCompact:g,products:a,configuration:v,campaign:t,origin:"campaign",onAddToCart:m,onClickProduct:h,onMove:u}):(0,l.jsx)(s.A,{campaign:t,products:a,onAddToCart:m,onClickProduct:h})};var p=a(8206),g=a(28730),v=a(74390),A=a(51525),m=a(68182),h=a(48659),f=a(78349),y=(0,n.lazy)(()=>(0,v.D)(()=>Promise.all([a.e(234),a.e(919)]).then(a.bind(a,49752))));const E=e=>{var t=e.messageId,a=e.campaign,u=e.products,v=e.onMove,E=(0,r.z)(),b=(0,A.Q)().open,C=(0,d.j)(E,!0),x=(0,g.o)(),T=(0,m.B)(),w=(0,h.z)().trackSeen,S=(0,n.useRef)(null),_=(0,p.eb)().isAiAgentConversation,k=(0,n.useCallback)(e=>{(0,i.$s)(i.TZ.CHAT_PRODUCT_ADD_TO_CART,(0,o.h)({campaign:a,product:e,origin:"conversation",source:_?"ai-agent":void 0}))},[a,_]),I=(0,n.useCallback)(e=>{var t;(0,i.$s)(i.TZ.CHAT_PRODUCT_CLICKED,(0,o.h)({campaign:a,product:e,origin:"conversation",source:_?"ai-agent":void 0}));var n=null!==(t=e.tracking_url)&&void 0!==t?t:e.url;if(x&&T)b(e);else if(n){var r,s;null===(r=window)||void 0===r||null===(s=r.open)||void 0===s||s.call(r,n)}},[a,_,x,T,b]),O=(0,n.useMemo)(()=>Boolean(u.length>1),[u]),R=(0,n.useMemo)(()=>"xs"===E,[E]);return(0,n.useEffect)(()=>{u.length&&(0,i.$s)(i.TZ.CHAT_PRODUCTS_DELIVERED,{products:u,origin:"conversation"})},[u]),(0,n.useEffect)(()=>{if(S.current){var e=u.map(e=>({id:e.id.toString()})),a=i.TZ.PRODUCT_RECOMMENDATIONS_SEEN;return w(S.current,{event:a,metadata:{products:e}},{deduplicationKey:"".concat(a,"-").concat(t)})}},[t,u,w]),x&&O?(0,l.jsx)(f.OS,{ref:S,children:(0,l.jsx)(y,{campaign:a,products:u,onAddToCart:k,onClickProduct:I})}):O?(0,l.jsx)(f.bS,{widgetSize:E,ref:S,children:(0,l.jsx)(c.Ay,{campaign:a,isCompact:R,products:u,configuration:C,origin:"conversation",onAddToCart:k,onClickProduct:I,onMove:v})}):(0,l.jsx)(f.OS,{ref:S,children:(0,l.jsx)(s.A,{campaign:a,products:u,onAddToCart:k,onClickProduct:I})})}},51525:(e,t,a)=>{a.d(t,{Q:()=>A,z:()=>v});var n=a(57970),i=a(68831),o=a(47420),r=a(32663),s=a(49195),c=a(21253),d=a(72082),l=a(24771),u=a(94177),p=(0,c.createContext)(void 0),g=e=>e,v=e=>{var t=e.children,a=(0,c.useState)(!1),n=(0,r.A)(a,2),v=n[0],A=n[1],m=(0,c.useState)(null),h=(0,r.A)(m,2),f=h[0],y=h[1],E=(0,c.useState)(null),b=(0,r.A)(E,2),C=b[0],x=b[1],T=(0,c.useState)(!1),w=(0,r.A)(T,2),S=w[0],_=w[1],k=(0,c.useState)(null),I=(0,r.A)(k,2),O=I[0],R=I[1],M=(0,l.J)().getAssetByName,D=(0,c.useCallback)(()=>{y(null),R(null),_(!1)},[y,R,_]),U=(0,c.useCallback)(function(){var e=(0,o.A)((0,i.A)().m(function e(t){var a,n,o,c,l;return(0,i.A)().w(function(e){for(;;)switch(e.p=e.n){case 0:if(t.url){e.n=1;break}return _(!1),R("Product URL is required"),e.a(2);case 1:return e.p=1,_(!0),R(null),e.n=2,Promise.all([M("snippets/product-details-storefront-ui.html"),(0,d.O)(t.url)]);case 2:a=e.v,n=(0,r.A)(a,2),o=n[0],c=n[1],y(c),x(g(o)),_(!1),e.n=4;break;case 3:e.p=3,l=e.v,s.Ay.setContext("product-details-drawer",{campaignProduct:t}),s.Ay.error(l),R("Failed to fetch product details"),_(!1);case 4:return e.a(2)}},e,null,[[1,3]])}));return function(t){return e.apply(this,arguments)}}(),[_,R,y,x,M]),N=(0,c.useCallback)(e=>{A(!1),null===e||void 0===e||e()},[A]),H=(0,c.useCallback)(e=>{U(e),A(!0)},[U]),G=(0,c.useMemo)(()=>!!O,[O]),P=(0,c.useMemo)(()=>({isOpen:v,product:f,pdpBaseUrl:C,open:H,close:N,clearProduct:D,hasError:G,isLoading:S}),[v,f,C,H,N,D,G,S]);return(0,u.jsx)(p.Provider,{value:P,children:t})},A=()=>{var e=(0,c.useContext)(p);if(!e)throw new Error("useProductDetailsDrawer must be used within a ProductDetailsDrawerProvider");return(0,n.A)({},e)}},61042:(e,t,a)=>{a.d(t,{A:()=>r});var n=a(54171),i=a(59181),o=a(68233);const r=()=>{var e,t,a,r,s=(0,n.d)(e=>e.application.settings.name),c=(0,n.d)(i.Z0);return(null===(e=o.default.chatApplication())||void 0===e||null===(t=e.texts)||void 0===t||null===(a=t[c])||void 0===a||null===(r=a.texts)||void 0===r?void 0:r.chatTitle)||s}},67734:(e,t,a)=>{a.d(t,{T:()=>n});var n=function(e){return e.STRING="string",e.EMAIL="email",e}({})},68182:(e,t,a)=>{a.d(t,{B:()=>i});var n=a(68233),i=()=>n.default.getChatFeatureFlag("chat-client-ui-product-details-drawer")},75135:(e,t,a)=>{e.exports=a(76932)},76932:(e,t,a)=>{var n=a(21253);var i="function"===typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e===1/t)||e!==e&&t!==t},o=n.useState,r=n.useEffect,s=n.useLayoutEffect,c=n.useDebugValue;function d(e){var t=e.getSnapshot;e=e.value;try{var a=t();return!i(e,a)}catch(n){return!0}}var l="undefined"===typeof window||"undefined"===typeof window.document||"undefined"===typeof window.document.createElement?function(e,t){return t()}:function(e,t){var a=t(),n=o({inst:{value:a,getSnapshot:t}}),i=n[0].inst,l=n[1];return s(function(){i.value=a,i.getSnapshot=t,d(i)&&l({inst:i})},[e,a,t]),r(function(){return d(i)&&l({inst:i}),e(function(){d(i)&&l({inst:i})})},[e]),c(a),a};t.useSyncExternalStore=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:l},78349:(e,t,a)=>{a.d(t,{Jc:()=>k,Kt:()=>x,MR:()=>w,OS:()=>M,SD:()=>I,X9:()=>S,ZD:()=>O,as:()=>R,bS:()=>D,jH:()=>T,wq:()=>C});var n,i,o,r,s,c,d,l,u,p,g,v,A,m=a(27413),h=a(96859),f=a(62494),y=a(63168),E=a(72631),b=a(99165),C=f.A.div(n||(n=(0,m.A)(["\n position: relative;\n display: flex;\n justify-content: flex-start;\n margin: 0 -20px;\n box-sizing: border-box;\n"]))),x=f.A.div(i||(i=(0,m.A)(["\n position: relative;\n width: 100%;\n box-sizing: border-box;\n"]))),T=f.A.div(o||(o=(0,m.A)(["\n position: relative;\n\n display: flex;\n flex-wrap: nowrap;\n gap: ","px;\n\n ","\n\n margin-left: ",";\n\n transition: transform 400ms cubic-bezier(0.165, 0.84, 0.44, 1) 0s;\n backface-visibility: hidden;\n transform-style: preserve-3d;\n touch-action: pan-Y;\n will-change: transform;\n\n &.slideMeDemo {\n animation-delay: 5s;\n animation-duration: 2s;\n animation-name: shake;\n animation-timing-function: cubic-bezier(0.14, 0.75, 0.2, 1.01);\n animation-iteration-count: 2;\n }\n\n @keyframes shake {\n from {\n transform: ",";\n }\n\n 50% {\n transform: translate3d(-30px, 0px, 0px);\n }\n\n to {\n transform: ",";\n }\n }\n"])),e=>e.frameGutter,e=>{var t=e.isChatRedesign,a=e.isCompact;return!t&&(0,h.css)(r||(r=(0,m.A)(["\n padding-bottom:\n ","\n ? ","\n : ","px;\n "])),a,y.et,y.EG)},e=>e.requiresPadding?"-30px":"0",e=>{var t=e.navigationPadding;return"translate3d(".concat(t,", 0px, 0px)")},e=>{var t=e.navigationPadding;return"translate3d(".concat(t,", 0px, 0px)")}),w=f.A.div(s||(s=(0,m.A)(["\n flex-shrink: 0;\n\n transition: transform 400ms cubic-bezier(0.165, 0.84, 0.44, 1) 0s;\n transform: scaleY(0.85);\n\n &.highlighted {\n transform: scaleY(1);\n }\n"]))),S=f.A.div(c||(c=(0,m.A)([""]))),_=f.A.button(d||(d=(0,m.A)(["\n position: absolute;\n top: 50%;\n transform: translateY(-50%);\n\n width: 40px;\n height: 40px;\n\n margin: 0;\n padding: 0;\n border: 0;\n outline: none;\n\n box-shadow: 0px 2px 4px rgba(22, 22, 22, 0.16);\n border-radius: 80px;\n\n background: ",";\n\n color: ",";\n\n cursor: pointer;\n\n :focus {\n outline: none;\n }\n\n svg {\n vertical-align: middle;\n font-size: 16px;\n }\n"])),b.nY.neutral1,b.nY.neutral6),k=(0,f.A)(_)(l||(l=(0,m.A)(["\n left: '20px';\n"]))),I=(0,f.A)(_)(u||(u=(0,m.A)(["\n right: ",";\n"])),e=>e.requiresPadding?"60px":"30px"),O=f.A.div(p||(p=(0,m.A)(["\n display: flex;\n flex-direction: row;\n justify-content: center;\n gap: 4px;\n\n padding: ","px 0\n ","px;\n"])),y.Cz,y.qS),R=f.A.div(g||(g=(0,m.A)(["\n width: ","px;\n height: ","px;\n\n border-radius: 50%;\n\n background: ",";\n\n cursor: pointer;\n\n &.active {\n background: ",";\n border-radius: 40px;\n width: 20px;\n }\n"])),y.Dh,y.Dh,b.nY.neutralGrey2,b.nY.neutralGrey3),M=f.A.div(v||(v=(0,m.A)(["\n display: flex;\n width: 100%;\n justify-content: center;\n margin-right: -","px;\n"])),E.li/2),D=f.A.div(A||(A=(0,m.A)(["\n margin-right: ","px;\n display: flex;\n width: ",";\n justify-content: flex-start;\n"])),e=>"xs"===e.widgetSize?-E.li:-(E.li+E.li/2),e=>"xs"===e.widgetSize?"100%":"unset")},80127:(e,t,a)=>{a.d(t,{A:()=>n});var n=a(21253).useLayoutEffect},91066:(e,t,a)=>{a.d(t,{y:()=>n});var n=function(e){return e.PAGE="page",e.DRAWER="drawer",e}({})},94271:(e,t,a)=>{a.d(t,{V:()=>pe});var n=a(68831),i=a(47420),o=a(32663),r=a(21253),s=a(54607),c=a(79215),d=a(67734),l=a(75412),u=a(42188),p=function(e){return e.EMAIL="email",e.CHAT="chat",e}({}),g=a(62912),v=a(49195),A=a(68233),m=a(54171),h=a(61042),f=a(87978),y=a(67280),E=a(18992),b=a(18176),C=a(65597),x=a(83593),T=a(60438),w=a(56031),S=a(28730),_=a(39283),k=a(30702),I=a(91066),O=a(42631),R=a(47823),M=a(57972),D=a(46806);function U(){var e=(0,M.useDispatch)(),t=(0,h.A)(),a=(0,r.useCallback)(function(){var a=(0,i.A)((0,n.A)().m(function a(i){var o,r,s,c,d;return(0,n.A)().w(function(a){for(;;)switch(a.n){case 0:return o=i.message,r=i.metadata,a.n=1,(0,D.p)(o);case 1:s=a.v,c=s.text,d=s.html,e((0,f.S0)({text:c,html:d,helpdeskBot:l.$X.AI_AGENT_BOT,chatTitle:t,metadata:r}));case 2:return a.a(2)}},a)}));return function(e){return a.apply(this,arguments)}}(),[e,t]);return(0,r.useMemo)(()=>({dispatchMessageAsBot:a}),[a])}var N=a(57970),H=a(69593),G=a(25684),P=a.n(G),L=a(81321),B=a(62684),z=a(80875),F=a(30232),j=a(63143),W=e=>e.toLowerCase(),V=e=>{var t=(0,r.useCallback)((e,t,a)=>{var n,i=a.blackListedEventPatterns,o=a.blacklistExactStates,r=a.blacklistStates,s=a.alwaysAllowedEvents,c=null===(n=e.event)||void 0===n?void 0:n.type;if(!c)return!0;var d,l=W(c),u=(0,B.A)(s);try{for(u.s();!(d=u.n()).done;){var p=d.value;if(l===W(p))return!0}}catch(w){u.e(w)}finally{u.f()}var g,v=(0,B.A)(i);try{for(v.s();!(g=v.n()).done;){var A=g.value,m=W(A);if(l.includes(m))return!1}}catch(w){v.e(w)}finally{v.f()}var h,f=W(t),y=(0,B.A)(r);try{for(y.s();!(h=y.n()).done;){var E=h.value,b=W(E);if(f.includes(b))return!1}}catch(w){y.e(w)}finally{y.f()}var C,x=(0,B.A)(o);try{for(x.s();!(C=x.n()).done;){var T=C.value;if(W(T)===t)return!1}}catch(w){x.e(w)}finally{x.f()}return!0},[]),a=(0,r.useCallback)((e,t)=>t&&e?Object.keys(e).reduce((a,n)=>(t.includes(n)&&(a[n]=e[n]),a),{}):{},[]),o=(0,r.useCallback)(function(){var o=(0,i.A)((0,n.A)().m(function i(o,r){var s,c,d,l,u,p,g,v,A,m,h,f;return(0,n.A)().w(function(n){for(;;)switch(n.n){case 0:if(e&&e.enabled){n.n=1;break}return n.a(2);case 1:if(s=e.machineName,c=e.blacklistEvents,d=void 0===c?[]:c,l=e.blacklistExactStates,u=void 0===l?[]:l,p=e.blacklistStates,g=void 0===p?[]:p,v=e.alwaysAllowedEvents,A=void 0===v?[]:v,m=(0,z.n)(r.value),t(o,m,{blackListedEventPatterns:d,blacklistExactStates:u,blacklistStates:g,alwaysAllowedEvents:A})){n.n=2;break}return n.a(2);case 2:return h=(0,N.A)((0,N.A)((0,N.A)({},(0,F.n)({})),a(r.context,e.trackContext)),{},{machine:{state:m,sessionId:o.actorRef.sessionId,event:o.event.type}}),n.n=3,(0,j.F)();case 3:null===(f=n.v)||void 0===f||f.info("[".concat(s,"] - ").concat(o.event.type),h);case 4:return n.a(2)}},i)}));return function(e,t){return o.apply(this,arguments)}}(),[t,a,e]);return(0,r.useEffect)(()=>{null!==e&&void 0!==e&&e.enabled&&(0,j.F)()},[null===e||void 0===e?void 0:e.enabled]),{trackMachine:o}};function q(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=arguments.length>2?arguments[2]:void 0,o=a.localStorageKey,s=a.ttlOptions,c=a.tracking,d=V(c).trackMachine,l=(0,r.useMemo)(()=>{try{var t=function(e){try{var t=window.localStorage.getItem(e);if(!t)return;return JSON.parse(t)}catch(a){return}}(o);if(!t)return;if(!Y(s))return;return e.resolveState(t)}catch(a){return void v.Ay.error(a,{reason:"Failed to restore snapshot"})}},[e,o,s]),u=(0,r.useCallback)(function(){var e=(0,i.A)((0,n.A)().m(function e(t){var a;return(0,n.A)().w(function(e){for(;;)switch(e.n){case 0:if("@xstate.snapshot"===t.type&&(0,L.o_)(t.actorRef)){e.n=1;break}return e.a(2);case 1:try{a=t.actorRef.getPersistedSnapshot(),(0,L.it)(a)&&(K(o,a),d(t,a))}catch(n){v.Ay.error(n,{reason:"Failed to persist snapshot"})}case 2:return e.a(2)}},e)}));return function(t){return e.apply(this,arguments)}}(),[o,d]);return(0,H.zl)(e,(0,N.A)((0,N.A)({},t),{},{snapshot:l,inspect:u}))}var Y=e=>!e||(!e.timestamp||Math.abs(P()().diff(e.timestamp,"h"))<=e.ttlInHours);function K(e,t){try{var a=JSON.stringify(t);return(0,w.AP)(e,a),!0}catch(n){return v.Ay.error(n,{reason:"Failed to persist snapshot"}),!1}}var Q=a(98995),X=a(82463),Z=a(71674),$=a(24758),J=a(73857),ee=a(89958),te=a(99722),ae=a(45190),ne=a(93276),ie=a(58518),oe=a(71979),re=a(85502),se=a(78956),ce=(0,ee.bh)(ae.default.getState()),de=(0,te.J)(ae.default.getState()),le=(0,Z.mj)({types:{input:{},context:{},events:{},emitted:{}},actions:re.d,guards:oe.E,actors:se.k}).createMachine({context:e=>{var t=e.input,a=void 0===t?{}:t,n=(0,ne.H)(a);return(0,N.A)({statesHistory:[],aiAgentEnabled:!0,chatTitle:"",isConnected:!1,isChatOnline:!1,capturedEmail:null,lastShopperMessage:null,waitTime:null,isInputDisabled:!1,emailCaptureEnabled:!0,emailCaptureEnforcement:null,timeoutEnabled:!1},n)},id:"awesomeGorgias",initial:"deactivated",states:{deactivated:{always:{target:"activated",guard:{type:"aiAgentEnabled"}}},activated:{initial:"idle",on:{authContinueToSignInSurveyRequest:{target:"#awesomeGorgias.activated.authentication.continueToSignInSurvey"},authWasItHelpfulSurveyRequest:{target:"#awesomeGorgias.activated.authentication.wasItHelpfulSurvey"},aiAgentOutcomeCloseSilent:{target:"#awesomeGorgias.activated.closeSilent"},aiAgentOutcomeHandover:{target:"#awesomeGorgias.activated.handover"},aiAgentOutcomeHandoverSilent:{target:"#awesomeGorgias.activated.handover.handoverSuccess"},aiAgentOutcomeSnooze:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation.ongoingAiAgentConversation_waitingResponse"}},states:{idle:{on:{shopperEnteredAMessage:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation",guard:{type:"shouldTriggerAiAgent"}},agentEnteredMessage:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation",guard:{type:"shouldTriggerAiAgentFromAgentMessage"}}},entry:{type:"initNewFlow"}},authentication:{exit:["closeHelpfulSurveyResponse"],on:{shopperEnteredAMessage:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation"},aiAgentOutcomeHandoverFallback:{target:"#awesomeGorgias.activated.handover.fallback"}},initial:"continueToSignInSurvey",states:{continueToSignInSurvey:{always:{actions:"dispatchContinueToSignInButton"},on:{agentEnteredMessage:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation",guard:e=>{var t=e.event.payload.message.content.helpdeskMetadata;return(null===t||void 0===t?void 0:t.ai_agent_message_type)!==l.Qp.REQUEST_AUTHENTICATION}}}},wasItHelpfulSurvey:{entry:{type:"dispatchMessageAsBot",params:{message:ce.wasThatHelpful}},always:{actions:"dispatchAuthHelpfulSurvey"},on:{shopperEnteredAMessage:[{target:"#awesomeGorgias.activated.closedSuccess",guard:"isCloseSurveyResultPositive"}],agentEnteredMessage:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation",guard:e=>{var t=e.event.payload.message.content,a=t.helpdeskMetadata;return("text"in t?t.text:null)!==ce.wasThatHelpful&&(null===a||void 0===a?void 0:a.ai_agent_message_type)!==l.Qp.REQUEST_AUTHENTICATION_SURVEY}}}}}},ongoingAiAgentConversation:{on:{aiAgentOutcomeHandoverFallback:{target:"#awesomeGorgias.activated.handover.fallback"},aiAgentOutcomeTimeout:{target:"#awesomeGorgias.activated.handover.fallback",guard:"isBackendTimeoutEnabled"}},initial:"ongoingAiAgentConversation_waitingAiAgentResponse",states:{ongoingAiAgentConversation_waitingAiAgentResponse:{after:{[(0,ie.$X)()]:[{target:"waitForSync",guard:(0,$.d)(["isTimeoutEnabled","couldBeOutOfSync"])},{target:"timeout",guard:"isTimeoutEnabled"}]},on:{aiAgentOutcomeResetTimeout:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation.ongoingAiAgentConversation_waitingAiAgentResponse",reenter:!0},shopperEnteredAMessage:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation.ongoingAiAgentConversation_waitingAiAgentResponse",reenter:!0}}},waitForSync:{after:{[ie.w9]:[{target:"#awesomeGorgias.activated.ongoingAiAgentConversation.waitForSync",guard:"couldBeOutOfSync",reenter:!0},{target:"timeout"}]},on:{aiAgentOutcomeResetTimeout:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation.ongoingAiAgentConversation_waitingAiAgentResponse",reenter:!0},shopperEnteredAMessage:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation.ongoingAiAgentConversation_waitingAiAgentResponse",reenter:!0}}},timeout:{entry:{type:"signal",params:{metadata:{ai_agent_message_type:l.T0.CHAT_HANDOVER_TO_AGENT_TIMEOUT_AI_AGENT_RESPONSE}}},always:{target:"#awesomeGorgias.activated.handover.fallback"}},ongoingAiAgentConversation_waitingResponse:{on:{shopperEnteredAMessage:{target:"ongoingAiAgentConversation_waitingAiAgentResponse"}}}}},handover:{id:"handover",initial:"selectAvailability",entry:"logStateHistory",states:{selectAvailability:{always:[{target:"online",guard:"isChatOnline"},{target:"offline"}]},online:{initial:"checkAutoReplySettings",states:{checkAutoReplySettings:{always:[{target:"dynamicWaitTimeFlow",guard:"isDynamicWaitTimeFlow"},{target:"emailCapture"}]},dynamicWaitTimeFlow:{initial:"fetchWaitTime",states:{fetchWaitTime:{invoke:{src:"fetchWaitTime",onDone:{actions:(0,J.a)({waitTime:e=>e.event.output}),target:"selectHandoverType"},onError:{actions:(0,J.a)({waitTime:ie.mV}),target:"selectHandoverType"}}},selectHandoverType:{always:[{target:"longWaitTime",guard:(0,$.n)("isWaitTimeShort")},{target:"#awesomeGorgias.activated.handover.online.emailCapture"}]},longWaitTime:{initial:"longHandoverSurvey",states:{longHandoverSurvey:{always:{actions:["hideInput","dispatchHandoverLongSurveyButtons"]},exit:["showInput","closeHelpfulSurveyResponse"],on:{shopperEnteredAMessage:[{target:"#awesomeGorgias.activated.handover.online.emailCapture",guard:(0,$.d)(["isHandoverSurveyResultPositive","emailCaptureEnabled"])},{target:"#awesomeGorgias.activated.handover.handoverSuccess",guard:"isHandoverSurveyResultPositive"},{target:"#awesomeGorgias.activated.handover.offline",guard:"shouldSwitchToEmailFromSurvey"}]}}}}}},emailCapture:{initial:"checkEmailCapture",states:{checkEmailCapture:{always:[{target:"optionalEmailCapture",guard:"shouldDisplayOptionalEmailCapture"},{target:"requiredEmailCapture",guard:"shouldDisplayRequiredEmailCapture"},{target:"#awesomeGorgias.activated.handover.handoverSuccess"}]},optionalEmailCapture:{invoke:{src:"typingAnimation",onDone:{target:"#awesomeGorgias.activated.handover.handoverSuccess",actions:{type:"dispatchHandoverEmailCapture"}}}},requiredEmailCapture:{initial:"askEmail",states:{askEmail:{invoke:{src:"typingAnimation",onDone:{target:"waitEmail",actions:{type:"dispatchHandoverEmailCapture"}}}},waitEmail:{exit:"showInput",always:{actions:"hideInput"},on:{fieldCaptureSubmitted:{guard:"emailWasSubmitted",target:"#awesomeGorgias.activated.handover.handoverSuccess"}}}}}}}}},offline:{initial:"emailCapture",states:{emailCapture:{exit:"showInput",always:{actions:"hideInput"},invoke:{src:"typingAnimation",onDone:{actions:"dispatchHandoverOfflineAskEmail"}},on:{fieldCaptureSubmitted:{guard:"emailWasSubmitted",target:"#awesomeGorgias.activated.handover.handoverSuccess",actions:{type:"dispatchOfflineEmailCaptured",params:e=>({email:e.event.payload.content})}}}}}},handoverSuccess:{always:{guard:"canStartAiAgentAfterHandover",target:"#awesomeGorgias.activated.idle"}},fallback:{invoke:{src:"typingAnimation",onDone:{target:"selectAvailability",actions:{type:"dispatchMessageAsBot",params:{message:de.aiAgentHandoverFallbackMessage}}}}}}},closedSuccess:{initial:"closedSuccess_typingMessage",states:{closedSuccess_typingMessage:{after:{2e3:{target:"closedSuccess_message"}},entry:{type:"dispatchIsAgentTyping",params:{isTyping:!0}},exit:{type:"dispatchIsAgentTyping",params:{isTyping:!1}}},closedSuccess_message:{entry:{type:"dispatchMessageAsBot",params:{message:ce.happyToHelp}},on:{shopperEnteredAMessage:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation.ongoingAiAgentConversation_waitingAiAgentResponse"}}}}},closeSilent:{on:{shopperEnteredAMessage:{target:"#awesomeGorgias.activated.ongoingAiAgentConversation.ongoingAiAgentConversation_waitingAiAgentResponse"}}}}}},on:{trigger_aiAgentDisabled:{guard:"aiAgentDisabled",target:"#awesomeGorgias.deactivated"},contextUpdate_autoResponderConfig:{actions:(0,J.a)({autoResponderConfig:e=>e.event.payload})},contextUpdate_aiAgentEnabled:{actions:(0,J.a)({aiAgentEnabled:e=>e.event.payload.aiAgentEnabled})},contextUpdate_timeoutEnabled:{actions:(0,J.a)({timeoutEnabled:e=>e.event.payload.timeoutEnabled})},contextUpdate_backendTimeoutEnabled:{actions:(0,J.a)({backendTimeoutEnabled:e=>e.event.payload.backendTimeoutEnabled})},contextUpdate_chatTitle:{actions:(0,J.a)({chatTitle:e=>e.event.payload.chatTitle})},contextUpdate_isConnected:{actions:(0,J.a)({isConnected:e=>e.event.payload.isConnected})},contextUpdate_isChatOnline:{actions:(0,J.a)({isChatOnline:e=>e.event.payload.isChatOnline})},contextUpdate_capturedEmail:{actions:(0,J.a)({capturedEmail:e=>e.event.payload.capturedEmail})},contextUpdate_lastShopperMessage:{actions:(0,J.a)({lastShopperMessage:e=>e.event.payload.textContent,lastShopperMessageCreatedAt:e=>e.event.payload.createdAt})},contextUpdate_emailCaptureEnforcement:{actions:(0,J.a)({emailCaptureEnforcement:e=>e.event.payload.emailCaptureEnforcement})},contextUpdate_isInputDisabled:{actions:[{type:"inputDisabledChanged",params(e){var t=e.context,a=e.event;return{currentValue:Boolean(t.isInputDisabled),newValue:a.payload.isInputDisabled}}},(0,J.a)({isInputDisabled:e=>e.event.payload.isInputDisabled})]},contextUpdate_emailCaptureEnabled:{actions:(0,J.a)({emailCaptureEnabled:e=>e.event.payload.emailCaptureEnabled})},contextUpdate_lastProcessedMessageId:{actions:(0,J.a)({lastProcessedMessageId:e=>e.event.payload.lastProcessedMessageId})},contextUpdate_conversationId:{actions:(0,J.a)({conversationId:e=>e.event.payload.conversationId})}}}),ue=a(45579),pe=()=>{var e=(0,m.w)(),t=(0,_.L)(),a=t.setQuickReplyButtons,M=t.resetQuickReplyButtons,D=(0,T.o)().sspTexts,N=(()=>{var e=(0,r.useMemo)(()=>new E.X2("leader-election-channel"),[]),t=(0,r.useMemo)(()=>(0,b.X)(e),[]),a=(0,r.useState)(()=>t.isLeader),n=(0,o.A)(a,2),i=n[0],s=n[1];return(0,r.useEffect)(()=>(s(t.isLeader),t.awaitLeadership().then(()=>{s(!0)}),()=>{e.close(),t.die()}),[e,t]),{isLeader:i}})(),H=N.isLeader,G=U().dispatchMessageAsBot,P=A.default.getChatFeatureFlag("chat-ai-agent-timeout"),L=A.default.getChatFeatureFlag("chat-ai-agent-timeout-backend"),B=(0,m.d)(e=>e.automation.aiAgent.enabled),z=(0,h.A)(),F=(0,m.d)(e=>[e.application.status.isChatOnline,e.application.status.isConnected,e.conversation.aiAgentExecutionPhase,e.conversation.aiAgentExecutionPhaseUpdatedAt]),j=(0,o.A)(F,4),W=j[0],V=j[1],Y=j[2],K=j[3],Z=(0,m.d)(e=>e.user.email),$=(0,m.d)(e=>e.application.credentials.conversationId),J=(0,m.d)(e=>e.application.settings.preferences.autoResponder),ee=(0,r.useMemo)(()=>{var e=window.localStorage.getItem(A.default.localStorageLastMessageTimestamp),t=window.localStorage.getItem(A.default.localStorageChatLastPendingMessageKey);return e||t},[A.default.localStorageLastMessageTimestamp]),te=(0,r.useMemo)(()=>(0,s.Sx)((0,i.A)((0,n.A)().m(function t(){return(0,n.A)().w(function(t){for(;;)switch(t.n){case 0:return e((0,C.Ns)({isOn:!0})),t.n=1,new Promise(e=>setTimeout(e,2e3));case 1:e((0,C.Ns)({isOn:!1}));case 2:return t.a(2)}},t)}))),[e]),ae=(0,r.useCallback)((t,a)=>{var n=a.email;e((0,y.K)(n)),e((0,f.r_)(n)),e((0,f.$7)({channel:p.EMAIL}))},[e]),ne=(0,r.useMemo)(()=>({ttlInHours:ie.iG,timestamp:ee?new Date(ee):void 0}),[ee]),oe=q((0,r.useMemo)(()=>le.provide({actions:{dispatchOfflineEmailCaptured:ae},actors:{typingAnimation:te}}),[te,ae]),{input:{aiAgentEnabled:B,chatTitle:z,isChatOnline:W,capturedEmail:Z}},{localStorageKey:A.default.aiAgentStateMachineName,ttlOptions:ne,tracking:{enabled:B,machineName:"ai-agent-machine",blacklistEvents:["contextUpdate_","xstate.init"],trackContext:["conversationId"],blacklistExactStates:["deactivated","activated.idle"],blacklistStates:["typing"],alwaysAllowedEvents:["shopperEnteredAMessage","agentEnteredMessage"]}}),re=(0,o.A)(oe,3),se=re[0],ce=re[1],de=re[2],pe=(0,m.d)(e=>Boolean(e.application.settings.preferences.emailCaptureEnabled&&e.application.settings.preferences.emailCaptureEnforcement===u.jQ.ALWAYS_REQUIRED&&e.automation.aiAgent.enabled)),ge=(0,m.d)(e=>{var t;return null===(t=e.application.settings.preferences.emailCaptureEnabled)||void 0===t||t}),ve=(0,m.d)(e=>e.application.settings.preferences.emailCaptureEnforcement),Ae=(0,r.useCallback)(t=>{var a,n,i;if((0,ue.c)("\ud83d\udc81 ".concat(t.fromAgent?"agent":"shopper"," \ud83d\udc49 ").concat("html"in t.content?t.content.html:"text"in t.content?t.content.text:t.content),"\ud83d\udcf8 xstate",se,"\ud83d\udce8",t),(null===(a=t.content)||void 0===a||null===(n=a.metadata)||void 0===n?void 0:n.origin)!==l.SL.CONVERSATION_STARTER){(0,w.AP)(A.default.localStorageLastMessageTimestamp,t.createdDatetime);var o=(null===(i=t.content)||void 0===i?void 0:i.fieldCaptureType)===d.T.EMAIL&&pe;ce({type:"contextUpdate_isInputDisabled",payload:{isInputDisabled:o}});var r="text"in t.content?t.content.text:null,s=(0,X.XZ)(r);if(t.fromAgent||(t.id!==se.context.lastProcessedMessageId&&e((0,C.dc)(g.$.ANALYZING)),ce({type:"contextUpdate_lastShopperMessage",payload:{createdAt:t.createdDatetime,textContent:r}}),(0,ue.c)("\ud83c\udf00 dispatch event `shopperEnteredAMessage`",r),ce({type:"shopperEnteredAMessage",payload:{message:t}}),ce({type:"contextUpdate_lastProcessedMessageId",payload:{lastProcessedMessageId:t.id}}),s)){var c=se.matches({activated:"ongoingAiAgentConversation"}),u=(0,X.zN)({message:t,isOngoingConversation:c});switch(u){case Q.i.AUTHENTICATION:ce({type:"authContinueToSignInSurveyRequest"}),(0,ue.c)("\ud83c\udf00 dispatch event `authContinueToSignInSurveyRequest`");break;case Q.i.AUTHENTICATION_SURVEY:ce({type:"authWasItHelpfulSurveyRequest"}),(0,ue.c)("\ud83c\udf00 dispatch event `authWasItHelpfulSurveyRequest`");break;case Q.i.TIMEOUT:ce({type:"aiAgentOutcomeTimeout"}),(0,ue.c)("\ud83c\udf00 dispatch event `aiAgentOutcomeTimeout`");break;case Q.i.CLOSE_SILENT:ce({type:"aiAgentOutcomeCloseSilent"}),(0,ue.c)("\ud83c\udf00 dispatch event `aiAgentOutcomeCloseSilent`");break;case Q.i.HANDOVER:ce({type:"aiAgentOutcomeHandover"}),(0,ue.c)("\ud83c\udf00 dispatch event `aiAgentOutcomeHandover`");break;case Q.i.HANDOVER_SILENT:ce({type:"aiAgentOutcomeHandoverSilent"}),(0,ue.c)("\ud83c\udf00 dispatch event `aiAgentOutcomeHandoverSilent`");break;case Q.i.HANDOVER_FALLBACK:ce({type:"aiAgentOutcomeHandoverFallback"}),(0,ue.c)("\ud83c\udf00 dispatch event `aiAgentOutcomeHandoverFallback`");break;case Q.i.SNOOZE:ce({type:"aiAgentOutcomeSnooze"}),(0,ue.c)("\ud83c\udf00 dispatch event `aiAgentOutcomeSnooze`");break;case Q.i.RESET_TIMEOUT:ce({type:"aiAgentOutcomeResetTimeout"}),(0,ue.c)("\ud83c\udf00 dispatch event `aiAgentOutcomeResetTimeout`");break;case null:break;default:v.Ay.error(new Error("[AIAGENT] Unhandled AI Agent outcome: ".concat(u)))}u&&e((0,C.bx)(u)),s||((0,ue.c)("\ud83c\udf00 dispatch event `agentEnteredMessage`",r),ce({type:"agentEnteredMessage",payload:{message:t}})),ce({type:"contextUpdate_lastProcessedMessageId",payload:{lastProcessedMessageId:t.id}})}}},[ce,se]),me=(0,r.useCallback)(function(){var t=(0,i.A)((0,n.A)().m(function t(i){var o,r,s;return(0,n.A)().w(function(t){for(;;)switch(t.n){case 0:o=i.type,r=i.payload,s=o,t.n="hideInput"===s?1:"showInput"===s?2:"initNewFlow"===s?3:"dispatchIsAgentTyping"===s?4:"dispatchHandoverOfflineAskEmail"===s?5:"dispatchHandoverLongSurveyButtons"===s?7:"closeHelpfulSurveyResponse"===s?8:"dispatchOptionalEmailCapture"===s?9:"inputDisabledChanged"===s?11:"dispatchSignal"===s?13:"dispatchProcessHtmlContentAsBot"===s?15:"dispatchContinueToSignInButton"===s||"dispatchAuthHelpfulSurvey"===s||"stateHistoryUpdated"===s?19:20;break;case 1:return e((0,x.os)(!1)),t.a(3,21);case 2:return e((0,x.os)(!0)),t.a(3,21);case 3:return e((0,C.il)(null)),t.a(3,21);case 4:return e((0,C.Ns)({isOn:!(null===r||void 0===r||!r.isTyping),isPermanent:null===r||void 0===r?void 0:r.isPermanent})),t.a(3,21);case 5:if(H){t.n=6;break}return t.a(2);case 6:return e((0,f.sS)({text:"",helpdeskBot:l.$X.AI_AGENT_BOT,chatTitle:z,fieldCaptureTitle:D("email"),fieldCaptureType:d.T.EMAIL})),t.a(3,21);case 7:return a([{displayText:D("stayInChat")},{displayText:D("receiveByEmail")}]),t.a(3,21);case 8:return M(),t.a(3,21);case 9:if(H){t.n=10;break}return t.a(2);case 10:return e((0,f.ep)({text:"",helpdeskBot:l.$X.AI_AGENT_BOT,chatTitle:z})),t.a(3,21);case 11:if(r.hasChanged){t.n=12;break}return t.a(2);case 12:return e((0,x.os)(!r.isInputDisabled)),t.a(3,21);case 13:if(H){t.n=14;break}return t.a(2);case 14:return e((0,f.PK)({helpdeskBot:l.$X.AI_AGENT_BOT,chatTitle:z,metadata:r.metadata})),t.a(3,21);case 15:if(H){t.n=16;break}return t.a(2);case 16:if(r){t.n=17;break}return v.Ay.error(new Error("[AIAGENT] Missing payload in dispatchProcessHtmlContentAsBot")),t.a(2);case 17:return t.n=18,G({message:r.message,metadata:r.metadata});case 18:return r.focus&&e((0,C.Ng)(!0)),t.a(3,21);case 19:return t.a(3,21);case 20:return v.Ay.error(new Error("[AIAGENT] Unhandled handleEventEmitted type: ".concat(o))),t.a(3,21);case 21:return t.a(2)}},t)}));return function(e){return t.apply(this,arguments)}}(),[e,H,G]);return function(e){var t=e.actor,a=(0,O.A)().startAuth,o=(0,_.L)(),s=o.setQuickReplyButtons,c=o.resetQuickReplyButtons,d=(0,T.o)().sspTexts,u=(0,S.o)(),p=U().dispatchMessageAsBot,g=(0,r.useCallback)(function(){var e=(0,i.A)((0,n.A)().m(function e(t){return(0,n.A)().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,p({message:d("aiAgentAuthenticationSuccess"),metadata:{idToken:t,ai_agent_message_type:l.T0.AUTHENTICATION_SUCCESS}});case 1:return e.a(2)}},e)}));return function(t){return e.apply(this,arguments)}}(),[p,d]),v=(0,r.useCallback)((0,i.A)((0,n.A)().m(function e(){return(0,n.A)().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,p({message:d("aiAgentAuthenticationFailed"),metadata:{ai_agent_message_type:l.T0.AUTHENTICATION_FAILED}});case 1:return e.a(2)}},e)})),[p,d]),A=(0,r.useCallback)((0,i.A)((0,n.A)().m(function e(){var t,i,o;return(0,n.A)().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,t=u?I.y.DRAWER:I.y.PAGE,i=R.W.AI_AGENT,e.n=1,a({source:i,renderMode:t});case 1:if((o=e.v).authOutcome!==k.h.SUCCESS){e.n=2;break}return c(),e.n=2,g(o.idToken);case 2:if(o.authOutcome!==k.h.EXIT_UNABLE_TO_LOGIN){e.n=3;break}return c(),e.n=3,v();case 3:e.n=5;break;case 4:return e.p=4,e.v,e.n=5,v();case 5:return e.a(2)}},e,null,[[0,4]])})),[a,c,g,v]),m=(0,r.useCallback)(()=>{s([{displayText:d("verifyOrderDetails"),onClick:A}])},[A,s,d]),h=(0,r.useCallback)(()=>{s([{displayText:d("yesThanks")},{displayText:d("noContinueToSignIn"),onClick:A}])},[A,s,d]);(0,r.useEffect)(()=>{var e=[t.on("dispatchAuthHelpfulSurvey",h),t.on("dispatchContinueToSignInButton",m)];return()=>e.forEach(e=>e.unsubscribe())},[t,m,h])}({actor:de}),(0,r.useEffect)(()=>{var e=de.on("*",me);return()=>e.unsubscribe()},[de,me]),(0,r.useEffect)(()=>{(0,ue.c)("\ud83d\udcf8 xstate",JSON.stringify(null===se||void 0===se?void 0:se.value),se)},[de,se]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_aiAgentEnabled' \ud83d\udc49 ".concat(B)),ce({type:"contextUpdate_aiAgentEnabled",payload:{aiAgentEnabled:B}}),B||((0,ue.c)("trigger_aiAgentDisabled' \ud83d\udc49 ".concat(B)),ce({type:"trigger_aiAgentDisabled",payload:{aiAgentEnabled:B}}))},[B]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_timeoutEnabled' \ud83d\udc49 ".concat(P)),ce({type:"contextUpdate_timeoutEnabled",payload:{timeoutEnabled:!!P}})},[P]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_backendTimeoutEnabled' \ud83d\udc49 ".concat(L)),ce({type:"contextUpdate_backendTimeoutEnabled",payload:{backendTimeoutEnabled:!!L}})},[L]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_chatTitle \ud83d\udc49 ".concat(z)),ce({type:"contextUpdate_chatTitle",payload:{chatTitle:z}})},[z]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_isChatOnline \ud83d\udc49 ".concat(W)),ce({type:"contextUpdate_isChatOnline",payload:{isChatOnline:W}})},[W]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_isConnected \ud83d\udc49 ".concat(V)),ce({type:"contextUpdate_isConnected",payload:{isConnected:V}})},[V,ce]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_emailCaptureEnabled \ud83d\udc49 ".concat(ge)),ce({type:"contextUpdate_emailCaptureEnabled",payload:{emailCaptureEnabled:ge}})},[ge]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_emailCaptureEnforcement \ud83d\udc49 ".concat(ve)),ce({type:"contextUpdate_emailCaptureEnforcement",payload:{emailCaptureEnforcement:ve}})},[ve]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_capturedEmail \ud83d\udc49 ".concat(Z)),ce({type:"contextUpdate_capturedEmail",payload:{capturedEmail:Z}})},[Z]),(0,r.useEffect)(()=>{var e;(0,ue.c)("contextUpdate_autoResponderConfig \ud83d\udc49 ".concat(JSON.stringify(J))),ce({type:"contextUpdate_autoResponderConfig",payload:{isEnabled:null!==(e=null===J||void 0===J?void 0:J.enabled)&&void 0!==e&&e,replyType:null===J||void 0===J?void 0:J.reply}})},[J]),(0,r.useEffect)(()=>{(0,ue.c)("contextUpdate_conversationId \ud83d\udc49 ".concat($)),ce({type:"contextUpdate_conversationId",payload:{conversationId:$}})},[$]),(0,c.A)(()=>{Y&&Y!==g.$.ANALYZING&&(ce({type:"aiAgentOutcomeResetTimeout"}),(0,ue.c)("\ud83c\udf00 dispatch event `aiAgentOutcomeResetTimeout`"))},[Y,K,ce]),(e=>{var t=e.forceProcess,a=e.handleNewLiveChatMessage,n=(0,m.d)(e=>e.conversation.latestLiveChatMessageReceived),i=(0,r.useCallback)(e=>{if(t)return!0;var a=window.localStorage.getItem(A.default.localStorageLastMessageTimestamp);return!a||new Date(e.createdDatetime)>new Date(a)},[t]);(0,r.useEffect)(()=>{n&&i(n)&&a(n)},[n,i])})({handleNewLiveChatMessage:Ae,forceProcess:se.matches({activated:"authentication"})||se.matches({activated:"ongoingAiAgentConversation"})}),{state:se,send:ce,actor:de}}}}]); //# sourceMappingURL=923.801cb1c5c4253e5f.js.map