@deepdesk/deepdesk-sdk 10.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Deepdesk SDK
2
+
3
+ ## Getting started
4
+
5
+ ### Prerequisites
6
+
7
+ - [Node.js](https://nodejs.org/en/download/) v16
8
+ - Npm v8
9
+
10
+ ### Setup
11
+
12
+ Copy-paste `example.env` to `.env` and provide values for missing environment vars.
13
+
14
+ ```bash
15
+ cp example.env .env
16
+ ```
17
+
18
+ Install Node.js dependencies
19
+
20
+ ```bash
21
+ npm ci
22
+ ```
23
+
24
+ ### Development
25
+
26
+ Run tests
27
+
28
+ ```bash
29
+ npm run test
30
+ ```
31
+
32
+ Run code linting
33
+
34
+ ```bash
35
+ npm run lint
36
+ ```
37
+
38
+ Run playground to test and develop the DeepdeskSDK
39
+
40
+ ```bash
41
+ npm run dev
42
+ ```
43
+
44
+ ### Cross project development
45
+
46
+ If you want to test/debug/develop the DeepdeskSDK in another project. You could link this package in the other project.
47
+
48
+ First make the DeepdeskSDK available on you local machine. And start it in linked development mode:
49
+
50
+ ```bash
51
+ npm run link
52
+ npm run dev-linked
53
+ ```
54
+
55
+ Then link the DeepdeskSDK to the project you are working on. Depending on the dev-watch setup, changes made in the DeepdeskSDK are reflected in the other project.
56
+
57
+ ```bash
58
+ # other project (eg. deepdesk-chrome-extension)
59
+ npm link @deepdesk/deepdesk-sdk
60
+ ```
@@ -0,0 +1,6 @@
1
+ "use strict";var td=Object.create;var go=Object.defineProperty;var nd=Object.getOwnPropertyDescriptor;var od=Object.getOwnPropertyNames;var sd=Object.getPrototypeOf,rd=Object.prototype.hasOwnProperty;var V=(t,e)=>{for(var n in e)go(t,n,{get:e[n],enumerable:!0})},Ni=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of od(e))!rd.call(t,s)&&s!==n&&go(t,s,{get:()=>e[s],enumerable:!(o=nd(e,s))||o.enumerable});return t};var _=(t,e,n)=>(n=t!=null?td(sd(t)):{},Ni(e||!t||!t.__esModule?go(n,"default",{value:t,enumerable:!0}):n,t)),id=t=>Ni(go({},"__esModule",{value:!0}),t);var uf={};V(uf,{Card:()=>D,Chip:()=>qa,ContentEditableInput:()=>Lt,DeepdeskAPI:()=>Je,DeepdeskSDK:()=>uo,InputMediator:()=>Me,InputType:()=>et,KeyboardHint:()=>Cs,Label:()=>qs,Locale:()=>Sn,Section:()=>Rt,SectionList:()=>js,Sources:()=>Ye,Suggestion:()=>O,SuggestionList:()=>Re,TextAreaInput:()=>Oe,ToggleButton:()=>Et,attachFile:()=>jp,authenticateWithKey:()=>Vp,createOverlayContainer:()=>Wt,createRangeFromOffsets:()=>It,escapeHTML:()=>ln,fetchPlatformConfig:()=>qp,formatTextMarkup:()=>Up,getRangeOffsets:()=>Ws,getRangeText:()=>ao,isSupportedInputElement:()=>Qs,updateContentEditable:()=>Kp,updateTextArea:()=>Bp,useStyles:()=>h,waitForElementVisibilityChange:()=>Zs});module.exports=id(uf);var Di=/(?:[.,;:!?\\n]|:\\)|:\\(|:-\\)|:-\\()/g,Nt=/(((\$!\{)|(\{))[a-zA-Z0-9_.]+\})/g;var Hi=/x-deepdesk-(([a-z0-9\-_])+-version)/,Ye=(p=>(p.SEARCH="search",p.TEMPLATE="template",p.ELASTIC_SEARCH="studio-search",p.GPT="gpt",p.TRIE="trie",p.TRIE_WITH_TYPOS="trie-with-typos",p.SEMANTIC="semantic",p.TEXT_RECOMMENDATION="text_recommendation",p.URL_RECOMMENDATION="url_recommendation",p.LINK_RECOMMENDATION="link_recommendation",p.PERSONAL_COLLECTION="personal-collection",p.PERSONAL_COLLECTION_SEARCH="personal-collection-search",p))(Ye||{}),et=(s=>(s.TAB="tab",s.ARROW="arrow",s.HOTKEY="hotkey",s.MOUSE="mouse",s))(et||{});var Qe=require("react-dom");var vc=require("react");var Fi=require("@reduxjs/toolkit"),Bi=require("react-redux");var Sn=(n=>(n.NL_NL="nl-NL",n.EN_US="en-US",n))(Sn||{});var ad={locale:"en-US",deanonymize:!1,fallbackImage:!1,isEmbedded:!1,showAutoflows:!1,showCustomMessages:!1,showImages:!1,showPersonalCollectionLink:!1,showSearch:!1,showImageSearch:!1,showStyleSuggestions:!1,showMidSentenceSuggestions:!1,showSuggestionsBeforePattern:!1,showSuggestionsAfterPattern:!1,showTabCompletion:!0,showTextSuggestions:!0,showEntitiesCommand:!1,showSummaryCommand:!1,showKnowledgeSearch:!1,textSuggestionsCount:3,recommendTextSuggestions:!0,searchTriggerKey:"k",visible:!0,insertLink:!1,inlineSuggestions:!1,adminUrl:void 0},Ki=(0,Fi.createSlice)({name:"settings",initialState:ad,reducers:{set(t,e){Object.entries(e.payload).forEach(n=>{let[o,s]=n;typeof s>"u"||(t[o]=s)})}}}),{set:vn}=Ki.actions,tr=t=>e=>e.settings[t],E=t=>(0,Bi.useSelector)(tr(t)),Ui=Ki.reducer;var Vl=require("react"),on=require("react-redux");var Ee=require("@reduxjs/toolkit"),Wi=require("diff"),Gi=require("react-redux");function Vi(t){return typeof t=="object"&&!Array.isArray(t)&&t!==null}function tt(t,e,n=10){let o=typeof t,s=typeof e;if(n===0)throw new Error("Max depth deepEqual, possible circular references?");return o!==s?!1:t==null||o==="string"||o==="number"||o==="boolean"?t===e:Array.isArray(t)&&Array.isArray(e)?t.length!==e.length?!1:t.every((r,i)=>tt(r,e[i],n-1)):Vi(t)&&Vi(e)?Object.keys(t).length!==Object.keys(e).length?!1:Object.keys(t).every(i=>tt(t[i],e[i],n-1)):!1}function ld(t){return Math.max(...t.map(e=>e.length))}function cd(t,e){let n=t.reduce((o,s)=>{if(s){let r=o[s]?o[s]+1:1;return{...o,[s]:r}}return o},{});return Object.keys(n).reduce((o,s)=>(n[s]<e&&o.push(s),o),[])}function qi(t,e){let o=[...t.map(({text:s})=>s.split(/\b(\w+)\b/))];for(let s=0;s<ld(o);s++){let r=cd(o.map(a=>a[s]),e),i=o.filter(a=>!r.includes(a[s]));if(i.length>=e)o=i;else return{text:o[0].slice(0,s).join("").replace(/ (\?| |!|\.|,|\n)/g,"$1").trimEnd(),source:"mixed"}}}var ud=2;function nr(t,e=""){if(t.length===0)return;if(t.length===1)return t[0];let n=qi(t,ud);return n&&n.text!==e?n:t[0]}var ye=require("@reduxjs/toolkit"),ji={current:null,isSupported:null},R=(0,ye.createAction)("resetConversation"),fo=t=>{let{current:e}=t.conversation;return(e==null?void 0:e.sessionId)||null},ho=t=>{let{current:e}=t.conversation;return(e==null?void 0:e.id)||null},yo=t=>t.conversation.isSupported,or=(0,ye.createAsyncThunk)("conversation/isSupported",(t,e)=>{let{deepdeskAPI:n}=e.extra;return n.isConversationSupported(t.sessionId,t.options)}),So=(0,ye.createAsyncThunk)("conversation/create",(t,e)=>{let{deepdeskAPI:n}=e.extra;return n.createConversation(t)}),vo=(0,ye.createAsyncThunk)("conversation/bySessionId",(t,e)=>{let{deepdeskAPI:n}=e.extra;return n.getConversationBySessionId(t.sessionId,t.options)}),xo=(0,ye.createAsyncThunk)("conversation/update",(t,e)=>{let{deepdeskAPI:n}=e.extra,o=ho(e.getState());if(!o)throw new Error("No current conversation to update");return n.updateConversation(o,t)}),sr=(0,ye.createAsyncThunk)("conversation/upsert",(t,e)=>{let{deepdeskAPI:n}=e.extra;return n.getConversationBySessionId(t.sessionId).catch(()=>null).then(o=>{if(!o)return n.createConversation(t);let{agentId:s,agentName:r,agentEmail:i,agentNickname:a,tags:l}=t;return n.updateConversation(o.id,{agentId:s,agentEmail:i,agentName:r,agentNickname:a,tags:l})})}),Co=(0,ye.createAsyncThunk)("conversation/postMessages",(t,e)=>{let{deepdeskAPI:n}=e.extra,o=ho(e.getState());if(!o)throw new Error("No current conversation to update messages");return n.postMessages(o,t.map(s=>({...s})))}),pd=[So.rejected,vo.rejected,xo.rejected,Co.rejected].map(t=>t==null?void 0:t.toString()),dd=(0,ye.createSlice)({name:"conversation",initialState:ji,reducers:{},extraReducers:t=>{t.addCase(or.fulfilled,(e,n)=>{e.isSupported=n.payload}).addCase(So.fulfilled,(e,n)=>{var o;e.current=n.payload,e.isSupported=((o=n.payload)==null?void 0:o.hasActiveProfile)??null}).addCase(vo.fulfilled,(e,n)=>{var o;e.current=n.payload,e.isSupported=((o=n.payload)==null?void 0:o.hasActiveProfile)??null}).addCase(sr.fulfilled,(e,n)=>{var o;e.current=n.payload,e.isSupported=((o=n.payload)==null?void 0:o.hasActiveProfile)??null}).addCase(xo.fulfilled,(e,n)=>{var o;e.current=n.payload,e.isSupported=((o=n.payload)==null?void 0:o.hasActiveProfile)??null}).addCase(Co.fulfilled,(e,n)=>{e.current&&(e.current.messages=n.payload)}).addCase(R,()=>ji).addMatcher(e=>pd.includes(e.type),(e,n)=>{throw new Error(n.error.message)})}}),zi=dd.reducer;var nt={text:"",html:null,selection:{start:0,end:0},stagedSuggestion:null,userCommitted:{text:"",selection:{start:0,end:0}},tabCompletionSuggestion:void 0,previousKeyDownEvent:null,textSuggestions:[],selectedSuggestionIndex:-1,metrics:{numCharsTyped:0,numCharsPasted:0,numCharsCut:0,numCharsDeleted:0,numPaste:0,agentStartedTypingTimestamp:null,pastes:[],deletions:[],offeredTextSuggestions:[],textSuggestions:[],cuts:[]}};function bo(t){let{key:e,shiftKey:n,ctrlKey:o,metaKey:s,altKey:r}=t;return{key:e,shiftKey:n,ctrlKey:o,metaKey:s,altKey:r}}var wo=(0,Ee.createAction)("input/replaceText"),Eo=(0,Ee.createAction)("input/keyDown"),xn=(0,Ee.createAction)("input/sendMessage"),_o=(0,Ee.createAction)("input/sendEditSuggestionMessage"),Po=(0,Ee.createAction)("input/uiInputChange"),ko=(0,Ee.createAction)("input/applyImageSuggestion"),Ae=(0,Ee.createAction)("input/sendEvent");function To(t){if(!t.stagedSuggestion)return;let{text:e,suggestion:{source:n,abVariant:o,abTestName:s,trainingJobs:r,sourceText:i},eventMetrics:{inputType:a},replace:l}=t.stagedSuggestion,c=n==="search"||n==="personal-collection-search",u=c||l==="selection"?e:e.slice(t.userCommitted.text.substring(0,t.userCommitted.selection.start).length);t.userCommitted.text=t.text,t.userCommitted.selection=t.selection,t.metrics.textSuggestions=[...t.metrics.textSuggestions,{text:u,source:n,abVariant:o,abTestName:s,inputType:a,sourceText:i,trainingJobs:r||[],searchTerm:c?t.userCommitted.text:null}],t.stagedSuggestion=null,t.textSuggestions=[],t.selectedSuggestionIndex=-1}var $i=t=>(0,Ee.createSlice)({name:t,initialState:nt,reducers:{initialInput(e,n){let{text:o,selection:s,html:r}=n.payload;e.text=o,e.selection.start=(s==null?void 0:s.start)??o.length,e.selection.end=(s==null?void 0:s.end)??o.length,e.userCommitted.text=o,e.userCommitted.selection.start=(s==null?void 0:s.start)??o.length,e.userCommitted.selection.end=(s==null?void 0:s.end)??o.length,e.html=r||null},reset(e){Object.assign(e,{...nt,selection:e.selection})},resetToCommitted(e){e.text=e.userCommitted.text,e.selection=e.userCommitted.selection,e.stagedSuggestion=null,e.tabCompletionSuggestion=nr(e.textSuggestions,e.userCommitted.text)},setInputHtml(e,n){e.html=n.payload},changeSelection(e,n){n.payload&&(tt(e.selection,n.payload)||(e.selection=n.payload,e.userCommitted.selection=e.selection,e.stagedSuggestion&&To(e)))},userInput(e,n){var i,a,l,c;if(e.previousKeyDownEvent){let{key:u,shiftKey:d,ctrlKey:p,metaKey:m,altKey:g}=e.previousKeyDownEvent;switch(u){case"Enter":d&&(e.metrics.numCharsTyped+=1);break;case"Backspace":case"Delete":{let{text:f}=e,{text:T}=n.payload,b=(0,Wi.diffChars)(f,T);f.length-T.length>1&&e.metrics.deletions.push(...b.filter(y=>y.removed).map(y=>y.value)),e.metrics.numCharsDeleted+=f.length-T.length;break}case"C":case"V":case"X":if(!p&&!m){e.metrics.numCharsTyped+=1;let f=((i=e.selection)==null?void 0:i.start)!==void 0&&((a=e.selection)==null?void 0:a.end)!==void 0?e.text.substring(e.selection.start,e.selection.end):null;f&&f.length>0&&(e.metrics.numCharsDeleted+=f.length,e.metrics.deletions.push(f))}break;case"Shift":break;default:if(!p&&!m&&!g){e.metrics.numCharsTyped+=1;let f=((l=e.selection)==null?void 0:l.start)!==void 0&&((c=e.selection)==null?void 0:c.end)!==void 0?e.text.substring(e.selection.start,e.selection.end):null;f&&f.length>0&&(e.metrics.numCharsDeleted+=f.length,e.metrics.deletions.push(f))}}}!e.metrics.agentStartedTypingTimestamp&&n.payload.text!==e.text&&(e.metrics.agentStartedTypingTimestamp=Date.now()),n.payload.text===""&&(e.metrics=nt.metrics,e.textSuggestions=[]),e.text!==n.payload.text&&To(e);let{text:o,html:s,selection:r}=n.payload;r&&(e.selection.start=r.start,e.selection.end=r.end,e.userCommitted.selection.start=r.start,e.userCommitted.selection.end=r.end),e.text=o,e.html=s||null,e.userCommitted.text=o,e.previousKeyDownEvent=null},stageSuggestion(e,n){let{text:o}=n.payload;switch(e.stagedSuggestion=n.payload,e.tabCompletionSuggestion=void 0,n.payload.replace){case"selection":e.text=`${e.text.slice(0,e.selection.start)}${o}${e.text.slice(e.selection.end)}`,e.selection.end=e.selection.start+o.length,e.selection.start+=o.length;break;case"until-selection-end":e.text=`${o}${e.text.slice(e.selection.end)}`,e.selection.start=o.length,e.selection.end=o.length;break;default:throw new Error(`Unknown replace ${n.payload.replace}`)}n.payload.eventMetrics.inputType==="tab"&&To(e)},commitSuggestion(e){To(e)},offeredTextSuggestion(e,n){let{text:o,suggestion:{source:s}}=n.payload;e.metrics.offeredTextSuggestions.find(i=>i.text===o)||e.metrics.offeredTextSuggestions.push({text:o,source:s})},registerCut(e,n){let{metrics:o}=e,s=n.payload;e.metrics={...e.metrics,numCharsCut:o.numCharsCut+s.length,cuts:[...o.cuts,s]}},registerPaste(e,n){let{metrics:o}=e,{text:s,selectionText:r}=n.payload,i=o.numCharsDeleted+(r&&r.length?r.length:0),a=r&&r.length?[...o.deletions,r]:o.deletions;e.metrics={...e.metrics,numCharsDeleted:i,deletions:a,numCharsPasted:o.numCharsPasted+s.length,numPaste:o.numPaste+1,pastes:[...o.pastes,s]}},registerKeyDown(e,n){e.previousKeyDownEvent=n.payload},nextTextSuggestionIndex(e){let n=e.textSuggestions.length;e.selectedSuggestionIndex=e.selectedSuggestionIndex<n-1?e.selectedSuggestionIndex+1:e.selectedSuggestionIndex},previousTextSuggestionIndex(e){e.selectedSuggestionIndex=e.selectedSuggestionIndex>=0?e.selectedSuggestionIndex-1:e.selectedSuggestionIndex},setTextSuggestions(e,n){if(e.selectedSuggestionIndex=-1,e.textSuggestions=n.payload,n.payload.length===0)return;let o=e.userCommitted.text.substring(0,e.userCommitted.selection.end),s=nr(n.payload,o);e.tabCompletionSuggestion=s!=null&&s.text.includes(o)?s:void 0},setSelectedTextSuggestionIndex(e,n){e.selectedSuggestionIndex=n.payload},mergeMetrics(e,{payload:n}){e.metrics.numCharsTyped+=n.numCharsTyped,e.metrics.numCharsPasted+=n.numCharsPasted,e.metrics.numCharsCut+=n.numCharsCut,e.metrics.numCharsDeleted+=n.numCharsDeleted,e.metrics.numPaste+=n.numPaste,e.metrics.pastes.push(...n.pastes),e.metrics.deletions.push(...n.deletions)}},extraReducers:e=>{e.addCase(R,n=>{n.tabCompletionSuggestion=nt.tabCompletionSuggestion,n.previousKeyDownEvent=nt.previousKeyDownEvent,n.textSuggestions=nt.textSuggestions,n.selectedSuggestionIndex=nt.selectedSuggestionIndex,n.metrics=nt.metrics})}}),rr=$i("input"),Dt=t=>t.input.userCommitted.text.substring(0,t.input.userCommitted.selection.end),md=t=>t.input.selection,Xi=()=>(0,Gi.useSelector)(md),{userInput:Ji,changeSelection:ir,initialInput:Qi,mergeMetrics:Zi,nextTextSuggestionIndex:Yi,offeredTextSuggestion:ea,previousTextSuggestionIndex:ta,registerCut:na,registerKeyDown:oa,registerPaste:sa,reset:ra,resetToCommitted:Cn,setInputHtml:ia,setSelectedTextSuggestionIndex:Ro,setTextSuggestions:ot,stageSuggestion:Se,commitSuggestion:st}=rr.actions,X=$i("overlay");var Ht=require("react");var Io=_(require("react")),aa=_(require("classnames")),Tn=Io.default.createContext({});function h(t,e){let o=(0,Io.useContext)(Tn)[t];return o?Object.entries(e).reduce((s,[r,i])=>{let a=o[r];return{...s,[r]:(0,aa.default)(i,a)}},{}):e}var la={root:"_root_1qp5s_1",content:"_content_1qp5s_23"};var ar=require("react/jsx-runtime"),gd=({isOpen:t,autoFocus:e,children:n,onClose:o,onBack:s,overlayAriaLabel:r,contentAriaLabel:i})=>{let a=(0,Ht.useRef)(null),l=(0,Ht.useRef)(null),c=h("Dialog",la);return(0,Ht.useEffect)(()=>{var p,m;let u=g=>{g.key==="Escape"&&(g.preventDefault(),g.stopPropagation(),s())},d=g=>{let f=window.getSelection();f!=null&&f.toString()||g.target===a.current&&t&&o()};return(p=a.current)==null||p.addEventListener("click",d),(m=a.current)==null||m.addEventListener("keyup",u),()=>{var g,f;(g=a.current)==null||g.removeEventListener("click",d),(f=a.current)==null||f.removeEventListener("keyup",u)}},[a,l,s,o]),(0,Ht.useEffect)(()=>{var u,d;!a.current||!t||!e||(d=(u=a.current)==null?void 0:u.querySelector("input, textarea"))==null||d.focus()},[t,e,a]),t?(0,ar.jsx)("div",{role:"dialog","data-testid":"dialog",className:c.root,"aria-label":r,ref:a,children:(0,ar.jsx)("div",{ref:l,"data-testid":"dialog-content",className:c.content,"aria-label":i,children:n})}):null},Ft=gd;var Nr=require("react"),ss=require("react-redux");var lr={};V(lr,{enUS:()=>fd,nlNL:()=>hd});var fd={dismiss:[{type:0,value:"Close"}],add:[{type:0,value:"Add to message"}],next:[{type:0,value:"Next"}],previous:[{type:0,value:"Previous"}],warning:[{type:0,value:"Are you sure you want to discard the message?"}]},hd={dismiss:[{type:0,value:"Sluiten"}],add:[{type:0,value:"Toevoegen"}],next:[{type:0,value:"Volgende"}],previous:[{type:0,value:"Vorige"}],warning:[{type:0,value:"Weet je zeker dat je de wijzigingen wilt weggooien?"}]};var ca={root:"_root_l80t9_1",content:"_content_l80t9_3",title:"_title_l80t9_7",actions:"_actions_l80t9_15",pagination:"_pagination_l80t9_20",primaryButton:"_primaryButton_l80t9_51",primaryButtons:"_primaryButtons_l80t9_55"};var jo=require("react");var cr=function(t,e){return cr=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var s in o)Object.prototype.hasOwnProperty.call(o,s)&&(n[s]=o[s])},cr(t,e)};function bn(t,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");cr(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var te=function(){return te=Object.assign||function(e){for(var n,o=1,s=arguments.length;o<s;o++){n=arguments[o];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},te.apply(this,arguments)};function ua(t,e){var n={};for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&e.indexOf(o)<0&&(n[o]=t[o]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,o=Object.getOwnPropertySymbols(t);s<o.length;s++)e.indexOf(o[s])<0&&Object.prototype.propertyIsEnumerable.call(t,o[s])&&(n[o[s]]=t[o[s]]);return n}function Lo(t,e,n){if(n||arguments.length===2)for(var o=0,s=e.length,r;o<s;o++)(r||!(o in e))&&(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var Ao;(function(t){t[t.EXPECT_ARGUMENT_CLOSING_BRACE=1]="EXPECT_ARGUMENT_CLOSING_BRACE",t[t.EMPTY_ARGUMENT=2]="EMPTY_ARGUMENT",t[t.MALFORMED_ARGUMENT=3]="MALFORMED_ARGUMENT",t[t.EXPECT_ARGUMENT_TYPE=4]="EXPECT_ARGUMENT_TYPE",t[t.INVALID_ARGUMENT_TYPE=5]="INVALID_ARGUMENT_TYPE",t[t.EXPECT_ARGUMENT_STYLE=6]="EXPECT_ARGUMENT_STYLE",t[t.INVALID_NUMBER_SKELETON=7]="INVALID_NUMBER_SKELETON",t[t.INVALID_DATE_TIME_SKELETON=8]="INVALID_DATE_TIME_SKELETON",t[t.EXPECT_NUMBER_SKELETON=9]="EXPECT_NUMBER_SKELETON",t[t.EXPECT_DATE_TIME_SKELETON=10]="EXPECT_DATE_TIME_SKELETON",t[t.UNCLOSED_QUOTE_IN_ARGUMENT_STYLE=11]="UNCLOSED_QUOTE_IN_ARGUMENT_STYLE",t[t.EXPECT_SELECT_ARGUMENT_OPTIONS=12]="EXPECT_SELECT_ARGUMENT_OPTIONS",t[t.EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE=13]="EXPECT_PLURAL_ARGUMENT_OFFSET_VALUE",t[t.INVALID_PLURAL_ARGUMENT_OFFSET_VALUE=14]="INVALID_PLURAL_ARGUMENT_OFFSET_VALUE",t[t.EXPECT_SELECT_ARGUMENT_SELECTOR=15]="EXPECT_SELECT_ARGUMENT_SELECTOR",t[t.EXPECT_PLURAL_ARGUMENT_SELECTOR=16]="EXPECT_PLURAL_ARGUMENT_SELECTOR",t[t.EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT=17]="EXPECT_SELECT_ARGUMENT_SELECTOR_FRAGMENT",t[t.EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT=18]="EXPECT_PLURAL_ARGUMENT_SELECTOR_FRAGMENT",t[t.INVALID_PLURAL_ARGUMENT_SELECTOR=19]="INVALID_PLURAL_ARGUMENT_SELECTOR",t[t.DUPLICATE_PLURAL_ARGUMENT_SELECTOR=20]="DUPLICATE_PLURAL_ARGUMENT_SELECTOR",t[t.DUPLICATE_SELECT_ARGUMENT_SELECTOR=21]="DUPLICATE_SELECT_ARGUMENT_SELECTOR",t[t.MISSING_OTHER_CLAUSE=22]="MISSING_OTHER_CLAUSE",t[t.INVALID_TAG=23]="INVALID_TAG",t[t.INVALID_TAG_NAME=25]="INVALID_TAG_NAME",t[t.UNMATCHED_CLOSING_TAG=26]="UNMATCHED_CLOSING_TAG",t[t.UNCLOSED_TAG=27]="UNCLOSED_TAG"})(Ao||(Ao={}));var Mo=class{constructor(e){console.warn(`[vite-messages-plugin]: Message "${e}" was not precompiled. Did you use the correct extenstion *.messages.ts?`)}};var ve;(function(t){t[t.literal=0]="literal",t[t.argument=1]="argument",t[t.number=2]="number",t[t.date=3]="date",t[t.time=4]="time",t[t.select=5]="select",t[t.plural=6]="plural",t[t.pound=7]="pound",t[t.tag=8]="tag"})(ve||(ve={}));var Oo;(function(t){t[t.number=0]="number",t[t.dateTime=1]="dateTime"})(Oo||(Oo={}));function ur(t){return t.type===ve.literal}function pa(t){return t.type===ve.argument}function No(t){return t.type===ve.number}function Do(t){return t.type===ve.date}function Ho(t){return t.type===ve.time}function Fo(t){return t.type===ve.select}function Bo(t){return t.type===ve.plural}function da(t){return t.type===ve.pound}function Ko(t){return t.type===ve.tag}function Uo(t){return!!(t&&typeof t=="object"&&t.type===Oo.number)}function wn(t){return!!(t&&typeof t=="object"&&t.type===Oo.dateTime)}function pr(t){t.forEach(function(e){if(delete e.location,Fo(e)||Bo(e))for(var n in e.options)delete e.options[n].location,pr(e.options[n].value);else No(e)&&Uo(e.style)||(Do(e)||Ho(e))&&wn(e.style)?delete e.style.location:Ko(e)&&pr(e.children)})}function ma(t,e){e===void 0&&(e={}),e=te({shouldParseSkeletons:!0,requiresOtherClause:!0},e);var n=new Mo(t,e).parse();if(n.err){var o=SyntaxError(Ao[n.err.kind]);throw o.location=n.err.location,o.originalMessage=n.err.message,o}return e!=null&&e.captureLocation||pr(n.val),n.val}function Vo(t,e){var n=e&&e.cache?e.cache:Td,o=e&&e.serializer?e.serializer:Cd,s=e&&e.strategy?e.strategy:Sd;return s(t,{cache:n,serializer:o})}function yd(t){return t==null||typeof t=="number"||typeof t=="boolean"}function ga(t,e,n,o){var s=yd(o)?o:n(o),r=e.get(s);return typeof r>"u"&&(r=t.call(this,o),e.set(s,r)),r}function fa(t,e,n){var o=Array.prototype.slice.call(arguments,3),s=n(o),r=e.get(s);return typeof r>"u"&&(r=t.apply(this,o),e.set(s,r)),r}function dr(t,e,n,o,s){return n.bind(e,t,o,s)}function Sd(t,e){var n=t.length===1?ga:fa;return dr(t,this,n,e.cache.create(),e.serializer)}function vd(t,e){return dr(t,this,fa,e.cache.create(),e.serializer)}function xd(t,e){return dr(t,this,ga,e.cache.create(),e.serializer)}var Cd=function(){return JSON.stringify(arguments)};function mr(){this.cache=Object.create(null)}mr.prototype.get=function(t){return this.cache[t]};mr.prototype.set=function(t,e){this.cache[t]=e};var Td={create:function(){return new mr}},qo={variadic:vd,monadic:xd};var yt;(function(t){t.MISSING_VALUE="MISSING_VALUE",t.INVALID_VALUE="INVALID_VALUE",t.MISSING_INTL_API="MISSING_INTL_API"})(yt||(yt={}));var En=function(t){bn(e,t);function e(n,o,s){var r=t.call(this,n)||this;return r.code=o,r.originalMessage=s,r}return e.prototype.toString=function(){return"[formatjs Error: ".concat(this.code,"] ").concat(this.message)},e}(Error);var gr=function(t){bn(e,t);function e(n,o,s,r){return t.call(this,'Invalid values for "'.concat(n,'": "').concat(o,'". Options are "').concat(Object.keys(s).join('", "'),'"'),yt.INVALID_VALUE,r)||this}return e}(En);var ha=function(t){bn(e,t);function e(n,o,s){return t.call(this,'Value for "'.concat(n,'" must be of type ').concat(o),yt.INVALID_VALUE,s)||this}return e}(En);var ya=function(t){bn(e,t);function e(n,o){return t.call(this,'The intl string context variable "'.concat(n,'" was not provided to the string "').concat(o,'"'),yt.MISSING_VALUE,o)||this}return e}(En);var z;(function(t){t[t.literal=0]="literal",t[t.object=1]="object"})(z||(z={}));function bd(t){return t.length<2?t:t.reduce(function(e,n){var o=e[e.length-1];return!o||o.type!==z.literal||n.type!==z.literal?e.push(n):o.value+=n.value,e},[])}function wd(t){return typeof t=="function"}function _n(t,e,n,o,s,r,i){if(t.length===1&&ur(t[0]))return[{type:z.literal,value:t[0].value}];for(var a=[],l=0,c=t;l<c.length;l++){var u=c[l];if(ur(u)){a.push({type:z.literal,value:u.value});continue}if(da(u)){typeof r=="number"&&a.push({type:z.literal,value:n.getNumberFormat(e).format(r)});continue}var d=u.value;if(!(s&&d in s))throw new ya(d,i);var p=s[d];if(pa(u)){(!p||typeof p=="string"||typeof p=="number")&&(p=typeof p=="string"||typeof p=="number"?String(p):""),a.push({type:typeof p=="string"?z.literal:z.object,value:p});continue}if(Do(u)){var m=typeof u.style=="string"?o.date[u.style]:wn(u.style)?u.style.parsedOptions:void 0;a.push({type:z.literal,value:n.getDateTimeFormat(e,m).format(p)});continue}if(Ho(u)){var m=typeof u.style=="string"?o.time[u.style]:wn(u.style)?u.style.parsedOptions:o.time.medium;a.push({type:z.literal,value:n.getDateTimeFormat(e,m).format(p)});continue}if(No(u)){var m=typeof u.style=="string"?o.number[u.style]:Uo(u.style)?u.style.parsedOptions:void 0;m&&m.scale&&(p=p*(m.scale||1)),a.push({type:z.literal,value:n.getNumberFormat(e,m).format(p)});continue}if(Ko(u)){var g=u.children,f=u.value,T=s[f];if(!wd(T))throw new ha(f,"function",i);var b=_n(g,e,n,o,s,r),y=T(b.map(function(C){return C.value}));Array.isArray(y)||(y=[y]),a.push.apply(a,y.map(function(C){return{type:typeof C=="string"?z.literal:z.object,value:C}}))}if(Fo(u)){var S=u.options[p]||u.options.other;if(!S)throw new gr(u.value,p,Object.keys(u.options),i);a.push.apply(a,_n(S.value,e,n,o,s));continue}if(Bo(u)){var S=u.options["=".concat(p)];if(!S){if(!Intl.PluralRules)throw new En(`Intl.PluralRules is not available in this environment.
2
+ Try polyfilling it using "@formatjs/intl-pluralrules"
3
+ `,yt.MISSING_INTL_API,i);var w=n.getPluralRules(e,{type:u.pluralType}).select(p-(u.offset||0));S=u.options[w]||u.options.other}if(!S)throw new gr(u.value,p,Object.keys(u.options),i);a.push.apply(a,_n(S.value,e,n,o,s,p-(u.offset||0)));continue}}return bd(a)}function Ed(t,e){return e?te(te(te({},t||{}),e||{}),Object.keys(t).reduce(function(n,o){return n[o]=te(te({},t[o]),e[o]||{}),n},{})):t}function _d(t,e){return e?Object.keys(t).reduce(function(n,o){return n[o]=Ed(t[o],e[o]),n},te({},t)):t}function fr(t){return{create:function(){return{get:function(e){return t[e]},set:function(e,n){t[e]=n}}}}}function Pd(t){return t===void 0&&(t={number:{},dateTime:{},pluralRules:{}}),{getNumberFormat:Vo(function(){for(var e,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];return new((e=Intl.NumberFormat).bind.apply(e,Lo([void 0],n,!1)))},{cache:fr(t.number),strategy:qo.variadic}),getDateTimeFormat:Vo(function(){for(var e,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];return new((e=Intl.DateTimeFormat).bind.apply(e,Lo([void 0],n,!1)))},{cache:fr(t.dateTime),strategy:qo.variadic}),getPluralRules:Vo(function(){for(var e,n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];return new((e=Intl.PluralRules).bind.apply(e,Lo([void 0],n,!1)))},{cache:fr(t.pluralRules),strategy:qo.variadic})}}var Sa=function(){function t(e,n,o,s){n===void 0&&(n=t.defaultLocale);var r=this;if(this.formatterCache={number:{},dateTime:{},pluralRules:{}},this.format=function(c){var u=r.formatToParts(c);if(u.length===1)return u[0].value;var d=u.reduce(function(p,m){return!p.length||m.type!==z.literal||typeof p[p.length-1]!="string"?p.push(m.value):p[p.length-1]+=m.value,p},[]);return d.length<=1?d[0]||"":d},this.formatToParts=function(c){return _n(r.ast,r.locales,r.formatters,r.formats,c,void 0,r.message)},this.resolvedOptions=function(){var c;return{locale:((c=r.resolvedLocale)===null||c===void 0?void 0:c.toString())||Intl.NumberFormat.supportedLocalesOf(r.locales)[0]}},this.getAst=function(){return r.ast},this.locales=n,this.resolvedLocale=t.resolveLocale(n),typeof e=="string"){if(this.message=e,!t.__parse)throw new TypeError("IntlMessageFormat.__parse must be set to process `message` of type `string`");var i=s||{},a=i.formatters,l=ua(i,["formatters"]);this.ast=t.__parse(e,te(te({},l),{locale:this.resolvedLocale}))}else this.ast=e;if(!Array.isArray(this.ast))throw new TypeError("A message must be provided as a String or AST.");this.formats=_d(t.formats,o),this.formatters=s&&s.formatters||Pd(this.formatterCache)}return Object.defineProperty(t,"defaultLocale",{get:function(){return t.memoizedDefaultLocale||(t.memoizedDefaultLocale=new Intl.NumberFormat().resolvedOptions().locale),t.memoizedDefaultLocale},enumerable:!1,configurable:!0}),t.memoizedDefaultLocale=null,t.resolveLocale=function(e){if(!(typeof Intl.Locale>"u")){var n=Intl.NumberFormat.supportedLocalesOf(e);return n.length>0?new Intl.Locale(n[0]):new Intl.Locale(typeof e=="string"?e:e[0])}},t.__parse=ma,t.formats={number:{integer:{maximumFractionDigits:0},currency:{style:"currency"},percent:{style:"percent"}},date:{short:{month:"numeric",day:"numeric",year:"2-digit"},medium:{month:"short",day:"numeric",year:"numeric"},long:{month:"long",day:"numeric",year:"numeric"},full:{weekday:"long",month:"long",day:"numeric",year:"numeric"}},time:{short:{hour:"numeric",minute:"numeric"},medium:{hour:"numeric",minute:"numeric",second:"numeric"},long:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"},full:{hour:"numeric",minute:"numeric",second:"numeric",timeZoneName:"short"}}},t}();function kd(t,e){return e.split(".").reduce((n,o)=>n?n[o]:void 0,t)}var Rd="dummy",hr=(0,jo.createContext)(null);function P(t){let e=(0,jo.useContext)(hr);if(!e)throw new Error("useTranslator() may be used only in the context of a <LocaleContext> component.");let n=t[e]??{};return(o,s)=>{let r=kd(n,o);return r?new Sa(r).format(s):(e!==Rd&&console.warn(`${o} does not exist in messages of ${e}`),`[${o}]`)}}var Pn=require("react/jsx-runtime"),zo=()=>(0,Pn.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 256 512","aria-labelledby":"angleLeftTitle",children:[(0,Pn.jsx)("title",{id:"angleLeftTitle",children:"AngleLeft"}),(0,Pn.jsx)("path",{d:"M192 448c-8.188 0-16.38-3.125-22.62-9.375l-160-160c-12.5-12.5-12.5-32.75 0-45.25l160-160c12.5-12.5 32.75-12.5 45.25 0s12.5 32.75 0 45.25L77.25 256l137.4 137.4c12.5 12.5 12.5 32.75 0 45.25C208.4 444.9 200.2 448 192 448z"})]});var kn=require("react/jsx-runtime"),va=()=>(0,kn.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 256 512","aria-labelledby":"angleRightTitle",children:[(0,kn.jsx)("title",{id:"angleRightTitle",children:"AngleRight"}),(0,kn.jsx)("path",{d:"M64 448c-8.188 0-16.38-3.125-22.62-9.375c-12.5-12.5-12.5-32.75 0-45.25L178.8 256L41.38 118.6c-12.5-12.5-12.5-32.75 0-45.25s32.75-12.5 45.25 0l160 160c12.5 12.5 12.5 32.75 0 45.25l-160 160C80.38 444.9 72.19 448 64 448z"})]});var Rn=_(require("classnames")),le=_(require("react"));var yr={root:"_root_9kn3u_10",fadein:"_fadein_9kn3u_1",isClickable:"_isClickable_9kn3u_47",isSelected:"_isSelected_9kn3u_52",actions:"_actions_9kn3u_76",actionsIsFixed:"_actionsIsFixed_9kn3u_98",actionButton:"_actionButton_9kn3u_106",dropdownList:"_dropdownList_9kn3u_127",dropdownButton:"_dropdownButton_9kn3u_142",dropdownItem:"_dropdownItem_9kn3u_152",dropdownItemButton:"_dropdownItemButton_9kn3u_161",actionButtonIsPrimary:"_actionButtonIsPrimary_9kn3u_175",actionButtonIsDisabled:"_actionButtonIsDisabled_9kn3u_179",labels:"_labels_9kn3u_187",label:"_label_9kn3u_187"};var ae=require("react/jsx-runtime"),Bt=(0,le.createContext)(yr),Id=({fixed:t,children:e,...n})=>{let o=(0,le.useContext)(Bt);return(0,ae.jsx)("div",{...n,className:(0,Rn.default)(o.actions,{[o.actionsIsFixed]:t}),children:e})},Ld=({className:t,primary:e,disabled:n,label:o,children:s})=>{let r=(0,le.useContext)(Bt);return(0,ae.jsxs)("div",{className:(0,Rn.default)(t,r.actionButton,r.dropdownButton,{[r.actionButtonIsPrimary]:e,[r.actionButtonIsDisabled]:n}),onMouseDown:i=>i.stopPropagation(),children:[o,(0,ae.jsx)("ul",{className:r.dropdownList,children:s})]})},Ad=({index:t,label:e,onClick:n})=>{let o=(0,le.useContext)(Bt);return(0,ae.jsx)("li",{className:o.dropdownItem,children:(0,ae.jsx)("button",{className:o.dropdownItemButton,type:"button","data-index":t,onClick:n,children:e})})},Md=({className:t,primary:e,disabled:n,onClick:o,label:s})=>{let r=(0,le.useContext)(Bt);return(0,ae.jsx)("button",{type:"button",className:(0,Rn.default)(t,r.actionButton,{[r.actionButtonIsPrimary]:e,[r.actionButtonIsDisabled]:n}),onClick:o??(i=>i.stopPropagation()),disabled:n,"aria-hidden":n,children:s})},Sr=({labels:t})=>{let e=(0,le.useContext)(Bt);return(0,ae.jsx)("div",{className:e.labels,children:t.map(n=>(0,ae.jsx)("span",{className:e.label,children:n},n))})},Kt=le.default.forwardRef(({className:t,selected:e,onClick:n,children:o,as:s="div",...r},i)=>{let a=h("Suggestion",yr),l=(0,le.useCallback)(c=>{c.preventDefault(),n&&n(c)},[n]);return(0,ae.jsx)(s,{...r,ref:i,className:(0,Rn.default)(t,a.root,{[a.isSelected]:e,[a.isClickable]:!!n}),onClick:l,children:(0,ae.jsx)(Bt.Provider,{value:a,children:o})})});Kt.Labels=Sr;Kt.Actions=Id;Kt.ActionButton=Md;Kt.DropdownButton=Ld;Kt.DropdownItem=Ad;var O=Kt;var ue=require("react"),Na=require("react-redux"),Da=require("interweave"),_r=_(require("classnames"));var vr={root:"_root_7hhs4_1",agentText:"_agentText_7hhs4_3",textInput:"_textInput_7hhs4_8",textInputWrapper:"_textInputWrapper_7hhs4_27",alert:"_alert_7hhs4_31",alertText:"_alertText_7hhs4_50",warning:"_warning_7hhs4_60",success:"_success_7hhs4_69"};var Ca=require("interweave"),Ta=_(require("classnames"));var Ut=require("react");function xa(t,e){let n;return[(...o)=>{window.cancelAnimationFrame(n);let s=e?e(...o):o;n=window.requestAnimationFrame(()=>{t(...s)})},()=>window.cancelAnimationFrame(n)]}function Wo(t){let e=(0,Ut.useRef)(null),[n,o]=(0,Ut.useState)(!1);return(0,Ut.useEffect)(()=>{let s=!1,r=parseFloat(window.getComputedStyle(document.body).zoom??"1"),[i,a]=xa((u,d)=>{let p=e.current;if(!p)return;let m=u/r,g=d/r,f=p.getBoundingClientRect(),T=m>f.x&&m<f.x+f.width&&g>f.y&&g<f.y+f.height;T&&!s?(s=!0,o(!0)):!T&&s&&(s=!1,o(!1))},({clientX:u,clientY:d})=>[u,d]),[l,c]=xa(()=>{s=!1,o(!1)});return t.addEventListener("mousemove",i),t.addEventListener("mouseleave",l),()=>{a(),c(),t.removeEventListener("mousemove",i),t.removeEventListener("mouseleave",l)}},[e]),[e,n]}var ce={root:"_root_kpc8q_1",agentText:"_agentText_kpc8q_4",tabText:"_tabText_kpc8q_9",hint:"_hint_kpc8q_10",matchSelection:"_matchSelection_kpc8q_14",focus:"_focus_kpc8q_20",resetIndent:"_resetIndent_kpc8q_24",matchKeyword:"_matchKeyword_kpc8q_28",matchPlaceholder:"_matchPlaceholder_kpc8q_29",hover:"_hover_kpc8q_35",hintText:"_hintText_kpc8q_67",popover:"_popover_kpc8q_75",popoverRoot:"_popoverRoot_kpc8q_80",popoverContentContainer:"_popoverContentContainer_kpc8q_84",popoverContent:"_popoverContent_kpc8q_84",selectionOptions:"_selectionOptions_kpc8q_110",selectionOptionsIsHidden:"_selectionOptionsIsHidden_kpc8q_115",selectionOptionsButton:"_selectionOptionsButton_kpc8q_119",caret:"_caret_kpc8q_135",popoverSuggestionsRoot:"_popoverSuggestionsRoot_kpc8q_139",suggestionsOverlayInputStyles:"_suggestionsOverlayInputStyles_kpc8q_144"};var xr=require("react/jsx-runtime"),Od=({inputElement:t,children:e})=>{let n=h("TabCompletion",ce),[o,s]=Wo(t);return(0,xr.jsx)("mark",{ref:o,className:(0,Ta.default)(n.matchPlaceholder,{[n.hover]:s}),children:e})},Vt=class extends Ca.Matcher{match(e){let n=e.match(/(((\$!\{)|(\{))[a-zA-Z0-9_.]+\}(?!\}))/);return n?{index:n.index,length:n[0].length,match:n[0],matchString:n[0],valid:!0}:null}replaceWith(e,n){return(0,xr.jsx)(Od,{inputElement:n.inputElement,children:e},`placeholder_${n.matchString}_${n.key}`)}asTag(){return"mark"}};var qt=require("react");function Go(t){return t.contentEditable==="true"}function Nd(t){let e=0,n=0,o=window.getSelection();if(o.rangeCount!==0){let s=o.getRangeAt(0),r=s.cloneRange();r.selectNodeContents(t),r.setEnd(s.endContainer,s.endOffset),n=r.toString().length,r.selectNodeContents(t),r.setEnd(s.startContainer,s.startOffset),e=r.toString().length}return{selectionStart:e,selectionEnd:n}}function ba(t){let{selectionStart:e,selectionEnd:n}=Go(t)?Nd(t):t;return[e,n]}function $o(t){let[,e]=(0,qt.useState)(),n=(0,qt.useRef)(null);return n.current=ba(t),(0,qt.useEffect)(()=>{let o=()=>{let[s,r]=n.current??[],i=ba(t);(!i||s!==i[0]||r!==i[1])&&(n.current=i,e({}))};return t.addEventListener("keyup",o),t.addEventListener("click",o),t.addEventListener("focus",o),document.addEventListener("selectionchange",o),()=>{t.removeEventListener("keyup",o),t.removeEventListener("click",o),t.removeEventListener("focus",o),document.removeEventListener("selectionchange",o)}},[t]),n.current}function Xo(t,e){if(!e)return;let n=t,{value:o}=n,[s,r]=e,i=o.match(Nt);if(!i||i.length===0)return;let a=0;i.find(l=>{let c=o.indexOf(l,a);return s>c&&r<c+l.length?(n.selectionStart=c,n.selectionEnd=c+l.length,!0):(a=c+l.length,!1)})}var wa=require("react");function jt(t){(0,wa.useEffect)(()=>{let e=n=>{n.isWithinRoot||t(n)};return document.body.addEventListener("mouseup",e),()=>{document.body.removeEventListener("mouseup",e)}},[t])}function St(t){t.addEventListener("mouseup",e=>{e.isWithinRoot=!0},!0)}var Ea,_e=new Map,Dd=["bottom","height","left","right","top","width"],Hd=(t={},e={})=>Dd.some(n=>t[n]!==e[n]),_a=()=>{let t=[];_e.forEach((e,n)=>{if(!n.isConnected){e.rect=null,t.push(e),_e.delete(n);return}let o=n.getBoundingClientRect();Hd(o,e.rect)&&(e.rect=o,t.push(e))}),t.forEach(e=>{e.callbacks.forEach(n=>n(e.rect))}),_e.size!==0&&(Ea=window.requestAnimationFrame(_a))};function Pa(t,e){return{observe(){let n=_e.size===0;if(_e.has(t)){let o=_e.get(t);o.callbacks.push(e),o.rect&&e(o.rect)}else _e.set(t,{rect:void 0,callbacks:[e]});n&&_a()},unobserve(){let n=_e.get(t);if(n){let o=n.callbacks.indexOf(e);o>=0&&n.callbacks.splice(o,1),n.callbacks.length||_e.delete(t),_e.size||cancelAnimationFrame(Ea)}}}}var ka,Pe=new Map,Ra=()=>{Pe.forEach((t,e)=>{if(!e.isConnected){Pe.delete(e);return}let{clientHeight:n,scrollHeight:o}=e,s=o>n;t.visible!==s&&(t.visible=s,t.callbacks.forEach(r=>r(t.visible)))}),Pe.size!==0&&(ka=window.requestAnimationFrame(Ra))};function Ia(t,e){return{observe(){let n=Pe.size===0;Pe.has(t)?Pe.get(t).callbacks.push(e):Pe.set(t,{visible:void 0,callbacks:[e]}),n&&Ra()},unobserve(){let n=Pe.get(t);if(n){let o=n.callbacks.indexOf(e);o>=0&&n.callbacks.splice(o,1),n.callbacks.length||Pe.delete(t),Pe.size||cancelAnimationFrame(ka)}}}}var Cr=["borderLeftWidth","borderRightWidth","borderTopWidth","borderBottomWidth","borderStyle","boxSizing","color","overflowWrap","fontFamily","fontSize","fontSizeAdjust","fontStretch","fontWeight","fontKerning","lineHeight","letterSpacing","paddingLeft","paddingTop","paddingRight","paddingBottom","width","height","textIndent","whiteSpace","wordBreak","wordSpacing","wordWrap"];function Tr(t,e,n){return n.forEach(o=>{e.style[o]=t[o]})}function zt(t){return parseFloat(t)}function Jo(t){return Math.round(t*1e6)}function La(t){return t/1e6}function br(t,e,n){if(t.boxSizing==="content-box")return;let{clientWidth:o}=e,s=zt(t.width),r=zt(t.borderLeftWidth),i=zt(t.borderRightWidth),a=zt(t.paddingRight),l=La(Jo(s)-Jo(r)-Jo(i)),c=La(Jo(o));if(l-c>2){let u=l-c;n.style.paddingRight=`${a+u}px`}}function Wt(t,e={}){var l;let n=e.overlayContainer||document.createElement("div");n.style.display="none",n.style.position="fixed",n.style.pointerEvents="none",n.style.borderColor="transparent",St(n);let o=window.getComputedStyle(t),s=!0,r=()=>{n.scrollTop=t.scrollTop};Tr(o,n,Cr),br(o,t,n),e.mirrorOverflow&&(n.style.overflow="hidden",t.addEventListener("scroll",r));let i=Ia(t,()=>{Tr(o,n,Cr),br(o,t,n),r(),setTimeout(r,0)}),a=Pa(t,c=>{if(c===null){e.onRemove&&e.onRemove(),n.remove();return}if(c.height===0&&c.width===0){if(s===!0)return;e.onHide&&e.onHide(),n.style.display="none",s=!0;return}if(Tr(o,n,Cr),br(o,t,n),r(),n.style.top=`${c.top}px`,n.style.left=`${c.left}px`,e.closestScrollElement&&e.closestScrollElement!==t){let u=e.closestScrollElement.getBoundingClientRect(),d=window.getComputedStyle(e.closestScrollElement),p=zt(d.borderTopWidth),m=zt(d.borderBottomWidth),g=u.top+p-c.top,f=c.top+c.height+-(u.top+u.height-m);n.style.clipPath=`inset(${g}px 0px ${f}px 0px)`}s&&(n.style.display="block",e.onShow&&e.onShow(),s=!1)});return e.appendTo?e.appendTo.appendChild(n):(l=t.parentElement)==null||l.appendChild(n),a.observe(),i.observe(),[n,()=>{t.removeEventListener("scroll",r),a.unobserve(),i.unobserve()}]}var wr={};V(wr,{enUS:()=>Fd,nlNL:()=>Bd});var Fd={placeholders:[{type:6,value:"placeholderSize",options:{"=0":{value:[{type:0,value:"No placeholders found"}]},one:{value:[{type:0,value:"There is one placeholder in your message"}]},other:{value:[{type:0,value:"There are "},{type:7},{type:0,value:" placeholders in your message"}]}},offset:0,pluralType:"cardinal"}]},Bd={placeholders:[{type:6,value:"placeholderSize",options:{"=0":{value:[{type:0,value:"Alle placeholders zijn uit je bericht"}]},one:{value:[{type:0,value:"Er is 1 placeholder in jouw bericht"}]},other:{value:[{type:0,value:"Er zijn "},{type:7},{type:0,value:" placeholders in jouw bericht"}]}},offset:0,pluralType:"cardinal"}]};var In=require("react/jsx-runtime"),Aa=()=>(0,In.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 512 512","aria-labelledby":"circleCheckTitle",children:[(0,In.jsx)("title",{id:"circleCheckTitle",children:"Check"}),(0,In.jsx)("path",{d:"M243.8 339.8C232.9 350.7 215.1 350.7 204.2 339.8L140.2 275.8C129.3 264.9 129.3 247.1 140.2 236.2C151.1 225.3 168.9 225.3 179.8 236.2L224 280.4L332.2 172.2C343.1 161.3 360.9 161.3 371.8 172.2C382.7 183.1 382.7 200.9 371.8 211.8L243.8 339.8zM512 256C512 397.4 397.4 512 256 512C114.6 512 0 397.4 0 256C0 114.6 114.6 0 256 0C397.4 0 512 114.6 512 256zM256 48C141.1 48 48 141.1 48 256C48 370.9 141.1 464 256 464C370.9 464 464 370.9 464 256C464 141.1 370.9 48 256 48z"})]});var Er=require("react/jsx-runtime"),Ma=()=>(0,Er.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",fill:"currentColor",children:(0,Er.jsx)("path",{d:"M256 32c14.2 0 27.3 7.5 34.5 19.8l216 368c7.3 12.4 7.3 27.7 .2 40.1S486.3 480 472 480H40c-14.3 0-27.6-7.7-34.7-20.1s-7-27.8 .2-40.1l216-368C228.7 39.5 241.8 32 256 32zm0 128c-13.3 0-24 10.7-24 24V296c0 13.3 10.7 24 24 24s24-10.7 24-24V184c0-13.3-10.7-24-24-24zm32 224c0-17.7-14.3-32-32-32s-32 14.3-32 32s14.3 32 32 32s32-14.3 32-32z"})});var Oa=(i=>(i.CUT="Cut",i.BACKSPACE="Backspace",i.DELETE="Delete",i.ERASEEOF="EraseEof",i.UNDO="Undo",i.CLEAR="Clear",i))(Oa||{}),Me=class{constructor(e){this.element=e;this.currentText=this.getText(),this.currentHTML=this.getHTML(),this.listen()}eventListeners={};disposeHandlers=[];currentText="";currentHTML="";currentSelection=null;isFocused=!1;isActive=!0;isSettingValue=!1;isSubmitting=!1;isPossibleClearInputAction=!1;isDisposed=!1;addEventListener(e,n){let o=s=>{n(s)};this.element.addEventListener(e,o),this.disposeHandlers.push(()=>{this.element.removeEventListener(e,o)})}removeEventListener(e,n){this.element.removeEventListener(e,n)}triggerChange(){let e=this.getText(),n=this.getHTML(),o=e!==this.currentText;this.isActive&&(e===""&&this.currentText!==""&&!this.isSettingValue&&!this.isPossibleClearInputAction&&(this.isSubmitting=!0,this.emit("submit")),!this.isSettingValue&&o&&!this.isSubmitting&&this.emit("change",{plainText:e,rawHtml:n}),this.currentText=e,this.isSubmitting=!1,(this.currentHTML!==n||n===null&&o)&&(this.emit("updated",{plainText:e,rawHtml:n}),this.currentHTML=n))}handleKeyUp(e){let{key:n,shiftKey:o}=e;(n==="Enter"&&o===!0||n==="Backspace")&&this.triggerChange()}handleFocus(){this.isFocused||this.emit("focus"),this.isFocused=!0}handleBlur(){this.isPossibleClearInputAction=!1,this.isFocused&&this.emit("blur"),this.isFocused=!1}handleKeyDown(e){let{key:n,ctrlKey:o,metaKey:s}=e;this.isPossibleClearInputAction=Object.values(Oa).includes(n)||n.toLowerCase()==="z"&&(o||s),this.emit("keydown",e)}handleCut(){let e=this.currentSelection;this.isPossibleClearInputAction=!0,e&&this.emit("cut",{selectionText:this.getSelectedText()})}handlePaste(e){let n=(e.clipboardData||window.clipboardData).getData("text");this.emit("paste",{pastedText:n,selectionText:this.getSelectedText()})}listen(){let e=()=>{let o=document.activeElement===this.element?this.getSelection():null;tt(this.currentSelection,o)||(this.currentSelection=o,this.emit("selection",o))};document.addEventListener("selectionchange",e),this.disposeHandlers.push(()=>{window.document&&document.removeEventListener("selectionchange",e)}),this.addEventListener("keydown",o=>this.handleKeyDown(o)),this.addEventListener("keyup",o=>this.handleKeyUp(o)),this.addEventListener("input",()=>this.triggerChange()),this.addEventListener("change",()=>this.triggerChange()),this.addEventListener("focus",()=>this.handleFocus()),this.addEventListener("blur",()=>this.handleBlur()),this.addEventListener("cut",()=>this.handleCut()),this.addEventListener("paste",o=>this.handlePaste(o)),document.activeElement===this.element&&setTimeout(()=>{this.handleFocus()},0);let n=new MutationObserver(()=>{this.element.isConnected||(this.emit("unmounted"),this.dispose())});n.observe(document.body,{subtree:!0,childList:!0}),this.disposeHandlers.push(()=>{n.disconnect()})}focus(){this.element.focus()}emit(e,...n){this.isDisposed||this.eventListeners[e]&&this.eventListeners[e].forEach(o=>{o(...n)})}on(e,n){this.isDisposed||(this.eventListeners[e]||(this.eventListeners[e]=[]),this.eventListeners[e].push(n))}activate(){let e=this.isActive===!1;this.isActive=!0,e&&this.triggerChange()}deactivate(){this.isActive=!1}dispose(){this.disposeHandlers.forEach(e=>e()),this.eventListeners={},this.isDisposed=!0}};var Oe=class extends Me{getText(){return this.element.value}getHTML(){return null}getSelection(){let{selectionStart:e,selectionEnd:n}=this.element;return{start:e,end:n}}getSelectedText(){return this.currentSelection?this.getText().slice(this.currentSelection.start,this.currentSelection.end):""}applyChanges(e){if(!this.isActive)return;this.isSettingValue=!0;let n=this.getText(),o=e(this.element);Promise.resolve(o).then(()=>{this.currentText=this.getText(),n!==this.currentText&&this.triggerChange(),this.isSettingValue=!1})}listen(){super.listen();let e=Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,"value");Object.defineProperty(this.element,"value",{configurable:!0,get:()=>{var s;return(s=e==null?void 0:e.get)==null?void 0:s.call(this.element)},set:s=>{var r;(r=e==null?void 0:e.set)==null||r.call(this.element,s),this.triggerChange()}});let n=this.element.disabled,o=new MutationObserver(()=>{this.element.disabled!==n&&(n=this.element.disabled,this.emit(n?"disabled":"enabled"))});o.observe(this.element,{attributes:!0,attributeFilter:["disabled"]}),this.disposeHandlers.push(()=>o.disconnect())}};var J=require("react/jsx-runtime"),Kd=({value:t,onUse:e,...n})=>{var u;let o=P(wr),s=(0,Na.useDispatch)(),r=h("EditSuggestionTextInput",vr),[i,a]=(0,ue.useState)(null),l=(0,ue.useRef)(null),c=((u=t.match(Nt))==null?void 0:u.length)||0;return(0,ue.useEffect)(()=>{let d;return l.current&&(a(l.current),d=new Oe(l.current),d.on("change",({plainText:p})=>{s(X.actions.userInput({text:p,selection:d.getSelection()}))}),d.on("keydown",p=>{s(X.actions.registerKeyDown(bo(p))),p.code==="Enter"&&p.shiftKey&&e(d.getText())}),d.on("paste",({pastedText:p,selectionText:m})=>{s(X.actions.registerPaste({text:p,selectionText:m}))}),d.on("cut",({selectionText:p})=>{s(X.actions.registerCut(p))})),()=>{s(X.actions.reset()),d.dispose(),d.deactivate()}},[l]),(0,ue.useEffect)(()=>{t&&l.current&&(l.current.value=t)},[t,l]),(0,ue.useEffect)(()=>{l.current&&setTimeout(()=>{if(!l.current)return;let d=l.current.value.length;l.current.setSelectionRange(d,d),l.current.focus()},0)},[l]),(0,J.jsxs)("div",{className:r.textInputWrapper,children:[(0,J.jsx)("textarea",{...n,ref:l,"data-testid":"edit-suggestion-dialog-textarea",className:r.textInput,defaultValue:t,onChange:()=>{}}),i&&(0,J.jsx)(Ud,{inputElement:l.current,value:t}),(0,J.jsxs)("div",{className:(0,_r.default)(r.alert,c===0?r.success:r.warning),children:[(0,J.jsx)("div",{className:r.alertText,children:o("placeholders",{placeholderSize:c})}),c===0?(0,J.jsx)(Aa,{}):(0,J.jsx)(Ma,{})]})]})},Ud=({inputElement:t,value:e})=>{let n=h("EditSuggestionTextInput",vr),o=(0,ue.useRef)(null),s=$o(t);return(0,ue.useEffect)(()=>{Xo(t,s)},[s,t]),(0,J.jsx)(Vd,{inputElement:t,children:(0,J.jsxs)("div",{ref:o,className:(0,_r.default)(n.root,n.agentText),children:[(0,J.jsx)(Da.Interweave,{noWrap:!0,disableLineBreaks:!0,content:e,matchers:[new Vt("placeholders")],inputElement:t,boundaryRef:o}),(0,J.jsx)("br",{})]})})},Vd=({inputElement:t,children:e})=>{let n=(0,ue.useRef)(null);return(0,ue.useEffect)(()=>{if(!n.current)return()=>{};let[o,s]=Wt(t,{overlayContainer:n.current,mirrorOverflow:!0});return()=>{s()}},[n.current]),(0,J.jsx)("div",{ref:n,children:e})},Ha=Kd;var Qt=require("react");var Q={root:"_root_1vexi_1",list:"_list_1vexi_2",listWrapper:"_listWrapper_1vexi_6",listHorizontal:"_listHorizontal_1vexi_10",page:"_page_1vexi_19",search:"_search_1vexi_25",pageNav:"_pageNav_1vexi_33",pageBackButton:"_pageBackButton_1vexi_38",listHeading:"_listHeading_1vexi_52",listItem:"_listItem_1vexi_60",listItemContent:"_listItemContent_1vexi_69",listItemText:"_listItemText_1vexi_87",listItemDescription:"_listItemDescription_1vexi_95",truncate:"_truncate_1vexi_102",lineClamp:"_lineClamp_1vexi_108",listItemTitle:"_listItemTitle_1vexi_115",listItemAction:"_listItemAction_1vexi_122",listItemPrimaryAction:"_listItemPrimaryAction_1vexi_136",listItemSelected:"_listItemSelected_1vexi_141",sources:"_sources_1vexi_145",sourcesTitle:"_sourcesTitle_1vexi_152",source:"_source_1vexi_145",icon:"_icon_1vexi_167",searchIcon:"_searchIcon_1vexi_184",searchInputWrapper:"_searchInputWrapper_1vexi_189",searchInput:"_searchInput_1vexi_189",select:"_select_1vexi_210",selectType:"_selectType_1vexi_227",selectWrapper:"_selectWrapper_1vexi_231",image:"_image_1vexi_261",imageSrc:"_imageSrc_1vexi_268",imageTitle:"_imageTitle_1vexi_279",actions:"_actions_1vexi_284",actionsWrapper:"_actionsWrapper_1vexi_286",actionsBar:"_actionsBar_1vexi_292",actionButton:"_actionButton_1vexi_301",actionShortcut:"_actionShortcut_1vexi_319",actionShortcutFixKerning:"_actionShortcutFixKerning_1vexi_326"};var Ln=require("react/jsx-runtime"),qd=({src:t,title:e})=>{let n=h("CommandPalette",Q);return(0,Ln.jsxs)("div",{className:n.image,children:[(0,Ln.jsx)("img",{src:t,alt:e,className:n.imageSrc}),e&&(0,Ln.jsx)("span",{className:n.imageTitle,children:e})]})},Fa=qd;var Ba=_(require("react")),Ka=_(require("classnames"));var An=require("react/jsx-runtime");function Pr({children:t,heading:e,orientation:n}){let o=h("CommandPalette",Q);return Ba.default.Children.count(t)===0?null:(0,An.jsxs)("div",{"data-testid":"commandpalette-list",className:o.list,children:[e&&(0,An.jsx)("h4",{className:o.listHeading,children:e}),(0,An.jsx)("div",{className:(0,Ka.default)(o.listWrapper,n==="horizontal"&&o.listHorizontal),children:t})]})}var Mn=_(require("classnames"));var Ua={root:"_root_nkim0_1"};var kr={};V(kr,{enUS:()=>jd,nlNL:()=>zd});var jd={experimental:[{type:0,value:"Experimental"}]},zd={experimental:[{type:0,value:"Experimenteel"}]};var Rr=require("react/jsx-runtime"),Va=({children:t})=>{let e=h("Chip",Ua);return(0,Rr.jsx)("span",{className:e.root,children:t})},rt=()=>{let t=P(kr);return(0,Rr.jsx)(Va,{children:t("experimental")})},qa=Va;var Qo=_(require("react")),Wa=require("react/jsx-runtime"),ja=Qo.default.createContext(void 0);function it(){let t=Qo.default.useContext(ja);if(t===void 0)throw new Error("useCommandPalette must be used within the CommandPalette component");return t}var za=({children:t,page:e,isOpen:n,onChangeOpen:o,selected:s,setSelected:r})=>{let i=Qo.default.useMemo(()=>({page:e,isOpen:n,onChangeOpen:o,selected:s,setSelected:r}),[n,e,s]);return(0,Wa.jsx)(ja.Provider,{value:i,children:t})};var pe=require("react/jsx-runtime");function Ir({closeOnSelect:t=!0,lineClamp:e,children:n,onClick:o,index:s,isExperimental:r,description:i,sources:a,styles:l,...c}){let{selected:u,onChangeOpen:d}=it(),p=h("CommandPalette",Q);function m(g){o(g),t&&d(!1)}return(0,pe.jsxs)("div",{className:(0,Mn.default)(p.listItem,u===s&&p.listItemSelected),children:[(0,pe.jsxs)("button",{type:"button",className:(0,Mn.default)("command-palette-list-item",p.listItemAction,p.listItemPrimaryAction),"aria-disabled":c.disabled??!1,onClick:m,...c,children:[(0,pe.jsxs)("div",{className:p.listItemContent,children:[typeof n=="string"?(0,pe.jsx)("p",{className:(0,Mn.default)(p.listItemText,p.truncate,l==null?void 0:l.title),children:n}):n,i&&(0,pe.jsx)("p",{className:(0,Mn.default)(p.listItemDescription,l==null?void 0:l.description,e?p.lineClamp:p.truncate),children:i})]}),r&&(0,pe.jsx)(rt,{})]}),a&&(0,pe.jsxs)("div",{className:p.sources,children:[(0,pe.jsx)("span",{className:p.sourcesTitle,children:"Sources"}),a.map(g=>g.url?(0,pe.jsx)("a",{className:p.source,href:g.url,target:"_blank",title:g.url,rel:"noopener noreferrer",children:g.name},g.url):(0,pe.jsx)("span",{className:p.source,children:g.name},g.name))]})]})}var On={};V(On,{enUS:()=>Wd,nlNL:()=>Gd});var Wd={visitUrl:[{type:0,value:"Visit"}],back:[{type:0,value:"Back"}]},Gd={visitUrl:[{type:0,value:"Bekijk"}],back:[{type:0,value:"Terug"}]};var Gt=require("react/jsx-runtime");function Lr({children:t,id:e,onDismiss:n}){let o=P(On),s=h("CommandPalette",Q),{page:r}=it();return r!==e?null:(0,Gt.jsxs)("div",{className:s.page,id:`page_${e}`,tabIndex:-1,children:[n&&(0,Gt.jsx)("div",{className:s.pageNav,children:(0,Gt.jsxs)("button",{className:s.pageBackButton,type:"button",onClick:n,children:[(0,Gt.jsx)(zo,{}),o("back")]})}),t]})}var at=require("react");var Zo=()=>/Mac/i.test(navigator.platform);var Xt=require("@reduxjs/toolkit");var $d={info(...t){console.info("[Deepdesk]",...t)},warn(...t){console.warn("[Deepdesk]",...t)},error(...t){console.error("[Deepdesk]",...t)}},k=$d;var $t=require("@reduxjs/toolkit");function Xd(t){return t.replace(/(_\w)/g,e=>e[1].toUpperCase())}function M(t){return Array.isArray(t)?t.map(M):typeof t=="object"&&t!==null?Object.keys(t).reduce((e,n)=>({...e,[Xd(n)]:M(t[n])}),{}):t}function Ar(t){return t.replace(/[A-Z]/g,e=>`_${e.toLowerCase()}`)}function U(t){return Array.isArray(t)?t.map(U):typeof t=="object"&&t!==null?Object.keys(t).reduce((e,n)=>({...e,[Ar(n)]:U(t[n])}),{}):t}var Jd={agentInfo:void 0,agentSettings:{},visitorInfo:void 0,fetchState:"idle"},Dn=t=>{var e,n,o;return{timezone:((e=t.info.visitorInfo)==null?void 0:e.visitorTimeZone)||Intl.DateTimeFormat().resolvedOptions().timeZone,agentName:((n=t.info.agentInfo)==null?void 0:n.agentNickname)||"",visitorName:((o=t.info.visitorInfo)==null?void 0:o.visitorName)||""}},Nn=(0,$t.createAsyncThunk)("info/setAgentInfo",async(t,e)=>{let{deepdeskAPI:n}=e.extra;if(!t.agentId&&!t.agentNickname)throw new Error("At least provide agentId or agentNickname");let o=await n.client.get("/apis/admin/session/me/",{version:null}),s={};return o.external_id||(s.external_id=t.agentId),o.nickname||(s.nickname=t.agentNickname),!s.external_id&&!s.nickname?M(o):(await n.client.patch("/apis/admin/session/me/",s,{version:null}),M(o))}),Mr=(0,$t.createAsyncThunk)("info/setAgentSettings",async(t,e)=>{let{deepdeskAPI:n}=e.extra,o=await n.client.get("/apis/admin/session/me/",{version:null}),s={...typeof o.ui_config=="object"?o.ui_config:{},...t};return await n.client.patch("/apis/admin/session/me/",{ui_config:s}),s}),Or=(0,$t.createAsyncThunk)("info/getAgentSettings",async(t,e)=>{let{deepdeskAPI:n}=e.extra;return(await n.client.get("/apis/admin/session/me/",{version:null})).ui_config}),Ga=t=>t.info.agentInfo,$a=(0,$t.createSlice)({name:"info",initialState:Jd,reducers:{setVisitorInfo(t,e){t.visitorInfo={...t.visitorInfo,...e.payload}}},extraReducers:t=>{t.addCase(Nn.pending,(e,n)=>{e.fetchState="loading",e.agentInfo={...e.agentInfo,...n.meta.arg}}).addCase(Nn.rejected,e=>{e.fetchState="error"}).addCase(Nn.fulfilled,(e,n)=>{e.fetchState="done",e.agentInfo={...e.agentInfo,...n.meta.arg,agentId:n.payload.externalId||n.meta.arg.agentId||"",agentNickname:n.payload.nickname||n.meta.arg.agentNickname||""}}).addCase(Mr.fulfilled,(e,n)=>{e.agentSettings=n.payload}).addCase(Or.fulfilled,(e,n)=>{e.agentSettings=n.payload}).addCase(R,e=>{e.visitorInfo=void 0})}}),{setVisitorInfo:Xa}=$a.actions,Ja=$a.reducer;var Yo={list:[],fetchState:"idle",isOpen:!1},Qa=t=>t.search.isOpen,Za=t=>t.search.list;function Ya(t,e=n=>n){return n=>n.search.list.filter(o=>o.type===t).map(e)}var vt=(0,Xt.createAsyncThunk)("search/getAll",async(t,e)=>{var i;let{deepdeskAPI:n}=e.extra,o=e.getState(),s=(i=o.conversation.current)==null?void 0:i.profileCode;if(!s)throw new Error("Profile should be provided in order to be able to search");let{results:r}=await n.search({profile:s,query:t.query,filters:{type:t.type},params:Dn(o),tags:t.tags});return r}),de=(0,Xt.createAction)("search/setIsOpen"),el=(0,Xt.createSlice)({name:"search",initialState:Yo,reducers:{resetSearch(t){t.fetchState=Yo.fetchState,t.list=Yo.list}},extraReducers:t=>{t.addCase(vt.pending,e=>{e.fetchState="loading"}).addCase(vt.rejected,(e,n)=>{e.fetchState="error",k.error(n.error)}).addCase(vt.fulfilled,(e,n)=>{e.fetchState="done",e.list=n.payload}).addCase(de,(e,n)=>{e.isOpen=n.payload}).addCase(R,()=>Yo)}}),{resetSearch:es}=el.actions,tl=el.reducer;var Qd=/(https?:\/\/[^\s]+)/,ts=t=>t.split(" ").find(e=>Qd.test(e));var nl=_(require("classnames"));var ns=require("react/jsx-runtime"),Zd=({onClick:t,shortKeys:e,children:n,...o})=>{let s=h("CommandPalette",Q);return(0,ns.jsxs)("button",{type:"button",...o,onClick:t,className:s.actionButton,children:[n,e&&e.map(r=>(0,ns.jsx)("span",{className:(0,nl.default)(s.actionShortcut,r===8629&&s.actionShortcutFixKerning),children:typeof r=="number"?String.fromCharCode(r):r},r))]})},Jt=Zd;var Ne=require("react/jsx-runtime"),Yd=({children:t,primaryLabel:e,secondaryLabel:n,onPrimary:o,onSecondary:s,list:r})=>{let i=h("CommandPalette",Q),a=P(On),{selected:l,setSelected:c}=it(),u=r[l],d=u&&typeof u.text=="string"&&ts(u.text),p=(0,at.useRef)(null);function m(S){if(!p.current)return;let w=p.current.querySelectorAll(".command-palette-list-item"),C=0,x=0;S==="down"?(w.forEach(($,K)=>{K===l&&(C=K)}),x=C===w.length-1?0:C+1):S==="up"?(w.forEach(($,K)=>{K===l&&(C=K)}),x=C?C-1:w.length-1):c(0);let B=w[x];B&&typeof x=="number"&&(c(x),B.scrollIntoView&&B.scrollIntoView({behavior:"smooth",block:x?"center":"end"}))}function g(){if(!p.current)return;let S=p.current.querySelectorAll(".command-palette-list-item"),w=0;S.forEach((x,B)=>{B===l&&(w=B)});let C=S[w];C&&C.click()}let f=()=>{d&&window.open(d,"_blank")},T=()=>{u&&o(u,l)},b=()=>{!u.type||["IMAGE","command"].includes(u.type)||s&&s(u,l)},y=(0,at.useCallback)(S=>{if(S.key==="Enter"&&S.altKey&&d){f();return}if(S.key==="Enter"&&S.shiftKey){b();return}if(S.key==="ArrowDown"){S.preventDefault(),S.stopPropagation(),m("down");return}if(S.key==="ArrowUp"){S.preventDefault(),S.stopPropagation(),m("up");return}S.key==="Enter"&&l!==-1&&(S.preventDefault(),S.stopPropagation(),g())},[l]);return(0,at.useEffect)(()=>(window.addEventListener("keyup",y),()=>{window.removeEventListener("keyup",y)}),[y]),(0,Ne.jsxs)("div",{className:i.actions,children:[(0,Ne.jsx)("div",{className:i.actionsWrapper,ref:p,children:t}),(0,Ne.jsxs)("div",{className:i.actionsBar,children:[d&&(0,Ne.jsx)(Jt,{onClick:f,shortKeys:[Zo()?8997:"ALT",8629],children:a("visitUrl")}),u&&(0,Ne.jsxs)(at.Fragment,{children:[s&&u.type&&!["command","image"].includes(u.type.toLowerCase())&&(0,Ne.jsx)(Jt,{onClick:b,shortKeys:[8679,8629],children:n}),(0,Ne.jsx)(Jt,{onClick:T,shortKeys:[8629],children:e})]})]})]})},sl=Yd;var rl=require("react");var Hn=require("react/jsx-runtime"),os=()=>(0,Hn.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",height:"24px",viewBox:"0 0 24 24",width:"24px",fill:"currentColor",children:[(0,Hn.jsx)("path",{d:"M0 0h24v24H0z",fill:"none"}),(0,Hn.jsx)("path",{d:"M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"})]});var xe=require("react/jsx-runtime");function em({onChange:t,onChangeType:e,placeholder:n,typePlaceholder:o,types:s,value:r,selectedType:i},a){let l=h("CommandPalette",Q);return(0,xe.jsxs)("div",{className:l.search,children:[(0,xe.jsx)("div",{className:l.searchIcon,children:(0,xe.jsx)(os,{})}),(0,xe.jsxs)("div",{className:l.searchInputWrapper,children:[(0,xe.jsx)("input",{ref:a,spellCheck:!1,onChange:c=>{t(c.currentTarget.value)},onFocus:c=>{c.currentTarget.select()},className:l.searchInput,placeholder:n,value:r,type:"text",id:"command-palette-search-input",autoFocus:!0}),s&&s.length>0&&(0,xe.jsx)("div",{className:l.selectWrapper,children:(0,xe.jsxs)("select",{"data-testid":"command-palette-type-select",className:l.select,onChange:c=>e(c.target.value===o?void 0:c.target.value),value:i||o,children:[o&&(0,xe.jsx)("option",{children:o}),s.map(c=>(0,xe.jsx)("option",{value:c.value,children:c.label},c.value))]})})]})]})}var il=(0,rl.forwardRef)(em);var Fn=require("react/jsx-runtime");function xt({placeholder:t="Start typing to search...",typePlaceholder:e="All types",defaultPage:n="search",page:o,onChangePage:s,onChangeSearch:r,onChangeType:i,onChangeOpen:a,selectedType:l,types:c,children:u,isOpen:d,search:p}){let[m,g]=(0,Qt.useState)(0),f=(0,Qt.useRef)(null),T=()=>{s&&s(n),i(void 0),r(""),a(!1)},b=()=>{var y;if(o!==n&&s){s(n);return}if(l&&i){i(void 0),(y=f.current)==null||y.focus();return}if(p.length>0){r("");return}a(!1)};return(0,Qt.useEffect)(()=>{g(0)},[p,o]),(0,Fn.jsx)(Ft,{autoFocus:!0,contentAriaLabel:"Search Results",overlayAriaLabel:"Command Palette",isOpen:d,onBack:b,onClose:T,children:(0,Fn.jsxs)(za,{selected:m,setSelected:g,isOpen:d,onChangeOpen:a,page:o,children:[o===n&&(0,Fn.jsx)(il,{ref:f,onChange:r,onChangeType:i,placeholder:t,value:p,selectedType:l,types:c,typePlaceholder:e}),u]})})}xt.Page=Lr;xt.List=Pr;xt.Image=Fa;xt.ListItem=Ir;xt.ActionsBar=sl;xt.Button=Jt;var I=xt;var G=require("react/jsx-runtime"),tm=({suggestion:t,onUse:e,onDismiss:n,onTouched:o,onNext:s,onPrevious:r})=>{let i=t.text||t.url||t.message,a=h("EditSuggestionForm",ca),l=(0,ss.useDispatch)(),c=P(lr),u=(0,ss.useSelector)(g=>g.overlayInput.text);(0,Nr.useEffect)(()=>{t&&(l(X.actions.reset()),l(X.actions.stageSuggestion({text:i,suggestion:t,eventMetrics:{inputType:"mouse"},replace:"until-selection-end"})),l(X.actions.commitSuggestion()))},[t]);let d=g=>{g.preventDefault(),p(u)},p=g=>{l(_o(g)),e(g)},m=g=>f=>{u!==i?window.confirm(c("warning"))&&g(f):g(f)};return(0,Nr.useEffect)(()=>{o&&o(u!==i)},[o,t,u]),(0,G.jsxs)("div",{className:a.root,children:[(0,G.jsxs)("div",{className:a.content,children:[t.title&&(0,G.jsx)("h3",{className:a.title,children:t.title}),t.searchKeywords&&t.searchKeywords.length>0&&(0,G.jsx)(Sr,{labels:t.searchKeywords}),(0,G.jsx)(Ha,{onUse:p,value:u})]}),(0,G.jsxs)("form",{className:a.actions,onSubmit:d,children:[(0,G.jsxs)("div",{children:[(0,G.jsx)("button",{disabled:!r,className:a.pagination,type:"button",onClick:r&&m(r),children:(0,G.jsx)(zo,{})}),(0,G.jsx)("button",{disabled:!s,className:a.pagination,type:"button",onClick:s&&m(s),children:(0,G.jsx)(va,{})})]}),(0,G.jsxs)("div",{className:a.primaryButtons,children:[(0,G.jsx)(I.Button,{onClick:m(n),shortKeys:["esc"],children:c("dismiss")}),(0,G.jsx)(I.Button,{shortKeys:[8679,8629],type:"submit",children:c("add")})]})]})]})},rs=tm;var Ct=require("@reduxjs/toolkit");var nm=["{amount}"," {amount}","{date}","{email}","{iban}","{name}","{postal_code}","{street}","{tarif}","{usage}","{3_digits}","{4_digits}","{5_digits}","{6_digits}","{7_digits}","{8_digits}","{9_digits}","{10_digits}"],om=new RegExp(nm.map(t=>`(?:${t.replace("{","\\{").replace("}","\\}")})`).join("|"));function al(t,e){let n=t.split(om),o=0,s=[];for(let r=0;r<n.length;r++){let i=n[r];if(s.push(i),r===n.length-1)break;if(e.indexOf(i)===-1)return t;let a=n[r+1],l=r===n.length-2;o+=i.length;let c=o;if(l){let d=a.charAt(0),p=0;do c=d?e.indexOf(d,c+1):-1,p+=1;while(c!==-1&&a.indexOf(e.slice(c))!==0);if(c===-1&&p>2)return t}else c=a&&a!==""?e.indexOf(a,o):-1;let u=c===-1?e.slice(o):e.slice(o,c);s.push(u),o=c}return s.join("")}function ll(t,e){return typeof e=="boolean"?t:t.slice(0,e)}var ul={suggestions:[],fetchState:"idle",isInitialRequest:null},cl={default:ul},pl=t=>e=>e.textSuggestions[t].suggestions,dl=t=>e=>{var n;return((n=e.textSuggestions[t])==null?void 0:n.suggestions)??[]},ml=t=>{let e=Object.keys(t.textSuggestions).map(n=>{var o;return(o=t.textSuggestions[n])==null?void 0:o.fetchState});return e.length===0?!0:e.every(n=>n!=="done")},Zt=t=>t.textSuggestions,gl=t=>e=>e.text.startsWith(t),is=(0,Ct.createAction)("textSuggestions/refresh"),De=(0,Ct.createAsyncThunk)("textSuggestions/recommendations",async(t,e)=>{var c;let{deepdeskAPI:n}=e.extra,o=e.getState(),s=(c=o.conversation.current)==null?void 0:c.id,{textSuggestionsCount:r,inlineSuggestions:i}=o.settings,a=Dt(o);if(!s)throw new Error("No current conversation to fetch text suggestions");let l=await n.getTextSuggestions(s,Dn(o),t);if(t==="default"){let u=i?l.filter(gl(a)):l;e.dispatch(ot(u.slice(0,r)))}return l}),Bn=(0,Ct.createAsyncThunk)("textSuggestions/autocompletions",async(t,e)=>{var c;let{deepdeskAPI:n}=e.extra,o=e.getState(),s=(c=o.conversation.current)==null?void 0:c.id,{textSuggestionsCount:r,deanonymize:i,inlineSuggestions:a}=o.settings;if(!s)throw new Error("No current conversation to fetch text suggestions");let l=await n.getAutocompleteSuggestions(s,{...Dn(o),input:t});if(!e.getState().input.text)throw new Error("Abort");return a&&(l=l.filter(gl(t))),i&&(l=l.map(u=>({...u,text:u.source!=="trie-with-typos"?al(u.text,t):u.text}))),l=ll(l,r),e.dispatch(ot(l)),l}),fl=(0,Ct.createSlice)({name:"textSuggestions",initialState:cl,reducers:{setTextSuggestions:{reducer(t,e){let{contentType:n}=e.payload;t[n].fetchState="done",t[n].suggestions=e.payload.suggestions},prepare(t,e){return{payload:{contentType:t,suggestions:e}}}},setSuggestionState(t,e){return e.payload}},extraReducers:t=>{t.addCase(De.pending,(e,n)=>{let o=n.meta.arg,s=e[o]||ul;return{...e,[o]:{...s,fetchState:"loading",isInitialRequest:s.isInitialRequest===null}}}).addCase(De.rejected,(e,n)=>{let o=n.meta.arg;e[o].fetchState="error"}).addCase(De.fulfilled,(e,n)=>{let o=n.meta.arg;e[o].fetchState="done",e[o].suggestions=n.payload}).addCase(Bn.pending,e=>{e.default.fetchState="loading"}).addCase(Bn.rejected,e=>{e.default.fetchState="error"}).addCase(Bn.fulfilled,(e,n)=>{e.default.fetchState="done",e.default.suggestions=n.payload}).addCase(R,()=>cl)}}),{setTextSuggestions:hl,setSuggestionState:yl}=fl.actions,Sl=fl.reducer;var xl=require("@reduxjs/toolkit");var vl={contentType:null,suggestion:null},Cl=t=>t.activeSuggestion.suggestion,Tl=t=>t.activeSuggestion.contentType,bl=(0,xl.createSlice)({name:"activeSuggestion",initialState:vl,reducers:{setActiveSuggestion(t,e){let{contentType:n,suggestion:o}=e.payload;t.contentType=n,t.suggestion=o},resetActiveSuggestion(t){t.contentType=null,t.suggestion=null}},extraReducers:t=>{t.addCase(R,()=>vl)}}),{setActiveSuggestion:He,resetActiveSuggestion:Dr}=bl.actions,wl=bl.reducer;var Hr={};V(Hr,{enUS:()=>sm,nlNL:()=>rm});var sm={warning:[{type:0,value:"Are you sure you want to discard the message?"}],editContentLabel:[{type:0,value:"Edit and view suggestion"}],overlayLabel:[{type:0,value:"Close dialog"}]},rm={warning:[{type:0,value:"Weet je zeker dat je de wijzigingen wilt weggooien?"}],editContentLabel:[{type:0,value:"Bewerk en bekijk suggestie"}],overlayLabel:[{type:0,value:"Sluit"}]};var El=require("@reduxjs/toolkit"),im={showTabHint:!1,inputHasFocus:!1,overlayCollapsed:!1,openOverlayWhenTyping:!1,overlayCollapsedUserOverwrite:!1};var _l=({ui:t})=>t.overlayCollapsed;var Pl=(0,El.createSlice)({name:"ui",initialState:im,reducers:{setShowTabHint(t,e){t.showTabHint=e.payload},setInputHasFocus(t,e){t.overlayCollapsedUserOverwrite!==!0&&(e.payload===!0&&(t.overlayCollapsed=!1),t.inputHasFocus=e.payload)},setOverlayCollapsed(t,e){e.payload.collapse===!1&&(t.openOverlayWhenTyping=!1),!(e.payload.skipWhenInputFocus&&t.inputHasFocus)&&(t.overlayCollapsed=e.payload.collapse)},setOpenOverlayWhenTyping(t,e){t.openOverlayWhenTyping=e.payload},setOverlayCollapsedUserOverwrite(t,e){t.overlayCollapsedUserOverwrite=e.payload,t.overlayCollapsed=e.payload}}}),{setShowTabHint:Kn,setInputHasFocus:Yt,setOverlayCollapsed:en,setOpenOverlayWhenTyping:kl,setOverlayCollapsedUserOverwrite:Rl}=Pl.actions,Il=Pl.reducer;var Un=_(require("react")),Al=require("react/jsx-runtime"),Ll=Un.default.createContext(null),Vn=({broadcastEvents:t,children:e})=>{let n=Un.default.useMemo(()=>t,[]);return(0,Al.jsx)(Ll.Provider,{value:n,children:e})},ke=()=>{let t=(0,Un.useContext)(Ll);if(!t)throw new Error("You should use the useBroadcastEvents within a BroadcastEventsProvider");return t};var tn=require("@reduxjs/toolkit");var am={isLoggedIn:!0,loginFetchState:"idle",verifyFetchState:"idle",showLoginOverlay:!1},Fe=t=>t.auth.isLoggedIn,Ml=t=>t.auth.loginFetchState,Ol=t=>t.auth.verifyFetchState,Nl=t=>t.auth.showLoginOverlay,Tt=(0,tn.createAsyncThunk)("auth/validate",async(t,e)=>e.extra.deepdeskAPI.isLoggedIn()),Dl=(0,tn.createAsyncThunk)("auth/requestLogin",async({email:t},e)=>{let{deepdeskAPI:n}=e.extra;return n.requestLoginByEmail(t)}),qn=(0,tn.createAsyncThunk)("auth/verifyLoginToken",async({token:t},e)=>{let{deepdeskAPI:n}=e.extra;return n.verifyLoginToken(t)}),Hl=(0,tn.createSlice)({name:"auth",initialState:am,reducers:{setIsLoggedIn(t,e){t.isLoggedIn=e.payload},setShowLoginOverlay(t,e){t.showLoginOverlay=e.payload}},extraReducers:t=>{t.addCase(Tt.pending,e=>{e.loginFetchState="loading"}),t.addCase(Tt.fulfilled,(e,{payload:n})=>{e.isLoggedIn=n,e.loginFetchState="done"}),t.addCase(Tt.rejected,e=>{e.loginFetchState="error",e.isLoggedIn=!1}),t.addCase(qn.pending,e=>{e.verifyFetchState="loading"}),t.addCase(qn.rejected,e=>{e.verifyFetchState="error"}),t.addCase(qn.fulfilled,(e,n)=>{n.payload.isLoggedIn?e.verifyFetchState="done":e.verifyFetchState="error"})}}),{setIsLoggedIn:Fl,setShowLoginOverlay:Bl}=Hl.actions,Kl=Hl.reducer;var Fr="SetActiveSuggestion",nn="ShowLoginOverlay",Br="UserLoggedIn",Be="ApplySuggestion",Kr="ApplyImageSuggestion",lm=t=>({[Fr]:e=>{t.dispatch(yl(e.state)),t.dispatch(He({contentType:e.contentType,suggestion:e.suggestion}))},[nn]:e=>{t.dispatch(Bl(e))},[Br]:()=>{t.dispatch(Tt())},[Kr]:e=>{t.dispatch(ko({suggestion:e.suggestion}))},[Be]:e=>{t.dispatch(Se({...e,eventMetrics:{inputType:"mouse"},replace:"selection"})),t.dispatch(st())}}),Ul=lm;var Ur=require("react/jsx-runtime"),cm=()=>{var g;let[t,e]=(0,Vl.useState)(!1),n=(0,on.useSelector)(Cl),o=(0,on.useSelector)(Tl),s=(0,on.useSelector)(Zt),r=(0,on.useDispatch)(),i=ke(),a=P(Hr),l=()=>{n!==null&&t?window.confirm(a("warning"))&&c():c()},c=()=>{r(Dr()),r(Yt(!0)),r(X.actions.reset())},u=(f,T)=>{r(Dr()),r(Yt(!0)),i.send(Be,{text:f,suggestion:T})};if(n===null||o===null)return null;let d=(g=s[o])==null?void 0:g.suggestions.indexOf(n),p=d===0||d===null?void 0:()=>r(He({contentType:o,suggestion:s[o].suggestions[d-1]})),m=d===s[o].suggestions.length-1||d===null?void 0:()=>r(He({contentType:o,suggestion:s[o].suggestions[d+1]}));return(0,Ur.jsx)(Ft,{autoFocus:!0,isOpen:d!==null,onClose:l,onBack:l,contentAriaLabel:a("editContentLabel"),overlayAriaLabel:a("overlayLabel"),children:(0,Ur.jsx)(rs,{onTouched:e,onDismiss:c,onUse:f=>u(f,n),suggestion:n,onNext:m,onPrevious:p})})},ql=cm;var qr=require("react-redux");var as=_(require("classnames")),Ce=require("react"),ls=require("react-redux");var zl=_(require("classnames"));var jl={root:"_root_1ukx5_1"};var Wl=require("react/jsx-runtime"),um=({className:t,value:e,...n})=>{let o=h("TextInput",jl);return(0,Wl.jsx)("input",{className:(0,zl.default)(t,o.root),type:"text",value:e,...n})},jn=um;var Vr={};V(Vr,{enUS:()=>pm,nlNL:()=>dm});var pm={back:[{type:0,value:"Back"}],promptTitle:[{type:0,value:"Sign in to Deepdesk"}],verifyCodeTitle:[{type:0,value:"Paste the code from your email"}],verifyCodeBody:[{type:0,value:"Copy the code from the email you just received and paste it here."}],verifyCodeInputPlaceholder:[{type:0,value:"Paste link or code here"}],verifyCodeSubmitLabel:[{type:0,value:"Sign in"}],verifyCodeError:[{type:0,value:"Sign in failed. The code is probably no longer valid. Please "},{type:8,value:"login",children:[{type:0,value:"request new code"}]},{type:0,value:"."}],requestCodeTitle:[{type:0,value:"Have a code sent to your email"}],requestCodeBody:[{type:0,value:"Enter your email and request a code. If you are an existing Deepdesk user you will receive an email with a code. If you are a new user you will receive an email asking to request access to Deepdesk first."}],requestCodeInputPlaceholder:[{type:0,value:"Enter your email"}],requestCodeSubmitLabel:[{type:0,value:"Request code"}]},dm={back:[{type:0,value:"Terug"}],promptTitle:[{type:0,value:"Login bij Deepdesk"}],verifyCodeTitle:[{type:0,value:"Plak de code uit je email"}],verifyCodeBody:[{type:0,value:"Kopieer de code uit de email en plak deze hier."}],verifyCodeInputPlaceholder:[{type:0,value:"Plak hier de code"}],verifyCodeSubmitLabel:[{type:0,value:"Inloggen"}],verifyCodeError:[{type:0,value:"Inloggen is niet gelukt. De code is waarschijnlijk niet meer geldig. "},{type:8,value:"login",children:[{type:0,value:"Vraag een nieuwe code aan"}]},{type:0,value:"."}],requestCodeTitle:[{type:0,value:"Verstuur een login code naar je email"}],requestCodeBody:[{type:0,value:"Voer je e-mailadres in en krijg een login code. Als je een bestaande Deepdesk gebruiker bent krijg je een email met een code. Als je een nieuwe gebruiker bent wordt er een email verstuurd met een toegangsverzoek voor Deepdesk."}],requestCodeInputPlaceholder:[{type:0,value:"Typ hier je e-mailadres"}],requestCodeSubmitLabel:[{type:0,value:"Code aanvragen"}]};var Gl={root:"_root_1edpl_1",anchorButton:"_anchorButton_1edpl_5",errorMessage:"_errorMessage_1edpl_19",title:"_title_1edpl_25",subtitle:"_subtitle_1edpl_31",text:"_text_1edpl_38",input:"_input_1edpl_43",actions:"_actions_1edpl_48",button:"_button_1edpl_55",primaryButton:"_primaryButton_1edpl_70"};var H=require("react/jsx-runtime");var mm=t=>{try{let e=new URL(t);return new URLSearchParams(e.search).get("token")||void 0}catch{return t}},gm=({agentEmail:t,isOpen:e,origin:n="",onSuccess:o,onDismiss:s})=>{let r=P(Vr),i=h("LoginTokenDialog",Gl),a=(0,ls.useSelector)(Ol),l=(0,ls.useDispatch)(),[c,u]=(0,Ce.useState)(t||""),[d,p]=(0,Ce.useState)(0),[m,g]=(0,Ce.useState)(""),f=(0,Ce.useCallback)(async S=>{S.preventDefault(),l(Dl({email:c})),p(1)},[n,c]),T=()=>{g(""),p(0)},b=(0,Ce.useCallback)(async S=>{S.preventDefault();let w=mm(S.target.elements.token.value);if(!w){g(r("verifyCodeError",{login:y}));return}l(qn({token:w}))},[n]),y=(0,Ce.useMemo)(()=>S=>(0,H.jsx)("button",{type:"button","data-testid":"login-token-dialog-back-button",className:i.anchorButton,onClick:T,children:S},"back-button"),[]);return(0,Ce.useEffect)(()=>{a==="error"&&g(r("verifyCodeError",{login:y})),a==="done"&&o()},[a]),(0,H.jsx)(Ft,{autoFocus:!0,isOpen:e,contentAriaLabel:r("promptTitle"),overlayAriaLabel:r("promptTitle"),onClose:s,onBack:s,children:(0,H.jsxs)("div",{className:i.root,children:[(0,H.jsx)("h1",{className:i.title,children:r("promptTitle")}),d===0&&(0,H.jsxs)("form",{onSubmit:f,children:[(0,H.jsx)("h2",{className:i.subtitle,children:r("requestCodeTitle")}),(0,H.jsx)("p",{className:i.text,children:r("requestCodeBody")}),(0,H.jsx)(jn,{className:i.input,name:"email",placeholder:r("requestCodeInputPlaceholder"),value:c,onChange:S=>u(S.target.value)}),(0,H.jsx)("div",{className:i.actions,children:(0,H.jsx)("button",{type:"submit",className:(0,as.default)(i.button,i.primaryButton),children:r("requestCodeSubmitLabel")})})]}),d===1&&(0,H.jsxs)("form",{onSubmit:b,children:[(0,H.jsx)("h2",{className:i.subtitle,children:r("verifyCodeTitle")}),(0,H.jsx)("p",{className:i.text,children:r("verifyCodeBody")}),(0,H.jsx)(jn,{className:i.input,name:"token",placeholder:r("verifyCodeInputPlaceholder"),disabled:["loading","done"].includes(a)}),m&&(0,H.jsx)("div",{className:i.errorMessage,children:m}),(0,H.jsxs)("div",{className:i.actions,children:[(0,H.jsx)("button",{type:"button",className:(0,as.default)(i.button),onClick:T,children:r("back")}),(0,H.jsx)("button",{type:"submit",className:(0,as.default)(i.button,i.primaryButton),disabled:["loading","done"].includes(a),children:r("verifyCodeSubmitLabel")})]})]})]})})},$l=gm;var Jl=require("react/jsx-runtime"),fm=()=>{let t=(0,qr.useSelector)(Nl),e=(0,qr.useSelector)(Ga),n=E("adminUrl"),o=ke(),s=()=>o.send(nn,!1),r=()=>{o.send(nn,!1),o.send(Br)};return(0,Jl.jsx)($l,{isOpen:t,agentEmail:e==null?void 0:e.agentEmail,origin:n,onDismiss:s,onSuccess:r})},Xl=fm;var yc=_(require("lodash.debounce")),Y=require("react"),wt=require("react-redux");var cs=require("@reduxjs/toolkit");var hm={data:null,fetchState:"idle"},Ql=t=>t.contentTypes.data,zn=(0,cs.createAsyncThunk)("contentTypes/getContentTypes",async(t,e)=>e.extra.deepdeskAPI.getContentTypes()),ym=(0,cs.createSlice)({name:"contentTypes",initialState:hm,reducers:{},extraReducers:t=>{t.addCase(zn.pending,e=>{e.fetchState="loading"}).addCase(zn.rejected,e=>{e.fetchState="error"}).addCase(zn.fulfilled,(e,n)=>{e.fetchState="done",e.data=n.payload})}}),Zl=ym.reducer;function Wn(t){let e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.left="-999999px",e.style.top="-999999px",document.body.appendChild(e),e.focus(),e.select(),document.execCommand("copy"),e.remove()}var Yl=require("react");function ec(t,e){(0,Yl.useEffect)(()=>{let n=o=>{var s;((s=navigator==null?void 0:navigator.platform)!=null&&s.toLowerCase().includes("mac")?o.metaKey:o.ctrlKey)&&o.key===t&&(o.preventDefault(),o.stopPropagation(),e())};return document.addEventListener("keydown",n),()=>{document.removeEventListener("keydown",n)}},[])}var Gn=require("react"),ds=require("react-redux");var us=require("@reduxjs/toolkit");var tc={data:null,fetchState:"idle"},ps=t=>{var r;let e=[],{visitorName:n}=t.info.visitorInfo??{},{agentName:o,agentNickname:s}=t.info.agentInfo??{};return o&&o!==n&&e.push(o),s&&s!==n&&e.push(s),((r=t.entities.data)==null?void 0:r.filter(i=>!e.includes(i.text)))??null},Te=(0,us.createAsyncThunk)("entities/getEntities",async(t,e)=>{let{deepdeskAPI:n,dynamicThunkObject:o}=e.extra;if(!o.conversationQuery)return Promise.resolve([]);let s=o.conversationQuery,r=await s();return r.length===0?Promise.resolve([]):n.getEntities(r)}),Sm=t=>t.filter((e,n)=>n===t.findIndex(o=>o.text===e.text)),vm=(0,us.createSlice)({name:"entities",initialState:tc,reducers:{},extraReducers:t=>{t.addCase(Te.pending,e=>{e.fetchState="loading"}).addCase(Te.rejected,e=>{e.fetchState="error"}).addCase(Te.fulfilled,(e,n)=>{e.fetchState="done",e.data=Sm(e.data?[...e.data,...n.payload]:n.payload)}).addCase(R,()=>tc)}}),nc=vm.reducer;var jr={};V(jr,{enUS:()=>xm,nlNL:()=>Cm});var xm={title:[{type:0,value:"Copy to your clipboard"}],noResults:[{type:0,value:"No entities have been found"}],copy:[{type:0,value:"Copy"}],use:[{type:0,value:"Use"}]},Cm={title:[{type:0,value:"Kopieer naar klembord"}],noResults:[{type:0,value:"Er zijn geen entiteiten gevonden"}],copy:[{type:0,value:"Kopieer"}],use:[{type:0,value:"Gebruik"}]};var oc={root:"_root_313jm_1",title:"_title_313jm_5",empty:"_empty_313jm_16"};var Ke=require("react/jsx-runtime"),Tm=({onCopy:t,onUse:e})=>{let n=(0,Gn.useRef)(null),o=h("EntitiesList",oc),s=P(jr),r=(0,ds.useSelector)(ps),i=(0,ds.useDispatch)();return(0,Gn.useEffect)(()=>{i(Te())},[]),(0,Gn.useEffect)(()=>{n.current&&n.current.focus()},[n]),(0,Ke.jsxs)("div",{className:o.root,ref:n,tabIndex:-1,children:[(0,Ke.jsxs)("h3",{className:o.title,children:[s("title")," ",(0,Ke.jsx)(rt,{})]}),r&&r.length>0&&(0,Ke.jsx)(I.ActionsBar,{primaryLabel:s("copy"),secondaryLabel:s("use"),onPrimary:(a,l)=>t(r[l]),onSecondary:(a,l)=>e(r[l]),list:r.map(a=>({text:a.text,type:a.label,primaryAction:"copy",secondaryAction:"use"})),children:(0,Ke.jsx)(I.List,{children:r.map((a,l)=>(0,Ke.jsx)(I.ListItem,{index:l,closeOnSelect:!0,onClick:()=>t(a),children:a.text},a.text))},"entities")}),r&&r.length===0&&(0,Ke.jsx)("p",{className:o.empty,children:s("noResults")})]})},sc=Tm;var we=require("react"),$n=require("react-redux");var ms=require("@reduxjs/toolkit");var rc={data:null,fetchState:"idle"},ic=t=>t.summary.data,ac=t=>t.summary.fetchState==="error",Ue=(0,ms.createAsyncThunk)("summary/getSummary",async(t,e)=>{let{deepdeskAPI:n,dynamicThunkObject:o}=e.extra;if(!o.conversationQuery)return Promise.reject(new Error("setConversationQuery method is not defined"));let s=o.conversationQuery,r=await s();if(r.length===0)return Promise.reject(new Error("No messages are included"));let i=await n.getSummary(r);return{original:r,summary:i}}),bm=(0,ms.createSlice)({name:"summary",initialState:rc,reducers:{},extraReducers:t=>{t.addCase(Ue.pending,e=>{e.data=null,e.fetchState="loading"}).addCase(Ue.rejected,e=>{e.data=null,e.fetchState="error"}).addCase(Ue.fulfilled,(e,n)=>{e.fetchState="done",n.payload&&(e.data=n.payload.summary)}).addCase(R,()=>rc)}}),lc=bm.reducer;var zr={};V(zr,{enUS:()=>wm,nlNL:()=>Em});var wm={title:[{type:0,value:"Conversation summary"}],copy:[{type:0,value:"Copy"}],error:[{type:0,value:"Could not generate a summary"}],loading:[{type:0,value:"Generating summary, this may take a few moments."}]},Em={title:[{type:0,value:"Gesprek samenvatting"}],copy:[{type:0,value:"Kopieer"}],error:[{type:0,value:"Kon helaas geen samenvatting genereren."}],loading:[{type:0,value:"Samenvatting wordt gemaakt, dit kan even duren."}]};var cc={root:"_root_gn7se_1",title:"_title_gn7se_5",actions:"_actions_gn7se_16",main:"_main_gn7se_22",textInput:"_textInput_gn7se_26",loading:"_loading_gn7se_45",error:"_error_gn7se_49"};var be=require("react/jsx-runtime"),_m=({onCopy:t})=>{let e=(0,we.useRef)(null),n=h("SummaryForm",cc),[o,s]=(0,we.useState)(""),r=P(zr),i=(0,$n.useSelector)(ic),a=(0,$n.useSelector)(ac),l=(0,$n.useDispatch)(),c=()=>{l(Ae({name:"summary copied to clipboard",data:{originalText:i,finalText:o},options:{includeConversationData:!0}})),t(o)};return(0,we.useEffect)(()=>{l(Ue())},[]),(0,we.useEffect)(()=>{s(i||"")},[i]),(0,we.useEffect)(()=>{e.current&&i&&e.current.focus()},[e,i]),(0,we.useEffect)(()=>{let u=d=>{d.key==="Enter"&&d.shiftKey&&c()};return document.addEventListener("keydown",u),()=>{document.removeEventListener("keydown",u)}},[o]),(0,be.jsxs)("div",{className:n.root,tabIndex:-1,children:[(0,be.jsxs)("h3",{className:n.title,children:[r("title")," ",(0,be.jsx)(rt,{})]}),a?(0,be.jsx)("p",{className:n.error,children:r("error")}):(0,be.jsxs)(we.Fragment,{children:[(0,be.jsx)("div",{className:n.main,children:(0,be.jsx)("textarea",{placeholder:i?void 0:r("loading"),disabled:!i,className:n.textInput,ref:e,value:o,onChange:u=>s(u.target.value)})}),(0,be.jsx)("div",{className:n.actions,children:(0,be.jsx)(I.Button,{shortKeys:[8679,8629],onClick:c,children:r("copy")})})]})]})},Wr=_m;var Gr={};V(Gr,{enUS:()=>Pm,nlNL:()=>km});var Pm={personalCollectionLink:[{type:0,value:"Go to Personal Collection"}],tutorialLink:[{type:0,value:"Go to Deepdesk tutorial"}],dashboardLink:[{type:0,value:"Go to Deepdesk dashboard"}],searchPlaceholder:[{type:0,value:"Start typing to search..."}],urlSuggestions:[{type:0,value:"Link suggestions"}],personalSuggestions:[{type:0,value:"Personal suggestions"}],pinnedMessages:[{type:0,value:"Pinned messages"}],imageSuggestions:[{type:0,value:"Images"}],typePlaceholder:[{type:0,value:"All types"}],navigation:[{type:0,value:"Navigation"}],entitiesClipboard:[{type:0,value:"Conversation clipper"}],summaryClipboard:[{type:0,value:"Summarize conversation"}],knowledgeSearch:[{type:0,value:"Knowledge assist"}],commands:[{type:0,value:"Commands"}],use:[{type:0,value:"Use"}],preview:[{type:0,value:"Preview"}],warning:[{type:0,value:"Are you sure you want to discard the message?"}]},km={personalCollectionLink:[{type:0,value:"Ga naar persoonlijke collectie"}],tutorialLink:[{type:0,value:"Ga naar Deepdesk tutorial"}],dashboardLink:[{type:0,value:"Ga naar Deepdesk dashboard"}],searchPlaceholder:[{type:0,value:"Begin met typen om te zoeken..."}],personalSuggestions:[{type:0,value:"Persoonlijke suggesties"}],urlSuggestions:[{type:0,value:"Link suggesties"}],imageSuggestions:[{type:0,value:"Afbeeldingen"}],navigation:[{type:0,value:"Navigatie"}],typePlaceholder:[{type:0,value:"Alle types"}],pinnedMessages:[{type:0,value:"Actueel"}],entitiesClipboard:[{type:0,value:"Klembord"}],summaryClipboard:[{type:0,value:"Vat gesprek samen"}],knowledgeSearch:[{type:0,value:"Knowledge assist"}],commands:[{type:0,value:"Acties"}],use:[{type:0,value:"Gebruik"}],preview:[{type:0,value:"Bewerk"}],warning:[{type:0,value:"Weet je zeker dat je de wijzigingen wilt weggooien?"}]};var bt=_(require("react")),Jn=require("react-redux");var $r={};V($r,{enUS:()=>Rm,nlNL:()=>Im});var Rm={title:[{type:0,value:"Knowledge Search"}],use:[{type:0,value:"Use"}],loading:[{type:0,value:"Loading..."}],error:[{type:0,value:"Something went wrong, please try again later."}],anotherQuestion:[{type:0,value:"Send a message..."}]},Im={title:[{type:0,value:"Knowledge Search"}],use:[{type:0,value:"Gebruik"}],loading:[{type:0,value:"Laden..."}],error:[{type:0,value:"Er ging iets mis, probeer het later opnieuw."}],anotherQuestion:[{type:0,value:"Stuur een bericht..."}]};var uc={root:"_root_1qchz_1",title:"_title_1qchz_5",empty:"_empty_1qchz_16",status:"_status_1qchz_20",form:"_form_1qchz_26",input:"_input_1qchz_39",submit:"_submit_1qchz_51",question:"_question_1qchz_59",answer:"_answer_1qchz_63"};var rn=require("@reduxjs/toolkit");var Xr={data:[],fetchState:"idle"},pc=t=>{var e;return(e=t.answer)==null?void 0:e.data},dc=t=>t.answer.fetchState,gs=(0,rn.createAction)("answer/resetKnowledgeSearch"),sn=(0,rn.createAsyncThunk)("answer/getAnswer",async(t,e)=>{var i;let{deepdeskAPI:n}=e.extra,o=e.getState().answer.data;if(!((i=e.getState().profile.data)==null?void 0:i.code))throw new Error("Profile is not defined");let r=await n.knowledgeSearch(t,o);return{question:t,answer:r}}),Lm=(0,rn.createSlice)({name:"answer",initialState:Xr,reducers:{},extraReducers:t=>{t.addCase(sn.pending,e=>{e.fetchState="loading"}).addCase(sn.rejected,e=>{e.fetchState="error"}).addCase(sn.fulfilled,(e,n)=>{e.fetchState="done",e.data=[...e.data,n.payload]}).addCase(R,()=>Xr).addCase(gs,()=>Xr)}}),mc=Lm.reducer;var Xn=require("react/jsx-runtime"),gc=()=>(0,Xn.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",viewBox:"0 0 512 512","aria-labelledby":"paperPlaneTitle",children:[(0,Xn.jsx)("title",{id:"paperPlaneTitle",children:"PaperPlane"}),(0,Xn.jsx)("path",{d:"M498.1 5.6c10.1 7 15.4 19.1 13.5 31.2l-64 416c-1.5 9.7-7.4 18.2-16 23s-18.9 5.4-28 1.6L284 427.7l-68.5 74.1c-8.9 9.7-22.9 12.9-35.2 8.1S160 493.2 160 480V396.4c0-4 1.5-7.8 4.2-10.7L331.8 202.8c5.8-6.3 5.6-16-.4-22s-15.7-6.4-22-.7L106 360.8 17.7 316.6C7.1 311.3 .3 300.7 0 288.9s5.9-22.8 16.1-28.7l448-256c10.7-6.1 23.9-5.5 34 1.4z"})]});var Z=require("react/jsx-runtime"),Am=({onUse:t,question:e})=>{let[n,o]=bt.default.useState(""),{setSelected:s}=it(),r=(0,bt.useRef)(null),i=h("EntitiesList",uc),a=P($r),l=(0,Jn.useDispatch)(),c=(0,Jn.useSelector)(pc),u=(0,Jn.useSelector)(dc),d=async p=>{p.preventDefault(),p.stopPropagation(),n!==""&&l(sn(n))};return(0,bt.useEffect)(()=>{var p;e&&u==="idle"?l(sn(e)):(p=r.current)==null||p.focus()},[r,u]),(0,bt.useEffect)(()=>{u==="done"&&(s(0),o(""))},[u,c]),(0,Z.jsxs)("div",{className:i.root,children:[(0,Z.jsxs)("h3",{className:i.title,children:[a("title")," ",(0,Z.jsx)(rt,{})]}),(0,Z.jsxs)(I.ActionsBar,{list:c.map(({answer:p})=>({text:p.answer,type:"answer"})),primaryLabel:a("use"),onPrimary:p=>t(p.text),children:[c.map(({question:p,answer:m},g)=>(0,Z.jsx)(I.List,{children:(0,Z.jsx)(I.ListItem,{index:g,description:m.answer,lineClamp:!0,closeOnSelect:!0,onClick:()=>t(m.answer),sources:m.sources,styles:{title:i.question,description:i.answer},children:p})},`${m.answer}_${g}`)),u==="loading"&&(0,Z.jsx)("p",{className:i.status,children:a("loading")}),u==="error"&&(0,Z.jsx)("p",{className:i.status,children:a("error")}),(0,Z.jsxs)("form",{className:i.form,onSubmit:d,children:[(0,Z.jsx)("input",{ref:r,placeholder:a("anotherQuestion"),className:i.input,type:"text",value:n,onFocus:()=>{s(-1)},onChange:p=>{s(-1),o(p.target.value)}}),(0,Z.jsx)("button",{type:"submit",className:i.submit,children:(0,Z.jsx)(gc,{})})]})]})]})},fc=Am;var F=require("react/jsx-runtime"),Mm=200,Om=5,Nm=4,Dm=t=>t.reduce((e,n)=>[...e,...n.list.map(o=>({...o,type:n.value}))],[]),hc=(t,e)=>!e||t.toLowerCase().includes(e.toLowerCase()),Hm=()=>{let t=(0,wt.useDispatch)(),e=ke(),n=P(Gr),[o,s]=(0,Y.useState)(!1),[r,i]=(0,Y.useState)(""),[a,l]=(0,Y.useState)("search"),[c,u]=(0,Y.useState)(null),[d,p]=(0,Y.useState)([]),[m,g]=(0,Y.useState)(),f=(0,wt.useSelector)(Fe),T=E("showSearch"),b=E("showEntitiesCommand"),y=E("showSummaryCommand"),S=E("showKnowledgeSearch"),w=E("showImageSearch"),C=E("searchTriggerKey"),x=(0,wt.useSelector)(Ql),B=(0,wt.useSelector)(Za),$=(0,wt.useSelector)(Qa),K=v=>er(B.filter(A=>A.type===v.toUpperCase()),v),ie=[{value:"PERSONAL",label:n("personalSuggestions"),list:K("PERSONAL"),lineClamp:!1,listOrientation:"vertical",shouldShow:!0},{value:"URL",label:n("urlSuggestions"),list:K("URL"),lineClamp:!1,listOrientation:"vertical",shouldShow:!0},{value:"STICKYMESSAGE",label:n("pinnedMessages"),list:K("STICKYMESSAGE"),lineClamp:!1,listOrientation:"vertical",shouldShow:!0},{value:"IMAGE",label:n("imageSuggestions"),lineClamp:!1,list:K("IMAGE"),listOrientation:"horizontal",shouldShow:w}].filter(v=>v.shouldShow),ft=[{label:n("entitiesClipboard"),onClick:()=>l("entities"),shouldShow:b&&hc(n("entitiesClipboard"),r),experimental:!0},{label:n("summaryClipboard"),onClick:()=>l("summary"),shouldShow:y&&hc(n("summaryClipboard"),r),experimental:!0},{label:r?`${n("knowledgeSearch")}: ${r}`:n("knowledgeSearch"),onClick:()=>l("knowledgeSearch"),shouldShow:S,experimental:!0}].filter(v=>v.shouldShow),Mt=(x==null?void 0:x.map(v=>({value:v.code.toUpperCase(),label:`${v.name}s`,list:K(v.code.toUpperCase()),listOrientation:"vertical",lineClamp:!0})))||[],zp=(0,Y.useCallback)((0,yc.default)((v,A)=>{t(vt({query:v,type:A,tags:["search-overlay"]}))},Mm),[]),po=Dm([...Mt,...ie]),Wp=(0,Y.useCallback)((v,A)=>{if(!A)return;let Ze=[...ie,...Mt].find(({value:Ot})=>Ot===A);Ze&&(l("edit"),u(v),p(Ze.list))},[l,c,Mt]),Ys=(0,Y.useCallback)((v,A)=>{switch(A.type){case"IMAGE":e.send(Kr,{suggestion:A});break;default:e.send(Be,{text:v,suggestion:A})}t(de(!1))},[t]),Gp=v=>{Wn(v.text),t(Ae({name:"entity copied",data:{entity:v,type:"copy"}})),t(de(!1))},$p=v=>{e.send(Be,{text:v,suggestion:{source:"knowledge-search",text:v}}),t(Ae({name:"answer used",data:{originalText:v},options:{includeConversationData:!0}})),t(gs()),t(de(!1))},Mi=v=>{Wn(v),t(de(!1))},Xp=v=>{e.send(Be,{text:v.text,suggestion:{source:"entity",text:v.text}}),t(de(!1))},Jp=c===null||d.indexOf(c)-1<0?void 0:()=>u(d[d.indexOf(c)-1]),Qp=c===null||d.indexOf(c)===d.length-1?void 0:()=>u(d[d.indexOf(c)+1]);function er(v,A){return v.slice(0,m?10:A.toLowerCase()==="image"?Nm:Om)}function Oi(v,A,Ze){return A.reduce((Ot,mo)=>Ze&&m===Ze?mo.length+Ot:er(mo,Ze).length+Ot,v)}function ht(v){return A=>{o?window.confirm(n("warning"))&&(v(A),s(!1)):v(A)}}return(0,Y.useEffect)(()=>{r?zp(r,m):t(es())},[r,m]),(0,Y.useEffect)(()=>{f&&t(zn())},[f]),ec(C,()=>t(de(!0))),T?(0,F.jsxs)(I,{placeholder:n("searchPlaceholder"),typePlaceholder:n("typePlaceholder"),onChangeSearch:i,onChangeOpen:ht(v=>t(de(v))),onChangeType:v=>g(v),onChangePage:ht(l),selectedType:m,search:r,page:a,isOpen:$,types:[...Mt,...ie],children:[(0,F.jsx)(I.Page,{id:"search",children:(0,F.jsxs)(I.ActionsBar,{list:[...ft.map(v=>({text:v.label,type:"command"})),...po.map(v=>({text:v.text||v.url||v.message,type:v.type}))],primaryLabel:n("use"),secondaryLabel:n("preview"),onPrimary:({text:v},A)=>Ys(v,po[A]),onSecondary:(v,A)=>Wp(po[A],po[A].type),children:[ft.length>0&&(0,F.jsx)(I.List,{heading:n("commands"),children:ft.map((v,A)=>(0,F.jsx)(I.ListItem,{index:Oi(A,[],"commands"),closeOnSelect:!1,onClick:v.onClick,isExperimental:v.experimental,children:v.label},v.label))}),[...Mt,...ie].map(({value:v,label:A,list:Ze,lineClamp:Ot,listOrientation:mo},Zp)=>(0,F.jsx)(I.List,{heading:A,orientation:mo==="horizontal"?"horizontal":"vertical",children:er(Ze,v).map((he,Yp)=>(0,F.jsx)(I.ListItem,{index:Oi(ft.length+Yp,[...Mt,...ie].slice(0,Zp).map(({list:ed})=>ed),v),closeOnSelect:!1,lineClamp:Ot,onClick:()=>Ys(he.text,he),description:v!=="IMAGE"?he.title&&he.text:void 0,children:v==="IMAGE"?(0,F.jsx)(I.Image,{title:he.title||he.text,src:he.image}):he.title||he.text},`${he.id}-${he.text}`))},v))]})}),(0,F.jsx)(I.Page,{id:"edit",onDismiss:ht(()=>{l("search"),u(null)}),children:c&&(0,F.jsx)(rs,{suggestion:c,onTouched:s,onDismiss:()=>{s(!1),l("search"),u(null),p([])},onNext:Qp,onPrevious:Jp,onUse:v=>{l("search"),Ys(v,c),t(de(!1)),p([]),u(null)}})}),(0,F.jsx)(I.Page,{id:"entities",onDismiss:ht(()=>{l("search")}),children:(0,F.jsx)(sc,{onUse:Xp,onCopy:Gp})}),(0,F.jsx)(I.Page,{id:"summary",onDismiss:ht(()=>{l("search")}),children:(0,F.jsx)(Wr,{onCopy:Mi})}),(0,F.jsx)(I.Page,{id:"generate",onDismiss:ht(()=>{l("search")}),children:(0,F.jsx)(Wr,{onCopy:Mi})}),(0,F.jsx)(I.Page,{id:"knowledgeSearch",onDismiss:ht(()=>{t(gs()),l("search")}),children:(0,F.jsx)(fc,{question:r,onUse:$p})})]}):null},Sc=Hm;var an=require("react/jsx-runtime"),Fm=()=>{let t=E("showSearch"),e=E("isEmbedded");return(0,an.jsxs)(vc.Fragment,{children:[t&&(0,an.jsx)(Sc,{}),(0,an.jsx)(ql,{}),e&&(0,an.jsx)(Xl,{})]})},xc=Fm;var Cc=require("react-redux");var Qn=require("react/jsx-runtime"),Bm=({children:t})=>{let n=E("locale").replace("-","");return(0,Qn.jsx)(hr.Provider,{value:n,children:t})},Km=({store:t,customStyles:e={},children:n})=>(0,Qn.jsx)(Cc.Provider,{store:t,children:(0,Qn.jsx)(Bm,{children:(0,Qn.jsx)(Tn.Provider,{value:e,children:n})})}),Zn=Km;var vs=_(require("classnames")),un=require("react"),qe=require("react-redux");var Tc=require("react");function bc(t,e){let[n,o]=(0,Tc.useState)(()=>{if(typeof window>"u")return e;try{let r=window.localStorage.getItem(t);return r?JSON.parse(r):e}catch(r){return k.error(r),e}});return[n,r=>{try{let i=r instanceof Function?r(n):r;o(i),typeof window<"u"&&window.localStorage.setItem(t,JSON.stringify(i))}catch(i){k.error(i)}}]}function fs(t){let{showMidSentenceSuggestions:e,showSuggestionsBeforePattern:n,showSuggestionsAfterPattern:o}=t.settings,{text:s,selection:r}=t.input.userCommitted;return r.start!==r.end?!1:r.end>=s.length?!0:e?n&&new RegExp(n).test(s.substring(r.end))||o&&new RegExp(o).test(s.substring(0,r.end))?!0:n===!1&&o===!1:!1}var Ec=_(require("classnames")),Ve=require("react");var Jr={};V(Jr,{enUS:()=>Um,nlNL:()=>Vm});var Um={loginPlease:[{type:8,value:"login",children:[{type:0,value:"Sign in"}]},{type:0,value:" to enable Deepdesk."}],snooze:[{type:0,value:"Snooze for "},{type:8,value:"min",children:[{type:0,value:"10 minutes"}]},{type:0,value:", "},{type:8,value:"hour",children:[{type:0,value:"1 hour"}]},{type:0,value:" or "},{type:8,value:"day",children:[{type:0,value:"1 day"}]}]},Vm={loginPlease:[{type:8,value:"login",children:[{type:0,value:"Log in"}]},{type:0,value:" bij Deepdesk."}],snooze:[{type:0,value:"Snooze voor "},{type:8,value:"min",children:[{type:0,value:"10 minuten"}]},{type:0,value:", "},{type:8,value:"hour",children:[{type:0,value:"1 uur"}]},{type:0,value:" of "},{type:8,value:"day",children:[{type:0,value:"1 dag"}]}]};var wc={root:"_root_1vfca_1",anchor:"_anchor_1vfca_6",anchorButton:"_anchorButton_1vfca_11"};var lt=require("react/jsx-runtime"),Qr=(t,e,n)=>o=>(0,lt.jsx)("button",{className:t.anchorButton,type:"button",value:e,onClick:n,children:o},e),qm=({className:t,loginUrl:e,isEmbedded:n,onSnooze:o})=>{let s=P(Jr),r=ke(),i=h("Login",wc),a=(0,Ve.useCallback)(g=>{g.preventDefault(),o&&o(parseInt(g.target.value,10))},[]),l=(0,Ve.useCallback)(g=>{g.preventDefault(),r.send(nn,!0)},[e]),c=(0,Ve.useMemo)(()=>g=>(0,lt.jsx)("a",{href:e,className:i.anchor,target:"_blank",rel:"noreferrer",children:g},"login"),[e]),u=(0,Ve.useCallback)(g=>(0,lt.jsx)("button",{type:"button",className:i.anchorButton,onClick:l,children:g},"prompt"),[l]),{min:d,hour:p,day:m}=(0,Ve.useMemo)(()=>({min:Qr(i,60*10,a),hour:Qr(i,60*60,a),day:Qr(i,60*60*12,a)}),[]);return(0,lt.jsxs)("div",{className:(0,Ec.default)(t,i.root),children:[s("loginPlease",{login:n?u:c}),o&&(0,lt.jsxs)(Ve.Fragment,{children:[(0,lt.jsx)("br",{}),s("snooze",{min:d,hour:p,day:m})]})]})},hs=qm;var Pc=require("react-redux");var _c={root:"_root_1g8fi_1",text:"_text_1g8fi_19"};var Yn=require("react/jsx-runtime"),jm=({title:t})=>{let e=h("SearchTrigger",_c),n=(0,Pc.useDispatch)();return(0,Yn.jsxs)("button",{type:"button",className:e.root,onClick:()=>n(de(!0)),children:[(0,Yn.jsx)(os,{}),(0,Yn.jsx)("span",{className:e.text,children:t})]})},kc=jm;var Ic=_(require("classnames"));var Rc={root:"_root_fp74r_1",isWithDivider:"_isWithDivider_fp74r_9"};var Lc=require("react/jsx-runtime"),zm=({withDivider:t,children:e})=>{let n=h("SuggestionList",Rc);return(0,Lc.jsx)("div",{className:(0,Ic.default)(n.root,{[n.isWithDivider]:t}),children:e})},Re=zm;var Bc=require("react");var Hc=require("interweave"),cn=require("react"),ys=require("react-redux");var Ac=require("react");function Mc(t,e,n){(0,Ac.useEffect)(()=>{let o=t.current;return o?(o.addEventListener(e,n),()=>{o.removeEventListener(e,n)}):()=>{}},[t,e,n])}var Wm=/[.*+?^${}()|[\]\\]/g,Gm=/[^0-9A-Za-zÀ-ÖØ-öø-ÿ](?=[0-9A-Za-zÀ-ÖØ-öø-ÿ]*$)/;function $m(t){return t.replace(Wm,"\\$&")}function Xm(t,e){let n=t.split("").findIndex((o,s)=>o!==e[s]);return n>-1?n:Math.min(t.length,e.length)}function Zr(t){return t.search(Gm)}function Oc(t,e=[]){let n=t;return e.forEach(o=>{if(!o)return;let s=new RegExp(`\\b(${$m(o)})\\b`,"gi");n=n.replace(s,"<strong>$1</strong>")}),n}function Nc(t){return t.replace(Nt,'<mark data-type="placeholder">$1</mark>')}function ln(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function Jm(t,e){return t.split("").map((i,a)=>({char:i,index:a})).filter(({char:i,index:a})=>/\s/.test(i)&&a<=e).map(({index:i})=>i).reverse()[0]}function Yr(t,e,n={}){if(e){let o=Xm(e.toLowerCase(),t.toLowerCase()),s=ln(t.substring(o,t.length));if(n.stripAgentPart){let l=t.substring(0,o),c=Zr(l);return`<span style="opacity: 0.5">${l.substring(c+1)}</span>${s}`}let i=e.split(Di).length>3||e.length>30?Jm(e.trim(),o):0;return`${`${i>0?"\u2026":""}${ln(t.substring(i,o))}`}<strong>${s}</strong>`}return t}var Dc={badge:"_badge_8rv7b_1",formattedText:"_formattedText_8rv7b_5"};var ei=require("react/jsx-runtime"),Zm=["search","personal-collection-search","studio-search"];function Ym(t,e,n,o={}){let s="";return Zm.includes(e)?s=Oc(Yr(t,n,{stripAgentPart:!0}),o.searchKeywords??[n]):s=Yr(t,n,o),o.placeholders===!0&&(s=Nc(s)),s}var eg=()=>{},tg=({index:t,selected:e,suggestion:n})=>{let o=E("inlineSuggestions"),s=(0,ys.useSelector)(Dt),r=(0,ys.useDispatch)(),i=h("TextSuggestion",Dc),a=(0,cn.useRef)(null);(0,cn.useEffect)(()=>{let c=setTimeout(()=>{r(ea({text:n.text,suggestion:n}))},500);return()=>{clearTimeout(c)}},[n]),Mc(a,"click",()=>{r(Ro(t)),r(Se({suggestion:n,text:n.text,eventMetrics:{inputType:"mouse"},replace:"until-selection-end"}))});let l=(0,cn.useMemo)(()=>Ym(n.text,n.source,s,{stripAgentPart:o,placeholders:!0,searchKeywords:n.searchKeywords}),[o,n.text,n.source,s,n.searchKeywords]);return n.source==="gpt"?null:(0,ei.jsx)(O,{ref:a,as:"button",selected:e,onClick:eg,children:(0,ei.jsx)(Hc.Interweave,{className:i.formattedText,content:l})})},Fc=tg;var ti=require("react/jsx-runtime"),ng=({suggestions:t,selectedIndex:e})=>(0,ti.jsx)(Bc.Fragment,{children:t.slice().map((n,o)=>(0,ti.jsx)(Fc,{index:o,selected:o===e,suggestion:n},`${n.text}-${n.source}`)).reverse()}),Kc=ng;var Vc=_(require("classnames"));var Uc={root:"_root_1wpmq_1",isCollapsed:"_isCollapsed_1wpmq_17"};var Ss=require("react/jsx-runtime"),og=({className:t,isCollapsed:e,title:n,onClick:o})=>{let s=h("ToggleButton",Uc);return(0,Ss.jsx)("button",{type:"button",className:(0,Vc.default)(s.root,t,{[s.isCollapsed]:e}),onClick:o,title:n,children:(0,Ss.jsx)("svg",{width:"14",height:"8",viewBox:"-2.5 -5 75 60",preserveAspectRatio:"none",children:(0,Ss.jsx)("path",{d:"M0,0 l35,50 l35,-50",fill:"none",stroke:"grey",strokeLinecap:"round",strokeWidth:"6"})})})},Et=og;var ni={};V(ni,{enUS:()=>sg,nlNL:()=>rg});var sg={arrowHint:[{type:0,value:"Tip: use arrow keys to navigate suggestions"}],searchHintWindows:[{type:0,value:"Press CTRL+"},{type:1,value:"searchTriggerKey"},{type:0,value:" to search"}],searchHintMac:[{type:0,value:"Press CMD+"},{type:1,value:"searchTriggerKey"},{type:0,value:" to search"}],open:[{type:0,value:"Open Deepdesk"}],collapse:[{type:0,value:"Close"}],search:[{type:0,value:"Search"}]},rg={arrowHint:[{type:0,value:"Tip: Selecteer suggesties met pijltoetsen"}],searchHintWindows:[{type:0,value:"Druk CTRL+"},{type:1,value:"searchTriggerKey"},{type:0,value:" om te zoeken"}],searchHintMac:[{type:0,value:"Druk CMD+"},{type:1,value:"searchTriggerKey"},{type:0,value:" om te zoeken"}],open:[{type:0,value:"Open Deepdesk"}],collapse:[{type:0,value:"Sluiten"}],search:[{type:0,value:"Zoeken"}]};var qc={root:"_root_4kcme_1",isInline:"_isInline_4kcme_14",toggleButton:"_toggleButton_4kcme_18",toggleButtonWrapper:"_toggleButtonWrapper_4kcme_22",toggleButtonWrapperHidden:"_toggleButtonWrapperHidden_4kcme_29",isCollapsed:"_isCollapsed_4kcme_33",collapsible:"_collapsible_4kcme_33",hints:"_hints_4kcme_41",hintsHidden:"_hintsHidden_4kcme_48",triggers:"_triggers_4kcme_53",triggersRight:"_triggersRight_4kcme_68"};var N=require("react/jsx-runtime"),ig=({inline:t=!1,textSuggestions:e,selectedIndex:n})=>{let o=h("SuggestionsOverlay",qc),s=P(ni),r=E("inlineSuggestions"),i=(0,qe.useSelector)(fs),a=Xi(),l=(0,qe.useDispatch)(),c=(0,un.useRef)(null),u=E("searchTriggerKey"),d=(0,qe.useSelector)(_l),p=(0,qe.useSelector)(Fe),m=(0,qe.useSelector)(yo),[g,f]=(0,un.useState)(null),T=E("showSearch"),b=E("showTextSuggestions"),y=E("adminUrl"),S=E("isEmbedded"),[w,C]=bc("dd-snooze-until-ms",0),x=d||w>Date.now(),B=e.filter(ie=>ie.source!=="gpt").length,$=()=>{x&&C(0),l(Rl(!x))},K=ie=>{let ft=Date.now()+ie*1e3;C(ft),k.info(`Snooze until: ${new Date(ft)}`),l(en({collapse:!0}))};return(0,un.useEffect)(()=>{B===0&&f(null)},[e,B]),jt(()=>{l(en({collapse:!0,skipWhenInputFocus:!0}))}),r!==t||p===null||m===!1?null:p===!1?(0,N.jsxs)("div",{ref:c,className:(0,vs.default)(o.root,{[o.isCollapsed]:x,[o.isInline]:t}),"data-inline":t,children:[!x&&(0,N.jsxs)("div",{className:o.triggers,children:[(0,N.jsx)("div",{style:{flex:1}}),(0,N.jsx)("div",{className:o.triggersRight,children:(0,N.jsx)(Et,{className:o.toggleButton,title:s("collapse"),onClick:$,isCollapsed:!1})})]}),(0,N.jsx)("div",{className:o.toggleButtonWrapper,children:(0,N.jsx)(Et,{className:o.toggleButton,title:s("open"),onClick:$,isCollapsed:!0})}),(0,N.jsx)("div",{className:o.collapsible,children:(0,N.jsx)(hs,{loginUrl:y,isEmbedded:S,onSnooze:K})})]}):!a||!i?null:(0,N.jsxs)("div",{ref:c,className:(0,vs.default)(o.root,{[o.isCollapsed]:x,[o.isInline]:t}),"data-inline":t,children:[!x&&(0,N.jsxs)("div",{className:o.triggers,children:[(0,N.jsx)("div",{style:{flex:1},children:T&&(0,N.jsx)("div",{style:{display:"inline-block"},onFocus:()=>{},onMouseOver:()=>f(s(Zo()?"searchHintMac":"searchHintWindows",{searchTriggerKey:u.toUpperCase()})),onMouseLeave:()=>f(null),children:(0,N.jsx)(kc,{title:s("search")})})}),(0,N.jsxs)("div",{className:o.triggersRight,onFocus:()=>{},children:[(0,N.jsx)("div",{className:(0,vs.default)(!g&&o.hintsHidden,o.hints),children:g}),(0,N.jsx)(Et,{className:o.toggleButton,title:s("collapse"),onClick:$,isCollapsed:!1})]})]}),(0,N.jsx)("div",{className:o.toggleButtonWrapper,children:(0,N.jsx)(Et,{className:o.toggleButton,title:s("open"),onClick:$,isCollapsed:!0})}),B>0&&b&&(0,N.jsx)("div",{className:o.collapsible,onFocus:()=>{},children:(0,N.jsx)(Re,{children:(0,N.jsx)(Kc,{suggestions:e,selectedIndex:n})})})]})},ag=({input:t})=>({selectedIndex:t.selectedSuggestionIndex,textSuggestions:t.textSuggestions}),xs=(0,qe.connect)(ag)(ig);var Ds=_(require("classnames")),gu=require("interweave"),We=require("react"),fu=require("react-redux");var jc=require("react"),lg=["div","span","mark","strong","b","i","u","em"];function oi(t,e,n=0){var r;let o=t[t.length-1],s=typeof o=="object"&&o!==null?(r=o.props)==null?void 0:r.tagName:void 0;if(s==="br")return t.pop(),[...t,...e,o];if(lg.includes(s)){let i=Array.isArray(o.props.children)?o.props.children:[o.props.children];return[...t.slice(0,t.length-1),(0,jc.cloneElement)(o,{children:oi(i,e,n+1)})]}return[...t,...e]}function je(t){return t.tagName.toLowerCase()==="textarea"}var Wc=_(require("classnames"));var zc={root:"_root_1s73o_1",isArrowUp:"_isArrowUp_1s73o_22",isArrowDown:"_isArrowDown_1s73o_23",isTab:"_isTab_1s73o_39",isEsc:"_isEsc_1s73o_44",isEnter:"_isEnter_1s73o_49"};var Gc=require("react/jsx-runtime");var cg=({className:t,keyCode:e,children:n,...o})=>{let s=h("KeyboardHint",zc);return(0,Gc.jsx)("span",{className:(0,Wc.default)(t,s.root,{[s.isArrowUp]:e==="arrow-up",[s.isArrowDown]:e==="arrow-down",[s.isTab]:e==="tab",[s.isEsc]:e==="esc",[s.isEnter]:e==="enter"}),...o,children:n})},Cs=cg;var Yc=require("interweave"),Es=require("react");var ri=_(require("classnames")),me=require("react");var Ts=require("react"),ug=["bottom","height","left","right","top","width"],pg=(t={},e={})=>ug.some(n=>t[n]!==e[n]),ze=new Map,$c,Xc=()=>{let t=[],e=[];ze.forEach((n,o)=>{if(o instanceof Element&&!o.isConnected){e.push(o);return}let s=o.getBoundingClientRect();pg(s,n.rect)&&(n.rect=s,t.push(n))}),e.forEach(n=>{ze.delete(n)}),t.forEach(n=>{n.callbacks.forEach(o=>o(n.rect))}),$c=window.requestAnimationFrame(Xc)};function dg(t,e){return{observe(){let n=ze.size===0;if(ze.has(t)){let o=ze.get(t);o.callbacks.push(e),o.rect&&e(o.rect)}else ze.set(t,{rect:void 0,hasRectChanged:!1,callbacks:[e]});n&&Xc()},unobserve(){let n=ze.get(t);if(n){let o=n.callbacks.indexOf(e);o>=0&&n.callbacks.splice(o,1),n.callbacks.length||ze.delete(t),ze.size||cancelAnimationFrame($c)}}}}function si(t){let[e,n]=(0,Ts.useState)(null);return(0,Ts.useLayoutEffect)(()=>{if(!t.current)return;let o=dg(t.current,s=>{n(s)});return o.observe(),()=>{o.unobserve()}},[t]),e}var pn=require("react"),Qc=require("react-dom");var Jc={root:"_root_1jq08_1"};var Zc=({children:t})=>{let[e,n]=(0,pn.useState)(null),o=(0,pn.useContext)(Tn);return(0,pn.useLayoutEffect)(()=>{let s=document.createElement("div");return St(s),s.classList.add(Jc.root),o!=null&&o.rootNode&&s.classList.add(o==null?void 0:o.rootNode),document.body.appendChild(s),n(s),()=>{s.isConnected&&document.body.removeChild(s)}},[]),e?(0,Qc.createPortal)(t,e):null};var Ie={ref:"_ref_1rcyi_1",root:"_root_1rcyi_7",positionAbove:"_positionAbove_1rcyi_13",positionBelow:"_positionBelow_1rcyi_17",positionLeft:"_positionLeft_1rcyi_21",positionRight:"_positionRight_1rcyi_25",alignStart:"_alignStart_1rcyi_29",alignCenter:"_alignCenter_1rcyi_34",alignEnd:"_alignEnd_1rcyi_40"};var bs=require("react/jsx-runtime"),dn=(t=!1)=>{let[e,n]=(0,me.useState)(t),o=(0,me.useCallback)(()=>n(!0),[]),s=(0,me.useCallback)(()=>n(!1),[]),r=(0,me.useCallback)(()=>n(a=>!a),[]),i=(0,me.useRef)(null);return{opened:e,open:o,close:s,toggle:r,triggerRef:i}};function ii(t,e=null,n=0){if(!t)return{display:"none"};let o=e?t.top-e.top<0||t.top<e.top-n?e.top-n:t.top+t.height>e.top+e.height+n?e.top+e.height+n-t.height:t.top:t.top,s=e?t.left<e.left-n?e.left-n:t.left+t.width>e.left+e.width+n?e.left+e.width+n-t.width:t.left:t.left;return{top:o,left:s,height:t.height,width:t.width}}var mn=({className:t,triggerRef:e,boundaryRef:n=(0,me.createRef)(),position:o="above",align:s="center",children:r,toStyle:i=ii,...a})=>{let l=si(e),c=si(n),u=(0,me.useMemo)(()=>i(l,c,0),[l,c]);return(0,bs.jsx)(Zc,{children:(0,bs.jsx)("div",{className:(0,ri.default)(Ie.ref,{[Ie.positionAbove]:o==="above",[Ie.positionBelow]:o==="below",[Ie.positionLeft]:o==="left",[Ie.positionRight]:o==="right",[Ie.alignStart]:s==="start",[Ie.alignCenter]:s==="center",[Ie.alignEnd]:s==="end"}),style:u,...a,role:"dialog",children:(0,bs.jsx)("div",{className:(0,ri.default)(t,Ie.root),children:r})})})};var ct=require("react/jsx-runtime"),mg=({inputStyle:t,inputElement:e})=>{let n=h("TabCompletion",ce),o=dn(document.activeElement===e);return jt(()=>o.close()),(0,Es.useEffect)(()=>{let s=()=>o.open();return e.addEventListener("focus",s),()=>{e.removeEventListener("focus",s)}},[]),(0,ct.jsxs)(Es.Fragment,{children:[(0,ct.jsx)("mark",{className:ce.caret,ref:o.triggerRef}),o.opened&&(0,ct.jsx)(mn,{className:n.popoverSuggestionsRoot,triggerRef:o.triggerRef,position:"above",align:"start",children:(0,ct.jsx)("div",{style:t,className:n.suggestionsOverlayInputStyles,children:(0,ct.jsx)(xs,{inline:!0})})})]})},ws=class extends Yc.Matcher{charCounter=0;charLength=0;found=!1;onlyAtEnd=!1;props;onBeforeParse(e,n){var o;return this.props=n,this.charCounter=0,this.onlyAtEnd=n.inlineSuggestionsOnlyAtEnd??!1,this.charLength=(je(n.inputElement)?n.inputElement.value.length:(o=n.inputElement.textContent)==null?void 0:o.length)??0,this.found=!1,e}match(e){if(this.found||!this.props||this.props.selection===null)return null;let[n,o]=this.props.selection;if(n!==o||this.onlyAtEnd&&n!==this.charLength)return null;let s=n,i=s>=this.charCounter&&s<=this.charCounter+e.length?{index:Zr(e.slice(0,s))+1-this.charCounter,length:0,match:"",valid:!0}:null;return i&&(this.found=!0),this.charCounter+=e.length,i??null}replaceWith(e,n){return(0,ct.jsx)(mg,{inputStyle:n.inputStyle,inputElement:n.inputElement},"caret")}asTag(){return"mark"}};var ou=_(require("classnames")),su=require("interweave"),gn=require("react");function eu(t){return t.replace(/[.*+^${}()|[\]\\]/g,"\\$&")}function _s(t){return e=>{t.forEach(n=>{typeof n=="function"?n(e):n!=null&&(n.current=e)})}}function tu(t){return t!=null}var nu=_(require("classnames")),Ps=require("react");var ai=require("react/jsx-runtime"),ks=(0,Ps.forwardRef)(({className:t,children:e,...n},o)=>{let s=(0,Ps.useRef)(null),r=h("TabCompletion",ce);return(0,ai.jsx)("div",{ref:_s([s,o]),className:(0,nu.default)(t,r.popoverContentContainer),...n,children:(0,ai.jsx)("div",{className:r.popoverContent,children:e})})});var ut=require("react/jsx-runtime"),gg=t=>e=>{let n=ii(e);return"top"in n&&(n.width=t.width-(e.left-t.left)-10),n},fg=({inputElement:t,boundaryRef:e,inputStyle:n,children:o,suggestion:s})=>{let r=h("TabCompletion",ce),i=dn(),a=(0,gn.useMemo)(()=>gg(t.getBoundingClientRect()),[t]),[l,c]=Wo(t);return(0,gn.useEffect)(()=>{c?i.open():i.close()},[c]),(0,ut.jsxs)(gn.Fragment,{children:[(0,ut.jsx)("mark",{ref:_s([l,i.triggerRef]),className:(0,ou.default)(r.matchKeyword,{[r.hover]:c}),"aria-haspopup":"dialog","aria-expanded":i.opened?"true":"false",children:o}),i.opened&&(0,ut.jsx)(mn,{className:r.popover,triggerRef:i.triggerRef,boundaryRef:e,position:"below",align:"start",toStyle:a,children:(0,ut.jsx)(ks,{style:n,children:(0,ut.jsx)("div",{className:r.hintText,children:s})})})]})},Rs=class extends su.Matcher{keywordMatches=[];preparedKeywordMatches=[];usedKeywordMatches=new Set;onBeforeParse(e,n){return n.keywordMatches&&n.keywordMatches!==this.keywordMatches&&(this.preparedKeywordMatches=n.keywordMatches.map(o=>({...o,keywordRegex:new RegExp(`\\b${eu(o.keyword)}\\b`,"i")})),this.keywordMatches=n.keywordMatches),this.usedKeywordMatches.clear(),e}match(e){let n=this.preparedKeywordMatches.map(s=>{if(this.usedKeywordMatches.has(s))return null;let r=e.match(s.keywordRegex);if(!r)return null;let i=e.charAt(r.index-1),a=e.charAt(r.index+s.keyword.length);return i==="{"&&a==="}"?null:{index:r.index,length:r[0].length,match:r[0],matchString:r[0],suggestion:s.suggestion,preparedKeywordMatch:s,valid:!0}}).filter(tu);if(n.length===0)return null;let o=n.reduce((s,r)=>r.index<s.index?r:s);return this.usedKeywordMatches.add(o.preparedKeywordMatch),o}replaceWith(e,n){return(0,ut.jsx)(fg,{inputElement:n.inputElement,suggestion:n.suggestion,inputStyle:n.inputStyle,boundaryRef:n.boundaryRef,children:e},`keyword_${n.matchString}_${n.key}`)}asTag(){return"mark"}};var Os=_(require("classnames")),pu=require("interweave"),q=require("react"),du=require("react-redux");var li=require("react/jsx-runtime"),ru=()=>(0,li.jsx)("svg",{width:"1.3em",height:"1.3em",focusable:"false","aria-hidden":"true",viewBox:"0 0 24 24","data-testid":"InsertLinkIcon",tabIndex:-1,children:(0,li.jsx)("path",{fill:"currentColor",d:"M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"})});var pt=require("react"),eo=require("react-redux"),cu=_(require("lodash.debounce"));var Is=_(require("classnames")),ge=_(require("react"));var iu={root:"_root_vr71j_1"};var _t=require("react/jsx-runtime"),au=()=>(0,_t.jsxs)("svg",{className:iu.root,width:"185",height:"170",viewBox:"0 0 185 170",xmlns:"http://www.w3.org/2000/svg",children:[(0,_t.jsx)("defs",{children:(0,_t.jsx)("style",{children:".cls-1 { fill: #b3b3b3; }"})}),(0,_t.jsx)("title",{children:"Failed loading image"}),(0,_t.jsx)("path",{className:"cls-1",d:"M15 130.896V16.994c0-1.097.898-1.994 2.007-1.994h150.986A2 2 0 0 1 170 16.994v69.147L133.015 51 87.26 120.377l-35.863-17.758L15 130.896zM2 0C.895 0 0 .887 0 2v166c0 1.105.887 2 2 2h181c1.105 0 2-.887 2-2V2c0-1.105-.887-2-2-2H2zm49 72c11.046 0 20-9.178 20-20.5S62.046 31 51 31s-20 9.178-20 20.5S39.954 72 51 72z",fillRule:"evenodd"})]});var ci={root:"_root_4e7lf_1",imageWrapper:"_imageWrapper_4e7lf_7",image:"_image_4e7lf_7",content:"_content_4e7lf_24",title:"_title_4e7lf_35",contentIsCropped:"_contentIsCropped_4e7lf_45",lineClamp:"_lineClamp_4e7lf_51"};var Pt=require("react/jsx-runtime"),Ls=(0,ge.createContext)(ci),hg=({title:t,src:e})=>{let n=(0,ge.useContext)(Ls),[o,s]=(0,ge.useState)(!1);return(0,ge.useEffect)(()=>{s(!1)},[e]),(0,Pt.jsx)("div",{className:n.imageWrapper,children:e&&!o?(0,Pt.jsx)("img",{className:n.image,alt:t,src:e,onError:()=>s(!0)}):(0,Pt.jsx)(au,{})})},yg=({className:t,lineClamp:e=!1,cropText:n=!1,children:o})=>{let s=(0,ge.useContext)(Ls);return(0,Pt.jsx)("div",{className:(0,Is.default)(s.content,t,{[s.contentIsCropped]:n,[s.lineClamp]:e}),children:o})},Sg=({as:t="h1",cropText:e=!1,className:n,children:o})=>{let s=(0,ge.useContext)(Ls);return ge.default.createElement(t,{className:(0,Is.default)(s.title,n,{[s.contentIsCropped]:e})},o)},As=({children:t})=>{let e=h("Card",ci);return(0,Pt.jsx)("div",{className:(0,Is.default)(e.root),children:(0,Pt.jsx)(Ls.Provider,{value:e,children:t})})};As.Image=hg;As.Content=yg;As.Title=Sg;var D=As;var lu={root:"_root_1muu8_1",content:"_content_1muu8_7"};function Ms(t,e,n){var s;let o=((s=t.imageSizes)==null?void 0:s[e])||t.image||n;if(!o)return null;try{return new URL(o).toString()}catch{return null}}function ui(t){return t.replace("https://www.","").replace("https://","")}var fe=require("react/jsx-runtime"),vg=3,xg=t=>({image:t.image||"",text:`https://${t.text}`,id:t.id,title:t.title}),Cg=({onSelectLink:t,onDismiss:e,placeholder:n,visitUrlText:o,linkCount:s=vg})=>{let r=h("LinkSearch",lu),[i,a]=(0,pt.useState)(""),l=(0,eo.useDispatch)(),c=(0,eo.useSelector)(pl("url")),u=(0,eo.useSelector)(Ya("URL",xg)),[d,p]=(0,pt.useState)(u.length-1),m=E("fallbackImage"),g=y=>{let S=y.target;a(S.value)},f=(y,S)=>{y.stopPropagation(),y.preventDefault(),window.open(S,"_blank")},T=y=>{var C;let S=d-1<0?u.length-1:d-1,w=d+1===u.length?0:d+1;y.code==="Escape"&&(a(""),e()),y.code==="ArrowUp"&&p(S),y.code==="ArrowDown"&&p(w),y.code==="Enter"&&t(((C=u[d])==null?void 0:C.text)||i)},b=(0,pt.useCallback)((0,cu.default)(y=>{l(vt({query:y,type:"URL",tags:["link-search"]}))},300),[]);return(0,pt.useEffect)(()=>{i&&b(i)},[i]),(0,pt.useEffect)(()=>()=>{l(es())},[]),(0,fe.jsxs)("div",{className:r.root,children:[(0,fe.jsx)(Re,{withDivider:!0,children:(i?u:c).slice(0,s).map((y,S)=>(0,fe.jsx)(O,{selected:d===S,onClick:()=>t(y.text),"data-testid":"linksearch-suggestion",children:(0,fe.jsxs)(D,{children:[(0,fe.jsx)(D.Image,{src:Ms(y,"small",m||void 0),title:y.title||y.text}),(0,fe.jsxs)(D.Content,{className:r.content,cropText:!0,children:[(0,fe.jsx)(D.Title,{children:y.title||ui(y.text)}),y.title&&ui(y.text)]}),(0,fe.jsx)(O.Actions,{children:(0,fe.jsx)(O.ActionButton,{label:o,onClick:w=>f(w,y.text)})})]})},y.text))}),(0,fe.jsx)(jn,{value:i,onChange:g,autoFocus:!0,placeholder:n,onKeyUp:T})]})},uu=Cg;var pi={};V(pi,{enUS:()=>Tg,nlNL:()=>bg});var Tg={insertLink:[{type:0,value:"Insert link"}],linkInputPlaceholder:[{type:0,value:"Search, type or paste link"}],visitUrl:[{type:0,value:"Visit"}]},bg={insertLink:[{type:0,value:"Voeg link toe"}],linkInputPlaceholder:[{type:0,value:"Zoek, typ of plak link"}],visitUrl:[{type:0,value:"Bekijk"}]};var ne=require("react/jsx-runtime"),wg=(0,q.forwardRef)((t,e)=>{let n=h("TabCompletion",ce);return(0,ne.jsx)("mark",{ref:e,className:(0,Os.default)(n.matchSelection)},"selection-start")}),Eg=({startRef:t,boundaryRef:e,inputStyle:n,inputElement:o,children:s})=>{let r=P(pi),i=h("TabCompletion",ce),a=(0,q.useRef)(null),l=(0,q.useRef)(null),[c,u]=(0,q.useState)(null),d=(0,du.useDispatch)(),p=dn(document.activeElement===o),[m]=(0,q.useState)(()=>document.createRange());p.triggerRef.current=m,(0,q.useEffect)(()=>()=>m.detach(),[]),(0,q.useEffect)(()=>{let f=t.current,T=a.current;!f||!T||(m.setStart(f,0),m.setEnd(T,0))},[t.current,a.current]),jt(()=>{p.close()});let g=(0,q.useCallback)(f=>{let T=m.toString(),b=/^http(s?):\/\//.test(f)?f:`https://${f}`;d(wo({text:`[${T}](${b})`}))},[]);return(0,ne.jsxs)(q.Fragment,{children:[(0,ne.jsx)("mark",{ref:a,className:(0,Os.default)(i.matchSelection),"aria-haspopup":"dialog","aria-expanded":p.opened?"true":"false",children:s}),p.opened&&(0,ne.jsx)(mn,{className:i.popoverRoot,triggerRef:p.triggerRef,boundaryRef:e,position:"above",align:"start",children:(0,ne.jsxs)(ks,{style:n,ref:l,children:[(0,ne.jsx)("div",{className:(0,Os.default)(i.selectionOptions,{[i.selectionOptionsIsHidden]:c!==null}),children:(0,ne.jsxs)("button",{type:"button",tabIndex:c===null?-1:void 0,className:i.selectionOptionsButton,onClick:()=>u("insertLink"),children:[(0,ne.jsx)(ru,{}),"\xA0",r("insertLink")]})}),c==="insertLink"&&(0,ne.jsx)(uu,{placeholder:r("linkInputPlaceholder"),visitUrlText:r("visitUrl"),onSelectLink:g,onDismiss:()=>{u(null),p.close()}})]})})]},"selection-end")},Ns=class extends pu.Matcher{charCount=0;foundIndex=0;startRef=null;props;onBeforeParse(e,n){return this.props=n,this.charCount=0,this.startRef=(0,q.createRef)(),this.foundIndex=0,e}match(e){if(!this.props||this.props.selection===null||this.foundIndex===2)return null;let[n,o]=this.props.selection;if(n===o)return null;let s=this.foundIndex===0?n:o,r=s>=this.charCount&&s<=this.charCount+e.length?{index:s-this.charCount,length:0,match:"",valid:!0}:null;r&&this.foundIndex++;let i=this.foundIndex===1;return r&&i?this.charCount+=s-this.charCount:this.charCount+=e.length,r?{isStart:i,...r}:null}replaceWith(e,n){return n.isStart?(0,ne.jsx)(wg,{ref:this.startRef}):(0,ne.jsx)(Eg,{inputElement:n.inputElement,startRef:this.startRef,boundaryRef:n.boundaryRef,inputStyle:n.inputStyle})}asTag(){return"mark"}};var mu={root:"_root_kpc8q_1",agentText:"_agentText_kpc8q_4",tabText:"_tabText_kpc8q_9",hint:"_hint_kpc8q_10",matchSelection:"_matchSelection_kpc8q_14",focus:"_focus_kpc8q_20",resetIndent:"_resetIndent_kpc8q_24",matchKeyword:"_matchKeyword_kpc8q_28",matchPlaceholder:"_matchPlaceholder_kpc8q_29",hover:"_hover_kpc8q_35",hintText:"_hintText_kpc8q_67",popover:"_popover_kpc8q_75",popoverRoot:"_popoverRoot_kpc8q_80",popoverContentContainer:"_popoverContentContainer_kpc8q_84",popoverContent:"_popoverContent_kpc8q_84",selectionOptions:"_selectionOptions_kpc8q_110",selectionOptionsIsHidden:"_selectionOptionsIsHidden_kpc8q_115",selectionOptionsButton:"_selectionOptionsButton_kpc8q_119",caret:"_caret_kpc8q_135",popoverSuggestionsRoot:"_popoverSuggestionsRoot_kpc8q_139",suggestionsOverlayInputStyles:"_suggestionsOverlayInputStyles_kpc8q_144"};var dt=require("react/jsx-runtime"),_g=({enabled:t,content:e,tabText:n,showTabHint:o,showTabCompletion:s,showStyleSuggestions:r,keywordMatches:i,inputElement:a,source:l})=>{let c=h("TabCompletion",mu),u=E("insertLink"),d=E("showMidSentenceSuggestions"),p=E("inlineSuggestions"),m=$o(a),g=(0,We.useRef)(null);(0,We.useEffect)(()=>{je(a)&&m&&Xo(a,m)},[m]);let f=(0,We.useCallback)(y=>{if(!s||!n)return y;let S=[(0,dt.jsx)("span",{className:c.resetIndent,children:"\u200B"},"u200B"),(0,dt.jsx)("span",{className:(0,Ds.default)(c.tabText,c.resetIndent),"data-source":l,children:n},"tabText")];return o&&S.push((0,dt.jsx)(Cs,{className:(0,Ds.default)(c.hint,c.resetIndent),keyCode:"tab"},"tabHint")),oi(y,S)},[s,n,o]),T=(0,We.useMemo)(()=>{let y=[];return p&&y.push(new ws("inline")),u&&y.push(new Ns("selection")),y.push(new Vt("placeholders")),r&&y.push(new Rs("keywords")),y},[p,u,r]),b=(0,We.useMemo)(()=>{let y=window.getComputedStyle(a);return{"--dd-color":y.color,"--dd-font-size":y.fontSize,"--dd-font-family":y.fontFamily,"--dd-font-variant":y.fontVariant}},[]);return t?(0,dt.jsxs)("div",{ref:y=>{y!=null&&y.parentElement&&(g.current=y==null?void 0:y.parentElement)},className:(0,Ds.default)(c.root,c.agentText),style:b,children:[(0,dt.jsx)(gu.Interweave,{noWrap:!0,disableLineBreaks:je(a),content:e||"\u200B",onAfterParse:f,matchers:T,selection:m,keywordMatches:i,inputElement:a,inputStyle:b,boundaryRef:g,inlineSuggestionsOnlyAtEnd:!d}),(0,dt.jsx)("br",{})]}):null},Pg=({input:t,ui:e,settings:n,styleSuggestions:o,conversation:s})=>{var f;let{tabCompletionSuggestion:r}=t,i=(r==null?void 0:r.text)||"",a=(r==null?void 0:r.source)||"",l=t.html??ln(t.text),c=i.indexOf(t.text)===0?i.slice(t.text.length):"",{showTabHint:u}=e,{isSupported:d}=s,{showTabCompletion:p,visible:m,showStyleSuggestions:g}=n;return{showTabHint:u,showStyleSuggestions:g,showTabCompletion:p,content:l,tabText:c,source:a,keywordMatches:((f=o.list)==null?void 0:f.keywordMatches)??[],enabled:m&&d!==!1}},hu=(0,fu.connect)(Pg)(_g);var gp=_(require("classnames")),fp=require("react"),j=require("react-redux");var mt=require("@reduxjs/toolkit");var yu={list:[],fetchState:"idle",isInitialRequest:null},vu=t=>t.autoflows.list||[],Su=t=>e=>{var n;return(n=e.list)==null?void 0:n.find(o=>o.triggerPayload===t)},Ge=(0,mt.createAsyncThunk)("autoflows/getAll",async(t,e)=>{let{deepdeskBrokerAPI:n}=e.extra;if(!n)throw new Error("Deepdesk Broker not initialized");return n.getAutoflows(t)}),di=(0,mt.createAsyncThunk)("autoflows/start",async(t,e)=>{let{dispatch:n}=e,{deepdeskBrokerAPI:o}=e.extra;if(!o)throw new Error("Deepdesk Broker not initialized");await o.startAutoflowSession(t),await n(Ge(t.platformSessionId))}),mi=(0,mt.createAsyncThunk)("autoflows/stop",async(t,e)=>{let{dispatch:n}=e,{deepdeskBrokerAPI:o}=e.extra;if(!o)throw new Error("Deepdesk Broker not initialized");await o.stopAutoflowSession(t.platformSessionId),await n(Ge(t.platformSessionId))}),kg=(0,mt.createSlice)({name:"autoflows",initialState:yu,reducers:{},extraReducers:t=>{t.addCase(di.pending,(e,n)=>{let o=Su(n.meta.arg.triggerPayload)(e);o.state="Started",o.isBusy=!0}),t.addCase(mi.pending,(e,n)=>{let o=Su(n.meta.arg.triggerPayload)(e);o.state="Aborted",o.isBusy=!0}),t.addCase(Ge.pending,e=>{e.isInitialRequest=e.isInitialRequest===null,e.fetchState="loading"}),t.addCase(Ge.rejected,e=>{e.fetchState="error"}),t.addCase(Ge.fulfilled,(e,n)=>{e.list=n.payload,e.fetchState="done"}),t.addCase(R,()=>yu)}}),xu=(0,mt.createAsyncThunk)("autoflows/openStream",(t,e)=>{let{dispatch:n}=e,{deepdeskBrokerAPI:o}=e.extra;if(!o)throw new Error("Deepdesk Broker not initialized");let s=o.openStream(t);s.on("sessionAborted",()=>{n(Ge(t))}),s.on("sessionCompleted",()=>{n(Ge(t))})}),Cu=(0,mt.createAsyncThunk)("autoflows/closeStream",(t,e)=>{let{deepdeskBrokerAPI:n}=e.extra;if(!n)throw new Error("Deepdesk Broker not initialized");n.closeStream(t)}),Tu=kg.reducer;var gt=require("@reduxjs/toolkit");var bu={list:[],fetchState:"idle",isInitialRequest:null,sentSuggestions:[],errorSuggestions:[],answeredSuggestions:[]},wu=t=>t.customMessages.list,Eu=t=>e=>!!e.customMessages.sentSuggestions.find(n=>n===t),_u=t=>e=>!!e.customMessages.answeredSuggestions.find(n=>n===t),Pu=t=>e=>!!e.customMessages.errorSuggestions.find(n=>n===t),to=(0,gt.createAsyncThunk)("customMessages/getAll",async(t,e)=>{let{deepdeskBrokerAPI:n}=e.extra;if(!n)throw new Error("Deepdesk Broker not initialized");return n.getCustomMessages(t)}),Hs=(0,gt.createAsyncThunk)("customMessages/send",async(t,e)=>{let{platformSessionId:n,suggestion:o}=t,{deepdeskBrokerAPI:s}=e.extra;if(!s)throw new Error("Deepdesk Broker not initialized");await s.sendCustomMessage(n,o)}),Fs=(0,gt.createAsyncThunk)("customMessages/answer",async(t,e)=>{let{platformSessionId:n,reply:o}=t,{deepdeskBrokerAPI:s}=e.extra;if(!s)throw new Error("Deepdesk Broker not initialized");await s.answerCustomMessage(n,o)}),ku=(0,gt.createSlice)({name:"customMessages",initialState:bu,reducers:{onCustomMessage(t,e){Array.isArray(e.payload)?t.list=e.payload:t.list=[e.payload]}},extraReducers:t=>{t.addCase(to.pending,e=>{e.isInitialRequest=e.isInitialRequest===null,e.fetchState="loading"}).addCase(to.rejected,e=>{e.fetchState="error"}).addCase(to.fulfilled,(e,n)=>{e.fetchState="done",e.list=n.payload||[]}).addCase(Hs.pending,(e,n)=>{e.sentSuggestions.push(n.meta.arg.suggestion.text),e.errorSuggestions=e.errorSuggestions.filter(o=>n.meta.arg.suggestion.text!==o)}).addCase(Hs.rejected,(e,n)=>{let o=e.sentSuggestions.indexOf(n.meta.arg.suggestion.text);e.errorSuggestions.push(...e.sentSuggestions.splice(o,1))}).addCase(Fs.pending,(e,n)=>{e.sentSuggestions.push(n.meta.arg.suggestion.text),e.answeredSuggestions.push(n.meta.arg.suggestion.text)}).addCase(Fs.rejected,(e,n)=>{let o=e.answeredSuggestions.indexOf(n.meta.arg.suggestion.text);e.errorSuggestions.push(...e.sentSuggestions.splice(o,1)),e.answeredSuggestions.splice(o,1)}).addCase(R,()=>bu)}}),Ru=(0,gt.createAsyncThunk)("customMessages/openStream",(t,e)=>{let{dispatch:n}=e,{deepdeskBrokerAPI:o}=e.extra;if(!o)throw new Error("Deepdesk Broker not initialized");o.openStream(t).on("customMessageSuggestion",r=>{n(ku.actions.onCustomMessage(r))})}),Iu=(0,gt.createAsyncThunk)("customMessages/closeStream",(t,e)=>{let{deepdeskBrokerAPI:n}=e.extra;if(!n)throw new Error("Deepdesk Broker not initialized");n.closeStream(t)}),Lu=ku.reducer;var no=require("@reduxjs/toolkit"),Rg={jwt:null,accountUrl:null,interval:null},Au=t=>e=>{let{exchangeToken:{jwt:n,accountUrl:o}}=e;return n&&o?`${o}/apis/admin/session/jwt/?jwt=${n}&redirect=${t}`:null},gi=(0,no.createAsyncThunk)("exchangeToken/getTemporaryExchangeToken",async(t,e)=>{let{deepdeskAPI:n}=e.extra,o=await n.getTemporaryExchangeToken();return{accountUrl:n.client.baseUrl,jwt:o}}),fi=(0,no.createAsyncThunk)("exchangeToken/pollExchangeToken",(t={},e)=>{let{interval:n=1e3*60*30}=t,{dispatch:o}=e;return o(gi()),setInterval(()=>o(gi()),n)}),Mu=(0,no.createSlice)({name:"exchangeToken",initialState:Rg,reducers:{stopPollExchangeToken(t){t.interval&&clearInterval(t.interval),t.interval=null}},extraReducers:t=>{t.addCase(gi.fulfilled,(e,n)=>{e.jwt=n.payload.jwt,e.accountUrl=n.payload.accountUrl}),t.addCase(fi.fulfilled,(e,n)=>{e.interval=n.payload})}}),{stopPollExchangeToken:Ou}=Mu.actions,Nu=Mu.reducer;var Bs=require("@reduxjs/toolkit");var Ig={data:null,fetchState:"idle"},Ks=t=>t.profile.data,Us=t=>t.profile.data?t.profile.data.uiConfig.widget.types.filter(e=>e.isActive):[],oo=(0,Bs.createAsyncThunk)("profile/getProfile",async(t,e)=>{let{deepdeskAPI:n}=e.extra,s=e.getState().conversation.current;if(!s||!s.profileCode)throw new Error("No conversation of conversation profileCode found");return n.getProfile(s.profileCode)}),Lg=(0,Bs.createSlice)({name:"profile",initialState:Ig,reducers:{},extraReducers:t=>{t.addCase(oo.pending,e=>{e.fetchState="loading"}).addCase(oo.rejected,e=>{e.fetchState="error"}).addCase(oo.fulfilled,(e,n)=>{e.fetchState="done",e.data=n.payload})}}),Du=Lg.reducer;function Hu(t){let{customMessages:e,autoflows:n}=t;return n.fetchState==="loading"&&n.isInitialRequest===!0||e.fetchState==="loading"&&e.isInitialRequest===!0}var Wu=require("react"),Gu=require("react-redux");var qu=_(require("classnames")),ju=require("react");var Bu=_(require("classnames"));var Fu={root:"_root_838fd_1"};var Uu=require("react/jsx-runtime"),Ag=({className:t,children:e})=>{let n=h("Unicode",Fu);return(0,Uu.jsx)("span",{className:(0,Bu.default)(t,n.root),children:e})},Ku=Ag;var Vu={isDisabled:"_isDisabled_1rmfm_1",buttonStart:"_buttonStart_1rmfm_5",root:"_root_1rmfm_8",buttonStop:"_buttonStop_1rmfm_8",stateBadge:"_stateBadge_1rmfm_19",isCompleted:"_isCompleted_1rmfm_26",isStarted:"_isStarted_1rmfm_30",isAborted:"_isAborted_1rmfm_34"};var hi={};V(hi,{enUS:()=>Mg,nlNL:()=>Og});var Mg={start:[{type:0,value:"Start"}],stop:[{type:0,value:"Stop"}],aborted:[{type:0,value:"Stopped"}],completed:[{type:0,value:"Completed"}],Aborted:[{type:0,value:"Stopped"}],Started:[{type:0,value:"Running"}],Completed:[{type:0,value:"Completed"}]},Og={start:[{type:0,value:"Start"}],stop:[{type:0,value:"Stop"}],aborted:[{type:0,value:"Stopped"}],completed:[{type:0,value:"Completed"}],Aborted:[{type:0,value:"Stopped"}],Started:[{type:0,value:"Running"}],Completed:[{type:0,value:"Completed"}]};var oe=require("react/jsx-runtime"),Dg=({disabled:t,state:e,displayName:n,description:o,onStartAutoflow:s,onStopAutoflow:r})=>{let i=h("Autoflow",Vu),a=P(hi),l=e==="Started"?"stop":"start",c=l==="start"?"\u25B6":l==="stop"?"\u25FC":"";return(0,oe.jsxs)(O,{className:(0,qu.default)(i.root,{[i.isDisabled]:t,[i.isCompleted]:e==="Completed",[i.isAborted]:e==="Aborted",[i.isStarted]:e==="Started"}),children:[(0,oe.jsx)(D,{children:(0,oe.jsxs)(D.Content,{children:[(0,oe.jsxs)(D.Title,{children:[e&&(0,oe.jsx)("span",{className:i.stateBadge,children:a(e)}),n]}),(0,oe.jsx)("span",{children:o})]})}),(0,oe.jsx)(O.Actions,{fixed:e==="Started",children:(0,oe.jsx)(O.ActionButton,{primary:!0,className:l==="start"?i.buttonStart:i.buttonStop,onClick:e==="Started"?r:s,disabled:t,label:(0,oe.jsxs)(ju.Fragment,{children:[(0,oe.jsx)(Ku,{children:c})," ",(0,oe.jsx)("span",{children:a(l)})]})})})]})},zu=Dg;var yi=require("react/jsx-runtime"),Hg=(t,e)=>{let n=e.filter(o=>o.state==="Started");return n.length>0?n.indexOf(t)===-1:!1},Fg=({autoflows:t,onStartAutoflow:e,onStopAutoflow:n,platformSessionId:o})=>(0,yi.jsx)(Wu.Fragment,{children:t.map(s=>(0,yi.jsx)(zu,{displayName:s.displayName,description:s.description,disabled:s.isBusy||Hg(s,t),state:s.state,onStartAutoflow:()=>e({platformSessionId:o,triggerPayload:s.triggerPayload}),onStopAutoflow:()=>n({platformSessionId:o,triggerPayload:s.triggerPayload})},s.displayName))}),Bg=({autoflows:t,conversation:e})=>{var n;return{autoflows:t.list,platformSessionId:(n=e.current)==null?void 0:n.sessionId}},Kg={onStartAutoflow:di,onStopAutoflow:mi},$u=(0,Gu.connect)(Bg,Kg)(Fg);var Vs=require("react"),Ju=require("react-redux"),xi=_(require("classnames"));var Si=require("react/jsx-runtime"),vi=()=>(0,Si.jsx)("svg",{width:"1em",height:"1em",viewBox:"0 0 512 512",xmlns:"http://www.w3.org/2000/svg",children:(0,Si.jsx)("path",{d:"M502.6 70.63l-61.25-61.25C435.4 3.371 427.2 0 418.7 0H255.1c-35.35 0-64 28.66-64 64l.0195 256C192 355.4 220.7 384 256 384h192c35.2 0 64-28.8 64-64V93.25C512 84.77 508.6 76.63 502.6 70.63zM464 320c0 8.836-7.164 16-16 16H255.1c-8.838 0-16-7.164-16-16L239.1 64.13c0-8.836 7.164-16 16-16h128L384 96c0 17.67 14.33 32 32 32h47.1V320zM272 448c0 8.836-7.164 16-16 16H63.1c-8.838 0-16-7.164-16-16L47.98 192.1c0-8.836 7.164-16 16-16H160V128H63.99c-35.35 0-64 28.65-64 64l.0098 256C.002 483.3 28.66 512 64 512h192c35.2 0 64-28.8 64-64v-32h-47.1L272 448z"})});var Xu={root:"_root_rjdyr_1",entity:"_entity_rjdyr_10",entityText:"_entityText_rjdyr_46",iconWrapper:"_iconWrapper_rjdyr_53",icon:"_icon_rjdyr_53",iconClicked:"_iconClicked_rjdyr_67"};var Le=require("react/jsx-runtime"),Ug=({entities:t})=>{let e=h("EntitiesWidgetList",Xu),[n,o]=(0,Vs.useState)(void 0),s=(0,Ju.useDispatch)(),r=()=>{o(void 0)},i=a=>{t&&(o(t.indexOf(a)),Wn(a.text),s(Ae({name:"entity copied",data:{entity:a,type:"copy"}})))};return(0,Vs.useEffect)(()=>{let a=setTimeout(r,500);return()=>{clearTimeout(a)}},[n]),!t||t.length===0?null:(0,Le.jsx)("div",{className:e.root,"data-testid":"widget-entities-list",children:t.map((a,l)=>(0,Le.jsxs)("button",{title:a.text,className:e.entity,type:"button",onClick:()=>i(a),children:[(0,Le.jsx)("span",{className:e.entityText,children:a.text}),(0,Le.jsxs)("span",{className:e.iconWrapper,children:[(0,Le.jsx)("span",{className:(0,xi.default)(e.icon),children:(0,Le.jsx)(vi,{})}),(0,Le.jsx)("span",{className:(0,xi.default)(e.icon,n===l&&e.iconClicked),children:(0,Le.jsx)(vi,{})})]})]},a.text))})},Qu=Ug;var tp=_(require("classnames")),Ci=require("react"),kt=require("react-redux");var Yu=_(require("classnames"));var Zu={root:"_root_4a08n_1"};var ep=require("react/jsx-runtime"),Vg=({className:t,children:e,...n})=>{let o=h("Label",Zu);return(0,ep.jsx)("span",{...n,className:(0,Yu.default)(t,o.root),children:e})},qs=Vg;var so={};V(so,{enUS:()=>qg,nlNL:()=>jg});var qg={preview:[{type:0,value:"Preview"}],useSuggestion:[{type:0,value:"Add"}],sendSuggestion:[{type:0,value:"Send"}],suggestionSent:[{type:0,value:"Sent"}],sendingError:[{type:0,value:"Sending failed"}],tryAgain:[{type:0,value:"Try again"}],editSuggestion:[{type:0,value:"Edit"}],visitUrl:[{type:0,value:"Visit"}],answer:[{type:0,value:"Answer"}]},jg={preview:[{type:0,value:"Preview"}],useSuggestion:[{type:0,value:"Gebruik"}],sendSuggestion:[{type:0,value:"Verzenden"}],suggestionSent:[{type:0,value:"Verzonden"}],sendingError:[{type:0,value:"Verzenden mislukt"}],tryAgain:[{type:0,value:"Probeer opnieuw"}],editSuggestion:[{type:0,value:"Bewerken"}],visitUrl:[{type:0,value:"Bekijk"}],answer:[{type:0,value:"Antwoord"}]};var $e={root:"_root_1e6ej_1",title:"_title_1e6ej_8",isUsed:"_isUsed_1e6ej_13",quickReplies:"_quickReplies_1e6ej_22",quickReply:"_quickReply_1e6ej_29",hasError:"_hasError_1e6ej_39",label:"_label_1e6ej_43",errorIcon:"_errorIcon_1e6ej_48"};var ee=require("react/jsx-runtime"),zg=({suggestion:t})=>{let e=P(so),n=(0,kt.useDispatch)(),o=(0,kt.useSelector)(Eu(t.text)),s=(0,kt.useSelector)(_u(t.text)),r=(0,kt.useSelector)(Pu(t.text)),i=(0,kt.useSelector)(fo),{replyOptions:a}=t,l=(0,Ci.useCallback)(u=>{u.preventDefault(),u.stopPropagation(),!(o||!i)&&n(Hs({platformSessionId:i,suggestion:t}))},[t,o,n,i]),c=(0,Ci.useCallback)(u=>{if(u.preventDefault(),u.stopPropagation(),!i||!a)return;let d=parseInt(u.target.dataset.index,10),p=a[d];n(Fs({platformSessionId:i,reply:p,suggestion:t}))},[t,o,n,i]);return(0,ee.jsxs)(O,{onClick:l,className:(0,tp.default)($e.root,{[$e.isUsed]:o,[$e.hasError]:r}),children:[(0,ee.jsx)(D,{children:(0,ee.jsxs)(D.Content,{children:[(0,ee.jsxs)(D.Title,{className:$e.title,children:[t.text," ",(0,ee.jsx)(qs,{className:$e.label,children:"analyse tool"})," ",r&&(0,ee.jsx)("span",{className:$e.errorIcon,role:"img","aria-label":e("sendingError"),title:e("sendingError"),children:"!"})]}),a&&a.length>0&&(0,ee.jsx)("ul",{className:$e.quickReplies,children:a.map(u=>(0,ee.jsx)("li",{className:$e.quickReply,children:u.title},u.title))})]})}),(0,ee.jsxs)(O.Actions,{fixed:r||o,children:[a&&a.length>0&&(0,ee.jsx)(O.DropdownButton,{label:e("answer"),disabled:s,children:a.map((u,d)=>(0,ee.jsx)(O.DropdownItem,{index:d,label:u.title,onClick:c},u.title))}),(0,ee.jsx)(O.ActionButton,{primary:!0,disabled:o,onClick:l,label:e(o?"suggestionSent":r?"tryAgain":"sendSuggestion")})]})]})},np=zg;var Ti=require("react/jsx-runtime"),op=()=>(0,Ti.jsx)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,Ti.jsx)("path",{d:"M17 13.5v6H5v-12h6m3-3h6v6m0-6-9 9",stroke:"currentColor",strokeWidth:"1.5",fill:"none",fillRule:"evenodd",strokeLinecap:"round",strokeLinejoin:"round"})});var sp={root:"_root_jlggj_1",subTitleContainer:"_subTitleContainer_jlggj_5",subtitle:"_subtitle_jlggj_9",suggestions:"_suggestions_jlggj_17"};var fn=require("react/jsx-runtime"),Wg=({title:t,children:e,...n})=>{let o=h("Section",sp);return(0,fn.jsxs)("section",{...n,className:o.root,children:[t&&(0,fn.jsx)("div",{className:o.subTitleContainer,children:(0,fn.jsx)("span",{className:o.subtitle,children:t})}),(0,fn.jsx)("div",{className:o.suggestions,children:e})]})},Rt=Wg;var ip=_(require("classnames")),ap=_(require("react"));var rp={root:"_root_19wxp_1"};var lp=require("react/jsx-runtime"),Gg=ap.default.forwardRef(({className:t,children:e},n)=>{let o=h("SectionList",rp);return(0,lp.jsx)("div",{ref:n,className:(0,ip.default)(o.root,t),children:e})}),js=Gg;var pp=require("react-redux");var cp=require("react");var se=require("react/jsx-runtime"),$g=({suggestion:t,lines:e,onEdit:n,onUse:o})=>{var p;let s=t.text||t.url||t.message,r=ts(s),i=P(so),a=E("showImages"),l=E("fallbackImage"),c=m=>{m.preventDefault(),m.stopPropagation(),o(s)},u=m=>{m.preventDefault(),m.stopPropagation(),n(t)},d=(0,cp.useCallback)(m=>{window.open(r,"_blank"),m.stopPropagation(),m.preventDefault()},[r]);return(0,se.jsxs)(O,{onClick:c,"data-testid":"edit-suggestion",children:[(0,se.jsxs)(D,{children:[a&&t.image&&(0,se.jsx)(D.Image,{src:Ms(t,"small",l||void 0),title:t.title}),(0,se.jsxs)(D.Content,{children:[t.title&&(0,se.jsx)(D.Title,{children:t.title}),t.searchKeywords&&((p=t.searchKeywords)==null?void 0:p.length)>0&&(0,se.jsx)(O.Labels,{labels:t.searchKeywords}),(0,se.jsx)(D.Content,{cropText:e==="single",lineClamp:e==="multiple",children:s})]})]}),(0,se.jsxs)(O.Actions,{children:[r&&(0,se.jsx)(O.ActionButton,{onClick:d,label:i("visitUrl")}),(0,se.jsx)(O.ActionButton,{primary:!0,onClick:u,label:i("preview")}),(0,se.jsx)(O.ActionButton,{primary:!0,onClick:c,label:i("useSuggestion")})]})]})},up=$g;var ro=require("react/jsx-runtime"),Xg=({contentType:t,lines:e,suggestions:n})=>{let o=ke(),s=(0,pp.useSelector)(Zt),r=a=>{o.send(Fr,{state:s,suggestion:a,contentType:t})},i=(a,l)=>{o.send(Be,{text:a,suggestion:{...l,source:l.source,sourceText:l.text}})};return(0,ro.jsx)(ro.Fragment,{children:n.map(a=>(0,ro.jsx)(up,{suggestion:a,lines:e,onEdit:l=>r(l),onUse:l=>i(l,a)},a.text||a.url||a.message))})},dp=Xg;var bi={};V(bi,{enUS:()=>Jg,nlNL:()=>Qg});var Jg={waiting:[{type:0,value:"Loading\u2026"}],notSupported:[{type:0,value:"This conversation is not supported"}],noResults:[{type:0,value:"No results found\u2026"}],titleAutoflows:[{type:0,value:"Autoflows"}],titleCustomMessages:[{type:0,value:"Quick replies"}],linkPersonalcollection:[{type:0,value:"Open Personal Collection"}],loginPlease:[{type:0,value:"Sign in to enable Deepdesk"}]},Qg={waiting:[{type:0,value:"Laden\u2026"}],notSupported:[{type:0,value:"Dit gesprek wordt niet ondersteund"}],noResults:[{type:0,value:"Geen resultaten gevonden\u2026"}],titleAutoflows:[{type:0,value:"Autoflows"}],titleCustomMessages:[{type:0,value:"Quick replies"}],linkPersonalcollection:[{type:0,value:"Open Personal Collection"}],loginPlease:[{type:0,value:"Log in om Deepdesk te gebruiken"}]};var mp={root:"_root_1cw95_1",loginText:"_loginText_1cw95_7",stateText:"_stateText_1cw95_8",sectionList:"_sectionList_1cw95_20",links:"_links_1cw95_24",link:"_link_1cw95_24"};var L=require("react/jsx-runtime"),zs=(t,e)=>{let n=(0,j.useSelector)(Fe);(0,fp.useEffect)(()=>n?e.every(o=>!!o)?t():()=>{}:()=>{},[...e,n])},Zg=()=>{let t=P(bi),e=(0,j.useDispatch)(),n=E("isEmbedded"),o=h("Widget",mp),s=E("showAutoflows"),r=E("showCustomMessages"),i=E("showPersonalCollectionLink"),a=(0,j.useSelector)(Ks),l=(0,j.useSelector)(Us),c=(0,j.useSelector)(vu),u=(0,j.useSelector)(ps),d=(0,j.useSelector)(wu),p=(0,j.useSelector)(ho),m=(0,j.useSelector)(yo),g=(0,j.useSelector)(Fe),f=(0,j.useSelector)(fo),T=(0,j.useSelector)(Hu),b=(0,j.useSelector)(Zt),y=(0,j.useSelector)(ml),S=(0,j.useSelector)(Au("/admin/personal-collection")),w=E("adminUrl");return zs(()=>(e(to(f)),e(Ru(f)),()=>{e(Iu(f))}),[e,m,r,f]),zs(()=>(e(Ge(f)),e(xu(f)),()=>{e(Cu(f))}),[e,m,s,f]),zs(()=>{l.forEach(({type:C})=>{e(C==="entities"?Te():De(C))})},[e,m,p,a]),zs(()=>(e(fi()),()=>{e(Ou())}),[e,m,i,p]),m===!1?(0,L.jsx)("div",{className:o.stateText,children:(0,L.jsx)("div",{children:(0,L.jsx)("p",{children:t("notSupported")})})},"supported"):g===!1?(0,L.jsx)("div",{className:o.loginText,children:(0,L.jsx)("div",{children:(0,L.jsx)(hs,{isEmbedded:n,loginUrl:w})})},"login"):!a||!f||g===null||y||T?(0,L.jsx)("div",{className:o.stateText,children:(0,L.jsx)("div",{children:(0,L.jsx)("p",{children:t("waiting")})})},"waiting"):(0,L.jsxs)("div",{className:(0,gp.default)(o.root),"data-testid":"widget",children:[S&&(0,L.jsx)("div",{className:o.links,children:(0,L.jsxs)("a",{className:o.link,target:"_blank",href:S,rel:"noreferrer",children:[t("linkPersonalcollection"),(0,L.jsx)(op,{})]})}),(0,L.jsxs)(js,{className:o.sectionList,children:[r&&d.length>0&&(0,L.jsx)(Rt,{"data-testid":"custom-messages",children:(0,L.jsx)(Re,{withDivider:!0,children:d.map(C=>(0,L.jsx)(np,{suggestion:C},C.text))})}),s&&c.length>0&&(0,L.jsx)(Rt,{title:t("titleAutoflows"),"data-testid":"autoflows",children:(0,L.jsx)(Re,{withDivider:!0,children:(0,L.jsx)($u,{})})}),l.map(({type:C,title:x,amount:B,lines:$})=>{var K;switch(C){case"entities":return u&&u.length>0&&(0,L.jsx)(Rt,{title:x,"data-testid":`type-${C}`,children:(0,L.jsx)(Qu,{entities:u})},C);default:return((K=b[C])==null?void 0:K.fetchState)==="done"&&b[C].suggestions.length>0&&(0,L.jsx)(Rt,{title:x,"data-testid":`type-${C}`,children:(0,L.jsx)(Re,{withDivider:!0,children:(0,L.jsx)(dp,{lines:$,contentType:C,suggestions:b[C].suggestions.slice(0,B)||[]})})},C)}})]})]})},hp=Zg;function yp(t){let e=new Range;return e.selectNodeContents(t),e}var io=/[\u200B-\u200D\uFEFF]/g;function It(t,e,n){let o=new Range;if(t.firstChild===null&&e===0&&n===0)return o.selectNodeContents(t),o;let s=0,r=!1;function i(l,c){let u=-1,d=/[\u200B-\u200D\uFEFF]/;if(!d.test(l))return c;for(let p=0;p<=l.length;p++)if(d.test(l[p])||u++,u===c)return p;throw new Error("Offset out of range")}function a(l){var c;switch(l.nodeType){case Node.TEXT_NODE:{let u=l.textContent,d=u.replace(io,""),p=s+d.length,m=e>=s&&e<=p,g=n>=s&&n<=p;if(m){let f=i(u,e-s);f===0&&!g?o.setStartBefore(l):o.setStart(l,f)}g&&(o.setEnd(l,i(u,n-s)),r=!0),s=p;break}case Node.ELEMENT_NODE:{if(l.tagName==="BR"&&(s===e&&o.setStartBefore(l),s++,s===n)){o.setEndAfter(l),r=!0;return}for(let d=0;d<l.childNodes.length&&(a(l.childNodes[d]),!r);d++);let u=(c=l.lastChild)==null?void 0:c.tagName;l.tagName==="DIV"&&u!=="DIV"&&u!=="BR"&&s++;break}default:break}}if(a(t),o.startContainer===document)throw new Error("Offsets out of bound");return o}function Ws(t,e){if(!t.contains(e.commonAncestorContainer))throw new Error("Range not within root element");let{startContainer:n,startOffset:o,endContainer:s,endOffset:r}=e,i,a,l=0;function c(u){let d=u===n,p=u===s;switch(u.nodeType){case Node.TEXT_NODE:{let m=u.textContent;d&&(i=l+m.substring(0,o).replace(io,"").length),p&&(a=l+m.substring(0,r).replace(io,"").length),l+=m.replace(io,"").length;break}case Node.ELEMENT_NODE:{let{tagName:m}=u,g=u.nextSibling===null;m==="BR"&&!g&&l++;for(let f=0;f<u.childNodes.length&&(d&&f===o&&(i=l),c(u.childNodes[f]),p&&f===r-1&&(a=l),a===void 0);f++);!p&&m==="DIV"&&!g&&l++,p&&(a=l);break}default:break}}if(c(t),a===void 0)throw new Error("Could not determine start and end");return{start:i??a,end:a}}function ao(t,e){if(!t.contains(e.commonAncestorContainer))throw new Error("Range not within root element");let{startContainer:n,startOffset:o,endContainer:s,endOffset:r}=e,i=-1,a="";function l(c){let u=c===n,d=c===s;switch(u&&i++,c.nodeType){case Node.TEXT_NODE:{if(i!==0)return;let p=u?o:0,m=d?r:void 0,g=c.textContent.replace(io,"");p===0&&m===void 0?a+=g:a+=g.substring(p,m);break}case Node.ELEMENT_NODE:{let{tagName:p}=c,m=c.nextSibling===null;i===0&&p==="BR"&&!m&&(a+=`
4
+ `);for(let g=u?o:0;g<(d?Math.min(r,c.childNodes.length):c.childNodes.length)&&(l(c.childNodes[g]),i!==1);g++);!d&&i===0&&p==="DIV"&&!m&&(a+=`
5
+ `);break}default:break}d&&i++}return l(t),a}var Lt=class extends Me{observer;getText(){let e=new Range;return e.selectNodeContents(this.element),ao(this.element,e)}getHTML(){return this.element.innerHTML||""}getSelection(){if(document.activeElement!==this.element)return null;let e=window.getSelection();if(!e||e.rangeCount===0)return null;let n=e.getRangeAt(0);return!n||!this.element.contains(n.commonAncestorContainer)?null:Ws(this.element,n)}getSelectedText(){if(!this.currentSelection)return"";let{start:e,end:n}=this.currentSelection;return ao(this.element,It(this.element,e,n))}applyChanges(e){var s;if(!this.isActive)return;this.isSettingValue=!0;let n=this.getText(),o=e(this.element);(s=this.observer)==null||s.takeRecords(),Promise.resolve(o).then(()=>{this.currentText=this.getText(),n!==this.currentText&&this.triggerChange(),this.isSettingValue=!1})}listen(){super.listen(),this.observer=new MutationObserver(()=>{setTimeout(()=>{this.triggerChange()},0)}),this.observer.observe(this.element,{attributes:!0,characterData:!0,childList:!0,subtree:!0});let e=this.element.isContentEditable,n=new MutationObserver(()=>{this.element.isContentEditable!==e&&(e=this.element.isContentEditable,this.emit(this.element.isContentEditable?"enabled":"disabled"))});n.observe(this.element,{attributes:!0,attributeFilter:["contenteditable"]}),this.disposeHandlers.push(()=>n.disconnect())}dispose(){super.dispose(),this.observer&&this.observer.disconnect()}};var wi=class{constructor(e){this.name=e;k.warn("BroadcastChannel is not supported")}postMessage(){}addEventListener(){}removeEventListener(){}close(){}},Ei=class{constructor(e,n){this.name=e;this.options=n;this.broadcastChannel=new this.options.broadcastChannelConstructor(e)}broadcastChannel;disposeHandlers=[];onMessage(e){this.broadcastChannel.addEventListener("message",e),this.disposeHandlers.push(()=>{this.broadcastChannel.removeEventListener("message",e)})}postMessage(e){this.broadcastChannel.postMessage(e)}close(){this.disposeHandlers.forEach(e=>e()),this.broadcastChannel.close()}},_i=class{constructor(e,n,o){this.name=e;this.targetOrigin=n;this.options=o;this.iframe=this.createIframe(),document.body.appendChild(this.iframe)}iframe;disposeHandlers=[];createIframe(){let e=`deepdesk-iframe-${this.name}`,n=document.getElementById(e);if(n)return n;let o=document.createElement("iframe"),s=`${this.targetOrigin}/v2/widget/liveengage/channel.html`,r=new URLSearchParams({channel:this.name,host:window.location.origin});return this.options.debug&&r.set("debug","1"),o.style.position="absolute",o.style.left="-999em",o.style.width="0px",o.style.height="0px",o.tabIndex=-1,o.id=e,o.title=`iframe-${this.name}`,o.src=`${s}?${r.toString()}`,o}onMessage(e){window.addEventListener("message",e),this.disposeHandlers.push(()=>{window.removeEventListener("message",e)})}postMessage(e){var n;(n=this.iframe.contentWindow)==null||n.postMessage(e,this.targetOrigin)}close(){var e;this.disposeHandlers.forEach(n=>n()),(e=this.iframe)==null||e.remove()}},Pi=class{sessionId;deepdeskUrl;channel;broadcastChannelConstructor;eventMap;isIntegration;constructor(e){this.deepdeskUrl=e.deepdeskUrl,this.broadcastChannelConstructor=e.broadcastChannelConstructor||window.BroadcastChannel||wi,this.isIntegration=e.deepdeskUrl!==(e.origin||window.location.origin),this.eventMap=e.eventMap,this.setSessionId("deepdesk-general")}setSessionId(e){if(this.sessionId===e)return;this.cleanup(),k.info("Set sessionId",e),this.sessionId=e,this.channel=this.isIntegration?new _i(e,this.deepdeskUrl,{debug:!0}):new Ei(e,{broadcastChannelConstructor:this.broadcastChannelConstructor});let n=o=>{var s,r;o.origin===this.deepdeskUrl&&o.data.type==="event"&&(k.info("Received broadcast event",this.sessionId,o),(r=(s=this.eventMap)[o.data.name])==null||r.call(s,o.data.payload))};this.channel.onMessage(n)}send(e,n){var s,r,i;if(!this.sessionId)return;k.info("broadcast event",{sessionId:this.sessionId,name:e,payload:n});let o={type:"event",name:e,payload:n};(r=(s=this.eventMap)[e])==null||r.call(s,n),(i=this.channel)==null||i.postMessage(o)}cleanup(){var e;(e=this.channel)==null||e.close(),delete this.channel}},Sp=Pi;var hn=class extends Error{constructor(n,o){super(n);this.body=o}name="CustomError"};var ki=t=>new Promise(e=>{setTimeout(e,t)});var yn=class extends hn{name="ClientError"},Ri=class extends hn{name="ServerError"},Xe=class t{constructor(e="",n={}){this.baseUrl=e;this.options=n;n.fetch&&(this.fetch=n.fetch)}latestRequestByUrl={};csrfToken;fetch=window.fetch.bind(window);static refreshingToken=null;patchFetch(e){this.fetch=e(this.fetch)}setCsrfToken(e){this.csrfToken=e}async request(e,n={}){let o={isStale:!1},s=`${this.baseUrl}${e}`,r=this.fetch,{abortLatest:i=!1,attempts:a=1,retryDelay:l=500,refreshTokenOn401:c=!0,retryOnError:u=w=>w instanceof TypeError,retryOnResponse:d=w=>w.status>=500,version:p="v1",...m}=n,g={credentials:"include",...m,headers:{"Content-Type":"application/json",...m.headers}};n.method!==void 0&&n.method!=="GET"&&this.csrfToken&&(g.headers={...g.headers,"X-CSRFToken":this.csrfToken}),typeof p=="string"&&(g.headers={...g.headers,"X-Deepdesk-API-Version":p});let f=a,T=!1;if(!r)throw new Error("fetch is not set");this.latestRequestByUrl[s]&&i&&(this.latestRequestByUrl[s].isStale=!0),this.latestRequestByUrl[s]=o;let b=async()=>(f--,r(s,g).then(async w=>d(w)&&!o.isStale&&f>0?(await ki(l),b()):w.status===401&&c===!0&&T===!1?(T=!0,await this.refreshToken(),b()):w).catch(async w=>{if(u(w)&&!o.isStale&&f>0)return await ki(l),b();throw w})),y=await b(),S=await y.json().catch(()=>null);if(o.isStale)throw new Error("Aborted");if(y.status>=500)throw new Ri("Server Error",S);if(y.status===401)throw new yn("Unauthorized",S);if(y.status===403)throw new yn("Forbidden",S);if(y.status===404)throw new yn("Not Found",S);if(y.status>=400)throw new yn("Bad Request",S);return delete this.latestRequestByUrl[s],S}async validateToken(){let{has_valid_access_token:e}=await this.get("/auth/validate");if(!e)return!1;let{is_logged_in:n}=await this.get("/apis/admin/session/validate/",{version:null});return!!n}refreshToken(){return t.refreshingToken||(t.refreshingToken=this.get("/auth/refresh",{refreshTokenOn401:!1}).finally(()=>{setTimeout(()=>{t.refreshingToken=null},1e3*60)})),t.refreshingToken}get(e,n){return this.request(e,n)}post(e,n,o){return this.request(e,{method:"POST",body:JSON.stringify(n),...o})}patch(e,n,o){return this.request(e,{method:"PATCH",body:JSON.stringify(n),...o})}put(e,n,o){return this.request(e,{method:"PUT",body:JSON.stringify(n),...o})}delete(e,n){return this.request(e,{method:"DELETE",...n})}};var Yg;(e=>{let t;(l=>(l.SEND_MESSAGE="Send Message",l.HANDLING_TIME="Handling Time",l.START_AUTOFLOW="Start Autoflow",l.ABORT_AUTOFLOW="Abort Autoflow",l.ADD_TO_PERSONAL_COLLECTION="Add to personal collection",l.DELETE_FROM_PERSONAL_COLLECTION="Delete from personal collection"))(t=e.EventType||={})})(Yg||={});function Gs(t){return{...M(t),tags:t.tags}}var Je=class t{constructor(e,n={}){this.options=n;this.client=new Xe(e,{fetch:n.fetch}),this.account=new URL(e).hostname.split(".").shift(),this.client.patchFetch(o=>async(s,r)=>{let i=await o(s,r);return this.handleDeepdeskVersionHeaders(i),i})}latestReceivedDeepdeskVersions={};client;account;shouldFetchCsrfToken=!0;static exchangeTokenPromise=null;async preflight(){if(this.shouldFetchCsrfToken){this.shouldFetchCsrfToken=!1;let e=await this.getCsrfToken();this.client.setCsrfToken(e)}return this.options.token?(t.exchangeTokenPromise||(t.exchangeTokenPromise=this.exchangeTokenForAccessCookie(this.options.token)),t.exchangeTokenPromise):Promise.resolve()}async createConversation(e){await this.preflight(),k.info(`Creating conversation for session ${e.sessionId} and agent ${e.agentId}`);let n=await this.client.post("/api/conversations",{...U(e),tags:e.tags},{version:"v2"});return Gs(n)}async getProfile(e){let n=await this.client.get(`/apis/admin/accounts/${this.account}/profiles/${e}/`,{version:null});return M(n)}async getContentTypes(){let e=await this.client.get("/apis/admin/content-types/",{version:null});return M(e)}async getPlatformConfig(){let{config:e}=await this.client.get("/platform/config/",{version:null});return M(e)}async checkUserExists(e){let{exists:n}=await this.client.get(`/apis/admin/accounts/${this.account}/users/exists?external_id=${e}`);return n}async getConversationBySessionId(e,n={}){await this.preflight(),k.info(`Getting conversation for session ${e}`);let{attempts:o=1,retryDelay:s=1e3}=n,r=await this.client.get(`/api/conversations/by_session_id/${e}`,{attempts:o,retryDelay:s,retryOnResponse:i=>i.status===404||i.status>=500,version:"v2"});return Gs(r)}async isConversationSupported(e,n={}){k.info(`Check if conversation for session ${e} is supported`);let{attempts:o=1,retryDelay:s=1e3}=n;return(await this.client.get(`/api/conversations/by_session_id/${e}/active_profile`,{attempts:o,retryDelay:s,retryOnResponse:i=>i.status===404||i.status>=500,version:"v2"})).has_active_profile}async updateConversation(e,n){let o=U(n);n.tags&&(o.tags=n.tags);let s=await this.client.put(`/api/conversations/${e}`,o,{version:"v2"});return Gs(s)}async postMessages(e,n){return(await this.client.post(`/api/conversations/${e}/messages`,n.map(s=>({...U(s),tags:s.tags})),{version:"v2"})).map(s=>Gs(s))}async sendEvent(e,n){let{data:o,...s}=n,r=Object.entries(this.latestReceivedDeepdeskVersions).reduce((i,[a,l])=>({...i,[a]:l}),{});return this.client.post("/api/events",U({...r,...s,data:o,name:e}),{version:"v2"})}async sendEventV1(e,n){let o=Object.entries(this.latestReceivedDeepdeskVersions).reduce((s,[r,i])=>({...s,[r]:i}),{});return this.client.post("/api/events",{event:e,data:U({...n,...o})})}async getEntities(e){return(await this.client.post("/api/entities",{messages:e})).entities}async getSummary(e){return(await this.client.post("/api/summary",{conversation:{messages:e}})).summary}async getTemporaryExchangeToken(){return(await this.client.get("/auth/exchange-token",{version:null})).jwt}async exchangeTokenForAccessCookie(e){return this.client.get(`/apis/admin/session/jwt/?jwt=${e}`,{version:null}).catch(n=>{throw k.warn(`Invalid token '${e}'`),n})}async authenticateWithKey(e,n){await this.client.post("/apis/admin/session/api-key/",U(n),{version:null,refreshTokenOn401:!1,headers:{apikey:e}})}async getTextSuggestions(e,n={},o){return o==="sticky-messages"?this.getPinnedMessages(e):(await this.client.post(`/api/conversations/${e}/recommend/${o}`,U(n),{abortLatest:!0})).map(r=>({...M(r),text:r.text||r.url||r.message,source:o,type:o})).filter((r,i,a)=>i===a.findIndex(l=>l.text===r.text))}async isLoggedIn(){return await this.preflight(),this.client.validateToken()}async getAutocompleteSuggestions(e,n){return(await this.client.post(`/api/conversations/${e}/autocomplete`,U(n),{abortLatest:!0})).map(s=>({score:1,source:s.source,sourceText:s.source_text,text:s.label,trainingJobs:s.training_jobs,searchKeywords:s.search_keywords,type:s.source})).filter((s,r,i)=>r===i.findIndex(a=>a.text===s.text))}async getPinnedMessages(e){let n=await this.client.get(`/api/conversations/${e}/sticky-messages`,{abortLatest:!0});return M(n).map(o=>({...o,text:o.message,source:"sticky-messages",type:"pinned-message"}))}async getStyleSuggestions(e){let n=await this.client.post("/api/style-suggestions",U(e),{abortLatest:!0});return M(n)}async search(e){let n=await this.client.post(`/api/profiles/${e.profile}/search`,U(e),{version:"v2"});return M(n)}async knowledgeSearch(e,n,o){let s=await this.client.post("/api/knowledge-search/search",U({question:e,profile:o,chatHistory:n.map(r=>({question:r.question,answer:r.answer.answer,timestamp:r.answer.timestamp}))}),{version:"v2"});return M(s)}async requestLoginByEmail(e){let n=await this.client.post("/apis/admin/session/passwordless/request/",{email:e},{version:null});return M(n)}async getCsrfToken(){let{token:e}=await this.client.get("/apis/admin/session/csrf/",{version:null});return e}async verifyLoginToken(e){let n=await this.client.post("/apis/admin/session/passwordless/login/",{token:e},{version:null});return M(n)}handleDeepdeskVersionHeaders(e){e.headers.forEach((n,o)=>{let s=o.toLowerCase(),r=s.match(Hi);if(!n||!r)return;let i=r[1].replace("-","_"),a=this.latestReceivedDeepdeskVersions[i];a&&n&&a!==n&&k.warn(`Overwritten Version header ${s}: ${JSON.stringify(a)} -> ${JSON.stringify(n)}`),this.latestReceivedDeepdeskVersions[i]=n})}};var lo=class{constructor(e,n){this.url=e;this.options={timeout:25e3,...n}}eventListeners={};options;timeoutTimer;eventSource;proxyEvent(e){this.eventSource.addEventListener(Ar(e),n=>{let{data:o}=n;try{let s=JSON.parse(o);this.emit(e,M(s))}catch{k.warn(`Invalid JSON for ${e}: ${o}`)}})}connect(){clearTimeout(this.timeoutTimer);let e=new EventSource(this.url,{withCredentials:!0});this.eventSource=e;let n=!1;e.onopen=()=>{n=!0},e.onerror=()=>{n&&e.readyState===2&&this.connect()},this.timeoutTimer=setTimeout(()=>{e.close(),this.connect()},this.options.timeout),Object.keys(this.eventListeners).forEach(o=>{this.proxyEvent(o)})}disconnect(){var e;clearTimeout(this.timeoutTimer),this.eventListeners={},(e=this.eventSource)==null||e.close()}emit(e,n){this.eventListeners[e]&&this.eventListeners[e].forEach(o=>o(n))}on(e,n){return this.eventListeners[e]||(this.eventListeners[e]=[]),this.eventListeners[e].push(n),this.proxyEvent(e),()=>{this.off(e,n)}}off(e,n){let o;this.eventListeners[e]&&(o=this.eventListeners[e].indexOf(n),o>-1&&this.eventListeners[e].splice(o,1))}};var ef;(e=>{let t;(r=>(r.Started="Started",r.Aborted="Aborted",r.Completed="Completed"))(t=e.AutoflowSessionState||={})})(ef||={});var co=class{constructor(e,n={}){this.apiUrl=e;this.client=new Xe(e,n)}client;streams={};logger=k;async getCustomMessages(e){let n=await this.client.get(`/sessions/${e}/suggestions`);return M(n.suggestions)}async sendCustomMessage(e,n){let o=await this.client.post(`/sessions/${e}/messages`,U(n));return M(o)}async answerCustomMessage(e,n){await this.client.post(`/sessions/${e}/answers`,U(n))}async getAutoflows(e){let n=await this.client.get(`/sessions/${e}/autoflows`);return M(n.autoflows)}async startAutoflowSession(e){let n=await this.client.post("/autoflow-sessions",U(e));return M(n)}async stopAutoflowSession(e){await this.client.delete(`/autoflow-sessions/${e}`)}openStream(e){return this.streams[e]||(this.streams[e]=new lo(`${this.apiUrl}/sessions/${e}/events`),this.streams[e].connect()),this.streams[e]}closeStream(e){this.streams[e]||(this.streams[e].disconnect(),delete this.streams[e])}};var Js=require("@reduxjs/toolkit");var xp=require("@reduxjs/toolkit");var vp={startTime:null,stopTime:null},Cp=(0,xp.createSlice)({name:"handlingTime",initialState:vp,reducers:{handlingTimeStart(t){if(t.startTime&&!t.stopTime)throw new Error("Timing already started");t.startTime=new Date,t.stopTime=null},handlingTimeStop(t){if(!t.startTime)throw new Error("Timing not started");t.stopTime=new Date},handlingTimeReset(t){t.startTime=null,t.stopTime=null}},extraReducers:t=>{t.addCase(R,()=>vp)}}),{handlingTimeStart:Tp,handlingTimeStop:$s,handlingTimeReset:bp}=Cp.actions,wp=Cp.reducer;var Xs=require("@reduxjs/toolkit");var Ii={list:{keywordMatches:[]},fetchState:"idle",isInitialRequest:null};var At=(0,Xs.createAsyncThunk)("styleSuggestions/getAll",async({text:t},e)=>{var i;let{deepdeskAPI:n}=e.extra,o=e.getState(),{showStyleSuggestions:s}=o.settings,r=(i=o.conversation.current)==null?void 0:i.profileCode;if(!s)return Ii.list;if(!r)throw new Error("No current conversation to fetch pinned messages");return n.getStyleSuggestions({profileCode:r,message:t})}),tf=(0,Xs.createSlice)({name:"styleSuggestions",initialState:Ii,reducers:{},extraReducers:t=>{t.addCase(At.pending,e=>{e.isInitialRequest=e.isInitialRequest===null,e.fetchState="loading"}).addCase(At.rejected,e=>{e.fetchState="error"}).addCase(At.fulfilled,(e,n)=>{e.fetchState="done",tt(e.list,n.payload)||(e.list=n.payload)}).addCase(R,()=>Ii)}}),Ep=tf.reducer;var _p=(t={})=>{let e,n=!0,o={getStyleSuggestions:At,debounce:500,...t};return s=>r=>i=>{var m;let a=s.getState().input.text,l=r(i),c=s.getState(),{showStyleSuggestions:u}=c.settings;if(!((m=c.conversation.current)==null?void 0:m.id)||!u)return l;let{text:p}=c.input;return p===a&&!n||(clearTimeout(e),p==="")||(e=setTimeout(()=>{n=!1,s.dispatch(o.getStyleSuggestions({text:p}))},t.debounce)),l}};function nf(t,e){return t.text===e.text&&t.selection.start===e.selection.start&&t.selection.end===e.selection.end}var Pp=(t={})=>{let e={getTextSuggestions:De,getAutocompleteSuggestions:Bn,debounce:200,check:fs,...t},n,o=!0;return s=>r=>i=>{var T;let{input:{userCommitted:a}}=s.getState(),l=r(i),c=s.getState(),{recommendTextSuggestions:u,showTabCompletion:d}=c.settings,p=(T=c.conversation.current)==null?void 0:T.id,m=i.type===is.toString();if(!p||!u&&!d)return l;let{input:{userCommitted:g}}=c;return nf(g,a)&&!o&&!m||(clearTimeout(n),!e.check(c))||(n=setTimeout(()=>{o=!1;let b=Dt(c);b===""?s.dispatch(e.getTextSuggestions("default")):s.dispatch(e.getAutocompleteSuggestions(b))},m?0:e.debounce)),l}};var kp=At.fulfilled.toString();function of(t,e){let n=new Set([...e.keywordMatches.map(s=>s.keyword)]),o=[];return n.forEach(s=>{let r=t.keywordMatches.filter(l=>l.keyword===s),i=e.keywordMatches.filter(l=>l.keyword===s),a=i.length-r.length;a<=0||o.push(...i.slice(0,a))}),o}var Rp=t=>e=>n=>o=>{var u;if(o.type!==kp){n(o);return}let s=e.getState().styleSuggestions.list;n(o);let r=e.getState(),i=r.styleSuggestions.list,a=(u=r.conversation)==null?void 0:u.current,{agentInfo:l}=r.info;if(s===i)return;let c=of(s,i);o.type===kp&&c.length>0&&t.sendEvent("style suggested",{conversationId:a==null?void 0:a.id,agentId:l.agentId??(a==null?void 0:a.agentId),agentName:l.agentName??(a==null?void 0:a.agentName),agentEmail:l.agentEmail??(a==null?void 0:a.agentEmail),data:{keywordMatches:c}})};var sf=(0,Js.combineReducers)({activeSuggestion:wl,answer:mc,auth:Kl,autoflows:Tu,conversation:zi,contentTypes:Zl,customMessages:Lu,exchangeToken:Nu,entities:nc,handlingTime:wp,info:Ja,input:rr.reducer,overlayInput:X.reducer,settings:Ui,profile:Du,search:tl,summary:lc,styleSuggestions:Ep,ui:Il,textSuggestions:Sl});function Ip(t){return(0,Js.configureStore)({reducer:sf,middleware:e=>[...e({thunk:{extraArgument:{dynamicThunkObject:t.dynamicThunkObject,deepdeskAPI:t.deepdeskAPI,deepdeskBrokerAPI:t.deepdeskBrokerAPI}},serializableCheck:!1}),Pp({debounce:200}),_p({debounce:500}),Rp(t.deepdeskAPI),...t.middleware?t.middleware:[]],preloadedState:t.preloadedState})}var rf=t=>{var e;return((e=t==null?void 0:t.type)==null?void 0:e.toLowerCase())??"unknown"},af=t=>e=>n=>o=>{var a;let s=e.getState(),r=tr("inlineSuggestions")(s);switch(o.type){case He.toString():{let l=dl(o.payload.contentType)(e.getState()),c=l.indexOf(o.payload.suggestion);t.emit("edit-suggestion",{contentType:o.payload.contentType,index:c,suggestions:l});break}case Se.toString():{let{start:l,end:c}=s.input.selection;t.emit("select-suggestion",{type:rf(o.payload.suggestion),...o.payload,replace:o.payload.replace==="selection"?{start:l,end:c}:{start:0,end:c}},{mayApplyChanges:!0});break}case wo.toString():{let{start:l,end:c}=s.input.selection;t.emit("replace",{...o.payload,replace:o.payload.replace==="selection"?{start:l,end:c}:{start:0,end:c}},{mayApplyChanges:!0});break}case Cn.toString():{let l=e.getState(),{text:c,selection:u}=l.input.userCommitted;t.emit("reset",{text:c,selectionAfter:u},{mayApplyChanges:!0});break}case ko.toString():t.emit("select-image",o.payload,{mayApplyChanges:!0}),t.sendEvent("Image attached",{conversationId:s.conversation.current.id,data:{path:o.payload.suggestion.image,title:o.payload.suggestion.title}});break;case Te.fulfilled.toString():o.payload.length>0&&t.sendEvent("entities found",{conversationId:s.conversation.current.id,data:{entities:o.payload}});break;case Ue.fulfilled.toString():t.sendEvent("conversation summarized",{conversationId:s.conversation.current.id,data:{inputText:JSON.stringify(o.payload.original),summary:o.payload.summary}});break;case Ae.toString():t.sendEvent(o.payload.name,{conversationId:((a=o.payload.options)==null?void 0:a.includeConversationData)&&s.conversation.current.id,data:o.payload.data});break;case Eo.toString():t.handleKeyDown(o.payload);break;case xn.toString():t.logSendMessage(o.payload);break;case _o.toString():t.logSendEditSuggestionMessage(o.payload);break;case Po.toString():t.handleInputChanged(o.payload);break;default:break}let i=n(o);switch(o.type){case xn.toString():t.handleAfterSendMessage(o.payload);break;case Kn.toString():t.onUpdateShowTabHint(o.payload);break;case $s.toString():t.logHandlingTime();break;case Se.toString():{r&&(e.dispatch(ot([])),e.dispatch(st()));break}default:break}return i},Lp=af;function Li(t){return t.toISOString().replace("T"," ").replace("Z","")}function Ap(t,e){var s,r,i;let{startTime:n,stopTime:o}=t.handlingTime;if(!n||!o)throw new Error("No startTime and stopTime for handling time metrics");return{conversationId:t.conversation.current.id,clientVersion:e.version,agentId:(s=t.info.agentInfo)==null?void 0:s.agentId,agentName:(r=t.info.agentInfo)==null?void 0:r.agentName,agentEmail:(i=t.info.agentInfo)==null?void 0:i.agentEmail,timeStart:Li(n),timeStop:Li(o)}}function Ai(t,e,n){var C,x,B;let{text:o,metrics:{numCharsTyped:s,numCharsPasted:r,numCharsCut:i,numCharsDeleted:a,numPaste:l,agentStartedTypingTimestamp:c,pastes:u,cuts:d,deletions:p,textSuggestions:m,offeredTextSuggestions:g}}=e[t],f=o.length,b=m.reduce(($,{text:K,searchTerm:ie})=>$+K.length-(ie?ie.length:0),0),y=c??Date.now(),S=(Date.now()-y)/1e3,w=s/S;return{conversationId:e.conversation.current.id,source:"agent",text:o,clientVersion:n.version,pastes:u,cuts:d,deletions:p,lenTextTyped:s,lenTextTotal:f,lenTextAssisted:b,lenTextPasted:r,lenTextCut:i,lenTextDeleted:a,timeTotalSeconds:S,charsPerSecond:w,numPastes:l,textSuggestionsV2:m,suggestionsCounters:[{source:"gpt",countOffered:g.filter($=>$.source==="gpt").length}],agentId:(C=e.info.agentInfo)==null?void 0:C.agentId,agentName:(x=e.info.agentInfo)==null?void 0:x.agentName,agentEmail:(B=e.info.agentInfo)==null?void 0:B.agentEmail}}function Mp(t,e){let n=t.closest(e);if(n)return n;let o=t.getRootNode().host;return o instanceof HTMLElement?Mp(o,e):null}function Op(t,e){return Mp(t,e)}function Np(t){return typeof t=="object"&&t!==null&&"name"in t&&"message"in t}function Qs(t){return t instanceof HTMLElement&&(je(t)||Go(t))}var Dp=(t,e)=>({value(){try{let n=sessionStorage.getItem(`dd-${t}`);if(!n)return e;try{return JSON.parse(n)}catch{return e}}catch{return e}},update(n){try{sessionStorage.setItem(`dd-${t}`,JSON.stringify(n))}catch{k.warn("[Deepdesk] SessionStorage is blocked by browser")}}});function lf(t){return t.offsetParent!==null}function Hp(t){if(!lf(t))return!1;let e=t.getBoundingClientRect();return e.top>=0&&e.left>=0&&e.bottom<=(window.innerHeight||document.documentElement.clientHeight)&&e.right<=(window.innerWidth||document.documentElement.clientWidth)}function Zs(t,e,n=100){let o=Hp(t);e({isVisible:o});let s=setInterval(()=>{let r=Hp(t);r!==o&&(o=r,e({isVisible:o}))},n);return()=>{clearTimeout(s)}}var re=require("react/jsx-runtime"),Fp=Dp("showTabHint",!0),uo=class t{static version="10.0.0-beta.12";static count=0;deepdeskApi;inputMediator=null;version;broadcastEvents;eventListeners={};unmountHandlers=[];widgetRoot=null;dynamicThunkObject={};isMounted=!1;instanceId;shouldRender=!0;store;constructor({deepdeskUrl:e,brokerUrl:n,version:o=t.version||"unknown",locale:s="en-US",token:r,fetch:i}){let a=e.replace(/\/api$/,"");this.deepdeskApi=new Je(a,{token:r,fetch:i}),this.version=o,this.instanceId=t.count++;let l={deepdeskAPI:this.deepdeskApi,dynamicThunkObject:this.dynamicThunkObject,middleware:[Lp({emit:(c,u,d)=>this.emit(c,u,d),handleAfterSendMessage:c=>this.handleAfterSendMessage(c),handleInputChanged:c=>this.handleInputChanged(c),handleKeyDown:c=>this.handleKeyDown(c),logHandlingTime:()=>this.logHandlingTime(),logSendMessage:c=>this.logSendMessage(c),logSendEditSuggestionMessage:c=>this.logSendEditMessage(c),onUpdateShowTabHint:c=>Fp.update(c),sendEvent:(c,u)=>this.deepdeskApi.sendEvent(c,u)})]};n&&Object.assign(l,{deepdeskBrokerAPI:new co(n)}),this.store=Ip(l),this.broadcastEvents=new Sp({debug:!0,deepdeskUrl:a,eventMap:Ul(this.store)}),this.store.dispatch(vn),this.store.dispatch(Kn(Fp.value())),this.store.dispatch(vn({locale:s,adminUrl:a}))}get state(){return this.store.getState()}get settings(){return this.state.settings}get selectedTextSuggestion(){return this.state.input.textSuggestions[this.state.input.selectedSuggestionIndex]??null}hasConversation(){return!!this.state.conversation.current}conversationId(){if(!this.hasConversation())throw new Error("No conversation loaded");return this.state.conversation.current.id}sessionId(){if(!this.hasConversation())throw new Error("No conversation loaded");return this.state.conversation.current.sessionId}shouldAbort(){return this.state.conversation.isSupported===!1?(k.warn("Conversation is not supported"),!0):this.hasConversation()?this.state.profile.data?!1:(k.warn("Profile has not been loaded (yet)"),!0):(k.warn("No conversation loaded (yet)"),!0)}login(){return this.store.dispatch(Fl(null)),this.store.dispatch(Tt()),new Promise(e=>{let n=this.store.subscribe(()=>{let o=this.store.getState();Fe(o)&&Ml(o)!=="loading"&&e()});this.unmountHandlers.push(()=>{n()})})}isLoggedIn(){return this.deepdeskApi.isLoggedIn()}async setPlatformAgentId(e){try{if((await this.deepdeskApi.client.get("/apis/admin/session/me/",{version:null})).external_id)return;await this.deepdeskApi.client.request("/apis/admin/session/me/",{method:"PATCH",body:JSON.stringify({external_id:e}),version:null})}catch(n){k.warn("Failed to attach user:",n)}}async isConversationSupported(e,n){return(await this.store.dispatch(or({sessionId:e,options:n}))).payload}async createConversation(e){return this.hasConversation()&&this.sessionId()!==e.sessionId&&this.resetConversation(),(await this.store.dispatch(So(e))).payload}async getConversationBySessionId(e,n){return this.hasConversation()&&this.sessionId()!==e&&this.resetConversation(),(await this.store.dispatch(vo({sessionId:e,options:n}))).payload}async upsertConversation(e){return this.hasConversation()&&this.sessionId()!==e.sessionId&&this.resetConversation(),(await this.store.dispatch(sr(e))).payload}async postMessages(e){return(await this.store.dispatch(Co(e))).payload}async updateConversation(e){return(await this.store.dispatch(xo(e))).payload}resetConversation(){this.store.dispatch(R()),this.dynamicThunkObject.conversationQuery=null}async getSummary(){let e=await this.store.dispatch(Ue());if(e.error)throw new Error(e.error.message);return e.payload.summary}configure(e){this.store.dispatch(vn(e))}setVisitorInfo(e){this.store.dispatch(Xa(e))}async setAgentInfo(e){await this.store.dispatch(Nn(e))}async setAgentSettings(e){await this.store.dispatch(Mr(e))}async getAgentSettings(){return(await this.store.dispatch(Or())).payload}async refresh(){if(this.shouldAbort())return Promise.resolve();let e=[];return this.store.dispatch(is()),e.push(this.refreshWidgetSuggestions()),Promise.all(e).then(()=>{})}notifyInputChanged(e){this.store.dispatch(Po(e))}syncInputHtml(e){this.store.dispatch(ia(e))}notifyKeyDown(e){this.store.dispatch(Eo(e))}notifyPaste(e,n){this.store.dispatch(sa({text:e,selectionText:n}))}notifyCut(e){this.store.dispatch(na(e))}notifyExternalSuggestion(e){this.store.dispatch(Se(e)),this.store.dispatch(st())}notifyEditSuggestion(e){this.store.dispatch(hl(e.contentType,e.suggestions)),this.store.dispatch(He({contentType:e.contentType,suggestion:typeof e.index=="number"?e.suggestions[e.index]:null}))}handleInputChanged(e){let{overlayCollapsed:n,openOverlayWhenTyping:o}=this.state.ui;n&&o&&this.store.dispatch(en({collapse:!1})),this.inputMediator&&this.store.dispatch(Ji({text:e,html:this.inputMediator.getHTML(),selection:this.inputMediator.getSelection()})),!this.shouldAbort()&&(this.isMounted||this.store.dispatch(ot([])))}handleKeyDown(e){let{overlayCollapsed:n}=this.state.ui,{textSuggestions:o,selectedSuggestionIndex:s,selection:r}=this.state.input,{inlineSuggestions:i}=this.state.settings,a=o.length>0,l=s!==-1;if(this.store.dispatch(oa(bo(e))),!(e.key!=="Tab"&&!this.settings.showTextSuggestions))switch(e.key){case"Up":case"ArrowUp":if(n||!a||!r||e.shiftKey)return;this.store.dispatch(Yi()),i||this.stageSelectedSuggestion({inputType:"arrow"}),e.preventDefault();return;case"Down":case"ArrowDown":{if(n||!a||!r||e.shiftKey)return;this.store.dispatch(ta());let{selectedSuggestionIndex:c}=this.state.input;c===-1?this.store.dispatch(Cn()):i||this.stageSelectedSuggestion({inputType:"arrow"}),e.preventDefault();return}case"Esc":case"Escape":{l?(this.store.dispatch(Ro(-1)),this.store.dispatch(Cn()),e.preventDefault()):n||(this.store.dispatch(en({collapse:!0})),this.store.dispatch(kl(!0)),e.preventDefault());return}case"Tab":{let{userCommitted:c}=this.state.input,u=c.text.substring(0,c.selection.end),{tabCompletionSuggestion:d}=this.state.input;this.store.dispatch(Kn(!1)),this.state.input.selectedSuggestionIndex>-1?this.stageSelectedSuggestion({inputType:"tab"}):this.settings.showTabCompletion&&d&&d.text.startsWith(u)&&(this.store.dispatch(Se({text:d.text,suggestion:d,eventMetrics:{inputType:"tab"},replace:"until-selection-end"})),this.store.dispatch(st())),e.preventDefault();break}default:}}handleAfterSendMessage(e){this.emit("send-message",e),this.store.dispatch(ra()),this.store.dispatch(ot([]))}handlingTimeStart(){this.state.handlingTime.startTime||(k.info("Start handling time"),this.store.dispatch(Tp()))}handlingTimeStop(){this.state.handlingTime.startTime&&(k.info("Stop handling time"),this.store.dispatch($s()))}logSendMessage(e){let n=Ai("input",this.state,{version:this.version});e&&Object.assign(n,{text:e}),this.deepdeskApi.sendEventV1("Send Message",n),this.emit("send-message-event",n)}logSendEditMessage(e){let n=Ai("overlayInput",this.state,{version:"v2"});e&&Object.assign(n,{text:e}),this.store.dispatch(Zi(this.state.overlayInput.metrics)),this.deepdeskApi.sendEvent("suggestion edited",{data:n})}logHandlingTime(){let e=Ap(this.state,{version:this.version});this.deepdeskApi.sendEventV1("Handling Time",e),this.store.dispatch(bp())}notifySubmit(e={}){this.shouldAbort()||(this.store.dispatch(st()),this.store.dispatch(xn(e.text??this.state.input.text)))}stageSelectedSuggestion(e){let n=this.state.input.selectedSuggestionIndex,{textSuggestions:o}=this.state.input;this.store.dispatch(Se({text:o[n].text,suggestion:o[n],eventMetrics:e,replace:"until-selection-end"}))}emit(e,n,o={}){let s=()=>{this.eventListeners[e]&&this.eventListeners[e].forEach(r=>{try{r(n)}catch(i){k.warn(`The following error occurred in deepdeskSDK.on('${e}', handler)`),k.error(i)}})};this.inputMediator&&o.mayApplyChanges?this.inputMediator.applyChanges(s):s()}on(e,n){return this.eventListeners[e]||(this.eventListeners[e]=[]),this.eventListeners[e].push(n),()=>{this.off(e,n)}}off(e,n){if(!e&&!n){this.eventListeners={};return}let o;this.eventListeners[e]&&(o=this.eventListeners[e].indexOf(n),o>-1&&this.eventListeners[e].splice(o,1))}setConversationQuery(e){this.dynamicThunkObject.conversationQuery=e}whenConversationLoaded(e){let n=()=>this.loadProfileConfig().then(()=>e());this.hasConversation()&&n();let o=this.hasConversation();this.store.subscribe(()=>{this.hasConversation()!==o&&(o=this.hasConversation(),o&&n())})}overlayContainerFactory(e,n,o,s){let[r,i]=Wt(o,s);return r.dataset.testid=e,n!=null&&n.rootNode&&r.classList.add(n.rootNode),this.unmountHandlers.push(()=>{(0,Qe.unmountComponentAtNode)(r),i(),r.remove()}),r}createContainer(e,n=document.body){let o=window.getComputedStyle(n),s=document.createElement("div");return St(s),s.dataset.testid=e,s.style.color=o.color,s.style.fontSize=o.fontSize,s.style.fontFamily=o.fontFamily,s.style.fontVariant=o.fontVariant,n.appendChild(s),this.unmountHandlers.push(()=>{(0,Qe.unmountComponentAtNode)(s),s.remove()}),s}mount(e,n={}){if(this.isMounted)throw new Error("[Deepdesk] This instance was already mounted. Make sure to unmount before you remount.");if(!Qs(e))throw new Error("[Deepdesk] Only mount on textarea or contentEditable div.");if(!this.shouldRender)return;let{customStyles:o={},showStyleSuggestions:s,showTabCompletion:r,showTextSuggestions:i,textSuggestionsCount:a,showMidSentenceSuggestions:l,showSuggestionsBeforePattern:c,showSuggestionsAfterPattern:u,isEmbedded:d,detectSubmit:p,insertLink:m,inputMediator:g,closestScrollSelector:f,appendOverlayTo:T,inlineSuggestions:b}=n;this.configure({showStyleSuggestions:s,showTabCompletion:r,textSuggestionsCount:a,showMidSentenceSuggestions:l,showSuggestionsBeforePattern:c,showSuggestionsAfterPattern:u,showTextSuggestions:i,insertLink:m,isEmbedded:d,inlineSuggestions:b});let y=f&&Op(e,f)||void 0,S=this.overlayContainerFactory("deepdesk-tab-completion",o,e,{appendTo:T,closestScrollElement:y,mirrorOverflow:!0,onRemove:()=>this.unmount()}),w=this.overlayContainerFactory("deepdesk-suggestions-overlay",o,y||e,{appendTo:T});n.automaticHandlingTime&&this.setupHandlingTime(e),(0,Qe.render)((0,re.jsx)(Zn,{store:this.store,customStyles:o,children:(0,re.jsx)(Vn,{broadcastEvents:this.broadcastEvents,children:(0,re.jsx)(hu,{inputElement:e})})}),S),(0,Qe.render)((0,re.jsx)(Zn,{store:this.store,customStyles:o,children:(0,re.jsx)(Vn,{broadcastEvents:this.broadcastEvents,children:(0,re.jsx)(xs,{})})}),w),(0,Qe.render)((0,re.jsx)(Zn,{store:this.store,customStyles:o,children:(0,re.jsx)(Vn,{broadcastEvents:this.broadcastEvents,children:(0,re.jsx)(xc,{})})}),this.createContainer("deepdesk-overlays")),St(e),this.inputMediator=g||(je(e)?new Oe(e):new Lt(e)),this.inputMediator.on("change",({plainText:x})=>{this.notifyInputChanged(x)}),this.inputMediator.on("updated",({rawHtml:x})=>{x!=null&&this.syncInputHtml(x)}),this.inputMediator.on("keydown",x=>{this.notifyKeyDown(x)}),this.inputMediator.on("paste",({pastedText:x,selectionText:B})=>{this.notifyPaste(x,B)}),this.inputMediator.on("cut",({selectionText:x})=>{this.notifyCut(x)});let C;this.inputMediator.on("selection",x=>{clearTimeout(C),x===null?C=setTimeout(()=>{x!==null&&this.store.dispatch(ir(x))},500):this.store.dispatch(ir(x))}),this.inputMediator.on("disabled",()=>{var x;(x=this.inputMediator)==null||x.deactivate(),this.configure({visible:!1})}),this.inputMediator.on("enabled",()=>{this.inputMediator&&(this.configure({visible:!0}),this.inputMediator.activate())}),this.inputMediator.on("submit",()=>{p&&this.notifySubmit()}),this.inputMediator.on("blur",()=>this.store.dispatch(Yt(!1))),this.inputMediator.on("focus",()=>this.store.dispatch(Yt(!0))),this.store.dispatch(Qi({text:this.inputMediator.getText(),html:this.inputMediator.getHTML(),selection:this.inputMediator.getSelection()})),this.whenConversationLoaded(()=>{var x;this.broadcastEvents.setSessionId((x=this.state.conversation.current)==null?void 0:x.sessionId)}),this.isMounted=!0}unmount(){var e;this.unmountHandlers.forEach(n=>n()),this.unmountHandlers=[],(e=this.inputMediator)==null||e.dispose(),this.broadcastEvents.cleanup(),this.isMounted=!1}renderWidget(e,n={}){if(this.widgetRoot&&k.warn("A widget was already rendered for this instance. Make sure to unmountWidget before rerendering"),!this.shouldRender)return;let{customStyles:o,showImages:s,showPersonalCollectionLink:r,isEmbedded:i}=n;this.widgetRoot=e,this.configure({showImages:s,showPersonalCollectionLink:r,isEmbedded:i}),(0,Qe.render)((0,re.jsx)(Zn,{store:this.store,customStyles:o,children:(0,re.jsx)(Vn,{broadcastEvents:this.broadcastEvents,children:(0,re.jsx)(hp,{})})}),e),this.whenConversationLoaded(()=>{var a;this.broadcastEvents.setSessionId((a=this.state.conversation.current)==null?void 0:a.sessionId)})}unmountWidget(){this.widgetRoot&&(0,Qe.unmountComponentAtNode)(this.widgetRoot),this.widgetRoot=null}setupHandlingTime(e){let n=Zs(e,({isVisible:o})=>{o?this.handlingTimeStart():this.handlingTimeStop()});this.unmountHandlers.push(()=>{this.handlingTimeStop(),n()}),this.whenConversationLoaded(()=>{this.handlingTimeStart()})}handleError(e){Np(e)&&e.message==="Unauthorized"&&this.login()}loadProfileConfigPromise=null;loadProfileConfig(){return this.loadProfileConfigPromise?this.loadProfileConfigPromise:(this.loadProfileConfigPromise=Promise.resolve().then(async()=>{await this.store.dispatch(oo());let e=Ks(this.state);e&&this.store.dispatch(vn({showSearch:e.search,showAutoflows:e.autoflows,showCustomMessages:e.customMessages,showImageSearch:e.imageSearch,showEntitiesCommand:e.entitiesCommand,showSummaryCommand:e.summarizer,showKnowledgeSearch:e.knowledgeSearch,recommendTextSuggestions:e.recommendTextSuggestions}))}),this.loadProfileConfigPromise)}async checkForTrialMode(e){try{let{account:n}=await this.deepdeskApi.getPlatformConfig();if(!n.isTrial){this.shouldRender=!0;return}if(k.info("Trial is active"),!await this.deepdeskApi.checkUserExists(e))throw new Error("User is not in trial");this.shouldRender=!0}catch(n){let{message:o}=n;k.info(o),this.shouldRender=!1}}async refreshWidgetSuggestions(){if(!this.widgetRoot||this.shouldAbort())return;let{uiConfig:e}=this.state.profile.data;if(!e.widget)return;let n=Us(this.state);try{n.forEach(({type:o})=>{o==="entities"?this.store.dispatch(Te()):this.store.dispatch(De(o))})}catch(o){this.handleError(o)}}};async function Bp(t,e,n={}){let{value:o}=t,{start:s,end:r}=n.replace??{start:0,end:o.length},i=`${o.slice(0,s)}${e}${o.slice(r)}`,a=n.selectionAfter??{start:s+e.length,end:s+e.length},l=()=>{if(n.setValue)return n.setValue(i);t.value=i};return Promise.resolve(l()).then(()=>{t.selectionStart=a.start,t.selectionEnd=a.end,t.blur(),t.focus()})}async function Kp(t,e,n={}){let o=n.replace?It(t,n.replace.start,n.replace.end):yp(t),s,r=()=>{if(n.setRange)return n.setRange(o.cloneRange());o.deleteContents(),s=document.createElement("span"),o.insertNode(s),e.split(`
6
+ `).reverse().forEach((i,a)=>{a>0&&o.insertNode(document.createElement("br")),o.insertNode(document.createTextNode(i))}),o.commonAncestorContainer===t&&o.surroundContents(document.createElement("div"))};return Promise.resolve(r()).then(()=>{try{if(n.selectionAfter!==!1){t.focus();let i=n.selectionAfter?It(t,n.selectionAfter.start,n.selectionAfter.end):(o.collapse(!1),o),a=window.getSelection();a==null||a.removeAllRanges(),a==null||a.addRange(i)}if(!s)return;s.scrollIntoView&&s.scrollIntoView({block:"nearest",inline:"nearest"})}finally{s&&s.remove()}})}function Up(t){return t.replace(/\[([\w\s\d]+)\]\((https?:\/\/[^\s]+)\)/g,'<a href="$2" target="_blank" rel="noreferrer">$1</a>')}async function Vp(t,e,n){await new Je(t).authenticateWithKey(e,n)}async function qp(t){let n=await new Xe(t).get("/platform/config/",{version:null});return M(n)}async function cf(t){let n=await(t.fetch??window.fetch)(t.url),o=await n.blob();return new File([o],t.name,{type:t.mimeType??n.headers.get("Content-Type")??"image/jpeg"})}async function jp(t,e){let n=await cf(e),o=new Event("change",{bubbles:!0,cancelable:!0});try{Object.defineProperty(t,"files",{configurable:!0,get:()=>[n]}),t.dispatchEvent(o)}finally{Object.hasOwn(t,"files")&&delete t.files}}0&&(module.exports={Card,Chip,ContentEditableInput,DeepdeskAPI,DeepdeskSDK,InputMediator,InputType,KeyboardHint,Label,Locale,Section,SectionList,Sources,Suggestion,SuggestionList,TextAreaInput,ToggleButton,attachFile,authenticateWithKey,createOverlayContainer,createRangeFromOffsets,escapeHTML,fetchPlatformConfig,formatTextMarkup,getRangeOffsets,getRangeText,isSupportedInputElement,updateContentEditable,updateTextArea,useStyles,waitForElementVisibilityChange});