@cas0570/chat-widget 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ChatWidget.d.ts +1 -1
- package/dist/components/PopoutWindow.d.ts +1 -1
- package/dist/geoapps-chat-widget.js +530 -493
- package/dist/geoapps-chat-widget.umd.cjs +22 -11
- package/dist/hooks/useAuth.d.ts +5 -4
- package/dist/types.d.ts +4 -3
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/token.d.ts +9 -0
- package/package.json +1 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
(function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode(':root{--gcw-color-white: #fff;--gcw-color-gray-50: #f9fafb;--gcw-color-gray-100: #f3f4f6;--gcw-color-gray-200: #e5e7eb;--gcw-color-gray-300: #d1d5db;--gcw-color-gray-400: #9ca3af;--gcw-color-gray-500: #6b7280;--gcw-color-gray-600: #4b5563;--gcw-color-gray-700: #374151;--gcw-color-gray-800: #1f2937;--gcw-color-gray-900: #111827;--gcw-color-primary: #3b82f6;--gcw-color-primary-hover: #2563eb;--gcw-color-primary-light: #eff6ff;--gcw-color-error: #ef4444;--gcw-color-success: #22c55e;--gcw-font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;--gcw-font-size-xs: .625rem;--gcw-font-size-sm: .75rem;--gcw-font-size-base: .875rem;--gcw-font-size-lg: 1rem;--gcw-spacing-1: .25rem;--gcw-spacing-2: .5rem;--gcw-spacing-3: .75rem;--gcw-spacing-4: 1rem;--gcw-spacing-6: 1.5rem;--gcw-spacing-8: 2rem;--gcw-spacing-10: 2.5rem;--gcw-spacing-12: 3rem;--gcw-spacing-16: 4rem;--gcw-spacing-20: 5rem;--gcw-radius-sm: .25rem;--gcw-radius-md: .5rem;--gcw-radius-lg: .75rem;--gcw-radius-xl: 1rem;--gcw-radius-2xl: 1.25rem;--gcw-radius-full: 9999px;--gcw-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / .05);--gcw-shadow-md: 0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);--gcw-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);--gcw-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);--gcw-shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / .25);--gcw-transition-fast: .15s ease;--gcw-transition-base: .2s ease;--gcw-transition-slow: .3s ease;--gcw-z-widget: 9999}.gcw-widget,.gcw-widget *,.gcw-widget *:before,.gcw-widget *:after{box-sizing:border-box;margin:0;padding:0;font-family:var(--gcw-font-family);line-height:1.5}.gcw-widget{font-family:var(--gcw-font-family);font-size:var(--gcw-font-size-base);line-height:1.5;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;color:var(--gcw-color-gray-800);text-align:left;letter-spacing:normal;word-spacing:normal;text-transform:none;text-indent:0;text-shadow:none;font-weight:400;font-style:normal}.gcw-container{position:fixed;z-index:var(--gcw-z-widget);display:flex;gap:var(--gcw-spacing-4)}.gcw-container--bottom-right{right:var(--gcw-spacing-4);bottom:var(--gcw-spacing-4);flex-direction:column-reverse;align-items:flex-end}.gcw-container--bottom-left{left:var(--gcw-spacing-4);bottom:var(--gcw-spacing-4);flex-direction:column-reverse;align-items:flex-start}.gcw-container--top-right{right:var(--gcw-spacing-4);top:var(--gcw-spacing-4);flex-direction:column;align-items:flex-end}.gcw-container--top-left{left:var(--gcw-spacing-4);top:var(--gcw-spacing-4);flex-direction:column;align-items:flex-start}.gcw-container--custom{flex-direction:column-reverse;align-items:flex-end}.gcw-container--custom.gcw-container--align-left{align-items:flex-start}.gcw-container--custom.gcw-container--flow-down{flex-direction:column}.gcw-toggle{position:relative;width:3.5rem;height:3.5rem;border:none;border-radius:var(--gcw-radius-full);background-color:var(--gcw-color-primary);color:var(--gcw-color-white);cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:var(--gcw-shadow-lg);transition:transform var(--gcw-transition-base),box-shadow var(--gcw-transition-base)}.gcw-toggle:hover{transform:scale(1.1);box-shadow:var(--gcw-shadow-xl)}.gcw-toggle:active{transform:scale(.95)}.gcw-toggle__icon{width:1.5rem;height:1.5rem;transition:transform var(--gcw-transition-slow)}.gcw-toggle__badge{position:absolute;top:-.25rem;right:-.25rem;width:1rem;height:1rem;border-radius:var(--gcw-radius-full);display:flex;align-items:center;justify-content:center;font-size:var(--gcw-font-size-xs);font-weight:700;animation:gcw-pulse 2s infinite}.gcw-toggle__badge--unread{background-color:var(--gcw-color-error);color:var(--gcw-color-white)}.gcw-toggle__badge--popout{background-color:var(--gcw-color-success)}.gcw-window{position:relative;display:flex;flex-direction:column;background-color:var(--gcw-color-white);border-radius:var(--gcw-radius-2xl);box-shadow:var(--gcw-shadow-2xl);border:1px solid var(--gcw-color-gray-200);overflow:hidden;animation:gcw-slide-up var(--gcw-transition-slow) ease-out}.gcw-window--small{width:365px;height:450px}.gcw-window--medium{width:380px;height:560px}.gcw-window--large{width:480px;height:680px}.gcw-window--fullscreen{width:calc(100vw - 2rem);height:calc(100vh - 6rem);max-width:56rem}.gcw-window{max-height:90vh;transition:width var(--gcw-transition-base),height var(--gcw-transition-base)}.gcw-header{display:flex;align-items:center;justify-content:space-between;padding:var(--gcw-spacing-3) var(--gcw-spacing-4);color:var(--gcw-color-white);flex-shrink:0}.gcw-header__left{display:flex;align-items:center;gap:var(--gcw-spacing-3)}.gcw-header__avatar{width:2.5rem;height:2.5rem;border-radius:var(--gcw-radius-full);background-color:#fff3;display:flex;align-items:center;justify-content:center}.gcw-header__avatar-icon{width:1.25rem;height:1.25rem}.gcw-header__info{display:flex;flex-direction:column;min-width:0;flex:1}.gcw-header__title{font-size:var(--gcw-font-size-base);font-weight:600;line-height:1.4;margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.gcw-header__subtitle{font-size:var(--gcw-font-size-sm);font-weight:400;line-height:1.4;opacity:.9;margin:0;word-wrap:break-word;overflow-wrap:break-word}.gcw-header__actions{display:flex;align-items:center;gap:.125rem}.gcw-header__btn{width:2rem;height:2rem;border:none;border-radius:var(--gcw-radius-full);background-color:transparent;color:inherit;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background-color var(--gcw-transition-fast)}.gcw-header__btn:hover{background-color:#fff3}.gcw-header__btn-icon{width:1rem;height:1rem}.gcw-header-menu{position:relative}.gcw-header-menu__dropdown{position:absolute;top:calc(100% + .25rem);right:0;min-width:12rem;background-color:var(--gcw-color-white);border-radius:var(--gcw-radius-lg);box-shadow:var(--gcw-shadow-xl);border:1px solid var(--gcw-color-gray-200);padding:var(--gcw-spacing-1) 0;z-index:10;animation:gcw-menu-appear var(--gcw-transition-fast) ease-out}.gcw-header-menu__item{display:flex;align-items:center;gap:var(--gcw-spacing-3);width:100%;padding:var(--gcw-spacing-2) var(--gcw-spacing-3);border:none;background:none;color:var(--gcw-color-gray-700);font-family:var(--gcw-font-family);font-size:var(--gcw-font-size-sm);cursor:pointer;transition:background-color var(--gcw-transition-fast);text-align:left;white-space:nowrap}.gcw-header-menu__item:hover{background-color:var(--gcw-color-gray-100)}.gcw-header-menu__item--danger{color:var(--gcw-color-error)}.gcw-header-menu__item--danger:hover{background-color:#fef2f2}.gcw-header-menu__icon{width:1rem;height:1rem;flex-shrink:0}.gcw-header-menu__divider{height:1px;background-color:var(--gcw-color-gray-200);margin:var(--gcw-spacing-1) 0}@keyframes gcw-menu-appear{0%{opacity:0;transform:translateY(-.25rem)}to{opacity:1;transform:translateY(0)}}.gcw-messages{flex:1;overflow-y:auto;padding:var(--gcw-spacing-4);display:flex;flex-direction:column;gap:var(--gcw-spacing-4)}.gcw-messages::-webkit-scrollbar{width:6px}.gcw-messages::-webkit-scrollbar-track{background:transparent}.gcw-messages::-webkit-scrollbar-thumb{background-color:var(--gcw-color-gray-300);border-radius:3px}.gcw-messages::-webkit-scrollbar-thumb:hover{background-color:var(--gcw-color-gray-400)}.gcw-empty{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:var(--gcw-spacing-6);color:var(--gcw-color-gray-400);text-align:center}.gcw-empty__icon{width:4rem;height:4rem;margin-bottom:var(--gcw-spacing-4);opacity:.5}.gcw-empty__text{font-size:var(--gcw-font-size-base);font-weight:400;line-height:1.5;margin:0}.gcw-session-loading{display:flex;flex-direction:column;align-items:center;gap:var(--gcw-spacing-3)}.gcw-session-loading__spinner{width:2rem;height:2rem;border:3px solid var(--gcw-color-gray-200);border-top-color:var(--gcw-color-primary);border-radius:50%;animation:gcw-spin .8s linear infinite}.gcw-bubble-row{display:flex}.gcw-bubble-row--user{justify-content:flex-end}.gcw-bubble-row--assistant{justify-content:flex-start}.gcw-bubble-wrapper{max-width:85%;display:flex;flex-direction:column}.gcw-bubble-wrapper--user{align-items:flex-end}.gcw-bubble-wrapper--assistant{align-items:flex-start}.gcw-bubble{padding:var(--gcw-spacing-2) var(--gcw-spacing-4);border-radius:var(--gcw-radius-2xl);font-size:var(--gcw-font-size-base);font-weight:400;line-height:1.6;letter-spacing:normal;word-wrap:break-word}.gcw-bubble--user{color:var(--gcw-color-white);border-bottom-right-radius:var(--gcw-radius-sm)}.gcw-bubble--assistant{background-color:var(--gcw-color-gray-100);color:var(--gcw-color-gray-800);border-bottom-left-radius:var(--gcw-radius-sm)}.gcw-bubble__timestamp{font-size:var(--gcw-font-size-xs);color:var(--gcw-color-gray-400);margin-top:var(--gcw-spacing-1);padding:0 var(--gcw-spacing-1)}.gcw-content p{margin-bottom:var(--gcw-spacing-2)}.gcw-content p:last-child{margin-bottom:0}.gcw-content strong{font-weight:600}.gcw-content em{font-style:italic}.gcw-content ul,.gcw-content ol{margin:var(--gcw-spacing-2) 0;padding-left:var(--gcw-spacing-6)}.gcw-content li{margin-bottom:var(--gcw-spacing-1)}.gcw-content code{background-color:#0000001a;padding:.125rem .375rem;border-radius:var(--gcw-radius-sm);font-size:.875em;font-family:SF Mono,Monaco,Consolas,monospace}.gcw-bubble--user .gcw-content code{background-color:#fff3}.gcw-content pre{background-color:var(--gcw-color-gray-800);color:var(--gcw-color-gray-100);padding:var(--gcw-spacing-3);border-radius:var(--gcw-radius-md);overflow-x:auto;margin:var(--gcw-spacing-2) 0}.gcw-content pre code{background-color:transparent;padding:0;font-size:var(--gcw-font-size-sm)}.gcw-content a{color:var(--gcw-color-primary);text-decoration:underline}.gcw-content a:hover{color:var(--gcw-color-primary-hover)}.gcw-bubble--user .gcw-content a{color:#ffffffe6}.gcw-md-heading{font-weight:600;margin-top:var(--gcw-spacing-3);margin-bottom:var(--gcw-spacing-1)}.gcw-md-heading--h2{font-size:var(--gcw-font-size-lg);font-weight:700}.gcw-md-heading--h3,.gcw-md-heading--h4{font-size:var(--gcw-font-size-base)}.gcw-md-heading--h5{font-size:var(--gcw-font-size-sm)}.gcw-md-paragraph{margin-bottom:var(--gcw-spacing-2)}.gcw-md-paragraph:last-child{margin-bottom:0}.gcw-md-list{margin:var(--gcw-spacing-2) 0;padding-left:var(--gcw-spacing-4)}.gcw-md-list--ul{list-style-type:disc}.gcw-md-list--ol{list-style-type:decimal}.gcw-md-list__item{font-size:var(--gcw-font-size-base);margin-bottom:var(--gcw-spacing-1)}.gcw-md-bold{font-weight:600}.gcw-md-italic{font-style:italic}.gcw-md-code{background-color:var(--gcw-color-gray-200);padding:.125rem var(--gcw-spacing-2);border-radius:var(--gcw-radius-sm);font-size:var(--gcw-font-size-sm);font-family:SF Mono,Monaco,Consolas,monospace}.gcw-bubble--user .gcw-md-code{background-color:#fff3}.gcw-md-code-block{background-color:var(--gcw-color-gray-800);color:var(--gcw-color-gray-100);padding:var(--gcw-spacing-3);border-radius:var(--gcw-radius-lg);font-size:var(--gcw-font-size-sm);overflow-x:auto;margin:var(--gcw-spacing-2) 0}.gcw-md-code-block code{font-family:SF Mono,Monaco,Consolas,monospace}.gcw-md-link{color:var(--gcw-color-primary);text-decoration:underline}.gcw-md-link:hover{color:var(--gcw-color-primary-hover)}.gcw-bubble--user .gcw-md-link{color:#ffffffe6}.gcw-sources{display:flex;flex-wrap:wrap;gap:var(--gcw-spacing-2);margin-top:var(--gcw-spacing-2)}.gcw-source{display:inline-flex;align-items:center;gap:var(--gcw-spacing-1);padding:var(--gcw-spacing-1) var(--gcw-spacing-2);border-radius:var(--gcw-radius-full);background-color:var(--gcw-color-primary-light);color:var(--gcw-color-primary);font-size:var(--gcw-font-size-sm);text-decoration:none;transition:background-color var(--gcw-transition-fast)}.gcw-source:hover{background-color:#dbeafe}.gcw-source__icon{width:.75rem;height:.75rem}.gcw-typing{display:flex;justify-content:flex-start}.gcw-typing__bubble{background-color:var(--gcw-color-gray-100);padding:var(--gcw-spacing-3) var(--gcw-spacing-4);border-radius:var(--gcw-radius-2xl);border-bottom-left-radius:var(--gcw-radius-sm)}.gcw-typing__dots{display:flex;gap:var(--gcw-spacing-1)}.gcw-typing__dot{width:.5rem;height:.5rem;background-color:var(--gcw-color-gray-400);border-radius:var(--gcw-radius-full);animation:gcw-typing-bounce 1.4s infinite ease-in-out both}.gcw-typing__dot:nth-child(1){animation-delay:-.32s}.gcw-typing__dot:nth-child(2){animation-delay:-.16s}.gcw-input-area{padding:var(--gcw-spacing-3);border-top:1px solid var(--gcw-color-gray-200);background-color:var(--gcw-color-white);flex-shrink:0}.gcw-input-row{display:flex;align-items:flex-end;gap:var(--gcw-spacing-2)}.gcw-input{flex:1;min-height:44px;max-height:120px;padding:var(--gcw-spacing-2) var(--gcw-spacing-4);border:1px solid var(--gcw-color-gray-200);border-radius:var(--gcw-radius-xl);background-color:var(--gcw-color-white);color:var(--gcw-color-gray-800);font-family:var(--gcw-font-family);font-size:var(--gcw-font-size-base);font-weight:400;line-height:1.5;letter-spacing:normal;resize:none;outline:none;transition:border-color var(--gcw-transition-fast),box-shadow var(--gcw-transition-fast)}.gcw-input:focus{border-color:var(--gcw-color-primary);box-shadow:0 0 0 3px #3b82f61a}.gcw-input:disabled{background-color:var(--gcw-color-gray-50);cursor:not-allowed}.gcw-input::placeholder{color:var(--gcw-color-gray-400)}.gcw-send-btn{width:2.5rem;height:2.5rem;flex-shrink:0;border:none;border-radius:var(--gcw-radius-lg);color:var(--gcw-color-white);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:opacity var(--gcw-transition-fast),transform var(--gcw-transition-fast)}.gcw-send-btn:hover:not(:disabled){opacity:.9}.gcw-send-btn:active:not(:disabled){transform:scale(.95)}.gcw-send-btn:disabled{opacity:.5;cursor:not-allowed}.gcw-send-btn__icon{width:1.25rem;height:1.25rem}.gcw-input-hint{font-size:var(--gcw-font-size-xs);color:var(--gcw-color-gray-400);text-align:center;margin-top:var(--gcw-spacing-2)}@keyframes gcw-slide-up{0%{opacity:0;transform:translateY(1rem)}to{opacity:1;transform:translateY(0)}}@keyframes gcw-pulse{0%,to{opacity:1}50%{opacity:.5}}@keyframes gcw-typing-bounce{0%,80%,to{transform:scale(0)}40%{transform:scale(1)}}@keyframes gcw-spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.gcw-spin{animation:gcw-spin 1s linear infinite}.gcw-history{display:flex;flex-direction:column;flex:1;overflow:hidden;animation:gcw-slide-in-left var(--gcw-transition-base) ease-out}.gcw-history__header{display:flex;align-items:center;gap:var(--gcw-spacing-3);padding:var(--gcw-spacing-2) var(--gcw-spacing-3);color:var(--gcw-color-white);flex-shrink:0}.gcw-history__title{flex:1;font-size:var(--gcw-font-size-base);font-weight:600;margin:0}.gcw-history__list{flex:1;overflow-y:auto;padding:var(--gcw-spacing-2) 0}.gcw-history__list::-webkit-scrollbar{width:6px}.gcw-history__list::-webkit-scrollbar-track{background:transparent}.gcw-history__list::-webkit-scrollbar-thumb{background-color:var(--gcw-color-gray-300);border-radius:3px}.gcw-history__loading{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:var(--gcw-spacing-3);padding:var(--gcw-spacing-8);color:var(--gcw-color-gray-400);font-size:var(--gcw-font-size-sm)}.gcw-history__empty{display:flex;align-items:center;justify-content:center;padding:var(--gcw-spacing-8);color:var(--gcw-color-gray-400);font-size:var(--gcw-font-size-sm)}.gcw-history__item{display:flex;align-items:center;justify-content:space-between;gap:var(--gcw-spacing-2);width:100%;padding:var(--gcw-spacing-3) var(--gcw-spacing-4);border:none;border-left:3px solid transparent;background:none;cursor:pointer;text-align:left;transition:background-color var(--gcw-transition-fast);font-family:var(--gcw-font-family)}.gcw-history__item:hover{background-color:var(--gcw-color-gray-50)}.gcw-history__item--active{background-color:var(--gcw-color-primary-light)}.gcw-history__item-content{display:flex;flex-direction:column;gap:.125rem;min-width:0;flex:1}.gcw-history__item-title{font-size:var(--gcw-font-size-sm);font-weight:500;color:var(--gcw-color-gray-800);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.gcw-history__item-meta{font-size:var(--gcw-font-size-xs);color:var(--gcw-color-gray-400)}.gcw-history__item-delete{flex-shrink:0;width:1.75rem;height:1.75rem;border:none;border-radius:var(--gcw-radius-md);background:transparent;color:var(--gcw-color-gray-300);cursor:pointer;display:flex;align-items:center;justify-content:center;opacity:0;transition:opacity var(--gcw-transition-fast),color var(--gcw-transition-fast),background-color var(--gcw-transition-fast)}.gcw-history__item:hover .gcw-history__item-delete{opacity:1}.gcw-history__item-delete:hover{color:var(--gcw-color-error);background-color:#ef44441a}.gcw-history__item-delete-icon{width:.875rem;height:.875rem}@keyframes gcw-slide-in-left{0%{opacity:0;transform:translate(-1rem)}to{opacity:1;transform:translate(0)}}.gcw-modal-overlay{position:absolute;top:0;right:0;bottom:0;left:0;background:#0006;display:flex;align-items:center;justify-content:center;z-index:100;animation:gcw-fade-in .15s ease-out;border-radius:var(--gcw-radius-2xl)}.gcw-modal{background:#fff;border-radius:.75rem;padding:1.25rem;margin:1rem;max-width:20rem;width:100%;box-shadow:0 8px 24px #00000026;animation:gcw-scale-in .15s ease-out}.gcw-modal__title{font-size:.9375rem;font-weight:600;color:#1f2937;margin:0 0 .5rem}.gcw-modal__message{font-size:.8125rem;color:#6b7280;line-height:1.5;margin:0 0 1.25rem}.gcw-modal__actions{display:flex;gap:.5rem;justify-content:flex-end}.gcw-modal__btn{padding:.4375rem .875rem;border-radius:.375rem;font-size:.8125rem;font-weight:500;cursor:pointer;border:1px solid #e5e7eb;transition:background-color .15s,border-color .15s}.gcw-modal__btn--cancel{background:#fff;color:#374151}.gcw-modal__btn--cancel:hover{background:#f9fafb;border-color:#d1d5db}.gcw-modal__btn--confirm{background:#3b82f6;color:#fff;border-color:#3b82f6}.gcw-modal__btn--confirm:hover{background:#2563eb;border-color:#2563eb}.gcw-modal__btn--danger{background:#ef4444;border-color:#ef4444}.gcw-modal__btn--danger:hover{background:#dc2626;border-color:#dc2626}@keyframes gcw-fade-in{0%{opacity:0}to{opacity:1}}@keyframes gcw-scale-in{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}')),document.head.appendChild(r)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
|
|
2
|
-
(function(u,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(u=typeof globalThis<"u"?globalThis:u||self,e(u.GeoAppsChatWidget={},u.React,u.React))})(this,function(u,e,i){"use strict";function ne({authUrl:t,headers:n={}}){const[s,l]=i.useState(!t),[a,r]=i.useState(!!t),[o,g]=i.useState(null),[d,c]=i.useState(null),p=i.useRef(n);p.current=n;const w=i.useCallback(async N=>{if(!t)return!0;try{const m=await fetch(t,{method:"GET",headers:{Accept:"application/json",...p.current},credentials:"include",signal:N});if(m.ok){const f=await m.json(),v={id:f.Id??f.id??"",email:f.Email??f.email??"",fullName:f.FullName??f.fullName??"",roles:Array.isArray(f.Roles??f.roles)?(f.Roles??f.roles).map(h=>typeof h=="string"?h:h.name??""):[]};return g(v),l(!0),c(null),!0}return g(null),l(!1),c(m.status===401?"Niet ingelogd":"Geen toegang"),!1}catch(m){return m instanceof DOMException&&m.name==="AbortError"||(g(null),l(!1),c("Authenticatie verificatie mislukt")),!1}},[t]);i.useEffect(()=>{if(!t)return;const N=new AbortController;return(async()=>{r(!0),await w(N.signal),N.signal.aborted||r(!1)})(),()=>{N.abort()}},[t,w]);const C=i.useCallback(async()=>w(),[w]);return{isAuthenticated:s,isLoading:a,user:o,error:d,recheckAuth:C}}const Le="gcw_session_",Ee="gcw_popout_",Te="gcw_read_";function J(t){return`${Le}${t||"default"}`}function oe(t,n){try{const s=J(n);t?localStorage.setItem(s,t):localStorage.removeItem(s)}catch(s){console.warn("Failed to save session ID:",s)}}function re(t){try{return localStorage.getItem(J(t))}catch{return null}}function D(t){try{localStorage.removeItem(J(t)),localStorage.removeItem(Y(t))}catch(n){console.warn("Failed to clear session:",n)}}function ae(t,n){const s=J(t),l=a=>{a.key===s&&n(a.newValue)};return window.addEventListener("storage",l),()=>window.removeEventListener("storage",l)}function Z(t){return`${Ee}${t||"default"}`}function V(t,n){try{t?localStorage.setItem(Z(n),"true"):localStorage.removeItem(Z(n))}catch(s){console.warn("Failed to save popout state:",s)}}function ie(t){try{return localStorage.getItem(Z(t))==="true"}catch{return!1}}function Y(t){return`${Te}${t||"default"}`}function K(t,n){try{t>0?localStorage.setItem(Y(n),String(t)):localStorage.removeItem(Y(n))}catch(s){console.warn("Failed to save read state:",s)}}function le(t){try{const n=localStorage.getItem(Y(t));return n&&parseInt(n,10)||0}catch{return 0}}function ce(t){const{apiUrl:n,tenantId:s,sessionId:l,headers:a={},onError:r,persist:o=!0}=t,[g,d]=i.useState([]),[c,p]=i.useState(!1),[w,C]=i.useState(!1),[N,m]=i.useState(null),[f,v]=i.useState(()=>l||(o?re(s):null)),h=i.useRef(null),k=i.useRef(!1),b=i.useCallback(()=>n.replace(/\/chat\/?$/,""),[n]),j=i.useCallback(async y=>{C(!0);try{const _=b(),L=await fetch(`${_}/sessions/${y}`,{method:"GET",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...a}});if(L.status===500)return console.error("Server error while loading session, will retry later"),!1;if(L.status===401)return console.info("Unauthorized while loading session, clearing session"),o&&D(s),v(null),!1;if(L.status===404)return console.info("Session not found, starting fresh"),o&&D(s),v(null),!1;if(L.status===429)return console.info("Rate limited while loading session, will retry later"),!1;if(!L.ok)throw new Error(`Failed to load session: ${L.status}`);const E=(await L.json()).messages.map(z=>{var O;return{id:z.id,role:z.role,content:z.content,timestamp:new Date(z.timestamp),sources:(O=z.citations)==null?void 0:O.map(I=>({title:I.title,url:I.url,relevance:I.relevance_score}))}});return d(E),v(y),!0}catch(_){return console.error("Failed to load session:",_),o&&D(s),v(null),!1}finally{C(!1)}},[b,s,a,o]);i.useEffect(()=>{k.current||(k.current=!0,f&&j(f))},[]),i.useEffect(()=>{o&&oe(f,s)},[f,s,o]),i.useEffect(()=>o?ae(s,_=>{_&&_!==f?j(_):_||(d([]),v(null))}):void 0,[s,o,f,j]);const B=i.useCallback(async y=>{var L;if(!y.trim()||c)return;h.current&&h.current.abort(),h.current=new AbortController;const _={id:`temp_${Date.now()}`,role:"user",content:y.trim(),timestamp:new Date};d(M=>[...M,_]),p(!0),m(null);try{const M=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...a},body:JSON.stringify({message:y.trim(),session_id:f}),signal:h.current.signal});if(!M.ok){if(M.status===500){const T={id:`temp_${Date.now()}_servererror`,role:"assistant",content:"Er is een fout opgetreden bij het verwerken van je bericht. Probeer het later opnieuw.",timestamp:new Date};d(P=>[...P,T]);return}if(M.status===401){const T={id:`temp_${Date.now()}_unauthorized`,role:"assistant",content:"Je sessie is verlopen of je hebt geen toegang. Vernieuw de pagina om opnieuw te verbinden.",timestamp:new Date};d(P=>[...P,T]),o&&D(s),v(null);return}if(M.status===429){const T={id:`temp_${Date.now()}_ratelimit`,role:"assistant",content:"Je stuurt te veel berichten achter elkaar. Wacht even en probeer het dan opnieuw.",timestamp:new Date};d(P=>[...P,T]);return}const I=await M.json().catch(()=>({}));throw new Error(I.detail||`Request failed with status ${M.status}`)}const E=await M.json(),z=(L=E.message.citations)==null?void 0:L.map(I=>({title:I.title,url:I.url,relevance:I.relevance_score})),O={id:`temp_${Date.now()}_assistant`,role:"assistant",content:E.message.content,timestamp:new Date,sources:z};d(I=>[...I,O]),E.session_id&&v(E.session_id)}catch(M){if(M.name==="AbortError")return;const E=M instanceof Error?M:new Error("An error occurred");m(E),r==null||r(E)}finally{p(!1),h.current=null}},[n,s,f,a,c,r]),X=i.useCallback(()=>{d([]),v(null),m(null),k.current=!1,o&&D(s)},[o,s]),W=i.useCallback(async()=>{if(f)try{const y=b();await fetch(`${y}/sessions/${f}`,{method:"DELETE",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...a}})}catch(y){console.error("Failed to delete session:",y)}d([]),v(null),m(null),k.current=!1,o&&D(s)},[f,b,s,a,o]),A=i.useCallback(async y=>{try{const _=b();await fetch(`${_}/sessions/${y}`,{method:"DELETE",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...a}})}catch(_){console.error("Failed to delete session:",_)}y===f&&(d([]),v(null),m(null),k.current=!1,o&&D(s))},[b,s,a,f,o]),S=i.useCallback(()=>{d([]),v(null),m(null),k.current=!1,o&&D(s)},[o,s]),te=i.useCallback(async y=>{await j(y)},[j]),se=i.useCallback(async()=>{try{const y=b(),_=await fetch(`${y}/sessions`,{method:"GET",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...a}});return _.ok?await _.json():(console.error("Failed to list sessions:",_.status),[])}catch(y){return console.error("Failed to list sessions:",y),[]}},[b,s,a]);return{messages:g,isLoading:c,isLoadingSession:w,error:N,sendMessage:B,clearMessages:X,deleteSession:W,deleteSessionById:A,startNewSession:S,switchSession:te,listSessions:se,sessionId:f}}let U=null;function de(t,n,s){const[l,a]=i.useState(()=>ie(t.tenantId)),r=i.useRef(U);i.useEffect(()=>{if(l&&!r.current){const c=window.open("","GeoAppsChatPopout");c&&c.location.href!=="about:blank"&&!c.closed?(r.current=c,U=c):(a(!1),V(!1,t.tenantId))}},[l,t.tenantId]),i.useEffect(()=>{if(!r.current)return;const c=setInterval(()=>{var p;(p=r.current)!=null&&p.closed&&(a(!1),r.current=null,U=null,V(!1,t.tenantId),s==null||s())},500);return()=>clearInterval(c)},[t.tenantId,s]);const o=i.useCallback(()=>{if(r.current&&!r.current.closed){r.current.focus();return}const c={small:{width:380,height:520},medium:{width:440,height:660},large:{width:560,height:780},fullscreen:{width:700,height:800}},{width:p,height:w}=c[n],C=(window.screen.width-p)/2,N=(window.screen.height-w)/2,m=window.open("","GeoAppsChatPopout",`width=${p},height=${w},left=${C},top=${N},resizable=yes,scrollbars=no`);if(!m){console.error("Failed to open popup window. Check if popups are blocked.");return}m.__CHAT_CONFIG__=t,m.document.write(be(t)),m.document.close(),r.current=m,U=m,a(!0),V(!0,t.tenantId)},[t,n]),g=i.useCallback(()=>{r.current&&!r.current.closed&&r.current.close(),r.current=null,U=null,a(!1),V(!1,t.tenantId)},[t.tenantId]),d=i.useCallback(()=>{r.current&&!r.current.closed&&r.current.focus()},[]);return{isPoppedOut:l,openPopout:o,closePopout:g,focusPopout:d}}const $e=["bottom-right","bottom-left","top-right","top-left"];function je(t){return typeof t=="string"&&$e.includes(t)}function De(t){if(je(t))return{className:`gcw-container--${t}`,style:{}};const n=t,s={},l=["gcw-container--custom"];return n.top!=null&&(s.top=n.top),n.bottom!=null&&(s.bottom=n.bottom),n.left!=null&&(s.left=n.left),n.right!=null&&(s.right=n.right),n.top!=null&&n.bottom==null&&l.push("gcw-container--flow-down"),n.left!=null&&n.right==null&&l.push("gcw-container--align-left"),{className:l.join(" "),style:s}}function Ae({apiUrl:t,authUrl:n,tenantId:s,title:l="Chat Assistent",subtitle:a="Hoe kan ik je helpen?",placeholder:r="Typ een bericht...",greeting:o,primaryColor:g="#3b82f6",position:d="bottom-right",defaultOpen:c=!1,defaultSize:p="medium",headers:w,onOpen:C,onClose:N,onMessageSent:m,onResponseReceived:f}){const{isAuthenticated:v,isLoading:h,recheckAuth:k}=ne({authUrl:n,headers:w}),[b,j]=i.useState(c),[B,X]=i.useState(p),[W,A]=i.useState(!1),{messages:S,isLoading:te,isLoadingSession:se,sendMessage:y,deleteSession:_,deleteSessionById:L,startNewSession:M,switchSession:E,listSessions:z,sessionId:O}=ce({apiUrl:t,tenantId:s,headers:w}),[I,T]=i.useState(()=>S.length>0),[P,F]=i.useState([]);i.useEffect(()=>{b&&o&&!I&&S.length===0&&T(!0)},[b,o,I,S.length]),i.useEffect(()=>{S.length>0&&T(!0)},[S.length]),i.useEffect(()=>{I&&o&&S.length===0?F([{id:"greeting",role:"assistant",content:o,timestamp:new Date}]):o&&S.length>0?F([{id:"greeting",role:"assistant",content:o,timestamp:new Date},...S]):F(S)},[S,I,o]);const{isPoppedOut:G,openPopout:Ge,focusPopout:Ve}=de({apiUrl:t,tenantId:s,title:l,subtitle:a,placeholder:r,primaryColor:g,sessionId:O,messages:P,headers:w},B,()=>{});i.useEffect(()=>{const x=S.filter($=>$.role==="assistant").length;if(x===0){A(!1);return}if(b||G)K(x,s),A(!1);else{const $=le(s);A(x>$)}},[b,G,S,s]);const Ie=()=>{if(G){Ve();return}const x=!b;if(j(x),x){C==null||C();const $=S.filter(xe=>xe.role==="assistant").length;$>0&&K($,s),A(!1)}else N==null||N()},Ke=async x=>{if(n&&!await k()){F(Re=>[...Re,{id:`auth-error-${Date.now()}`,role:"assistant",content:"Je sessie is verlopen of je hebt geen toegang. Vernieuw de pagina om opnieuw te verbinden.",timestamp:new Date}]);return}m==null||m(x),await y(x);const $=S[S.length-1];($==null?void 0:$.role)==="assistant"&&(f==null||f($.content))},Ue=async()=>{await _(),T(!1),F([]),A(!1),K(0,s)},Xe=()=>{M(),T(!1),F([]),A(!1),K(0,s)},Je=async x=>{await E(x),T(!0)},Ye=x=>{X(x)},qe=()=>{j(!1),Ge()},{className:Ze,style:Qe}=De(d);return h||!v?null:e.jsxs("div",{className:`gcw-widget gcw-container ${Ze}`,style:Qe,children:[e.jsx(fe,{isOpen:b,onClick:Ie,primaryColor:g,hasUnread:W&&!b&&!G,isPoppedOut:G}),b&&!G&&e.jsx(ue,{title:l,subtitle:a,placeholder:r,messages:P,isLoading:te,isLoadingSession:se,onSendMessage:Ke,onClose:Ie,onClear:Ue,onSizeChange:Ye,onPopout:qe,onNewSession:Xe,onSelectSession:Je,onListSessions:z,onDeleteSession:L,currentSessionId:O,primaryColor:g,size:B})]})}const ze={small:"gcw-window--small",medium:"gcw-window--medium",large:"gcw-window--large",fullscreen:"gcw-window--fullscreen"};function ue({title:t,subtitle:n,placeholder:s,messages:l,isLoading:a,isLoadingSession:r=!1,onSendMessage:o,onClose:g,onClear:d,onSizeChange:c,onPopout:p,onNewSession:w,onSelectSession:C,onListSessions:N,onDeleteSession:m,currentSessionId:f,primaryColor:v,size:h}){const[k,b]=i.useState(!1),[j,B]=i.useState(!1),X=()=>{const W=["small","medium","large","fullscreen"],S=(W.indexOf(h)+1)%W.length;c(W[S])};return e.jsxs("div",{className:`gcw-window ${ze[h]}`,children:[e.jsxs("div",{className:"gcw-header",style:{backgroundColor:v},children:[e.jsxs("div",{className:"gcw-header__left",children:[e.jsx("div",{className:"gcw-header__avatar",children:e.jsx(Ce,{className:"gcw-header__avatar-icon"})}),e.jsxs("div",{className:"gcw-header__info",children:[e.jsx("h3",{className:"gcw-header__title",children:t}),e.jsx("p",{className:"gcw-header__subtitle",children:n})]})]}),e.jsxs("div",{className:"gcw-header__actions",children:[e.jsx(ye,{size:h,onCycleSize:X,onPopout:p,onClear:()=>B(!0),onNewSession:()=>{w(),b(!1)},onShowHistory:()=>b(!0)}),e.jsx("button",{onClick:g,className:"gcw-header__btn",title:"Sluiten",children:e.jsx(Se,{className:"gcw-header__btn-icon"})})]})]}),j&&e.jsx(Q,{title:"Chat verwijderen",message:"Weet je zeker dat je dit gesprek wilt verwijderen? Dit kan niet ongedaan worden gemaakt.",confirmLabel:"Verwijderen",cancelLabel:"Annuleren",variant:"danger",onConfirm:()=>{B(!1),d()},onCancel:()=>B(!1)}),k?e.jsx(me,{currentSessionId:f,onBack:()=>b(!1),onSelectSession:C,onNewSession:w,onListSessions:N,onDeleteSession:m,primaryColor:v}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{messages:l,isLoading:a,isLoadingSession:r,primaryColor:v}),e.jsx(pe,{placeholder:s,isLoading:a,onSendMessage:o,primaryColor:v})]})]})}function Be({className:t}){return e.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})})}function Pe(t){return t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function He(t,n){return t.length<=n?t:t.slice(0,n-3)+"..."}function he({message:t,primaryColor:n}){const s=t.role==="user",l=s?"user":"assistant";return e.jsx("div",{className:`gcw-bubble-row gcw-bubble-row--${l}`,children:e.jsxs("div",{className:`gcw-bubble-wrapper gcw-bubble-wrapper--${l}`,children:[e.jsx("div",{className:`gcw-bubble gcw-bubble--${l}`,style:s?{backgroundColor:n}:void 0,children:e.jsx(we,{content:t.content,className:"gcw-content"})}),t.sources&&t.sources.length>0&&e.jsx("div",{className:"gcw-sources",children:t.sources.slice(0,3).map((a,r)=>e.jsxs("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",className:"gcw-source",children:[e.jsx(Be,{className:"gcw-source__icon"}),He(a.title,25)]},r))}),e.jsx("span",{className:"gcw-bubble__timestamp",children:Pe(t.timestamp)})]})})}function ge({messages:t,isLoading:n,isLoadingSession:s=!1,primaryColor:l}){var r;const a=i.useRef(null);return i.useEffect(()=>{var o;(o=a.current)==null||o.scrollIntoView({behavior:"smooth"})},[t,n]),s?e.jsx("div",{className:"gcw-empty",children:e.jsxs("div",{className:"gcw-session-loading",children:[e.jsx("div",{className:"gcw-session-loading__spinner"}),e.jsx("p",{className:"gcw-empty__text",children:"Chatgeschiedenis laden..."})]})}):t.length===0&&!n?e.jsxs("div",{className:"gcw-empty",children:[e.jsx("svg",{className:"gcw-empty__icon",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),e.jsx("p",{className:"gcw-empty__text",children:"Begin een gesprek door hieronder een bericht te typen"})]}):e.jsxs("div",{className:"gcw-messages",children:[t.map(o=>e.jsx(he,{message:o,primaryColor:l},o.id)),n&&((r=t[t.length-1])==null?void 0:r.role)!=="assistant"&&e.jsx(ve,{}),e.jsx("div",{ref:a})]})}function pe({placeholder:t,isLoading:n,onSendMessage:s,primaryColor:l}){const[a,r]=i.useState(""),o=i.useRef(null);i.useEffect(()=>{const c=o.current;c&&(c.style.height="auto",c.style.height=`${Math.min(c.scrollHeight,120)}px`)},[a]);const g=()=>{a.trim()&&!n&&(s(a),r(""),o.current&&(o.current.style.height="auto"))},d=c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),g())};return e.jsxs("div",{className:"gcw-input-area",children:[e.jsxs("div",{className:"gcw-input-row",children:[e.jsx("textarea",{ref:o,value:a,onChange:c=>r(c.target.value),onKeyDown:d,placeholder:t,disabled:n,rows:1,className:"gcw-input"}),e.jsx("button",{onClick:g,disabled:!a.trim()||n,className:"gcw-send-btn",style:{backgroundColor:l},title:"Verstuur bericht",children:n?e.jsxs("svg",{className:"gcw-send-btn__icon gcw-spin",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{style:{opacity:.25},cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{style:{opacity:.75},fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}):e.jsx("svg",{className:"gcw-send-btn__icon",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})})]}),e.jsx("p",{className:"gcw-input-hint",children:"Druk op Enter om te verzenden, Shift+Enter voor een nieuwe regel"})]})}function fe({isOpen:t,onClick:n,primaryColor:s,hasUnread:l,isPoppedOut:a}){return e.jsxs("button",{onClick:n,className:"gcw-toggle",style:{backgroundColor:s},title:a?"Chat is open in een ander venster":t?"Sluit chat":"Open chat",children:[l&&!t&&e.jsx("span",{className:"gcw-toggle__badge gcw-toggle__badge--unread",children:"!"}),a&&e.jsx("span",{className:"gcw-toggle__badge gcw-toggle__badge--popout"}),e.jsx("div",{className:"gcw-toggle__icon",children:a?e.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}):t?e.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}):e.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})})]})}function We(t){const n=new Date(t),l=new Date().getTime()-n.getTime(),a=Math.floor(l/6e4),r=Math.floor(l/36e5),o=Math.floor(l/864e5);return a<1?"Zojuist":a<60?`${a} min geleden`:r<24?`${r} uur geleden`:o<7?`${o} ${o===1?"dag":"dagen"} geleden`:n.toLocaleDateString("nl-NL",{day:"numeric",month:"short"})}function me({currentSessionId:t,onBack:n,onSelectSession:s,onNewSession:l,onDeleteSession:a,onListSessions:r,primaryColor:o}){const[g,d]=i.useState([]),[c,p]=i.useState(!0),[w,C]=i.useState(null);i.useEffect(()=>{let h=!1;return p(!0),r().then(k=>{h||(d(k),p(!1))}),()=>{h=!0}},[r]);const N=h=>{s(h),n()},m=(h,k)=>{h.stopPropagation(),C(k)},f=async()=>{if(!w)return;const h=w;C(null),await a(h),d(k=>k.filter(b=>b.id!==h))},v=()=>{l(),n()};return e.jsxs("div",{className:"gcw-history",children:[e.jsxs("div",{className:"gcw-history__header",style:{backgroundColor:o},children:[e.jsx("button",{className:"gcw-header__btn",onClick:n,title:"Terug",children:e.jsx(Me,{className:"gcw-header__btn-icon"})}),e.jsx("h3",{className:"gcw-history__title",children:"Gesprekken"}),e.jsx("button",{className:"gcw-header__btn",onClick:v,title:"Nieuw gesprek",children:e.jsx(ee,{className:"gcw-header__btn-icon"})})]}),e.jsx("div",{className:"gcw-history__list",children:c?e.jsxs("div",{className:"gcw-history__loading",children:[e.jsx("div",{className:"gcw-session-loading__spinner"}),e.jsx("span",{children:"Gesprekken laden..."})]}):g.length===0?e.jsx("div",{className:"gcw-history__empty",children:e.jsx("p",{children:"Geen eerdere gesprekken"})}):g.map(h=>e.jsxs("div",{className:`gcw-history__item ${h.id===t?"gcw-history__item--active":""}`,onClick:()=>N(h.id),style:h.id===t?{borderLeftColor:o}:void 0,role:"button",tabIndex:0,onKeyDown:k=>{k.key==="Enter"&&N(h.id)},children:[e.jsxs("div",{className:"gcw-history__item-content",children:[e.jsx("span",{className:"gcw-history__item-title",children:h.title||"Naamloos gesprek"}),e.jsxs("span",{className:"gcw-history__item-meta",children:[h.message_count," ",h.message_count===1?"bericht":"berichten"," · ",We(h.updated_at)]})]}),e.jsx("button",{className:"gcw-history__item-delete",onClick:k=>m(k,h.id),title:"Verwijder gesprek",children:e.jsx(R,{className:"gcw-history__item-delete-icon"})})]},h.id))}),w&&e.jsx(Q,{title:"Gesprek verwijderen",message:"Weet je zeker dat je dit gesprek wilt verwijderen? Dit kan niet ongedaan worden gemaakt.",confirmLabel:"Verwijderen",cancelLabel:"Annuleren",variant:"danger",onConfirm:f,onCancel:()=>C(null)})]})}function Q({title:t,message:n,confirmLabel:s="Bevestigen",cancelLabel:l="Annuleren",onConfirm:a,onCancel:r,variant:o="default"}){const g=i.useRef(null),d=i.useRef(null);i.useEffect(()=>{var p;(p=d.current)==null||p.focus()},[]),i.useEffect(()=>{const p=w=>{w.key==="Escape"&&r()};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[r]);const c=p=>{p.target===g.current&&r()};return e.jsx("div",{className:"gcw-modal-overlay",ref:g,onClick:c,children:e.jsxs("div",{className:"gcw-modal",role:"dialog","aria-modal":"true","aria-labelledby":"gcw-modal-title",children:[e.jsx("h4",{className:"gcw-modal__title",id:"gcw-modal-title",children:t}),e.jsx("p",{className:"gcw-modal__message",children:n}),e.jsxs("div",{className:"gcw-modal__actions",children:[e.jsx("button",{className:"gcw-modal__btn gcw-modal__btn--cancel",onClick:r,children:l}),e.jsx("button",{className:`gcw-modal__btn gcw-modal__btn--confirm ${o==="danger"?"gcw-modal__btn--danger":""}`,onClick:a,ref:d,children:s})]})]})})}function we({content:t,className:n}){if(!t)return null;const s=Oe(t);return e.jsx("div",{className:n,children:s.map((l,a)=>e.jsx(i.Fragment,{children:l},a))})}function Oe(t){const n=t.split(`
|
|
3
|
-
`),s=[];let
|
|
4
|
-
`)})},`code-${s.length}`));continue}if(o.trim()===""){a();continue}a(),s.push(e.jsx("p",{className:"gcw-md-paragraph",children:
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var r=document.createElement("style");r.appendChild(document.createTextNode(':root{--gcw-color-white: #fff;--gcw-color-gray-50: #f9fafb;--gcw-color-gray-100: #f3f4f6;--gcw-color-gray-200: #e5e7eb;--gcw-color-gray-300: #d1d5db;--gcw-color-gray-400: #9ca3af;--gcw-color-gray-500: #6b7280;--gcw-color-gray-600: #4b5563;--gcw-color-gray-700: #374151;--gcw-color-gray-800: #1f2937;--gcw-color-gray-900: #111827;--gcw-color-primary: #3b82f6;--gcw-color-primary-hover: #2563eb;--gcw-color-primary-light: #eff6ff;--gcw-color-error: #ef4444;--gcw-color-success: #22c55e;--gcw-font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;--gcw-font-size-xs: .625rem;--gcw-font-size-sm: .75rem;--gcw-font-size-base: .875rem;--gcw-font-size-lg: 1rem;--gcw-spacing-1: .25rem;--gcw-spacing-2: .5rem;--gcw-spacing-3: .75rem;--gcw-spacing-4: 1rem;--gcw-spacing-6: 1.5rem;--gcw-spacing-8: 2rem;--gcw-spacing-10: 2.5rem;--gcw-spacing-12: 3rem;--gcw-spacing-16: 4rem;--gcw-spacing-20: 5rem;--gcw-radius-sm: .25rem;--gcw-radius-md: .5rem;--gcw-radius-lg: .75rem;--gcw-radius-xl: 1rem;--gcw-radius-2xl: 1.25rem;--gcw-radius-full: 9999px;--gcw-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / .05);--gcw-shadow-md: 0 4px 6px -1px rgb(0 0 0 / .1), 0 2px 4px -2px rgb(0 0 0 / .1);--gcw-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);--gcw-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1);--gcw-shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / .25);--gcw-transition-fast: .15s ease;--gcw-transition-base: .2s ease;--gcw-transition-slow: .3s ease;--gcw-z-widget: 9999}.gcw-widget,.gcw-widget *,.gcw-widget *:before,.gcw-widget *:after{box-sizing:border-box;margin:0;padding:0;font-family:var(--gcw-font-family);line-height:1.5}.gcw-widget{font-family:var(--gcw-font-family);font-size:var(--gcw-font-size-base);line-height:1.5;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;color:var(--gcw-color-gray-800);text-align:left;letter-spacing:normal;word-spacing:normal;text-transform:none;text-indent:0;text-shadow:none;font-weight:400;font-style:normal}.gcw-container{position:fixed;z-index:var(--gcw-z-widget);display:flex;gap:var(--gcw-spacing-4)}.gcw-container--bottom-right{right:var(--gcw-spacing-4);bottom:var(--gcw-spacing-4);flex-direction:column-reverse;align-items:flex-end}.gcw-container--bottom-left{left:var(--gcw-spacing-4);bottom:var(--gcw-spacing-4);flex-direction:column-reverse;align-items:flex-start}.gcw-container--top-right{right:var(--gcw-spacing-4);top:var(--gcw-spacing-4);flex-direction:column;align-items:flex-end}.gcw-container--top-left{left:var(--gcw-spacing-4);top:var(--gcw-spacing-4);flex-direction:column;align-items:flex-start}.gcw-container--custom{flex-direction:column-reverse;align-items:flex-end}.gcw-container--custom.gcw-container--align-left{align-items:flex-start}.gcw-container--custom.gcw-container--flow-down{flex-direction:column}.gcw-toggle{position:relative;width:3.5rem;height:3.5rem;border:none;border-radius:var(--gcw-radius-full);background-color:var(--gcw-color-primary);color:var(--gcw-color-white);cursor:pointer;display:flex;align-items:center;justify-content:center;box-shadow:var(--gcw-shadow-lg);transition:transform var(--gcw-transition-base),box-shadow var(--gcw-transition-base)}.gcw-toggle:hover{transform:scale(1.1);box-shadow:var(--gcw-shadow-xl)}.gcw-toggle:active{transform:scale(.95)}.gcw-toggle__icon{width:1.5rem;height:1.5rem;transition:transform var(--gcw-transition-slow)}.gcw-toggle__badge{position:absolute;top:-.25rem;right:-.25rem;width:1rem;height:1rem;border-radius:var(--gcw-radius-full);display:flex;align-items:center;justify-content:center;font-size:var(--gcw-font-size-xs);font-weight:700;animation:gcw-pulse 2s infinite}.gcw-toggle__badge--unread{background-color:var(--gcw-color-error);color:var(--gcw-color-white)}.gcw-toggle__badge--popout{background-color:var(--gcw-color-success)}.gcw-window{position:relative;display:flex;flex-direction:column;background-color:var(--gcw-color-white);border-radius:var(--gcw-radius-2xl);box-shadow:var(--gcw-shadow-2xl);border:1px solid var(--gcw-color-gray-200);overflow:hidden;animation:gcw-slide-up var(--gcw-transition-slow) ease-out}.gcw-window--small{width:365px;height:450px}.gcw-window--medium{width:380px;height:560px}.gcw-window--large{width:480px;height:680px}.gcw-window--fullscreen{width:calc(100vw - 2rem);height:calc(100vh - 6rem);max-width:56rem}.gcw-window{max-height:90vh;transition:width var(--gcw-transition-base),height var(--gcw-transition-base)}.gcw-header{display:flex;align-items:center;justify-content:space-between;padding:var(--gcw-spacing-3) var(--gcw-spacing-4);color:var(--gcw-color-white);flex-shrink:0}.gcw-header__left{display:flex;align-items:center;gap:var(--gcw-spacing-3)}.gcw-header__avatar{width:2.5rem;height:2.5rem;border-radius:var(--gcw-radius-full);background-color:#fff3;display:flex;align-items:center;justify-content:center}.gcw-header__avatar-icon{width:1.25rem;height:1.25rem}.gcw-header__info{display:flex;flex-direction:column;min-width:0;flex:1}.gcw-header__title{font-size:var(--gcw-font-size-base);font-weight:600;line-height:1.4;margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.gcw-header__subtitle{font-size:var(--gcw-font-size-sm);font-weight:400;line-height:1.4;opacity:.9;margin:0;word-wrap:break-word;overflow-wrap:break-word}.gcw-header__actions{display:flex;align-items:center;gap:.125rem}.gcw-header__btn{width:2rem;height:2rem;border:none;border-radius:var(--gcw-radius-full);background-color:transparent;color:inherit;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background-color var(--gcw-transition-fast)}.gcw-header__btn:hover{background-color:#fff3}.gcw-header__btn-icon{width:1rem;height:1rem}.gcw-header-menu{position:relative}.gcw-header-menu__dropdown{position:absolute;top:calc(100% + .25rem);right:0;min-width:12rem;background-color:var(--gcw-color-white);border-radius:var(--gcw-radius-lg);box-shadow:var(--gcw-shadow-xl);border:1px solid var(--gcw-color-gray-200);padding:var(--gcw-spacing-1) 0;z-index:10;animation:gcw-menu-appear var(--gcw-transition-fast) ease-out}.gcw-header-menu__item{display:flex;align-items:center;gap:var(--gcw-spacing-3);width:100%;padding:var(--gcw-spacing-2) var(--gcw-spacing-3);border:none;background:none;color:var(--gcw-color-gray-700);font-family:var(--gcw-font-family);font-size:var(--gcw-font-size-sm);cursor:pointer;transition:background-color var(--gcw-transition-fast);text-align:left;white-space:nowrap;text-transform:none}.gcw-header-menu__item:hover{background-color:var(--gcw-color-gray-100)}.gcw-header-menu__item--danger{color:var(--gcw-color-error)}.gcw-header-menu__item--danger:hover{background-color:#fef2f2}.gcw-header-menu__icon{width:1rem;height:1rem;flex-shrink:0}.gcw-header-menu__divider{height:1px;background-color:var(--gcw-color-gray-200);margin:var(--gcw-spacing-1) 0}@keyframes gcw-menu-appear{0%{opacity:0;transform:translateY(-.25rem)}to{opacity:1;transform:translateY(0)}}.gcw-messages{flex:1;overflow-y:auto;padding:var(--gcw-spacing-4);display:flex;flex-direction:column;gap:var(--gcw-spacing-4)}.gcw-messages::-webkit-scrollbar{width:6px}.gcw-messages::-webkit-scrollbar-track{background:transparent}.gcw-messages::-webkit-scrollbar-thumb{background-color:var(--gcw-color-gray-300);border-radius:3px}.gcw-messages::-webkit-scrollbar-thumb:hover{background-color:var(--gcw-color-gray-400)}.gcw-empty{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;padding:var(--gcw-spacing-6);color:var(--gcw-color-gray-400);text-align:center}.gcw-empty__icon{width:4rem;height:4rem;margin-bottom:var(--gcw-spacing-4);opacity:.5}.gcw-empty__text{font-size:var(--gcw-font-size-base);font-weight:400;line-height:1.5;margin:0}.gcw-session-loading{display:flex;flex-direction:column;align-items:center;gap:var(--gcw-spacing-3)}.gcw-session-loading__spinner{width:2rem;height:2rem;border:3px solid var(--gcw-color-gray-200);border-top-color:var(--gcw-color-primary);border-radius:50%;animation:gcw-spin .8s linear infinite}.gcw-bubble-row{display:flex}.gcw-bubble-row--user{justify-content:flex-end}.gcw-bubble-row--assistant{justify-content:flex-start}.gcw-bubble-wrapper{max-width:85%;display:flex;flex-direction:column}.gcw-bubble-wrapper--user{align-items:flex-end}.gcw-bubble-wrapper--assistant{align-items:flex-start}.gcw-bubble{padding:var(--gcw-spacing-2) var(--gcw-spacing-4);border-radius:var(--gcw-radius-2xl);font-size:var(--gcw-font-size-base);font-weight:400;line-height:1.6;letter-spacing:normal;word-wrap:break-word}.gcw-bubble--user{color:var(--gcw-color-white);border-bottom-right-radius:var(--gcw-radius-sm)}.gcw-bubble--assistant{background-color:var(--gcw-color-gray-100);color:var(--gcw-color-gray-800);border-bottom-left-radius:var(--gcw-radius-sm)}.gcw-bubble__timestamp{font-size:var(--gcw-font-size-xs);color:var(--gcw-color-gray-400);margin-top:var(--gcw-spacing-1);padding:0 var(--gcw-spacing-1)}.gcw-content p{margin-bottom:var(--gcw-spacing-2)}.gcw-content p:last-child{margin-bottom:0}.gcw-content strong{font-weight:600}.gcw-content em{font-style:italic}.gcw-content ul,.gcw-content ol{margin:var(--gcw-spacing-2) 0;padding-left:var(--gcw-spacing-6)}.gcw-content li{margin-bottom:var(--gcw-spacing-1)}.gcw-content code{background-color:#0000001a;padding:.125rem .375rem;border-radius:var(--gcw-radius-sm);font-size:.875em;font-family:SF Mono,Monaco,Consolas,monospace}.gcw-bubble--user .gcw-content code{background-color:#fff3}.gcw-content pre{background-color:var(--gcw-color-gray-800);color:var(--gcw-color-gray-100);padding:var(--gcw-spacing-3);border-radius:var(--gcw-radius-md);overflow-x:auto;margin:var(--gcw-spacing-2) 0}.gcw-content pre code{background-color:transparent;padding:0;font-size:var(--gcw-font-size-sm)}.gcw-content a{color:var(--gcw-color-primary);text-decoration:underline}.gcw-content a:hover{color:var(--gcw-color-primary-hover)}.gcw-bubble--user .gcw-content a{color:#ffffffe6}.gcw-md-heading{font-weight:600;margin-top:var(--gcw-spacing-3);margin-bottom:var(--gcw-spacing-1)}.gcw-md-heading--h2{font-size:var(--gcw-font-size-lg);font-weight:700}.gcw-md-heading--h3,.gcw-md-heading--h4{font-size:var(--gcw-font-size-base)}.gcw-md-heading--h5{font-size:var(--gcw-font-size-sm)}.gcw-md-paragraph{margin-bottom:var(--gcw-spacing-2)}.gcw-md-paragraph:last-child{margin-bottom:0}.gcw-md-list{margin:var(--gcw-spacing-2) 0;padding-left:var(--gcw-spacing-4)}.gcw-md-list--ul{list-style-type:disc}.gcw-md-list--ol{list-style-type:decimal}.gcw-md-list__item{font-size:var(--gcw-font-size-base);margin-bottom:var(--gcw-spacing-1)}.gcw-md-bold{font-weight:600}.gcw-md-italic{font-style:italic}.gcw-md-code{background-color:var(--gcw-color-gray-200);padding:.125rem var(--gcw-spacing-2);border-radius:var(--gcw-radius-sm);font-size:var(--gcw-font-size-sm);font-family:SF Mono,Monaco,Consolas,monospace}.gcw-bubble--user .gcw-md-code{background-color:#fff3}.gcw-md-code-block{background-color:var(--gcw-color-gray-800);color:var(--gcw-color-gray-100);padding:var(--gcw-spacing-3);border-radius:var(--gcw-radius-lg);font-size:var(--gcw-font-size-sm);overflow-x:auto;margin:var(--gcw-spacing-2) 0}.gcw-md-code-block code{font-family:SF Mono,Monaco,Consolas,monospace}.gcw-md-link{color:var(--gcw-color-primary);text-decoration:underline}.gcw-md-link:hover{color:var(--gcw-color-primary-hover)}.gcw-bubble--user .gcw-md-link{color:#ffffffe6}.gcw-sources{display:flex;flex-wrap:wrap;gap:var(--gcw-spacing-2);margin-top:var(--gcw-spacing-2)}.gcw-source{display:inline-flex;align-items:center;gap:var(--gcw-spacing-1);padding:var(--gcw-spacing-1) var(--gcw-spacing-2);border-radius:var(--gcw-radius-full);background-color:var(--gcw-color-primary-light);color:var(--gcw-color-primary);font-size:var(--gcw-font-size-sm);text-decoration:none;transition:background-color var(--gcw-transition-fast)}.gcw-source:hover{background-color:#dbeafe}.gcw-source__icon{width:.75rem;height:.75rem}.gcw-typing{display:flex;justify-content:flex-start}.gcw-typing__bubble{background-color:var(--gcw-color-gray-100);padding:var(--gcw-spacing-3) var(--gcw-spacing-4);border-radius:var(--gcw-radius-2xl);border-bottom-left-radius:var(--gcw-radius-sm)}.gcw-typing__dots{display:flex;gap:var(--gcw-spacing-1)}.gcw-typing__dot{width:.5rem;height:.5rem;background-color:var(--gcw-color-gray-400);border-radius:var(--gcw-radius-full);animation:gcw-typing-bounce 1.4s infinite ease-in-out both}.gcw-typing__dot:nth-child(1){animation-delay:-.32s}.gcw-typing__dot:nth-child(2){animation-delay:-.16s}.gcw-input-area{padding:var(--gcw-spacing-3);border-top:1px solid var(--gcw-color-gray-200);background-color:var(--gcw-color-white);flex-shrink:0}.gcw-input-row{display:flex;align-items:flex-end;gap:var(--gcw-spacing-2)}.gcw-input{flex:1;min-height:44px;max-height:120px;padding:var(--gcw-spacing-2) var(--gcw-spacing-4);border:1px solid var(--gcw-color-gray-200);border-radius:var(--gcw-radius-xl);background-color:var(--gcw-color-white);color:var(--gcw-color-gray-800);font-family:var(--gcw-font-family);font-size:var(--gcw-font-size-base);font-weight:400;line-height:1.5;letter-spacing:normal;resize:none;outline:none;transition:border-color var(--gcw-transition-fast),box-shadow var(--gcw-transition-fast)}.gcw-input:focus{border-color:var(--gcw-color-primary);box-shadow:0 0 0 3px #3b82f61a}.gcw-input:disabled{background-color:var(--gcw-color-gray-50);cursor:not-allowed}.gcw-input::placeholder{color:var(--gcw-color-gray-400)}.gcw-send-btn{width:2.5rem;height:2.5rem;flex-shrink:0;border:none;border-radius:var(--gcw-radius-lg);color:var(--gcw-color-white);cursor:pointer;display:flex;align-items:center;justify-content:center;transition:opacity var(--gcw-transition-fast),transform var(--gcw-transition-fast)}.gcw-send-btn:hover:not(:disabled){opacity:.9}.gcw-send-btn:active:not(:disabled){transform:scale(.95)}.gcw-send-btn:disabled{opacity:.5;cursor:not-allowed}.gcw-send-btn__icon{width:1.25rem;height:1.25rem}.gcw-input-hint{font-size:var(--gcw-font-size-xs);color:var(--gcw-color-gray-400);text-align:center;margin-top:var(--gcw-spacing-2)}@keyframes gcw-slide-up{0%{opacity:0;transform:translateY(1rem)}to{opacity:1;transform:translateY(0)}}@keyframes gcw-pulse{0%,to{opacity:1}50%{opacity:.5}}@keyframes gcw-typing-bounce{0%,80%,to{transform:scale(0)}40%{transform:scale(1)}}@keyframes gcw-spin{0%{transform:rotate(0)}to{transform:rotate(360deg)}}.gcw-spin{animation:gcw-spin 1s linear infinite}.gcw-history{display:flex;flex-direction:column;flex:1;overflow:hidden;animation:gcw-slide-in-left var(--gcw-transition-base) ease-out}.gcw-history__header{display:flex;align-items:center;gap:var(--gcw-spacing-3);padding:var(--gcw-spacing-2) var(--gcw-spacing-3);color:var(--gcw-color-white);flex-shrink:0}.gcw-history__title{flex:1;font-size:var(--gcw-font-size-base);font-weight:600;margin:0}.gcw-history__list{flex:1;overflow-y:auto;padding:var(--gcw-spacing-2) 0}.gcw-history__list::-webkit-scrollbar{width:6px}.gcw-history__list::-webkit-scrollbar-track{background:transparent}.gcw-history__list::-webkit-scrollbar-thumb{background-color:var(--gcw-color-gray-300);border-radius:3px}.gcw-history__loading{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:var(--gcw-spacing-3);padding:var(--gcw-spacing-8);color:var(--gcw-color-gray-400);font-size:var(--gcw-font-size-sm)}.gcw-history__empty{display:flex;align-items:center;justify-content:center;padding:var(--gcw-spacing-8);color:var(--gcw-color-gray-400);font-size:var(--gcw-font-size-sm)}.gcw-history__item{display:flex;align-items:center;justify-content:space-between;gap:var(--gcw-spacing-2);width:100%;padding:var(--gcw-spacing-3) var(--gcw-spacing-4);border:none;border-left:3px solid transparent;background:none;cursor:pointer;text-align:left;transition:background-color var(--gcw-transition-fast);font-family:var(--gcw-font-family)}.gcw-history__item:hover{background-color:var(--gcw-color-gray-50)}.gcw-history__item--active{background-color:var(--gcw-color-primary-light)}.gcw-history__item-content{display:flex;flex-direction:column;gap:.125rem;min-width:0;flex:1}.gcw-history__item-title{font-size:var(--gcw-font-size-sm);font-weight:500;color:var(--gcw-color-gray-800);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.gcw-history__item-meta{font-size:var(--gcw-font-size-xs);color:var(--gcw-color-gray-400)}.gcw-history__item-delete{flex-shrink:0;width:1.75rem;height:1.75rem;border:none;border-radius:var(--gcw-radius-md);background:transparent;color:var(--gcw-color-gray-300);cursor:pointer;display:flex;align-items:center;justify-content:center;opacity:0;transition:opacity var(--gcw-transition-fast),color var(--gcw-transition-fast),background-color var(--gcw-transition-fast)}.gcw-history__item:hover .gcw-history__item-delete{opacity:1}.gcw-history__item-delete:hover{color:var(--gcw-color-error);background-color:#ef44441a}.gcw-history__item-delete-icon{width:.875rem;height:.875rem}@keyframes gcw-slide-in-left{0%{opacity:0;transform:translate(-1rem)}to{opacity:1;transform:translate(0)}}.gcw-modal-overlay{position:absolute;top:0;right:0;bottom:0;left:0;background:#0006;display:flex;align-items:center;justify-content:center;z-index:100;animation:gcw-fade-in .15s ease-out;border-radius:var(--gcw-radius-2xl)}.gcw-modal{background:#fff;border-radius:.75rem;padding:1.25rem;margin:1rem;max-width:20rem;width:100%;box-shadow:0 8px 24px #00000026;animation:gcw-scale-in .15s ease-out}.gcw-modal__title{font-size:.9375rem;font-weight:600;color:#1f2937;margin:0 0 .5rem}.gcw-modal__message{font-size:.8125rem;color:#6b7280;line-height:1.5;margin:0 0 1.25rem}.gcw-modal__actions{display:flex;gap:.5rem;justify-content:flex-end}.gcw-modal__btn{padding:.4375rem .875rem;border-radius:.375rem;font-size:.8125rem;font-weight:500;cursor:pointer;border:1px solid #e5e7eb;transition:background-color .15s,border-color .15s;text-transform:none}.gcw-modal__btn--cancel{background:#fff;color:#374151}.gcw-modal__btn--cancel:hover{background:#f9fafb;border-color:#d1d5db}.gcw-modal__btn--confirm{background:#3b82f6;color:#fff;border-color:#3b82f6}.gcw-modal__btn--confirm:hover{background:#2563eb;border-color:#2563eb}.gcw-modal__btn--danger{background:#ef4444;border-color:#ef4444}.gcw-modal__btn--danger:hover{background:#dc2626;border-color:#dc2626}@keyframes gcw-fade-in{0%{opacity:0}to{opacity:1}}@keyframes gcw-scale-in{0%{opacity:0;transform:scale(.95)}to{opacity:1;transform:scale(1)}}')),document.head.appendChild(r)}}catch(o){console.error("vite-plugin-css-injected-by-js",o)}})();
|
|
2
|
+
(function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.GeoAppsChatWidget={},c.React,c.React))})(this,function(c,e,l){"use strict";const Te="gcw_session_",$e="gcw_popout_",je="gcw_read_";function X(t){return`${Te}${t||"default"}`}function re(t,n){try{const s=X(n);t?localStorage.setItem(s,t):localStorage.removeItem(s)}catch(s){console.warn("Failed to save session ID:",s)}}function ae(t){try{return localStorage.getItem(X(t))}catch{return null}}function D(t){try{localStorage.removeItem(X(t)),localStorage.removeItem(Y(t))}catch(n){console.warn("Failed to clear session:",n)}}function ie(t,n){const s=X(t),i=a=>{a.key===s&&n(a.newValue)};return window.addEventListener("storage",i),()=>window.removeEventListener("storage",i)}function Q(t){return`${$e}${t||"default"}`}function V(t,n){try{t?localStorage.setItem(Q(n),"true"):localStorage.removeItem(Q(n))}catch(s){console.warn("Failed to save popout state:",s)}}function le(t){try{return localStorage.getItem(Q(t))==="true"}catch{return!1}}function Y(t){return`${je}${t||"default"}`}function U(t,n){try{t>0?localStorage.setItem(Y(n),String(t)):localStorage.removeItem(Y(n))}catch(s){console.warn("Failed to save read state:",s)}}function ce(t){try{const n=localStorage.getItem(Y(t));return n&&parseInt(n,10)||0}catch{return 0}}function P(t){if(!t)return{};try{const n=sessionStorage.getItem(t);if(!n)return{};const s=JSON.parse(n);if(s!=null&&s.access_token)return{Authorization:`Bearer ${s.access_token}`}}catch{}return{}}const R=new Map;function De(t){return{id:t.Id??t.id??"",email:t.Email??t.email??"",fullName:t.FullName??t.fullName??"",roles:Array.isArray(t.Roles??t.roles)?(t.Roles??t.roles).map(n=>typeof n=="string"?n:n.name??""):[]}}function Ae(t,n){const s=R.get(t);if(s)return s;const i=(async()=>{try{const a=await fetch(t,{method:"GET",headers:{Accept:"application/json",...P(n)}});if(a.ok){const r=await a.json();return{ok:!0,user:De(r),error:null}}return{ok:!1,user:null,error:a.status===401?"Niet ingelogd":"Geen toegang"}}catch{return{ok:!1,user:null,error:"Authenticatie verificatie mislukt"}}})();return R.set(t,i),i.finally(()=>R.delete(t)),i}function de({authUrl:t,tokenStorageKey:n}){const[s,i]=l.useState(!t),[a,r]=l.useState(!!t),[o,g]=l.useState(null),[d,u]=l.useState(null),h=l.useCallback(b=>{g(b.user),i(b.ok),u(b.error)},[]),f=l.useCallback(async()=>{if(!t)return!0;const b=await Ae(t,n);return h(b),b.ok},[t,n,h]);l.useEffect(()=>{if(!t)return;let b=!1;return(async()=>{r(!0),await f(),b||r(!1)})(),()=>{b=!0}},[t,f]);const N=l.useCallback(async()=>f(),[f]);return{isAuthenticated:s,isLoading:a,user:o,error:d,recheckAuth:N}}function ue(t){const{apiUrl:n,tenantId:s,sessionId:i,tokenStorageKey:a,onError:r,persist:o=!0}=t,[g,d]=l.useState([]),[u,h]=l.useState(!1),[f,N]=l.useState(!1),[b,m]=l.useState(null),[y,k]=l.useState(()=>i||(o?ae(s):null)),p=l.useRef(null),_=l.useRef(!1),w=l.useCallback(()=>n.replace(/\/chat\/?$/,""),[n]),j=l.useCallback(async v=>{N(!0);try{const S=w(),x=await fetch(`${S}/sessions/${v}`,{method:"GET",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...P(a)}});if(x.status===500)return console.error("Server error while loading session, will retry later"),!1;if(x.status===401)return console.info("Unauthorized while loading session, clearing session"),o&&D(s),k(null),!1;if(x.status===404)return console.info("Session not found, starting fresh"),o&&D(s),k(null),!1;if(x.status===429)return console.info("Rate limited while loading session, will retry later"),!1;if(!x.ok)throw new Error(`Failed to load session: ${x.status}`);const E=(await x.json()).messages.map(z=>{var F;return{id:z.id,role:z.role,content:z.content,timestamp:new Date(z.timestamp),sources:(F=z.citations)==null?void 0:F.map(I=>({title:I.title,url:I.url,relevance:I.relevance_score}))}});return d(E),k(v),!0}catch(S){return console.error("Failed to load session:",S),o&&D(s),k(null),!1}finally{N(!1)}},[w,s,o]);l.useEffect(()=>{_.current||(_.current=!0,y&&j(y))},[]),l.useEffect(()=>{o&&re(y,s)},[y,s,o]),l.useEffect(()=>o?ie(s,S=>{S&&S!==y?j(S):S||(d([]),k(null))}):void 0,[s,o,y,j]);const B=l.useCallback(async v=>{var x;if(!v.trim()||u)return;p.current&&p.current.abort(),p.current=new AbortController;const S={id:`temp_${Date.now()}`,role:"user",content:v.trim(),timestamp:new Date};d(M=>[...M,S]),h(!0),m(null);try{const M=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...P(a)},body:JSON.stringify({message:v.trim(),session_id:y}),signal:p.current.signal});if(!M.ok){if(M.status===500){const T={id:`temp_${Date.now()}_servererror`,role:"assistant",content:"Er is een fout opgetreden bij het verwerken van je bericht. Probeer het later opnieuw.",timestamp:new Date};d(H=>[...H,T]);return}if(M.status===401){const T={id:`temp_${Date.now()}_unauthorized`,role:"assistant",content:"Je sessie is verlopen of je hebt geen toegang. Vernieuw de pagina om opnieuw te verbinden.",timestamp:new Date};d(H=>[...H,T]),o&&D(s),k(null);return}if(M.status===429){const T={id:`temp_${Date.now()}_ratelimit`,role:"assistant",content:"Je stuurt te veel berichten achter elkaar. Wacht even en probeer het dan opnieuw.",timestamp:new Date};d(H=>[...H,T]);return}const I=await M.json().catch(()=>({}));throw new Error(I.detail||`Request failed with status ${M.status}`)}const E=await M.json(),z=(x=E.message.citations)==null?void 0:x.map(I=>({title:I.title,url:I.url,relevance:I.relevance_score})),F={id:`temp_${Date.now()}_assistant`,role:"assistant",content:E.message.content,timestamp:new Date,sources:z};d(I=>[...I,F]),E.session_id&&k(E.session_id)}catch(M){if(M.name==="AbortError")return;const E=M instanceof Error?M:new Error("An error occurred");m(E),r==null||r(E)}finally{h(!1),p.current=null}},[n,s,y,u,r]),J=l.useCallback(()=>{d([]),k(null),m(null),_.current=!1,o&&D(s)},[o,s]),O=l.useCallback(async()=>{if(y)try{const v=w();await fetch(`${v}/sessions/${y}`,{method:"DELETE",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...P(a)}})}catch(v){console.error("Failed to delete session:",v)}d([]),k(null),m(null),_.current=!1,o&&D(s)},[y,w,s,o]),A=l.useCallback(async v=>{try{const S=w();await fetch(`${S}/sessions/${v}`,{method:"DELETE",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...P(a)}})}catch(S){console.error("Failed to delete session:",S)}v===y&&(d([]),k(null),m(null),_.current=!1,o&&D(s))},[w,s,y,o]),C=l.useCallback(()=>{d([]),k(null),m(null),_.current=!1,o&&D(s)},[o,s]),ne=l.useCallback(async v=>{await j(v)},[j]),oe=l.useCallback(async()=>{try{const v=w(),S=await fetch(`${v}/sessions`,{method:"GET",headers:{"Content-Type":"application/json",...s&&{"X-Tenant-ID":s},...P(a)}});return S.ok?await S.json():(console.error("Failed to list sessions:",S.status),[])}catch(v){return console.error("Failed to list sessions:",v),[]}},[w,s]);return{messages:g,isLoading:u,isLoadingSession:f,error:b,sendMessage:B,clearMessages:J,deleteSession:O,deleteSessionById:A,startNewSession:C,switchSession:ne,listSessions:oe,sessionId:y}}let q=null;function he(t,n,s){const[i,a]=l.useState(()=>le(t.tenantId)),r=l.useRef(q);l.useEffect(()=>{i&&!r.current&&(a(!1),V(!1,t.tenantId))},[i,t.tenantId]),l.useEffect(()=>{if(!r.current)return;const u=setInterval(()=>{var h;(h=r.current)!=null&&h.closed&&(a(!1),r.current=null,q=null,V(!1,t.tenantId),s==null||s())},500);return()=>clearInterval(u)},[i,t.tenantId,s]);const o=l.useCallback(()=>{if(r.current&&!r.current.closed){r.current.focus();return}const u={small:{width:380,height:520},medium:{width:440,height:660},large:{width:560,height:780},fullscreen:{width:700,height:800}},{width:h,height:f}=u[n],N=(window.screen.width-h)/2,b=(window.screen.height-f)/2,m=window.open("","GeoAppsChatPopout",`width=${h},height=${f},left=${N},top=${b},resizable=yes,scrollbars=no`);if(!m){console.error("Failed to open popup window. Check if popups are blocked.");return}m.__CHAT_CONFIG__=t,m.document.open(),m.document.write(ve(t)),m.document.close(),r.current=m,q=m,a(!0),V(!0,t.tenantId)},[t,n]),g=l.useCallback(()=>{r.current&&!r.current.closed&&r.current.close(),r.current=null,q=null,a(!1),V(!1,t.tenantId)},[t.tenantId]),d=l.useCallback(()=>{r.current&&!r.current.closed&&r.current.focus()},[]);return{isPoppedOut:i,openPopout:o,closePopout:g,focusPopout:d}}const ze=["bottom-right","bottom-left","top-right","top-left"];function Be(t){return typeof t=="string"&&ze.includes(t)}function He(t){if(Be(t))return{className:`gcw-container--${t}`,style:{}};const n=t,s={},i=["gcw-container--custom"];return n.top!=null&&(s.top=n.top),n.bottom!=null&&(s.bottom=n.bottom),n.left!=null&&(s.left=n.left),n.right!=null&&(s.right=n.right),n.top!=null&&n.bottom==null&&i.push("gcw-container--flow-down"),n.left!=null&&n.right==null&&i.push("gcw-container--align-left"),{className:i.join(" "),style:s}}function Pe({apiUrl:t,authUrl:n,tenantId:s,title:i="Chat Assistent",subtitle:a="Hoe kan ik je helpen?",placeholder:r="Typ een bericht...",greeting:o,primaryColor:g="#3b82f6",position:d="bottom-right",defaultOpen:u=!1,defaultSize:h="medium",tokenStorageKey:f="geoapps-token",onOpen:N,onClose:b,onMessageSent:m,onResponseReceived:y}){const{isAuthenticated:k,isLoading:p,recheckAuth:_}=de({authUrl:n,tokenStorageKey:f}),[w,j]=l.useState(u),[B,J]=l.useState(h),[O,A]=l.useState(!1),{messages:C,isLoading:ne,isLoadingSession:oe,sendMessage:v,deleteSession:S,deleteSessionById:x,startNewSession:M,switchSession:E,listSessions:z,sessionId:F}=ue({apiUrl:t,tenantId:s,tokenStorageKey:f}),[I,T]=l.useState(()=>C.length>0),[H,G]=l.useState([]);l.useEffect(()=>{w&&o&&!I&&C.length===0&&T(!0)},[w,o,I,C.length]),l.useEffect(()=>{C.length>0&&T(!0)},[C.length]),l.useEffect(()=>{I&&o&&C.length===0?G([{id:"greeting",role:"assistant",content:o,timestamp:new Date}]):o&&C.length>0?G([{id:"greeting",role:"assistant",content:o,timestamp:new Date},...C]):G(C)},[C,I,o]);const{isPoppedOut:K,openPopout:Je,focusPopout:Xe}=he({apiUrl:t,tenantId:s,title:i,subtitle:a,placeholder:r,primaryColor:g,sessionId:F,messages:H,tokenStorageKey:f},B,()=>{});l.useEffect(()=>{const L=C.filter($=>$.role==="assistant").length;if(L===0){A(!1);return}if(w||K)U(L,s),A(!1);else{const $=ce(s);A(L>$)}},[w,K,C,s]);const xe=()=>{if(K){Xe();return}const L=!w;if(j(L),L){N==null||N();const $=C.filter(Ee=>Ee.role==="assistant").length;$>0&&U($,s),A(!1)}else b==null||b()},Ye=async L=>{if(n&&!await _()){G(nt=>[...nt,{id:`auth-error-${Date.now()}`,role:"assistant",content:"Je sessie is verlopen of je hebt geen toegang. Vernieuw de pagina om opnieuw te verbinden.",timestamp:new Date}]);return}m==null||m(L),await v(L);const $=C[C.length-1];($==null?void 0:$.role)==="assistant"&&(y==null||y($.content))},qe=async()=>{await S(),T(!1),G([]),A(!1),U(0,s)},Ze=()=>{M(),T(!1),G([]),A(!1),U(0,s)},Qe=async L=>{await E(L),T(!0)},Re=L=>{J(L)},et=()=>{j(!1),Je()},{className:tt,style:st}=He(d);return p||!k?null:e.jsxs("div",{className:`gcw-widget gcw-container ${tt}`,style:st,children:[e.jsx(we,{isOpen:w,onClick:xe,primaryColor:g,hasUnread:O&&!w&&!K,isPoppedOut:K}),w&&!K&&e.jsx(ge,{title:i,subtitle:a,placeholder:r,messages:H,isLoading:ne,isLoadingSession:oe,onSendMessage:Ye,onClose:xe,onClear:qe,onSizeChange:Re,onPopout:et,onNewSession:Ze,onSelectSession:Qe,onListSessions:z,onDeleteSession:x,currentSessionId:F,primaryColor:g,size:B})]})}const We={small:"gcw-window--small",medium:"gcw-window--medium",large:"gcw-window--large",fullscreen:"gcw-window--fullscreen"};function ge({title:t,subtitle:n,placeholder:s,messages:i,isLoading:a,isLoadingSession:r=!1,onSendMessage:o,onClose:g,onClear:d,onSizeChange:u,onPopout:h,onNewSession:f,onSelectSession:N,onListSessions:b,onDeleteSession:m,currentSessionId:y,primaryColor:k,size:p}){const[_,w]=l.useState(!1),[j,B]=l.useState(!1),J=()=>{const O=["small","medium","large","fullscreen"],C=(O.indexOf(p)+1)%O.length;u(O[C])};return e.jsxs("div",{className:`gcw-window ${We[p]}`,children:[e.jsxs("div",{className:"gcw-header",style:{backgroundColor:k},children:[e.jsxs("div",{className:"gcw-header__left",children:[e.jsx("div",{className:"gcw-header__avatar",children:e.jsx(Me,{className:"gcw-header__avatar-icon"})}),e.jsxs("div",{className:"gcw-header__info",children:[e.jsx("h3",{className:"gcw-header__title",children:t}),e.jsx("p",{className:"gcw-header__subtitle",children:n})]})]}),e.jsxs("div",{className:"gcw-header__actions",children:[e.jsx(_e,{size:p,onCycleSize:J,onPopout:h,onClear:()=>B(!0),onNewSession:()=>{f(),w(!1)},onShowHistory:()=>w(!0)}),e.jsx("button",{onClick:g,className:"gcw-header__btn",title:"Sluiten",children:e.jsx(Ne,{className:"gcw-header__btn-icon"})})]})]}),j&&e.jsx(ee,{title:"Chat verwijderen",message:"Weet je zeker dat je dit gesprek wilt verwijderen? Dit kan niet ongedaan worden gemaakt.",confirmLabel:"Verwijderen",cancelLabel:"Annuleren",variant:"danger",onConfirm:()=>{B(!1),d()},onCancel:()=>B(!1)}),_?e.jsx(be,{currentSessionId:y,onBack:()=>w(!1),onSelectSession:N,onNewSession:f,onListSessions:b,onDeleteSession:m,primaryColor:k}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{messages:i,isLoading:a,isLoadingSession:r,primaryColor:k}),e.jsx(me,{placeholder:s,isLoading:a,onSendMessage:o,primaryColor:k})]})]})}function Oe({className:t}){return e.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"})})}function Fe(t){return t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function Ge(t,n){return t.length<=n?t:t.slice(0,n-3)+"..."}function pe({message:t,primaryColor:n}){const s=t.role==="user",i=s?"user":"assistant";return e.jsx("div",{className:`gcw-bubble-row gcw-bubble-row--${i}`,children:e.jsxs("div",{className:`gcw-bubble-wrapper gcw-bubble-wrapper--${i}`,children:[e.jsx("div",{className:`gcw-bubble gcw-bubble--${i}`,style:s?{backgroundColor:n}:void 0,children:e.jsx(ye,{content:t.content,className:"gcw-content"})}),t.sources&&t.sources.length>0&&e.jsx("div",{className:"gcw-sources",children:t.sources.slice(0,3).map((a,r)=>e.jsxs("a",{href:a.url,target:"_blank",rel:"noopener noreferrer",className:"gcw-source",children:[e.jsx(Oe,{className:"gcw-source__icon"}),Ge(a.title,25)]},r))}),e.jsx("span",{className:"gcw-bubble__timestamp",children:Fe(t.timestamp)})]})})}function fe({messages:t,isLoading:n,isLoadingSession:s=!1,primaryColor:i}){var r;const a=l.useRef(null);return l.useEffect(()=>{var o;(o=a.current)==null||o.scrollIntoView({behavior:"smooth"})},[t,n]),s?e.jsx("div",{className:"gcw-empty",children:e.jsxs("div",{className:"gcw-session-loading",children:[e.jsx("div",{className:"gcw-session-loading__spinner"}),e.jsx("p",{className:"gcw-empty__text",children:"Chatgeschiedenis laden..."})]})}):t.length===0&&!n?e.jsxs("div",{className:"gcw-empty",children:[e.jsx("svg",{className:"gcw-empty__icon",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:1.5,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})}),e.jsx("p",{className:"gcw-empty__text",children:"Begin een gesprek door hieronder een bericht te typen"})]}):e.jsxs("div",{className:"gcw-messages",children:[t.map(o=>e.jsx(pe,{message:o,primaryColor:i},o.id)),n&&((r=t[t.length-1])==null?void 0:r.role)!=="assistant"&&e.jsx(ke,{}),e.jsx("div",{ref:a})]})}function me({placeholder:t,isLoading:n,onSendMessage:s,primaryColor:i}){const[a,r]=l.useState(""),o=l.useRef(null);l.useEffect(()=>{const u=o.current;u&&(u.style.height="auto",u.style.height=`${Math.min(u.scrollHeight,120)}px`)},[a]);const g=()=>{a.trim()&&!n&&(s(a),r(""),o.current&&(o.current.style.height="auto"))},d=u=>{u.key==="Enter"&&!u.shiftKey&&(u.preventDefault(),g())};return e.jsxs("div",{className:"gcw-input-area",children:[e.jsxs("div",{className:"gcw-input-row",children:[e.jsx("textarea",{ref:o,value:a,onChange:u=>r(u.target.value),onKeyDown:d,placeholder:t,disabled:n,rows:1,className:"gcw-input"}),e.jsx("button",{onClick:g,disabled:!a.trim()||n,className:"gcw-send-btn",style:{backgroundColor:i},title:"Verstuur bericht",children:n?e.jsxs("svg",{className:"gcw-send-btn__icon gcw-spin",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{style:{opacity:.25},cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{style:{opacity:.75},fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}):e.jsx("svg",{className:"gcw-send-btn__icon",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})})})]}),e.jsx("p",{className:"gcw-input-hint",children:"Druk op Enter om te verzenden, Shift+Enter voor een nieuwe regel"})]})}function we({isOpen:t,onClick:n,primaryColor:s,hasUnread:i,isPoppedOut:a}){return e.jsxs("button",{onClick:n,className:"gcw-toggle",style:{backgroundColor:s},title:a?"Chat is open in een ander venster":t?"Sluit chat":"Open chat",children:[i&&!t&&e.jsx("span",{className:"gcw-toggle__badge gcw-toggle__badge--unread",children:"!"}),a&&e.jsx("span",{className:"gcw-toggle__badge gcw-toggle__badge--popout"}),e.jsx("div",{className:"gcw-toggle__icon",children:a?e.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})}):t?e.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})}):e.jsx("svg",{fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"})})})]})}function Ke(t){const n=new Date(t),i=new Date().getTime()-n.getTime(),a=Math.floor(i/6e4),r=Math.floor(i/36e5),o=Math.floor(i/864e5);return a<1?"Zojuist":a<60?`${a} min geleden`:r<24?`${r} uur geleden`:o<7?`${o} ${o===1?"dag":"dagen"} geleden`:n.toLocaleDateString("nl-NL",{day:"numeric",month:"short"})}function be({currentSessionId:t,onBack:n,onSelectSession:s,onNewSession:i,onDeleteSession:a,onListSessions:r,primaryColor:o}){const[g,d]=l.useState([]),[u,h]=l.useState(!0),[f,N]=l.useState(null);l.useEffect(()=>{let p=!1;return h(!0),r().then(_=>{p||(d(_),h(!1))}),()=>{p=!0}},[r]);const b=p=>{s(p),n()},m=(p,_)=>{p.stopPropagation(),N(_)},y=async()=>{if(!f)return;const p=f;N(null),await a(p),d(_=>_.filter(w=>w.id!==p))},k=()=>{i(),n()};return e.jsxs("div",{className:"gcw-history",children:[e.jsxs("div",{className:"gcw-history__header",style:{backgroundColor:o},children:[e.jsx("button",{className:"gcw-header__btn",onClick:n,title:"Terug",children:e.jsx(Le,{className:"gcw-header__btn-icon"})}),e.jsx("h3",{className:"gcw-history__title",children:"Gesprekken"}),e.jsx("button",{className:"gcw-header__btn",onClick:k,title:"Nieuw gesprek",children:e.jsx(se,{className:"gcw-header__btn-icon"})})]}),e.jsx("div",{className:"gcw-history__list",children:u?e.jsxs("div",{className:"gcw-history__loading",children:[e.jsx("div",{className:"gcw-session-loading__spinner"}),e.jsx("span",{children:"Gesprekken laden..."})]}):g.length===0?e.jsx("div",{className:"gcw-history__empty",children:e.jsx("p",{children:"Geen eerdere gesprekken"})}):g.map(p=>e.jsxs("div",{className:`gcw-history__item ${p.id===t?"gcw-history__item--active":""}`,onClick:()=>b(p.id),style:p.id===t?{borderLeftColor:o}:void 0,role:"button",tabIndex:0,onKeyDown:_=>{_.key==="Enter"&&b(p.id)},children:[e.jsxs("div",{className:"gcw-history__item-content",children:[e.jsx("span",{className:"gcw-history__item-title",children:p.title||"Naamloos gesprek"}),e.jsxs("span",{className:"gcw-history__item-meta",children:[p.message_count," ",p.message_count===1?"bericht":"berichten"," · ",Ke(p.updated_at)]})]}),e.jsx("button",{className:"gcw-history__item-delete",onClick:_=>m(_,p.id),title:"Verwijder gesprek",children:e.jsx(te,{className:"gcw-history__item-delete-icon"})})]},p.id))}),f&&e.jsx(ee,{title:"Gesprek verwijderen",message:"Weet je zeker dat je dit gesprek wilt verwijderen? Dit kan niet ongedaan worden gemaakt.",confirmLabel:"Verwijderen",cancelLabel:"Annuleren",variant:"danger",onConfirm:y,onCancel:()=>N(null)})]})}function ee({title:t,message:n,confirmLabel:s="Bevestigen",cancelLabel:i="Annuleren",onConfirm:a,onCancel:r,variant:o="default"}){const g=l.useRef(null),d=l.useRef(null);l.useEffect(()=>{var h;(h=d.current)==null||h.focus()},[]),l.useEffect(()=>{const h=f=>{f.key==="Escape"&&r()};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[r]);const u=h=>{h.target===g.current&&r()};return e.jsx("div",{className:"gcw-modal-overlay",ref:g,onClick:u,children:e.jsxs("div",{className:"gcw-modal",role:"dialog","aria-modal":"true","aria-labelledby":"gcw-modal-title",children:[e.jsx("h4",{className:"gcw-modal__title",id:"gcw-modal-title",children:t}),e.jsx("p",{className:"gcw-modal__message",children:n}),e.jsxs("div",{className:"gcw-modal__actions",children:[e.jsx("button",{className:"gcw-modal__btn gcw-modal__btn--cancel",onClick:r,children:i}),e.jsx("button",{className:`gcw-modal__btn gcw-modal__btn--confirm ${o==="danger"?"gcw-modal__btn--danger":""}`,onClick:a,ref:d,children:s})]})]})})}function ye({content:t,className:n}){if(!t)return null;const s=Ve(t);return e.jsx("div",{className:n,children:s.map((i,a)=>e.jsx(l.Fragment,{children:i},a))})}function Ve(t){const n=t.split(`
|
|
3
|
+
`),s=[];let i=null;const a=()=>{i&&(i.type==="ul"?s.push(e.jsx("ul",{className:"gcw-md-list gcw-md-list--ul",children:i.items.map((r,o)=>e.jsx("li",{className:"gcw-md-list__item",children:r},o))},`list-${s.length}`)):s.push(e.jsx("ol",{className:"gcw-md-list gcw-md-list--ol",children:i.items.map((r,o)=>e.jsx("li",{className:"gcw-md-list__item",children:r},o))},`list-${s.length}`)),i=null)};for(let r=0;r<n.length;r++){const o=n[r];if(o.startsWith("#### ")){a(),s.push(e.jsx("h5",{className:"gcw-md-heading gcw-md-heading--h5",children:W(o.slice(5))},r));continue}if(o.startsWith("### ")){a(),s.push(e.jsx("h4",{className:"gcw-md-heading gcw-md-heading--h4",children:W(o.slice(4))},r));continue}if(o.startsWith("## ")){a(),s.push(e.jsx("h3",{className:"gcw-md-heading gcw-md-heading--h3",children:W(o.slice(3))},r));continue}if(o.startsWith("# ")){a(),s.push(e.jsx("h2",{className:"gcw-md-heading gcw-md-heading--h2",children:W(o.slice(2))},r));continue}const g=o.match(/^[\s]*[-*•]\s+(.+)/);if(g){(!i||i.type!=="ul")&&(a(),i={type:"ul",items:[]}),i.items.push(W(g[1]));continue}const d=o.match(/^[\s]*(\d+)[.)]\s+(.+)/);if(d){(!i||i.type!=="ol")&&(a(),i={type:"ol",items:[]}),i.items.push(W(d[2]));continue}if(o.startsWith("```")){a();const u=[];for(r++;r<n.length&&!n[r].startsWith("```");)u.push(n[r]),r++;s.push(e.jsx("pre",{className:"gcw-md-code-block",children:e.jsx("code",{children:u.join(`
|
|
4
|
+
`)})},`code-${s.length}`));continue}if(o.trim()===""){a();continue}a(),s.push(e.jsx("p",{className:"gcw-md-paragraph",children:W(o)},r))}return a(),s}function W(t){if(!t)return null;const n=[];let s=t,i=0;for(;s.length>0;){const a=s.match(/^\*\*(.+?)\*\*/);if(a){n.push(e.jsx("strong",{className:"gcw-md-bold",children:a[1]},i++)),s=s.slice(a[0].length);continue}const r=s.match(/^\*([^*]+?)\*/);if(r){n.push(e.jsx("em",{className:"gcw-md-italic",children:r[1]},i++)),s=s.slice(r[0].length);continue}const o=s.match(/^`([^`]+)`/);if(o){n.push(e.jsx("code",{className:"gcw-md-code",children:o[1]},i++)),s=s.slice(o[0].length);continue}const g=s.match(/^\[([^\]]+)\]\(([^)]+)\)/);if(g){n.push(e.jsx("a",{href:g[2],target:"_blank",rel:"noopener noreferrer",className:"gcw-md-link",children:g[1]},i++)),s=s.slice(g[0].length);continue}const d=s.search(/[\*`\[]/);if(d===-1){n.push(s);break}else d===0?(n.push(s[0]),s=s.slice(1)):(n.push(s.slice(0,d)),s=s.slice(d))}return n.length===1?n[0]:n}function ve(t){const n=t.messages.map(s=>({...s,timestamp:s.timestamp.toISOString()}));return`
|
|
5
5
|
<!DOCTYPE html>
|
|
6
6
|
<html lang="en">
|
|
7
7
|
<head>
|
|
8
8
|
<meta charset="UTF-8">
|
|
9
9
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
10
|
-
<title>${
|
|
10
|
+
<title>${Z(t.title)}</title>
|
|
11
11
|
<style>
|
|
12
12
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
13
13
|
html, body, #chat-root { height: 100%; width: 100%; }
|
|
@@ -282,8 +282,8 @@
|
|
|
282
282
|
</svg>
|
|
283
283
|
</div>
|
|
284
284
|
<div class="popout-header-info">
|
|
285
|
-
<div class="popout-title">${
|
|
286
|
-
<div class="popout-subtitle">${
|
|
285
|
+
<div class="popout-title">${Z(t.title)}</div>
|
|
286
|
+
<div class="popout-subtitle">${Z(t.subtitle)}</div>
|
|
287
287
|
</div>
|
|
288
288
|
</div>
|
|
289
289
|
<div class="popout-messages" id="messages-container"></div>
|
|
@@ -292,7 +292,7 @@
|
|
|
292
292
|
<textarea
|
|
293
293
|
class="popout-textarea"
|
|
294
294
|
id="message-input"
|
|
295
|
-
placeholder="${
|
|
295
|
+
placeholder="${Z(t.placeholder)}"
|
|
296
296
|
rows="1"
|
|
297
297
|
></textarea>
|
|
298
298
|
<button
|
|
@@ -311,7 +311,18 @@
|
|
|
311
311
|
</div>
|
|
312
312
|
<script>
|
|
313
313
|
(function() {
|
|
314
|
-
const config = ${JSON.stringify({apiUrl:t.apiUrl,tenantId:t.tenantId,sessionId:t.sessionId,primaryColor:t.primaryColor,
|
|
314
|
+
const config = ${JSON.stringify({apiUrl:t.apiUrl,tenantId:t.tenantId,sessionId:t.sessionId,primaryColor:t.primaryColor,tokenStorageKey:t.tokenStorageKey||"geoapps-token"})};
|
|
315
|
+
|
|
316
|
+
function getAuthHeaders() {
|
|
317
|
+
try {
|
|
318
|
+
const raw = window.opener?.sessionStorage?.getItem(config.tokenStorageKey)
|
|
319
|
+
|| sessionStorage.getItem(config.tokenStorageKey);
|
|
320
|
+
if (!raw) return {};
|
|
321
|
+
const token = JSON.parse(raw);
|
|
322
|
+
if (token?.access_token) return { Authorization: 'Bearer ' + token.access_token };
|
|
323
|
+
} catch (e) {}
|
|
324
|
+
return {};
|
|
325
|
+
}
|
|
315
326
|
|
|
316
327
|
const STORAGE_KEY = 'gcw_chat_' + (config.tenantId || 'default');
|
|
317
328
|
|
|
@@ -481,7 +492,7 @@
|
|
|
481
492
|
headers: {
|
|
482
493
|
'Content-Type': 'application/json',
|
|
483
494
|
...(config.tenantId && { 'X-Tenant-ID': config.tenantId }),
|
|
484
|
-
...
|
|
495
|
+
...getAuthHeaders()
|
|
485
496
|
},
|
|
486
497
|
body: JSON.stringify({
|
|
487
498
|
message: content.trim(),
|
|
@@ -563,4 +574,4 @@
|
|
|
563
574
|
<\/script>
|
|
564
575
|
</body>
|
|
565
576
|
</html>
|
|
566
|
-
`}function
|
|
577
|
+
`}function Z(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function ke(){return e.jsx("div",{className:"gcw-typing",children:e.jsx("div",{className:"gcw-typing__bubble",children:e.jsxs("div",{className:"gcw-typing__dots",children:[e.jsx("span",{className:"gcw-typing__dot"}),e.jsx("span",{className:"gcw-typing__dot"}),e.jsx("span",{className:"gcw-typing__dot"})]})})})}const Ue={small:"Klein",medium:"Middel",large:"Groot",fullscreen:"Volledig scherm"};function _e({size:t,onCycleSize:n,onPopout:s,onClear:i,onNewSession:a,onShowHistory:r}){const[o,g]=l.useState(!1),d=l.useRef(null);l.useEffect(()=>{if(!o)return;const h=N=>{d.current&&!d.current.contains(N.target)&&g(!1)},f=setTimeout(()=>{document.addEventListener("click",h)},0);return()=>{clearTimeout(f),document.removeEventListener("click",h)}},[o]),l.useEffect(()=>{if(!o)return;const h=f=>{f.key==="Escape"&&g(!1)};return document.addEventListener("keydown",h),()=>document.removeEventListener("keydown",h)},[o]);const u=h=>{h(),g(!1)};return e.jsxs("div",{className:"gcw-header-menu",ref:d,children:[e.jsx("button",{onClick:()=>g(!o),className:"gcw-header__btn",title:"Menu","aria-expanded":o,"aria-haspopup":"true",children:e.jsxs("svg",{className:"gcw-header__btn-icon",fill:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("circle",{cx:"12",cy:"5",r:"2"}),e.jsx("circle",{cx:"12",cy:"12",r:"2"}),e.jsx("circle",{cx:"12",cy:"19",r:"2"})]})}),o&&e.jsxs("div",{className:"gcw-header-menu__dropdown",role:"menu",children:[e.jsxs("button",{className:"gcw-header-menu__item",onClick:()=>u(a),role:"menuitem",children:[e.jsx(se,{className:"gcw-header-menu__icon"}),e.jsx("span",{children:"Nieuwe chat"})]}),e.jsxs("button",{className:"gcw-header-menu__item",onClick:()=>u(r),role:"menuitem",children:[e.jsx(Ie,{className:"gcw-header-menu__icon"}),e.jsx("span",{children:"Chat geschiedenis"})]}),e.jsx("div",{className:"gcw-header-menu__divider"}),e.jsxs("button",{className:"gcw-header-menu__item",onClick:()=>u(n),role:"menuitem",children:[e.jsx(Se,{size:t,className:"gcw-header-menu__icon"}),e.jsxs("span",{children:["Grootte: ",Ue[t]]})]}),e.jsxs("button",{className:"gcw-header-menu__item",onClick:()=>u(s),role:"menuitem",children:[e.jsx(Ce,{className:"gcw-header-menu__icon"}),e.jsx("span",{children:"Open in nieuw venster"})]}),e.jsx("div",{className:"gcw-header-menu__divider"}),e.jsxs("button",{className:"gcw-header-menu__item gcw-header-menu__item--danger",onClick:()=>u(i),role:"menuitem",children:[e.jsx(te,{className:"gcw-header-menu__icon"}),e.jsx("span",{children:"Chat verwijderen"})]})]})]})}function Se({size:t,className:n}){const s=t==="fullscreen"?"M9 9V4.5M9 9H4.5M9 9L3.75 3.75M9 15v4.5M9 15H4.5M9 15l-5.25 5.25M15 9h4.5M15 9V4.5M15 9l5.25-5.25M15 15h4.5M15 15v4.5m0-4.5l5.25 5.25":"M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4";return e.jsx("svg",{className:n,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:s})})}function Ce({className:t}){return e.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"})})}function Ne({className:t}){return e.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})}function te({className:t}){return e.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})}function Me({className:t}){return e.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"})})}function se({className:t}){return e.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})}function Ie({className:t}){return e.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})})}function Le({className:t}){return e.jsx("svg",{className:t,fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10 19l-7-7m0 0l7-7m-7 7h18"})})}c.ArrowLeftIcon=Le,c.ChatBubble=pe,c.ChatIcon=Me,c.ChatWidget=Pe,c.ChatWindow=ge,c.CloseIcon=Ne,c.ConfirmModal=ee,c.HeaderMenu=_e,c.HistoryIcon=Ie,c.MarkdownRenderer=ye,c.MessageInput=me,c.MessageList=fe,c.NewChatIcon=se,c.PopoutIcon=Ce,c.ResizeIcon=Se,c.SessionHistory=be,c.ToggleButton=we,c.TrashIcon=te,c.TypingIndicator=ke,c.clearSession=D,c.getAuthHeaders=P,c.getPopoutHTML=ve,c.loadPopoutState=le,c.loadSeenAssistantCount=ce,c.loadSessionId=ae,c.savePopoutState=V,c.saveSeenAssistantCount=U,c.saveSessionId=re,c.subscribeToSessionChanges=ie,c.useAuth=de,c.useChat=ue,c.usePopout=he,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/dist/hooks/useAuth.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { AuthUser } from '../types';
|
|
|
3
3
|
export interface UseAuthOptions {
|
|
4
4
|
/** URL to call for auth verification (e.g. /api/users/me). When omitted, auth is skipped and widget is always shown. */
|
|
5
5
|
authUrl?: string;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/** SessionStorage key that holds the GeoApps OIDC token object (default: "geoapps-token") */
|
|
7
|
+
tokenStorageKey?: string;
|
|
8
8
|
}
|
|
9
9
|
export interface UseAuthReturn {
|
|
10
10
|
/** Whether the user is authenticated */
|
|
@@ -21,9 +21,10 @@ export interface UseAuthReturn {
|
|
|
21
21
|
/**
|
|
22
22
|
* Hook that verifies user authentication by calling an auth URL.
|
|
23
23
|
*
|
|
24
|
-
* - On mount, fetches `authUrl` with
|
|
24
|
+
* - On mount, fetches `authUrl` with a Bearer token from sessionStorage.
|
|
25
25
|
* - 200 → authenticated, user info cached in state.
|
|
26
26
|
* - 401/403 → not authenticated.
|
|
27
27
|
* - Network / other errors → not authenticated (fail closed).
|
|
28
|
+
* - Concurrent calls to the same URL are deduplicated (single network request).
|
|
28
29
|
*/
|
|
29
|
-
export declare function useAuth({ authUrl,
|
|
30
|
+
export declare function useAuth({ authUrl, tokenStorageKey }: UseAuthOptions): UseAuthReturn;
|
package/dist/types.d.ts
CHANGED
|
@@ -20,7 +20,8 @@ export interface ChatConfig {
|
|
|
20
20
|
apiUrl: string;
|
|
21
21
|
tenantId?: string;
|
|
22
22
|
sessionId?: string;
|
|
23
|
-
|
|
23
|
+
/** SessionStorage key that holds the GeoApps OIDC token object (default: "geoapps-token") */
|
|
24
|
+
tokenStorageKey?: string;
|
|
24
25
|
}
|
|
25
26
|
export type WidgetSize = 'small' | 'medium' | 'large' | 'fullscreen';
|
|
26
27
|
/** Preset position shortcuts */
|
|
@@ -57,8 +58,8 @@ export interface ChatWidgetProps {
|
|
|
57
58
|
defaultOpen?: boolean;
|
|
58
59
|
/** Default widget size */
|
|
59
60
|
defaultSize?: WidgetSize;
|
|
60
|
-
/**
|
|
61
|
-
|
|
61
|
+
/** SessionStorage key that holds the GeoApps OIDC token (default: "geoapps-token") */
|
|
62
|
+
tokenStorageKey?: string;
|
|
62
63
|
/** Callback when chat is opened */
|
|
63
64
|
onOpen?: () => void;
|
|
64
65
|
/** Callback when chat is closed */
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the GeoApps Bearer token from sessionStorage.
|
|
3
|
+
*
|
|
4
|
+
* The GeoApps platform stores an OIDC token object in sessionStorage
|
|
5
|
+
* under a configurable key (default: "geoapps-token"). This utility
|
|
6
|
+
* parses that object and returns an Authorization header when a valid
|
|
7
|
+
* access_token is present.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getAuthHeaders(tokenStorageKey?: string): Record<string, string>;
|
package/package.json
CHANGED