/*! For license information please see aizen-widget.js.LICENSE.txt */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("React"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["React","ReactDOM"],t):"object"==typeof exports?exports.AizenWidget=t(require("React"),require("ReactDOM")):e.AizenWidget=t(e.React,e.ReactDOM)}(globalThis,(e,t)=>(()=>{var n={146(e,t,n){"use strict";var r=n(404),i={childContextTypes:!0,contextType:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,getDerivedStateFromError:!0,getDerivedStateFromProps:!0,mixins:!0,propTypes:!0,type:!0},o={name:!0,length:!0,prototype:!0,caller:!0,callee:!0,arguments:!0,arity:!0},a={$$typeof:!0,compare:!0,defaultProps:!0,displayName:!0,propTypes:!0,type:!0},s={};function l(e){return r.isMemo(e)?a:s[e.$$typeof]||i}s[r.ForwardRef]={$$typeof:!0,render:!0,defaultProps:!0,displayName:!0,propTypes:!0},s[r.Memo]=a;var c=Object.defineProperty,p=Object.getOwnPropertyNames,d=Object.getOwnPropertySymbols,u=Object.getOwnPropertyDescriptor,m=Object.getPrototypeOf,f=Object.prototype;e.exports=function e(t,n,r){if("string"!=typeof n){if(f){var i=m(n);i&&i!==f&&e(t,i,r)}var a=p(n);d&&(a=a.concat(d(n)));for(var s=l(t),h=l(n),g=0;g{var t=e&&e.__esModule?()=>e.default:()=>e;return i.d(t,{a:t}),t},i.d=(e,t)=>{for(var n in t)i.o(t,n)&&!i.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},i.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),i.nc=void 0;var o={};return(()=>{"use strict";i.d(o,{default:()=>kn});var e=i(883),t=i.n(e),n=i(338);const r=new class{constructor(){this.baseURL="https://chat.ai-zens.com"}setBaseURL(e){e&&"string"==typeof e?this.baseURL=e.replace(/\/$/,""):console.error("❌ [API] Invalid baseURL:",e)}setGetToken(e){this.getToken=e}async openConversation(){try{const e=await fetch(`${this.baseURL}/chat/open`,{method:"GET",headers:{Authorization:`Bearer ${this.getToken()}`,"Content-Type":"application/json"}});if(!e.ok){const t=await e.json().catch(()=>({}));throw new Error(t.detail||t.message||`開啟對話失敗: ${e.status}`)}return await e.json()}catch(e){throw e}}async getConversationHistory(e){let{offset:t=0,limit:n=20}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{const r=new URLSearchParams({offset:t.toString(),limit:Math.min(n,100).toString()}),i=`${this.baseURL}/chat/history/${e}?${r}`,o=await fetch(i,{method:"GET",headers:{Authorization:`Bearer ${this.getToken()}`,"Content-Type":"application/json"}});if(!o.ok){const e=await o.json().catch(()=>({}));throw new Error(e.detail||e.message||`獲取歷史失敗: ${o.status}`)}return await o.json()}catch(e){throw e}}async sendMessage(e,t){let{message:n=null,trigger_intent:r=null,location_href:i=null,metadata:o=null}=t;"function"==typeof siteSendEvent&&siteSendEvent("chat_event",{type:"sent",conversation_id:e,content:{message:n,trigger_intent:r,metadata:o}}).catch(()=>{});try{const t={message:n,trigger_intent:r,location_href:i,metadata:o},a=await fetch(`${this.baseURL}/chat/send/${e}`,{method:"POST",headers:{Authorization:`Bearer ${this.getToken()}`,"Content-Type":"application/json"},body:JSON.stringify(t)});if(!a.ok){const e=await a.json().catch(()=>({}));throw new Error(e.detail||e.message||`發送消息失敗: ${a.status}`)}return await a.json()}catch(e){throw e}}async closeConversation(e){try{const t=await fetch(`${this.baseURL}/chat/close/${e}`,{method:"POST",headers:{Authorization:`Bearer ${this.getToken()}`,"Content-Type":"application/json"}});if(!t.ok){const e=await t.json().catch(()=>({}));throw new Error(e.detail||e.message||`關閉對話失敗: ${t.status}`)}return await t.json()}catch(e){throw e}}async healthCheck(){try{return(await fetch(`${this.baseURL}/health`,{method:"GET"})).ok}catch(e){return!1}}},a="https://cdn.prod.website-files.com/64420a3911d6832c7ba8b105/69c5ff6e5e5fb27c84631f32_Aire%20avatar-small.png";var s=i(363),l=i(833),c=i.n(l);const p=function(e){function t(e,r,l,c,u){for(var m,f,h,g,v,k=0,S=0,C=0,j=0,$=0,R=0,O=h=m=0,z=0,B=0,M=0,P=0,G=l.length,N=G-1,U="",F="",H="",Y="";zm)&&(P=(U=U.replace(" ",":")).length),0r&&(r=(t=t.trim()).charCodeAt(0)),r){case 38:return t.replace(g,"$1"+e.trim());case 58:return e.trim()+t.replace(g,"$1"+e.trim());default:if(0<1*n&&0l.charCodeAt(8))break;case 115:a=a.replace(l,"-webkit-"+l)+";"+a;break;case 207:case 102:a=a.replace(l,"-webkit-"+(102r.charCodeAt(0)&&(r=r.trim()),r=[r],01?t-1:0),r=1;r0?" Args: "+n.join(", "):""))}var I=function(){function e(e){this.groupSizes=new Uint32Array(512),this.length=512,this.tag=e}var t=e.prototype;return t.indexOfGroup=function(e){for(var t=0,n=0;n=this.groupSizes.length){for(var n=this.groupSizes,r=n.length,i=r;e>=i;)(i<<=1)<0&&E(16,""+e);this.groupSizes=new Uint32Array(i),this.groupSizes.set(n),this.length=i;for(var o=r;o=this.length||0===this.groupSizes[e])return t;for(var n=this.groupSizes[e],r=this.indexOfGroup(e),i=r+n,o=r;o=L&&(L=t+1),T.set(e,t),R.set(t,e)},B="style["+j+'][data-styled-version="5.3.11"]',M=new RegExp("^"+j+'\\.g(\\d+)\\[id="([\\w\\d-]+)"\\].*?"([^"]*)'),P=function(e,t,n){for(var r,i=n.split(","),o=0,a=i.length;o=0;n--){var r=t[n];if(r&&1===r.nodeType&&r.hasAttribute(j))return r}}(n),o=void 0!==i?i.nextSibling:null;r.setAttribute(j,"active"),r.setAttribute("data-styled-version","5.3.11");var a=N();return a&&r.setAttribute("nonce",a),n.insertBefore(r,o),r},F=function(){function e(e){var t=this.element=U(e);t.appendChild(document.createTextNode("")),this.sheet=function(e){if(e.sheet)return e.sheet;for(var t=document.styleSheets,n=0,r=t.length;n=0){var n=document.createTextNode(t),r=this.nodes[e];return this.element.insertBefore(n,r||null),this.length++,!0}return!1},t.deleteRule=function(e){this.element.removeChild(this.nodes[e]),this.length--},t.getRule=function(e){return e0&&(c+=e+",")}),r+=""+s+l+'{content:"'+c+'"}/*!sc*/\n'}}}return r}(this)},e}(),Z=/(a)(d)/gi,X=function(e){return String.fromCharCode(e+(e>25?39:97))};function Q(e){var t,n="";for(t=Math.abs(e);t>52;t=t/52|0)n=X(t%52)+n;return(X(t%52)+n).replace(Z,"$1-$2")}var K=function(e,t){for(var n=t.length;n;)e=33*e^t.charCodeAt(--n);return e},J=function(e){return K(5381,e)};function ee(e){for(var t=0;t>>0);if(!t.hasNameForId(r,a)){var s=n(o,"."+a,void 0,r);t.insertRules(r,a,s)}i.push(a),this.staticRulesId=a}else{for(var l=this.rules.length,c=K(this.baseHash,n.hash),p="",d=0;d>>0);if(!t.hasNameForId(r,h)){var g=n(p,"."+h,void 0,r);t.insertRules(r,h,g)}i.push(h)}}return i.join(" ")},e}(),re=/^\s*\/\/.*$/gm,ie=[":","[",".","#"];function oe(e){var t,n,r,i,o=void 0===e?w:e,a=o.options,s=void 0===a?w:a,l=o.plugins,c=void 0===l?v:l,d=new p(s),u=[],m=function(e){function t(t){if(t)try{e(t+"}")}catch(e){}}return function(n,r,i,o,a,s,l,c,p,d){switch(n){case 1:if(0===p&&64===r.charCodeAt(0))return e(r+";"),"";break;case 2:if(0===c)return r+"/*|*/";break;case 3:switch(c){case 102:case 112:return e(i[0]+r),"";default:return r+(0===d?"/*|*/":"")}case-2:r.split("/*|*/}").forEach(t)}}}(function(e){u.push(e)}),f=function(e,r,o){return 0===r&&-1!==ie.indexOf(o[n.length])||o.match(i)?e:"."+t};function h(e,o,a,s){void 0===s&&(s="&");var l=e.replace(re,""),c=o&&a?a+" "+o+" { "+l+" }":l;return t=s,n=o,r=new RegExp("\\"+n+"\\b","g"),i=new RegExp("(\\"+n+"\\b){2,}"),d(a||!o?"":o,c)}return d.use([].concat(c,[function(e,t,i){2===e&&i.length&&i[0].lastIndexOf(n)>0&&(i[0]=i[0].replace(r,f))},m,function(e){if(-2===e){var t=u;return u=[],t}}])),h.hash=c.length?c.reduce(function(e,t){return t.name||E(15),K(e,t.name)},5381).toString():"",h}var ae=t().createContext(),se=(ae.Consumer,t().createContext()),le=(se.Consumer,new V),ce=oe();function pe(){return(0,e.useContext)(ae)||le}function de(){return(0,e.useContext)(se)||ce}function ue(n){var r=(0,e.useState)(n.stylisPlugins),i=r[0],o=r[1],a=pe(),s=(0,e.useMemo)(function(){var e=a;return n.sheet?e=n.sheet:n.target&&(e=e.reconstructWithOptions({target:n.target},!1)),n.disableCSSOMInjection&&(e=e.reconstructWithOptions({useCSSOMInjection:!1})),e},[n.disableCSSOMInjection,n.sheet,n.target]),l=(0,e.useMemo)(function(){return oe({options:{prefix:!n.disableVendorPrefixes},plugins:i})},[n.disableVendorPrefixes,i]);return(0,e.useEffect)(function(){c()(i,n.stylisPlugins)||o(n.stylisPlugins)},[n.stylisPlugins]),t().createElement(ae.Provider,{value:s},t().createElement(se.Provider,{value:l},n.children))}var me=function(){function e(e,t){var n=this;this.inject=function(e,t){void 0===t&&(t=ce);var r=n.name+t.hash;e.hasNameForId(n.id,r)||e.insertRules(n.id,r,t(n.rules,r,"@keyframes"))},this.toString=function(){return E(12,String(n.name))},this.name=e,this.id="sc-keyframes-"+e,this.rules=t}return e.prototype.getName=function(e){return void 0===e&&(e=ce),this.name+e.hash},e}(),fe=/([A-Z])/,he=/([A-Z])/g,ge=/^ms-/,xe=function(e){return"-"+e.toLowerCase()};function ye(e){return fe.test(e)?e.replace(he,xe).replace(ge,"-ms-"):e}var be=function(e){return null==e||!1===e||""===e};function ve(e,t,n,r){if(Array.isArray(e)){for(var i,o=[],a=0,s=e.length;a1?t-1:0),r=1;r?@[\\\]^`{|}~-]+/g,je=/(^-|-$)/g;function $e(e){return e.replace(Ce,"-").replace(je,"")}var Ae=function(e){return Q(J(e)>>>0)};function _e(e){return"string"==typeof e&&!0}var Ee=function(e){return"function"==typeof e||"object"==typeof e&&null!==e&&!Array.isArray(e)},Ie=function(e){return"__proto__"!==e&&"constructor"!==e&&"prototype"!==e};function Te(e,t,n){var r=e[n];Ee(t)&&Ee(r)?Re(r,t):e[n]=t}function Re(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r=0||(i[n]=e[n]);return i}(r,["componentId"]),o=t&&t+"-"+(_e(e)?e:$e(S(e)));return De(e,x({},n,{attrs:h,componentId:o}),i)},Object.defineProperty(b,"defaultProps",{get:function(){return this._foldedDefaultProps},set:function(e){this._foldedDefaultProps=o?Re({},n.defaultProps,e):e}}),Object.defineProperty(b,"toString",{value:function(){return"."+b.styledComponentId}}),a&&g()(b,n,{attrs:!0,componentStyle:!0,displayName:!0,foldedComponentIds:!0,shouldForwardProp:!0,styledComponentId:!0,target:!0,withComponent:!0}),b}var ze=function(e){return function e(t,n,r){if(void 0===r&&(r=w),!(0,s.isValidElementType)(n))return E(1,String(n));var i=function(){return t(n,r,ke.apply(void 0,arguments))};return i.withConfig=function(i){return e(t,n,x({},r,{},i))},i.attrs=function(i){return e(t,n,x({},r,{attrs:Array.prototype.concat(r.attrs,i).filter(Boolean)}))},i}(De,e)};["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","big","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","marquee","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr","circle","clipPath","defs","ellipse","foreignObject","g","image","line","linearGradient","marker","mask","path","pattern","polygon","polyline","radialGradient","rect","stop","svg","text","textPath","tspan"].forEach(function(e){ze[e]=ze(e)});var Be,Me=function(){function e(e,t){this.rules=e,this.componentId=t,this.isStatic=ee(e),V.registerId(this.componentId+1)}var t=e.prototype;return t.createStyles=function(e,t,n,r){var i=r(ve(this.rules,t,n,r).join(""),""),o=this.componentId+e;n.insertRules(o,o,i)},t.removeStyles=function(e,t){t.clearRules(this.componentId+e)},t.renderStyles=function(e,t,n,r){e>2&&V.registerId(this.componentId+e),this.removeStyles(e,n),this.createStyles(e,t,n,r)},e}();(Be=function(){var e=this;this._emitSheetCSS=function(){var t=e.instance.toString();if(!t)return"";var n=N();return""},this.getStyleTags=function(){return e.sealed?E(2):e._emitSheetCSS()},this.getStyleElement=function(){var n;if(e.sealed)return E(2);var r=((n={})[j]="",n["data-styled-version"]="5.3.11",n.dangerouslySetInnerHTML={__html:e.instance.toString()},n),i=N();return i&&(r.nonce=i),[t().createElement("style",x({},r,{key:"sc-0-0"}))]},this.seal=function(){e.sealed=!0},this.instance=new V({isServer:!0}),this.sealed=!1}.prototype).collectStyles=function(e){return this.sealed?E(2):t().createElement(ue,{sheet:this.instance},e)},Be.interleaveWithNodeStream=function(e){return E(3)};const Pe=ze;var Ge=i(848);const Ne="#ffffff",Ue=Pe.div` background: ${Ne}; color: #000; padding: 10px; display: flex; justify-content: space-between; align-items: center; position: relative; &::after { content: ""; /* 偽元素必須要有 content 屬性 */ display: block; /* 線的樣式 */ height: 1px; background-color: #d9d9d9; /* 寬度和定位 */ width: 95%; /* 設定為總寬度的 90% */ position: absolute; bottom: 0; /* 讓線貼齊 Header 的底部 */ left: 50%; /* 將線的左邊緣移到 Header 中間 */ transform: translateX(-50%); /* 將線向左移動其自身寬度的一半,實現置中 */ } `,Fe=Pe.div` display: flex; align-items: center; gap: 12px; `,He=Pe.div` position: relative; img { width: 40px; height: 40px; object-fit: contain; } /* 為不同動畫狀態添加特效 */ &.talking img { animation: pulse 1s ease-in-out infinite; } &.nodding img { animation: nod 0.8s ease-in-out; } &.thinking img { animation: glow 2s ease-in-out infinite; } @keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } } @keyframes nod { 0%, 100% { transform: translateY(0); } 25% { transform: translateY(-2px); } 75% { transform: translateY(2px); } } @keyframes glow { 0%, 100% { box-shadow: 0 0 0 rgba(105, 227, 109, 0); } 50% { box-shadow: 0 0 15px rgba(105, 227, 109, 0.5); } } `,Ye=Pe.div` .user-name { font-weight: 400; font-size: 16px; letter-spacing: 0.8px; } .user-status { font-size: 14px; font-weight: 480; display: flex; align-items: center; gap: 4px; } `,We=Pe.button` width: 32px; height: 32px; border-radius: 50%; border: none; background: transparent; color: ${Ne}; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s ease; &:hover { background: rgba(255, 255, 255, 0.1); } svg { width: 16px; height: 16px; flex-shrink: 0; fill: none; } `,qe=Pe.div` display: flex; gap: ${"8px"}; align-items: center; `,Ve=Pe(We)` display: none; /* 桌面端隐藏 */ @media (max-width: 600px) { display: flex; /* 移动端显示 */ } svg { width: 15px; height: 15px; } &:hover { opacity: 0.7; } `,Ze=t=>{let{onReset:n,onClose:r,onBackgroundChange:i,currentBackground:o,animationState:a="idle",isAiTyping:s=!1}=t;const[l,c]=(0,e.useState)(!1),[p,d]=(0,e.useState)("idle");return(0,e.useEffect)(()=>{s?d("thinking"):a&&d(a)},[s,a]),(0,Ge.jsxs)(Ue,{children:[(0,Ge.jsxs)(Fe,{children:[(0,Ge.jsx)(He,{className:p,children:(0,Ge.jsx)("img",{src:"https://cdn.prod.website-files.com/64420a3911d6832c7ba8b105/69c5ff72db8bccd82c87efa2_Aire-body.png",alt:"Aire",onLoad:()=>{"undefined"!=typeof window&&window.__AIZEN_DEBUG__},onError:e=>{}})}),(0,Ge.jsx)(Ye,{children:(0,Ge.jsx)("div",{className:"user-name",children:"Aire"})})]}),(0,Ge.jsxs)(qe,{children:[(0,Ge.jsx)(We,{onClick:n,title:"重新開始對話",children:(0,Ge.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",children:(0,Ge.jsx)("path",{d:"M13.1306 1.87308V0.915948C13.1306 0.826703 13.2968 0.554957 13.3741 0.484764C13.927 -0.0211245 14.6836 0.363431 14.7415 1.10246C14.8148 2.04404 14.6836 3.07939 14.7405 4.0315C14.6886 4.4321 14.4106 4.71137 14.0109 4.76351C13.0328 4.69683 11.9419 4.85125 10.9772 4.76501C10.2012 4.69532 9.99964 3.64795 10.6629 3.28345C10.6993 3.26339 10.8465 3.18718 10.8665 3.18718H12.158C12.1814 3.09844 12.135 3.12351 12.1101 3.10145C9.78505 1.01823 6.05826 1.13455 3.75472 3.18618C0.246009 6.31176 1.16573 12.048 5.4709 13.8896C9.51457 15.6193 14.1286 12.7775 14.3682 8.38645C14.3926 7.93873 14.2434 7.16209 14.44 6.80712C14.8168 6.12725 15.8264 6.3614 15.9342 7.15006C16.54 11.5707 12.8791 15.7366 8.51052 15.9858C1.38081 16.3929 -2.72275 7.94524 2.06998 2.62313C4.92795 -0.550077 9.87388 -0.898031 13.1306 1.87308Z",fill:"#2C2C2B"})})}),(0,Ge.jsx)(Ve,{onClick:r,title:"關閉聊天",children:(0,Ge.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",children:[(0,Ge.jsx)("path",{d:"M0.899689 0.849609L13.8995 13.8496",stroke:"#2C2C2B",strokeWidth:"1.75",strokeLinecap:"round"}),(0,Ge.jsx)("path",{d:"M13.8995 0.849609L0.899655 13.8496",stroke:"#2C2C2B",strokeWidth:"1.75",strokeLinecap:"round"})]})})]})]})},Xe=t().memo(Ze),Qe="#0073DF",Ke="#ffffff",Je="#f8f9fa",et="#e5e7eb",tt="#F6F6F6",nt="#A3A3A3",rt="#6b7280",it=" #2C2C2B",ot="4px",at="8px",st="12px",lt="13px",ct="16px",pt="20px",dt=((function(n){for(var r=arguments.length,i=new Array(r>1?r-1:0),o=1;oe.$hide?"none":"block"}; background: transparent !important; background-color: transparent !important; /* 🛡️ 樣式隔離:防止外部濾鏡或混合模式污染 */ isolation: isolate !important; color-scheme: light !important; `),ut=Pe.button` width: 45px !important; height: 45px !important; border-radius: 50% !important; background-color: ${e=>e.isOpen?Qe:"transparent"} !important; background: ${e=>e.isOpen?Qe:"transparent"} !important; border: none !important; cursor: pointer !important; transition: all 0.3s ease !important; display: flex !important; align-items: center !important; justify-content: center !important; position: relative !important; overflow: visible !important; bottom: -5px !important; right: 0px !important; /* 🎯 恢復為 0,讓容器回歸預設位置 */ z-index: 10 !important; padding: 0 !important; box-shadow: ${e=>e.isOpen?"0 4px 12px rgba(0,0,0,0.15)":"none"} !important; svg { width: 24px !important; height: 24px !important; display: block !important; } /* 🍎 iOS 特殊重置 */ -webkit-tap-highlight-color: transparent !important; -webkit-appearance: none !important; appearance: none !important; outline: none !important; box-shadow: none !important; filter: none !important; -webkit-filter: none !important; /* 🚀 強制開啟乾淨的 GPU 層,避免渲染殘影 */ transform: translate3d(0,0,0) !important; -webkit-transform: translate3d(0,0,0) !important; backface-visibility: hidden !important; -webkit-backface-visibility: hidden !important; @media (max-width: 600px) { &.active { display: none !important; } } `,mt=Pe.div` position: absolute; bottom: 28px; right: -28px; opacity: ${e=>e.show?1:0}; transform: ${e=>e.show?"translateY(0)":"translateY(10px)"}; transition: transform 0.3s ease, opacity 0.3s ease, right 0.3s ease, bottom 0.3s ease; pointer-events: ${e=>e.show?"auto":"none"}; z-index: 5; @media (max-width: 600px) { right: 72px; /* 🎯 長句時 bottom: 21px, 短句時維持 10px */ bottom: ${e=>e.$isLong?"-42px":"-40px"}; max-width: 260px; /* 讓 SVG 泡泡能完整顯示 */ } `,ft=(Pe.div` display: none; @media (max-width: 600px) { display: ${e=>e.show?"block":"none"}; position: fixed; bottom: 0; left: 0; width: 100%; height: ${e=>e.$isLong?"160px":"120px"}; /* 🎯 根據字數調整高度 */ background-image: ${e=>`url(${e.$bgImage})`}; background-size: 100% 100%; /* 🎯 強制填滿高度與寬度,展現完整漸層 */ background-position: bottom; background-repeat: no-repeat; z-index: -1; /* 確保在所有內容最底層 */ pointer-events: none; opacity: ${e=>e.show?1:0}; transition: opacity 0.3s ease; } `,Pe.div` position: relative; display: inline-flex; align-items: center; gap: 0; right: 20px; /* ✅ 移除 gap,改用絕對定位讓按鈕在左側外面 */ bottom: 32px; /* ✅ 桌機:close 按鈕在左側外面,只有 hover 時才顯示 */ /* ClosePromptButton 放在左側外面 */ > button { position: absolute; left: -5px; /* 在泡泡左邊外側 */ top: 20%; transform: translateY(-5%); } &:hover > button, &:focus-within > button { opacity: 1 !important; visibility: visible !important; pointer-events: auto !important; } @media (max-width: 600px) { position: relative; top: auto; right: -5px; /* 覆寫桌機的 bottom:32px。父層 PromptWrapper 高度常為 0,若同時設 top+bottom 會被算成極小高度(Safari 約 3px),從綠界返回後更易錯位 */ bottom: 32px !important; height: auto; font-size: 13px; padding: 0; /* 移除 padding,改由 PromptText 控制 */ white-space: normal; max-width: 260px; /* 讓 SVG 泡泡能完整顯示 */ min-width: 249px; width: auto; gap: 8px; /* 手機版保留 gap */ /* ✅ 右边对齐,文字增加時往左擴展 */ margin-left: auto; left: auto; > button { position: absolute; left: 0px; /* 在泡泡左邊外側 */ top: 0%; transform: translateY(0%); } /* ✅ 移除 ::after 小三角,改用 PromptText 的 SVG 背景(已包含箭頭) */ } `),ht=Pe.div` display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: center !important; text-align: flex-start !important; line-height: 1.5 !important; color: #000000 !important; font-weight: 400 !important; font-family: "Noto Sans TC", sans-serif !important; font-size: 15px !important; width: fit-content !important; max-width: 280px !important; min-width: 217px !important; min-height: 56px !important; height: auto !important; box-sizing: border-box !important; padding: 15px !important; background: #ffffff !important; border-radius: 18px !important; box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important; position: relative !important; /* 🎯 桌機版泡泡尾巴 (指向底部的機器人圖標) */ &::after { content: "" !important; position: absolute !important; bottom: -10px !important; right: 26px !important; width: 20px !important; height: 15px !important; background: #ffffff !important; clip-path: polygon(0 0, 100% 0, 50% 100%) !important; } /* ✅ 手機版適配 */ @media (max-width: 600px) { width: 217px !important; max-width: 255px !important; min-height: ${e=>e.$isLong?"46px !important":"21px !important"}; /* 手機版尾巴:長句時靠下,短句時垂直居中 */ &::after { right: -10px !important; top: ${e=>e.$isLong?"auto !important":"50% !important"}; bottom: ${e=>e.$isLong?"18px !important":"auto !important"}; transform: ${e=>e.$isLong?"none !important":"translateY(-50%) !important"}; width: 15px !important; height: 20px !important; clip-path: polygon(0 0, 0 100%, 100% 50%) !important; } } `,gt=Pe.button` width: 24px !important; height: 24px !important; min-width: 24px !important; min-height: 24px !important; border-radius: 50% !important; border: none !important; cursor: pointer !important; background-color: #ffffff !important; color: #111827 !important; /* svg stroke="currentColor" */ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important; transition: all 0.2s ease !important; display: flex !important; align-items: center !important; justify-content: center !important; padding: 0 !important; flex-shrink: 0 !important; position: relative !important; z-index: 10 !important; /* ✅ 手機版強制顯示 */ @media (max-width: 1024px) { opacity: 1 !important; visibility: visible !important; pointer-events: auto !important; } /* ✅ 桌機預設隱藏(hover PromptBubble 才出現) */ @media (min-width: 1025px) { opacity: 0 !important; visibility: hidden !important; pointer-events: none !important; } svg { width: 20px !important; height: 20px !important; display: block !important; } `,xt=Pe.div` width: 100% !important; height: 100% !important; display: flex !important; justify-content: center !important; align-items: center !important; position: relative !important; z-index: 999 !important; /* left: -15px; <-- 🎯 找到元兇!這行會讓內容往左偏移 15px */ background: transparent !important; background-color: transparent !important; overflow: visible !important; pointer-events: none !important; img { width: 135px !important; height: 135px !important; max-width: none !important; max-height: none !important; object-fit: contain !important; border-radius: 0% !important; display: block !important; position: absolute !important; top: 25% !important; left: 5% !important; transform: translate(-35%, -40%) !important; background: transparent !important; background-color: transparent !important; border: none !important; box-shadow: none !important; will-change: auto !important; } `,yt=Pe.div` position: fixed; bottom: 78px; right: 15px; width: 354px; height: calc(90vh - 100px); max-height: 583px; background: ${e=>e.background||Ke}; border-radius: 18px; box-shadow: ${"0 8px 32px rgba(0, 0, 0, 0.15)"}; display: flex; flex-direction: column; overflow: hidden; z-index: 99999; transform-origin: bottom right; /* 🎯 从右下角展开/收起 */ /* 🎬 收放动画效果 */ opacity: ${e=>e.isOpen?"1":"0"}; transform: ${e=>e.isOpen?"scale(1) translateY(0)":"scale(0.85) translateY(20px)"}; visibility: ${e=>e.isOpen?"visible":"hidden"}; pointer-events: ${e=>e.isOpen?"auto":"none"}; /* 🎯 关闭时禁用交互 */ transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.4s cubic-bezier(0.16, 1, 0.3, 1), background 0.3s ease; @media (max-width: 600px) { position: fixed; inset: 0; width: 100%; height: 100dvh; max-height: none; bottom: 0; right: 0; border-radius: 0; box-shadow: none; transform-origin: center bottom; /* 🎯 移动端从底部展开/收起 */ /* 🎬 移动端收放动画(从底部滑入/滑出) */ transform: ${e=>e.isOpen?"translateY(0)":"translateY(100%)"}; } `,bt=Pe.div` padding: 0px ${lt} ${st} ${lt}; background: #ffff; display: flex; align-items: center; position: relative; `,vt=Pe.input` flex: 1; padding: ${ct} 92px ${ct} 16px; border: 1px solid ${nt}; border-radius: 18px; font-size: 16px; outline: none; `,wt=Pe.button` background-color: transparent; display: flex; align-items: center; border-radius: 50%; position: absolute; right: 26px; top: 50%; transform: translateY(-50%) scale(1); scale: 1.4; border: none; color: ${Qe}; cursor: pointer; opacity: 1; transition: all 0.2s ease; `,kt=Pe.div` margin-bottom: ${e=>e.isLastMessage?e.isUser?"34px !important":"10px !important":e.isUser?"46px":"infoCards"===e.$messageType&&e.message?.isSplitInfo&&!e.message?.isLastSplit?"6px !important":"10px !important"}; margin-top: ${e=>e.isUser?"34px":"0px"}; text-align: ${e=>e.isUser?"right":"left"}; `,St=Pe.div` display: flex; align-items: flex-end; /* 🎯 统一对齐到底部,确保所有消息类型的底部在同一基准线 */ gap: ${e=>(e.isHorizontalCards,at)}; justify-content: ${e=>e.isUser?"flex-end":"flex-start"}; width: ${e=>"100%"}; position: relative; /* 🎯 互動模式切換: - 未回覆前:padding 為 0,頭像緊貼氣泡(流動模式)。 - 回覆後:套用您確定的 22px 地板(固定模式)。 - 如果是最後一則訊息:padding 為 0,讓 ChatContent 的 padding-bottom (12px) 決定距離。 */ ${e=>!e.isUser&&"\n margin: 0 !important;\n padding: 0 !important;\n "} `,Ct=Pe.div` display: flex; flex-direction: column; /* 🎯 根據發送者對齊,確保 User 訊息靠右,Bot 訊息靠左 */ align-items: ${e=>e.isUser?"flex-end":"flex-start"}; flex: 1; margin: 0; padding: 0; /* 🎬 讓機器人訊息平滑向上湧出 */ ${e=>!e.isUser&&e.hasUserRepliedOnce?"\n animation: messageSmoothFadeUp 4s cubic-bezier(0.22, 1, 0.36, 1) forwards;\n\n @keyframes messageSmoothFadeUp {\n 0% {\n opacity: 0;\n transform: translateY(3px);\n }\n 100% {\n opacity: 1;\n transform: translateY(0);\n }\n ":""} `,jt=Pe.div` width: 26px; height: 26px; flex-shrink: 0; margin: 0 !important; padding: 0 !important; align-self: flex-end; position: relative; /* 🎯 只有進入第二階段,才需要向上偏移 22px 以對齊氣泡底部 */ bottom: ${e=>(e.$hasUserRepliedOnce,"0px")}; z-index: 10; /* 🎯 根據接力邏輯控制顯示 */ visibility: ${e=>e.show?"visible":"hidden"}; opacity: ${e=>e.show?1:0}; transition: opacity 0s ease, visibility 0s ease; /* 🎯 關鍵:當訊息是 infoCards 時,讓頭像跟著最後一張卡片一起浮現 */ ${e=>"infoCards"===e.$messageType&&e.show?`\n opacity: 0;\n animation: avatarRiseIn 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards !important;\n /* 延遲時間計算:(卡片總數 - 1) * 0.5s 延遲 */\n animation-delay: ${.5*(e.$itemCount-1)}s !important;\n /* 🎯 重要:both 確保在延遲期間維持 0% 的狀態(即隱藏) */\n animation-fill-mode: both !important;\n @keyframes avatarRiseIn {\n 0% {\n opacity: 0;\n transform: translateY(10px);\n }\n 100% {\n opacity: 1;\n transform: translateY(0);\n }\n }\n `:""} img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; background: white; } `,$t=Pe.div` position: absolute; left: 12px; /* 對齊 ChatContent 的內邊距 */ bottom: 10px; /* 🎯 修正:從 16px 降為 10px,補平與 MessageAvatar 的 6px 落差 (82px -> 76px) */ width: 26px; height: 26px; border-radius: 50%; overflow: hidden; z-index: 1000; pointer-events: none; background: white; display: ${e=>e.show?"block":"none"}; img { width: 100%; height: 100%; object-fit: cover; } @media (max-width: 600px) { bottom: 10px; /* 🎯 手機版同步修正 */ left: 12px; } `,At=(Pe.div` height: 10px; margin-top: 5px; opacity: 0; pointer-events: none; visibility: hidden; `,Pe.div` display: inline-block; max-width: 240px; /* 🎯 稍微調整為 240px,確保「時光」能留在同一行,同時維持緊湊感 */ padding: 12px 14px; border-radius: 18px; /* 基礎圓角 */ font-size: 14px; line-height: 150%; letter-spacing: 0.28px; margin: 0; /* 🎯 統一底部對齊,移除 margin */ font-weight: 400; word-wrap: break-word; background: ${e=>e.isUser?Qe:tt}; color: ${e=>e.isUser?Ke:it}; white-space: pre-wrap; word-break: break-all; /* 🎯 確保中文換行更靈活 */ text-align: left; @media (max-width: 600px) { max-width: 280px; margin: 0; } @media (max-width: 375px) { max-width: 240px; margin: 0; } /* ======================================= ✨ 連續訊息的邊角樣式優化 (核心修改部分) ======================================= */ ${e=>{const t="0px",n="9px",r=!e.isFirstInGroup||!e.isLastInGroup;return e.isUser?`\n border-radius: ${n} ${n} ${t} ${n};\n `:r?e.isFirstInGroup&&!e.isLastInGroup?`\n border-radius: ${n} ${n} ${n} ${t};\n `:!e.isFirstInGroup&&e.isLastInGroup?`\n border-radius: ${t} ${n} ${n} ${n};\n `:e.isFirstInGroup||e.isLastInGroup?`border-radius: ${n};`:`\n border-radius: ${t} ${n} ${n} ${t};\n `:`border-radius:${n} ${n} ${n} ${t};`}} `),_t=Pe.div` flex: 1; position: relative; display: flex; flex-direction: column; overflow: hidden; `,Et=Pe.div` flex: 1; padding: 12px 12px 0 12px; overflow-y: auto; overflow-x: hidden; background: #ffff; position: relative; @media (max-width: 600px) { padding: 12px 12px 0 12px; } &::-webkit-scrollbar { width: 4px; } &::-webkit-scrollbar-track { background: transparent; } &::-webkit-scrollbar-thumb { background: ${et}; border-radius: 2px; } `,It=Pe.div` margin-bottom: 0px; display: flex; flex-direction: column; gap: 0px !important; `,Tt=Pe.div` display: flex; align-items: center; gap: ${ot}; padding: 8px 8px; border-radius: 9px 9px 9px 0px; `,Rt=Pe.span` width: 6px; height: 6px; background: #7b7b7b; border-radius: 50%; opacity: 0.5; animation: typing-bounce 1s infinite alternate; &:nth-child(2) { animation-delay: 0.2s; } &:nth-child(3) { animation-delay: 0.4s; } @keyframes typing-bounce { 0% { opacity: 0.5; transform: translateY(0); } 100% { opacity: 1; transform: translateY(-3px); } } `,Lt=Pe.div` display: flex; flex-direction: column; gap: ${at}; margin: 0; /* ✅ 移除 margin 确保头像对齐 */ align-items: flex-start; /* 🎬 整組按鈕一起進場動畫 */ opacity: 0; transform: translateY(10px); animation: suggestionGroupSlideIn 1s ease forwards; @keyframes suggestionGroupSlideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateX(0); } } `,Ot=Pe.div` display: flex; align-items: center; padding: 5px 16px; font-size: 14px; color: ${Qe}; background: ${Ke}; border: 1px solid ${Qe}; border-radius: 999px; cursor: pointer; transition: all 0.2s ease; font-weight: 400; white-space: nowrap; line-height: 150%; /* 21px */ letter-spacing: 0.28px; &:hover { background: ${Qe}; color: ${Ke}; } &:active { background: ${Qe}; color: ${Ke}; } `,Dt=Pe.div` display: flex; align-items: center; justify-content: center; margin: 0px 12px 12px 12px; /* 🎯 移除頂部 margin,讓 ChatContent 的 12px padding 決定距離 */ text-align: center; `,zt=Pe.div` color: ${nt}; border-radius: 12px; font-size: 12px; font-weight: 500; `,Bt=Pe.div` display: flex; flex-direction: column; align-items: center; justify-content: center; padding: ${pt}; gap: ${st}; `,Mt=Pe.div` color: ${rt}; font-size: 14px; `,Pt=(Pe.button` display: block; width: calc(100% - 24px); margin: ${st} ${st} 0 ${st}; padding: ${st}; background: ${Ke}; border: 1px solid ${et}; border-radius: 8px; color: ${Qe}; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.2s ease; display: flex; align-items: center; justify-content: center; gap: ${at}; &:hover { background: ${Je}; border-color: ${Qe}; } &:disabled { cursor: not-allowed; opacity: 0.6; } svg { animation: ${e=>e.isLoading?"spin 1s linear infinite":"none"}; } @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } `,t=>{let{onSend:n}=t;const[r,i]=(0,e.useState)(""),o=()=>{r.trim()&&(n(r),i(""))};return(0,Ge.jsxs)(bt,{children:[(0,Ge.jsx)(vt,{value:r,onChange:e=>i(e.target.value),onKeyPress:e=>"Enter"===e.key&&o(),placeholder:"輸入你想改善的情況..."}),(0,Ge.jsx)(wt,{visible:r.trim(),onClick:o,children:r.trim()?(0,Ge.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"23",height:"23",viewBox:"0 0 26 26",fill:"none",children:[(0,Ge.jsx)("rect",{width:"26",height:"26",rx:"13",fill:"#2783DE"}),(0,Ge.jsx)("path",{d:"M18.5963 7.00834C19.3413 6.92406 19.9823 7.48924 20 8.2182C18.6343 12.5728 17.0789 16.8762 15.6336 21.2091C15.2593 22.2426 13.7127 22.2691 13.3 21.2539L11.0071 15.4691L4.6349 13.3248C3.70677 12.8326 3.82488 11.5281 4.80212 11.1788L18.5963 7.00834Z",fill:"white"})]}):(0,Ge.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"23",height:"23",viewBox:"0 0 26 26",fill:"none",children:[(0,Ge.jsx)("rect",{width:"26",height:"26",rx:"13",fill:"#D9D9D9"}),(0,Ge.jsx)("path",{d:"M18.5963 7.00834C19.3413 6.92406 19.9823 7.48924 20 8.2182C18.6343 12.5728 17.0789 16.8762 15.6336 21.2091C15.2593 22.2426 13.7127 22.2691 13.3 21.2539L11.0071 15.4691L4.6349 13.3248C3.70677 12.8326 3.82488 11.5281 4.80212 11.1788L18.5963 7.00834Z",fill:"white"})]})})]})}),Gt=Pe.div` position: relative !important; /* 🎯 貼合左邊邊界核心:抵銷 parent padding (16px) + 頭像寬度 (32px) + 間距 (8px) = 56px */ width: 100% !important; /* 56px 左偏移 + 16px 右 padding */ max-width: 472px !important; height: 220px !important; margin: 0 !important; margin-left: -56px !important; /* 🎯 往左推到邊界 */ padding: 0 !important; box-sizing: border-box !important; -webkit-tap-highlight-color: transparent !important; /* 🍎 移除 iOS 点击高亮 */ user-select: none !important; /* 🚫 防止文字選擇,提升拖動體驗 */ overflow: visible !important; /* ✅ 改為 visible 让按钮完全显示 */ /* 🎬 整个轮播组件进场动画 */ opacity: 0; transform: translateY(10px); animation: messageSlideIn 0.5s ease forwards; @keyframes messageSlideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } } @media (max-width: 600px) { width: 100vw !important; /* 🎯 移動版:直接使用視窗寬度 */ max-width: 100vw !important; /* 🎯 移動版:限制為視窗寬度,防止溢出 */ height: 220px !important; /* ✅ 移動版也增加高度 */ margin-left: -56px !important; /* 🎯 移動端也要貼邊 */ padding: 0 !important; /* ✅ 移除 padding,讓 Viewport 佔滿全寬 */ } `,Nt=Pe.div` position: relative !important; width: 100% !important; height: 100% !important; /* 🎯 填满父容器 */ overflow-x: auto !important; overflow-y: hidden !important; -webkit-overflow-scrolling: touch !important; overscroll-behavior-x: contain !important; padding: 0 !important; box-sizing: border-box !important; background: transparent !important; /* 🎯 確保背景透明 */ touch-action: pan-x pan-y !important; /* ⛔ Hide horizontal scrollbar (ALL platforms) */ scrollbar-width: none; /* Firefox */ -ms-overflow-style: none; /* IE / legacy Edge */ &::-webkit-scrollbar { display: none; /* Chrome / Safari / iOS */ } `,Ut=Pe.div` display: flex !important; padding-left: 56px !important; /* 🎯 初始狀態對齊訊息文字 (抵銷 56px 負偏移) */ padding-right: 102px !important; gap: 10px !important; box-sizing: border-box !important; width: max-content !important; @media (max-width: 600px) { padding-right: 40px !important; } `,Ft=Pe.div` position: absolute !important; width: auto !important; min-width: 82px !important; height: 26px !important; top: 0px !important; left: 0px !important; background-color: #000 !important; border-radius: 900px !important; margin: 6px !important; z-index: 10 !important; box-sizing: border-box !important; display: flex !important; align-items: center !important; justify-content: center !important; padding: 0 10px !important; /* 🚀 修正閃爍:強制開啟 GPU 加速並鎖定渲染層 */ backface-visibility: hidden !important; transform: translateZ(0) !important; -webkit-font-smoothing: antialiased !important; `,Ht=Pe.div` display: flex !important; justify-content: center !important; align-items: center !important; color: white !important; font-size: 10px !important; font-weight: 700 !important; margin: 0 !important; letter-spacing: 0.5px !important; z-index: 10 !important; line-height: 1 !important; box-sizing: border-box !important; white-space: nowrap !important; /* 🚀 確保文字在滑動中不抖動 */ transform: translateZ(0) !important; `,Yt=Pe.div` background: #fff !important; border-radius: 9px !important; overflow: hidden !important; /* ✅ 1~2 張:不要用 auto 置中,確保在 mobile 也能對齊對話起點 */ margin: ${e=>e.$isSingle||e.$isStatic?"0":"0 auto"} !important; opacity: 1 !important; cursor: pointer !important; pointer-events: auto !important; position: relative !important; box-sizing: border-box !important; flex-shrink: 0 !important; width: ${e=>e.$isSingle?"100%":"158px"} !important; max-width: ${e=>e.$isSingle?"100%":"158px"} !important; min-width: ${e=>e.$isSingle?"0":"158px"} !important; transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.1) !important; /* 🎯 平滑的卡片過渡 */ will-change: transform !important; /* 🚀 GPU 加速 */ /* 🚀 修正閃爍:強制開啟 3D 渲染空間與隱藏背面,避免滑動時絕對定位元素閃爍 */ transform-style: preserve-3d !important; backface-visibility: hidden !important; transform: translateZ(0) !important; /* ✅ 手機版:就算只有一張卡片,也固定卡片寬度 158px(避免單張卡片變滿版) */ @media (max-width: 600px) { width: 158px !important; max-width: 158px !important; min-width: 158px !important; } `,Wt=Pe.img` width: 158px !important; height: 158px !important; aspect-ratio: 1/1 !important; border-radius: 9px !important; display: block !important; object-fit: cover !important; box-sizing: border-box !important; backface-visibility: hidden !important; /* 🚀 防止闪烁 */ transform: translateZ(0) !important; /* 🚀 GPU 加速 */ `,qt=Pe.a` display: block !important; text-decoration: none !important; color: inherit !important; cursor: pointer !important; `,Vt=Pe.div` padding: 6px 14px 5px 0px !important; box-sizing: border-box !important; `,Zt=Pe.div` display: flex !important; /* 啟用 Flexbox */ flex-direction: column !important; box-sizing: border-box !important; `,Xt=Pe.div` font-size: 15px !important; font-weight: 500 !important; color: #111827 !important; line-height: 1.4 !important; margin: 0 !important; padding: 0 !important; `,Qt=Pe.a` width: 100% !important; height: auto !important; font-weight: 300 !important; color: #7b7b7b !important; text-decoration: none !important; font-size: 13px !important; line-height: 1.4 !important; display: block !important; margin: 0 !important; padding: 0 !important; `,Kt=Pe.button` position: absolute !important; top: 40% !important; transform: translateY(-50%) !important; width: 43px !important; height: 100% !important; background-color: transparent !important; border-color: transparent !important; border: none !important; cursor: pointer !important; z-index: 10 !important; transition: all 0.2s ease !important; padding: 0 !important; margin: 0 !important; ${e=>e.isNext?"\n /* 🎯 電腦版:鎖定在 354px 寬度區域內 (56px 偏移 + 354px 寬 - 約 45px 按鈕寬) */\n left: auto !important;\n right: 60px !important;\n ":"left: 15px !important;"} @media (max-width: 600px) { /* 📱 手機版:維持原本相對右側定位,因為手機版通常是滿版 100vw */ ${e=>e.isNext?"right: 0px !important; left: auto !important;":"left: 15px !important;"} } `,Jt=t=>{let{items:n,onQuickAction:r}=t;const i=(0,e.useRef)(null),o=e=>{const t=i.current;if(!t)return;const n=t.scrollWidth-t.clientWidth,r=Math.min(Math.max(0,t.scrollLeft),n);let o=0;o=e<0?Math.max(168*e,-r):Math.min(168*e,n-r),t.scrollBy({left:o,behavior:"smooth"})},[a,s]=(0,e.useState)({});(0,e.useEffect)(()=>{s({})},[n]);const l=n?.length||0,c=1===l,p=l>=2,d=!p;return(0,Ge.jsxs)(Gt,{children:[p&&(0,Ge.jsx)(Kt,{onClick:()=>o(-1),children:(0,Ge.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"43",height:"43",viewBox:"0 0 43 43",fill:"none",children:[(0,Ge.jsx)("g",{filter:"url(#filter0_dd_1345_1137)",children:(0,Ge.jsx)("circle",{cx:"21.5",cy:"20.5",r:"17.5",fill:"#D9D9D9"})}),(0,Ge.jsx)("path",{d:"M23.9746 30L25 28.9717L17.0509 21L25 13.0283L23.9746 12L15 21L23.9746 30Z",fill:"white"}),(0,Ge.jsx)("defs",{children:(0,Ge.jsxs)("filter",{id:"filter0_dd_1345_1137",x:"0",y:"0",width:"43",height:"43",filterUnits:"userSpaceOnUse",colorInterpolationFilters:"sRGB",children:[(0,Ge.jsx)("feFlood",{floodOpacity:"0",result:"BackgroundImageFix"}),(0,Ge.jsx)("feColorMatrix",{in:"SourceAlpha",type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0",result:"hardAlpha"}),(0,Ge.jsx)("feOffset",{dy:"1"}),(0,Ge.jsx)("feGaussianBlur",{stdDeviation:"2"}),(0,Ge.jsx)("feComposite",{in2:"hardAlpha",operator:"out"}),(0,Ge.jsx)("feColorMatrix",{type:"matrix",values:"0 0 0 0 0.0470588 0 0 0 0 0.0470588 0 0 0 0 0.0509804 0 0 0 0.05 0"}),(0,Ge.jsx)("feBlend",{mode:"normal",in2:"BackgroundImageFix",result:"effect1_dropShadow_1345_1137"}),(0,Ge.jsx)("feColorMatrix",{in:"SourceAlpha",type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0",result:"hardAlpha"}),(0,Ge.jsx)("feOffset",{dy:"1"}),(0,Ge.jsx)("feGaussianBlur",{stdDeviation:"2"}),(0,Ge.jsx)("feComposite",{in2:"hardAlpha",operator:"out"}),(0,Ge.jsx)("feColorMatrix",{type:"matrix",values:"0 0 0 0 0.0470588 0 0 0 0 0.0470588 0 0 0 0 0.0509804 0 0 0 0.1 0"}),(0,Ge.jsx)("feBlend",{mode:"normal",in2:"effect1_dropShadow_1345_1137",result:"effect2_dropShadow_1345_1137"}),(0,Ge.jsx)("feBlend",{mode:"normal",in:"SourceGraphic",in2:"effect2_dropShadow_1345_1137",result:"shape"})]})})]})}),(0,Ge.jsx)(Nt,{ref:i,children:(0,Ge.jsx)(Ut,{children:n.map((e,t)=>(0,Ge.jsxs)(Yt,{$isSingle:c,$isStatic:d,className:[a[e.id]?"entered":""].filter(Boolean).join(" "),style:{"--card-index":t},onAnimationEnd:()=>{s(t=>t[e.id]?t:{...t,[e.id]:!0})},children:[(0,Ge.jsx)(Ft,{children:(0,Ge.jsxs)(Ht,{children:[e.tagText," · ",e.duration,"min"]})}),(0,Ge.jsx)(qt,{onClick:t=>{t.preventDefault(),t.stopPropagation(),r&&r(e)},children:(0,Ge.jsx)(Wt,{src:e.image,alt:e.title,draggable:"false",onDragStart:e=>e.preventDefault(),style:{userSelect:"none"}})}),(0,Ge.jsx)(Vt,{children:(0,Ge.jsxs)(Zt,{children:[(0,Ge.jsx)(Xt,{children:e.title}),(0,Ge.jsx)(Qt,{onClick:t=>{t.preventDefault(),t.stopPropagation(),r&&r(e)},children:e.description})]})})]},e.id))})}),p&&(0,Ge.jsx)(Kt,{isNext:!0,onClick:()=>o(1),children:(0,Ge.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"43",height:"43",viewBox:"0 0 43 43",fill:"none",children:[(0,Ge.jsx)("g",{filter:"url(#filter0_dd_1345_1140)",children:(0,Ge.jsx)("circle",{cx:"21.5",cy:"20.5",r:"17.5",fill:"#D9D9D9"})}),(0,Ge.jsx)("path",{d:"M19.0254 30L18 28.9717L25.9491 21L18 13.0283L19.0254 12L28 21L19.0254 30Z",fill:"white"}),(0,Ge.jsx)("defs",{children:(0,Ge.jsxs)("filter",{id:"filter0_dd_1345_1140",x:"0",y:"0",width:"43",height:"43",filterUnits:"userSpaceOnUse",colorInterpolationFilters:"sRGB",children:[(0,Ge.jsx)("feFlood",{floodOpacity:"0",result:"BackgroundImageFix"}),(0,Ge.jsx)("feColorMatrix",{in:"SourceAlpha",type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0",result:"hardAlpha"}),(0,Ge.jsx)("feOffset",{dy:"1"}),(0,Ge.jsx)("feGaussianBlur",{stdDeviation:"2"}),(0,Ge.jsx)("feComposite",{in2:"hardAlpha",operator:"out"}),(0,Ge.jsx)("feColorMatrix",{type:"matrix",values:"0 0 0 0 0.0470588 0 0 0 0 0.0470588 0 0 0 0 0.0509804 0 0 0 0.05 0"}),(0,Ge.jsx)("feBlend",{mode:"normal",in2:"BackgroundImageFix",result:"effect1_dropShadow_1345_1140"}),(0,Ge.jsx)("feColorMatrix",{in:"SourceAlpha",type:"matrix",values:"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0",result:"hardAlpha"}),(0,Ge.jsx)("feOffset",{dy:"1"}),(0,Ge.jsx)("feGaussianBlur",{stdDeviation:"2"}),(0,Ge.jsx)("feComposite",{in2:"hardAlpha",operator:"out"}),(0,Ge.jsx)("feColorMatrix",{type:"matrix",values:"0 0 0 0 0.0470588 0 0 0 0 0.0470588 0 0 0 0 0.0509804 0 0 0 0.1 0"}),(0,Ge.jsx)("feBlend",{mode:"normal",in2:"effect1_dropShadow_1345_1140",result:"effect2_dropShadow_1345_1140"}),(0,Ge.jsx)("feBlend",{mode:"normal",in:"SourceGraphic",in2:"effect2_dropShadow_1345_1140",result:"shape"})]})})]})})]})},en=t().memo(Jt),tn=Pe.div` position: relative !important; width: 100% !important; /* 🎯 占据可用宽度(会自动扣除头像空间) */ max-width: 100% !important; margin: 0 !important; /* ✅ 移除 margin 确保头像对齐 */ padding: 0 !important; box-sizing: border-box !important; overflow: hidden !important; `,nn=Pe.div` position: relative !important; width: 100% !important; max-width: 100% !important; overflow-y: hidden !important; overflow-x: hidden !important; height: auto !important; /* 🎯 自动高度,根据内容调整 */ max-height: 500px !important; /* 🎯 最大高度限制 */ padding: 0 !important; box-sizing: border-box !important; `,rn=Pe.div` display: flex !important; flex-direction: column !important; gap: 6px !important; width: 100% !important; box-sizing: border-box !important; ${e=>e.animateGroup?"\n /* 🎬 整組卡片一次進場(整行/整個區塊一起出現) */\n opacity: 0;\n transform: translateY(10px);\n animation: infoCardsGroupIn 0.3s ease both;\n\n @keyframes infoCardsGroupIn {\n from {\n opacity: 0;\n transform: translateY(10px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n ":""} `,on=Pe.div` width: 82px; height: 26px; margin-top: 2px; top: 0px; left: 0px; background-color: #000; border-radius: 900px; margin: 0px; z-index: 10; `,an=Pe.div` display: flex; justify-content: center; align-items: center; color: white; font-size: 10px; font-weight: 700; margin: 2px; letter-spacing: 0.5px; z-index: 10; `,sn=Pe.div` background: #ffff !important; border: 0.5px solid #d9d9d9 !important; width: 100% !important; /* 🎯 占据容器全宽(约 360px,已扣除头像空间) */ width: 276px !important; /* 🎯 最大宽度限制 */ min-height: 85px !important; height: auto !important; border-radius: 9px !important; overflow: hidden !important; margin: 0 !important; cursor: pointer !important; pointer-events: auto !important; position: relative !important; box-sizing: border-box !important; box-shadow: 0 8px 8px -4px rgba(0, 0, 0, 0.1), 0 2px 2px -1px rgba(0, 0, 0, 0.05) !important; display: flex !important; /* ✨ 將卡片內部設為 Flex 容器 */ align-items: center !important; /* ✨ 垂直居中對齊圖片和內容 */ transition: transform 0.2s ease, box-shadow 0.2s ease !important; &:hover { z-index: 5 !important; box-shadow: 0 12px 16px -4px rgba(0, 0, 0, 0.15), 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important; } ${e=>e.animateItems?"\n /* 🎬 單張卡片進場(一張一張出現,間隔 0.5s) */\n opacity: 0;\n transform: translateY(20px);\n animation: infoCardRiseIn 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;\n animation-delay: calc(var(--card-index) * 0.5s); /* 🎯 每張卡片間隔 0.5s */\n will-change: transform, opacity;\n\n @keyframes infoCardRiseIn {\n from {\n opacity: 0;\n transform: translateY(20px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n }\n ":"\n /* ❌ 沒有動畫時隱藏卡片 */\n opacity: 0;\n visibility: hidden;\n height: 0;\n min-height: 0;\n overflow: hidden;\n pointer-events: none;\n "} &:hover { box-shadow: 0 12px 16px -4px rgba(0, 0, 0, 0.15), 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important; } `,ln=Pe.img` width: 73px !important; height: 73px !important; min-width: 73px !important; min-height: 73px !important; margin: 6px 0px 6px 6px !important; aspect-ratio: 1/1 !important; border-radius: 9px !important; display: block !important; object-fit: cover !important; flex-shrink: 0 !important; `,cn=Pe.a` display: flex; align-items: center; text-decoration: none; color: inherit; `,pn=Pe.div` padding: 9px 7px 6px 6px; `,dn=Pe.div` display: flex; /* 啟用 Flexbox */ flex-direction: column; gap: 5px; `,un=Pe.div` display: flex; justify-content: center; height: 42px; font-size: 15px; font-weight: 500; color: #111827; `,mn=(Pe.a` width: 100%; height: auto; font-weight: 300; color: #7b7b7b; text-decoration: none; font-size: 13px; `,function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:24,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:22;return e?e.length>t?e.slice(0,n)+"......":e:""}),fn=t=>{let{items:n,animateGroup:r=!0,animateItems:i=!1,onQuickAction:o}=t;const{currentIndex:a,setCurrentIndex:s,isMobile:l,isDragging:c,dragX:p,handleDragStart:d,handleDragMove:u,handleDragEnd:m}=(()=>{const[t,n]=(0,e.useState)(0),[r,i]=(0,e.useState)(window.innerWidth<=600),[o,a]=(0,e.useState)(!1),[s,l]=(0,e.useState)(!1),[c,p]=(0,e.useState)(0),[d,u]=(0,e.useState)(0),[m,f]=(0,e.useState)(0);return(0,e.useEffect)(()=>{const e=()=>i(window.innerWidth<=600);return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]),{currentIndex:t,baseOffset:m,isMobile:r,isDragging:o,isClickBlocked:s,dragX:c,handleDragStart:e=>{a(!0),l(!1),u(e),p(0)},handleDragMove:(e,t,n)=>{if(!o)return;let r=e-d,i=r;const a=m+i,s=-t*n;if(a>0)i=.4*r;else if(a5&&l(!0),p(i)},handleDragEnd:(e,r)=>{if(!o)return;let i=t;c<-5&&t5&&t>0&&(i=t-1),f(-i*r),n(i),a(!1),p(0),setTimeout(()=>{l(!1)},100)},goToIndex:(e,t)=>{f(-e*t),n(e)}}})(),f=(0,e.useRef)(null);return(0,Ge.jsx)(tn,{children:(0,Ge.jsx)(nn,{children:(0,Ge.jsx)(rn,{ref:f,animateGroup:r,isMobile:l,currentIndex:a,totalItems:n.length,dragX:p,isDragging:c,onMouseDown:e=>d(e.clientX),onMouseMove:e=>u(e.clientX,n.length-1),onMouseUp:m,onMouseLeave:m,onTouchStart:e=>d(e.touches[0].clientX),onTouchMove:e=>u(e.touches[0].clientX,n.length-1),onTouchEnd:m,children:n.map((e,t)=>(0,Ge.jsxs)(sn,{animateItems:i,style:{"--card-index":t},"data-card-index":t,role:e.link||o?"link":void 0,tabIndex:e.link||o?0:void 0,onClick:()=>{c||o&&o(e)},onKeyDown:t=>{c||"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),o&&o(e))},children:[(0,Ge.jsx)(cn,{as:"div",onClick:t=>{c?t.preventDefault():(o&&o(e),t.stopPropagation())},children:(0,Ge.jsx)(ln,{src:e.image,alt:e.title,draggable:"false",onDragStart:e=>e.preventDefault(),style:{userSelect:"none"}})}),(0,Ge.jsx)(pn,{children:(0,Ge.jsxs)(dn,{children:[(0,Ge.jsx)(un,{title:e.title,children:mn(e.title)}),(0,Ge.jsx)(on,{children:(0,Ge.jsxs)(an,{children:[e.tagText," · ",e.duration,"min"," "]})})]})})]},e.id))})})})},hn=t().memo(fn),gn=e=>{let{size:t=14,style:n}=e;return(0,Ge.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",style:{display:"inline-block",verticalAlign:"middle",...n},children:[(0,Ge.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,Ge.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,Ge.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})},xn=e=>{let{message:n,isFirstInGroup:r,isLastInGroup:i,isLastMessage:o,onQuickAction:s,hasUserRepliedOnce:l,isLatestBotGroup:c,isBotActive:p}=e;const d=t().useRef(null),u=t().useRef(null),m=("cards"===n.type||"infoCards"===n.type||n.type,"cards"===n.type),f=l?i&&(!c||!p):i;return"typing"===n.type?(0,Ge.jsx)(kt,{isUser:!1,isLastInGroup:!0,isLastMessage:o,hasUserRepliedOnce:l,$messageType:"typing",children:(0,Ge.jsxs)(St,{isUser:!1,isFirstInGroup:!0,isHorizontalCards:!1,hasUserRepliedOnce:l,isLastMessage:o,children:[(0,Ge.jsx)(jt,{ref:d,hasUserRepliedOnce:l,show:!l,children:(0,Ge.jsx)("img",{src:a,alt:"冥想教練"})}),(0,Ge.jsx)(Ct,{isUser:!1,hasUserRepliedOnce:l,children:(0,Ge.jsx)("div",{style:{margin:0,padding:0,display:"flex",flexDirection:"column",alignItems:"flex-start"},children:(0,Ge.jsx)(At,{isUser:!1,isFirstInGroup:!0,isLastInGroup:!0,children:(0,Ge.jsx)(Tt,{style:{margin:0,padding:"2px 0"},children:[1,2,3].map(e=>(0,Ge.jsx)(Rt,{},e))})})})})]})}):(0,Ge.jsx)(kt,{isUser:"user"===n.sender,isLastInGroup:i,isLastMessage:o,hasUserRepliedOnce:l,$messageType:n.type,children:(0,Ge.jsxs)(St,{ref:u,isUser:"user"===n.sender,isFirstInGroup:r,isHorizontalCards:m,hasUserRepliedOnce:l,isLastMessage:o,children:["bot"===n.sender&&(0,Ge.jsx)(jt,{ref:d,$hasUserRepliedOnce:l,$messageType:n.type,$itemCount:n.items?.length||0,show:f,children:(0,Ge.jsx)("img",{src:a,alt:"冥想教練"})}),(0,Ge.jsx)(Ct,{isUser:"user"===n.sender,hasUserRepliedOnce:l,children:(0,Ge.jsx)("div",{style:{margin:0,padding:0,display:"flex",flexDirection:"column",alignItems:"flex-start"},children:"cards"===n.type?(0,Ge.jsx)("div",{style:{marginBottom:0},children:(0,Ge.jsx)("div",{"data-avatar-anchor":"bot-cards",children:(0,Ge.jsx)(en,{items:n.items,onQuickAction:s})})}):"infoCards"===n.type?(0,Ge.jsx)("div",{style:{marginBottom:0},children:(0,Ge.jsx)("div",{"data-avatar-anchor":"bot-infoCards",style:{paddingBottom:0},children:(0,Ge.jsx)(hn,{items:n.items,animateItems:!0,animateGroup:!1,onQuickAction:s})})}):"quickActions"===n.type?(0,Ge.jsx)("div",{style:{marginBottom:0},children:(0,Ge.jsx)(Lt,{"data-avatar-anchor":"bot-quickActions",children:n.actions.map((e,t)=>(0,Ge.jsxs)(Ot,{onClick:()=>{s(e?.action??e?.message??e?.url??e?.link??e?.href??e)},children:[e?.text??e?.name??e?.label??"",(e?.action?.link||e?.action?.url||e?.action?.href)&&(0,Ge.jsx)(gn,{size:14,style:{marginLeft:4}})]},t))})}):(0,Ge.jsx)("div",{style:{marginBottom:0},children:(0,Ge.jsx)(At,{isUser:"user"===n.sender,isFirstInGroup:r,isLastInGroup:i,children:(0,Ge.jsx)("span",{style:{whiteSpace:"pre-wrap",wordBreak:"break-word"},children:n.text??""})})})})})]})})},yn=n=>{let{conversationId:i,teaserText:o="冥想課程嗎6545645646?",displayMode:s="icon_with_teaser",avatarIcon:l="normal",demoMode:c=!1,onChatTeaserClose:p}=n;const[d,u]=(0,e.useState)(!1),[m,f]=(0,e.useState)(!1);(0,e.useEffect)(()=>{if("undefined"==typeof document)return;const e=new MutationObserver(e=>{const t=document.querySelector(".w-nav-button, .menu-button-custom");t&&f(t.classList.contains("w--open"))}),t=document.querySelector(".w-nav-button, .menu-button-custom");return t&&(e.observe(t,{attributes:!0,attributeFilter:["class"]}),f(t.classList.contains("w--open"))),()=>e.disconnect()},[]);const[h,g]=(0,e.useState)("#ffffff"),[x,y]=(0,e.useState)(!1),[b,v]=(0,e.useState)(!1),[w,k]=(0,e.useState)(!1),[S,C]=(0,e.useState)(0),j=(0,e.useRef)(0),$=(0,e.useRef)(!1);(0,e.useEffect)(()=>{const e=setTimeout(()=>{"true"===sessionStorage.getItem("chatTeaserClose")||k(e=>!d||e)},3e3);return()=>clearTimeout(e)},[d]);const A=(0,e.useRef)(null),_=(0,e.useRef)(null),E=(0,e.useRef)(null),[I,T]=(0,e.useState)(!1),R=(0,e.useRef)(null),L=(0,e.useRef)(null),O=(0,e.useRef)(null),D=(0,e.useRef)(null),z=(0,e.useMemo)(()=>(o||"").length>15,[o]),{messages:B,messagesEndRef:M,sendMessage:P,resetChat:G,refreshMessages:N,loadMoreHistory:U,hasMoreHistory:F,isLoading:H,isInitialized:Y,isBotStreaming:W,avatarIcon:q}=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};const n=(0,e.useRef)(Boolean(t?.demoMode)),i=(0,e.useRef)(!1),[o,a]=(0,e.useState)([]),[s,l]=(0,e.useState)(!1),[c,p]=(0,e.useState)(t?.avatarIcon||"normal"),[d,u]=(0,e.useState)(t.conversationId),[m,f]=(0,e.useState)(!1),[h,g]=(0,e.useState)(!0),[x,y]=(0,e.useState)(!1),b=(0,e.useRef)(null),v=(0,e.useRef)(!0),w=(0,e.useRef)(!1),k=(0,e.useRef)(Date.now()),S=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"smooth";setTimeout(()=>{b.current&&b.current.scrollIntoView({behavior:e})},100)},C=async()=>{if(m&&d&&!w.current&&!s&&!n.current){w.current=!0;try{const e=await r.getConversationHistory(d,{offset:-100,limit:100}),t=j(e);t.length>0&&(e.avatar_icon&&p(e.avatar_icon),a(e=>{const n=e.filter(e=>"typing"!==e.id);return n.length!==t.length||t.some((e,t)=>{const r=n[t];return!r||r.id!==e.id||r.text!==e.text})?t:e}))}catch(e){console.error("❌ [useChat] Refresh failed:",e)}finally{w.current=!1}}};(0,e.useEffect)(()=>{if("undefined"==typeof document)return;const e=()=>{"visible"===document.visibilityState&&C()};return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)},[m,d,s]),(0,e.useEffect)(()=>{o.length>0&&(v.current?(S("auto"),v.current=!1):S("smooth"))},[o,d]),(0,e.useEffect)(()=>{(async()=>{try{if(n.current)return u("demo_conversation"),y(!1),f(!0),void g(!1);let e=t?.conversationId;if(!e)throw new Error("useChat: conversationId is required");try{const t=await r.getConversationHistory(e,{offset:-100,limit:100}),n=t.turns||t.messages||t.history||[],i=j(t);t.avatar_icon&&p(t.avatar_icon),u(e),i.length>0&&(a(i),y(n.length>=100))}catch(e){throw console.error("❌ [History Debug] Fetch error:",e),e}f(!0)}catch(e){console.error("❌ [useChat Init] Fatal error during initialization:",e),f(!0)}finally{g(!1)}})()},[t?.conversationId]);const j=e=>{const t=[];let n=k.current,r=null;const i=e.turns||e.messages||e.history||e;return Array.isArray(i)?(i.forEach((e,n)=>{let i=(e=>{if(!e)return null;let t=e;"string"!=typeof e||e.includes("Z")||e.includes("+")||!e.includes("T")||(t=e+"Z");const n=new Date(t);return isNaN(n.getTime())?null:n})(e.timestamp||e.created_at||e.time);!i&&r?i=r:i&&(r=i);const o=String(e.role||"").toLowerCase();if("user"===o){let r=null;if(e.content&&Array.isArray(e.content)){const t=e.content.find(e=>e.message||e.text||e.name||e.trigger_intent);r=t?.message||t?.text||t?.name||t?.trigger_intent}if(r||(r=e.message||e.text||e.name||e.trigger_intent),r){const o=e.id||`u-${i?.getTime()||n}-${r.length}`;t.push({id:o,text:r,sender:"user",timestamp:i||new Date})}else console.warn(`⚠️ [handleHistoryApiResponse] User turn ${n} has no text:`,e)}else if("bot"===o||"assistant"===o)if(e.content&&Array.isArray(e.content)){const r=D(e.content).map((t,r)=>{const o=t.id||(e.id?`b-${e.id}-${r}`:`b-${i?.getTime()||n}-${r}`);return{...t,id:o,timestamp:i||new Date}});t.push(...r)}else if(e.message||e.text){const r=e.message||e.text,o=e.id||`b-${i?.getTime()||n}-${r.length}`;t.push({id:o,text:r,sender:"bot",senderName:"冥想教練",timestamp:i||new Date})}else console.warn(`⚠️ [handleHistoryApiResponse] Bot turn ${n} has no content/text:`,e);else console.warn(`⚠️ [handleHistoryApiResponse] Unknown role "${o}" in turn ${n}:`,e)}),k.current=n,t.length>1&&t[0].timestamp.getTime()>t[t.length-1].timestamp.getTime()&&t.reverse(),t):(console.error("❌ [handleHistoryApiResponse] history is not an array:",i),[])},$=(0,e.useRef)([]),A=(0,e.useRef)(0),_=(0,e.useRef)(!1),E=(0,e.useRef)(null),I=e=>new Promise(t=>setTimeout(t,e)),T=()=>{A.current+=1,$.current=[],_.current=!1,E.current=null},R=async e=>{if(!Array.isArray(e)||0===e.length)return;if($.current=[...$.current,...e],_.current)return;_.current=!0,l(!0);const t=A.current;E.current=t;try{for(;$.current.length>0&&A.current===t;){const e=$.current.shift();if(!e)continue;a(t=>[...t,e]);const t=O(e);await I(t)}}finally{E.current===t&&(_.current=!1,E.current=null,l(!1))}},L=()=>{T(),a(e=>e.filter(e=>"typing"!==e.id));const e=()=>k.current++;a(t=>[...t,{id:e(),sender:"user",text:"我想要減壓的冥想課程",timestamp:new Date}]),a(e=>[...e,{id:"typing",type:"typing",sender:"bot"}]),setTimeout(()=>{a(e=>e.filter(e=>"typing"!==e.id));const t=[{id:e(),sender:"bot",senderName:"冥想教練",text:"太好了!我先問你一個小問題:你想偏放鬆還是偏專注?",timestamp:new Date},{id:e(),type:"quickActions",sender:"bot",senderName:"冥想教練",timestamp:new Date,actions:[{text:"🌿 放鬆",action:{message:"放鬆"}},{text:"🎯 專注",action:{message:"專注"}},{text:"😴 睡眠",action:{message:"睡眠"}}]},{id:e(),sender:"bot",senderName:"冥想教練",text:"這裡有兩個精選課程,你可以直接點卡片圖片開連結:",timestamp:new Date},{id:e(),type:"cards",sender:"bot",senderName:"冥想教練",timestamp:new Date,items:[{id:"t1",title:"深度放鬆冥想",description:"釋放壓力,找回內心平靜",image:"https://images.unsplash.com/photo-1506126613408-eca07ce68773?w=400",tagText:"减压",duration:"15",link:"https://example.com/course/1"},{id:"t2",title:"正念呼吸練習",description:"專注當下,調節呼吸節奏",image:"https://images.unsplash.com/photo-1508672019048-805c876b67e2?w=400",tagText:"呼吸",duration:"10",link:"https://example.com/course/2"}]},{id:e(),sender:"bot",senderName:"冥想教練",text:"如果你想先看科普,我也整理了幾個主題:",timestamp:new Date},{id:e(),type:"infoCards",sender:"bot",senderName:"冥想教練",timestamp:new Date,items:[{id:"i1",title:"什麼是正念冥想?",image:"https://images.unsplash.com/photo-1506126613408-eca07ce68773?w=400",tagText:"科普",link:"https://example.com/info/1"},{id:"i2",title:"冥想對大腦的影響",image:"https://images.unsplash.com/photo-1499209974431-9dddcece7f88?w=400",tagText:"科普",link:"https://example.com/info/2"}]}];R(t)},600)};(0,e.useEffect)(()=>{if("undefined"!=typeof window&&(!0===window.__AIZEN_DEBUG__||!0===n.current))return window.__AIZEN_WIDGET_DEBUG__=window.__AIZEN_WIDGET_DEBUG__||{},window.__AIZEN_WIDGET_DEBUG__.injectTestSequence=L,window.__AIZEN_WIDGET_DEBUG__.replay=L,()=>{window.__AIZEN_WIDGET_DEBUG__&&(delete window.__AIZEN_WIDGET_DEBUG__.injectTestSequence,delete window.__AIZEN_WIDGET_DEBUG__.replay)}},[]),(0,e.useEffect)(()=>{n.current&&(i.current||m&&!h&&d&&(i.current=!0,setTimeout(()=>L(),500)))},[m,h,d]);const O=e=>{let t;return t="infoCards"===e.type||"cards"===e.type||"quickActions"===e.type?1500:(e.text?e.text.length:0)>100?1800:1500,t},D=e=>{const t=[];let n=k.current;return e.forEach(e=>{if(e.text&&t.push({id:n++,text:e.text,sender:"bot",senderName:"冥想教練",timestamp:new Date}),e.lessons&&e.lessons.length>0){const r=e.lessons;if(r.length>0&&r.every(e=>"科普"===e.category))r.forEach((e,i)=>{t.push({id:"info-"+n++,type:"infoCards",sender:"bot",senderName:"冥想教練",timestamp:new Date,items:[{...e,isCard:!0,id:e.id||"l-"+n++,title:e.title,image:e.button_image,tagText:e.category||e.subtitle||"",description:e.subtitle||"",duration:e.duration,category:e.category,link:e.url}],isSplitInfo:!0,splitIndex:i,isLastSplit:i===r.length-1})});else{const e=r.map(e=>({...e,isCard:!0,id:e.id||n++,title:e.title,image:e.button_image,tagText:e.category||e.subtitle||"",description:e.subtitle||"",duration:e.duration,category:e.category,link:e.url,ctaText:"進入課程",ctaLink:e.url}));t.push({id:n++,type:"cards",sender:"bot",senderName:"冥想教練",timestamp:new Date,items:e})}}e.actions&&e.actions.length>0&&t.push({id:n++,type:"quickActions",sender:"bot",senderName:"冥想教練",timestamp:new Date,actions:e.actions.map(e=>({text:e.name||e.text||e.label||e.message||"點擊",action:e}))})}),k.current=n,t};return{messages:o,messagesEndRef:b,sendMessage:async e=>{let i="",o=null,s=null,c=null;if("object"==typeof e&&null!==e){if(c=e,s=c.link||c.ctaLink||c.url||c.href,s||c.isCard)return s&&window.open(s,"_blank","noopener,noreferrer"),void(t.onCardAction&&t.onCardAction());i=c.name||c.text||c.message||c.title||"",o=c.trigger_intent,t.onCardAction&&t.onCardAction()}else i=e;if(i||o)if(a(e=>{const t=[...e.filter(e=>"typing"!==e.id)];return i&&"string"==typeof i&&i.trim()&&t.push({id:k.current++,text:i,sender:"user",timestamp:new Date}),t.push({id:"typing",type:"typing",sender:"bot"}),t}),n.current&&T(),!n.current&&m&&d){T();try{const e=await r.sendMessage(d,{message:i||void 0,trigger_intent:o||void 0,location_href:window.location.href});setTimeout(()=>{l(!0),a(e=>e.filter(e=>"typing"!==e.id)),e.avatar_icon&&p(e.avatar_icon),R(D(e.content))},300)}catch(e){setTimeout(()=>{a(e=>[...e.filter(e=>"typing"!==e.id),{id:k.current++,text:"抱歉,我現在無法正常回應。請檢查網路連線或稍後再試。",sender:"bot",senderName:"冥想教練",timestamp:new Date}])},800)}}else n.current&&setTimeout(()=>{a(e=>e.filter(e=>"typing"!==e.id))},500)},resetChat:async()=>{if(n.current)return a(e=>[...e.filter(e=>"typing"!==e.id),{id:"typing",type:"typing",sender:"bot"}]),T(),void setTimeout(()=>{a(e=>e.filter(e=>"typing"!==e.id));const e=()=>k.current++;R([{id:e(),sender:"bot",senderName:"冥想教練",text:"(Demo)我們重新開始囉!你想先看「課程」還是「科普」?",timestamp:new Date},{id:e(),type:"quickActions",sender:"bot",senderName:"冥想教練",timestamp:new Date,actions:[{text:"🎓 課程",action:{message:"課程"}},{text:"📚 科普",action:{message:"科普"}}]}])},500);if(d)try{a(e=>[...e.filter(e=>"typing"!==e.id),{id:"typing",type:"typing",sender:"bot"}]);const e=await r.sendMessage(d,{trigger_intent:"welcome",location_href:window.location.href});setTimeout(()=>{a(e=>e.filter(e=>"typing"!==e.id)),R(D(e.content))},800)}catch(e){a(e=>[...e.filter(e=>"typing"!==e.id),{id:k.current++,text:"重新開始對話時發生錯誤,請稍後再試。",sender:"bot",senderName:"冥想教練",timestamp:new Date}])}},refreshMessages:C,loadMoreHistory:async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;if(!d)return 0;try{const n=await r.getConversationHistory(d,{offset:e,limit:t}),i=j(n);return i.length>0?(a(e=>[...i,...e]),y(i.length>=t)):y(!1),i.length}catch(e){return 0}},isLoading:h,isBotStreaming:s,isInitialized:m,avatarIcon:c,conversationId:d,hasMoreHistory:x}}({demoMode:c,conversationId:i,avatarIcon:l}),V=(0,e.useCallback)(()=>{u(e=>{const t=!e;return t&&w&&k(!1),t})},[w]),Z=(0,e.useCallback)(()=>{u(!1)},[]),X=(0,e.useCallback)(()=>{"function"==typeof G&&G()},[G]);(0,e.useEffect)(()=>{},[d,Y]),(0,e.useEffect)(()=>{},[d]);const Q=(()=>{let e=-1;for(let t=B.length-1;t>=0;t--){const n=B[t];if("bot"!==n.sender&&"typing"!==n.type)break;e=t}return e})(),K=B.some(e=>"typing"===e.type),J=K||W,ee=(0,e.useRef)(null);(0,e.useEffect)(()=>{if(I)return;B.some(e=>"user"===e?.sender||"user"===e?.role)&&T(!0)},[B,I]);const te=e=>{P(e)},ne=B,re=e=>{const t=new Date(e);return isNaN(t.getTime())?"":`${t.getMonth()+1}/${t.getDate()} ${["星期日","星期一","星期二","星期三","星期四","星期五","星期六"][t.getDay()]}`};(0,e.useEffect)(()=>{if("undefined"==typeof window)return;const e=()=>C(e=>e+1);window.addEventListener("resize",e),window.addEventListener("orientationchange",e);const t=window.visualViewport,n=()=>e();return t&&(t.addEventListener("resize",n),t.addEventListener("scroll",n)),()=>{window.removeEventListener("resize",e),window.removeEventListener("orientationchange",e),t&&(t.removeEventListener("resize",n),t.removeEventListener("scroll",n))}},[]),(0,e.useEffect)(()=>{if("undefined"==typeof window)return;let e;const t=()=>{clearTimeout(e),e=window.setTimeout(()=>{C(e=>e+1),requestAnimationFrame(()=>{const e=window.scrollY;window.scrollTo(0,e)})},0)},n=()=>t(),r=()=>{"visible"===document.visibilityState&&t()};return window.addEventListener("pageshow",n),document.addEventListener("visibilitychange",r),window.addEventListener("focus",t),()=>{clearTimeout(e),window.removeEventListener("pageshow",n),document.removeEventListener("visibilitychange",r),window.removeEventListener("focus",t)}},[]),(0,e.useEffect)(()=>{const e=localStorage.getItem("aizen-chat-background");e&&g(e)},[]),(0,e.useEffect)(()=>{d&&B.length>0&&M.current&&requestAnimationFrame(()=>{M.current&&M.current.scrollIntoView({behavior:"instant",block:"end"})})},[d,B.length]),(0,e.useLayoutEffect)(()=>{if($.current&&_.current){const e=_.current.scrollHeight-j.current;e>0&&(_.current.scrollTop+=e),$.current=!1}},[B.length]),(0,e.useEffect)(()=>{if(!F||x||!d)return;const e=new IntersectionObserver(e=>{e[0].isIntersecting&&(async()=>{if(!x&&F&&_.current){j.current=_.current.scrollHeight,$.current=!0,y(!0);try{await U(B.length,20)}finally{y(!1)}}})()},{root:_.current,threshold:.1}),t=E.current;return t&&e.observe(t),()=>{t&&e.unobserve(t)}},[F,x,d,B.length]);const ie=w&&!d&&"icon_only"!==s,oe="undefined"!=typeof window&&window.innerWidth<=991;return(0,e.useLayoutEffect)(()=>{if("undefined"==typeof window||!ie)return;let e=!0,t=null;const n=t=>{if(!e)return;const n=L.current;if(!n)return;const r=n.getBoundingClientRect(),i=O.current,o=D.current,a=(i?.getBoundingClientRect(),o?.getBoundingClientRect(),document.querySelector(".aizen-toggle-button")),s=(a?.getBoundingClientRect(),function(){if("undefined"==typeof window)return{};const e=window.visualViewport,t=window.innerHeight,n=window.innerWidth,r=e?e.offsetTop+e.height:t,i="undefined"!=typeof document?document.documentElement:null;return{innerWidth:n,innerHeight:t,outerWidth:window.outerWidth,outerHeight:window.outerHeight,clientHeight:i?.clientHeight,clientWidth:i?.clientWidth,scrollHeight:i?.scrollHeight,devicePixelRatio:window.devicePixelRatio,visualViewport:e?{height:e.height,width:e.width,offsetTop:e.offsetTop,offsetLeft:e.offsetLeft,scale:e.scale,pageTop:e.pageTop,pageLeft:e.pageLeft}:null,innerMinusVisualHeight:null!=e?t-e.height:null,innerMinusVisualWidth:null!=e?n-e.width:null,visualBottomY:r}}());(function(){if("undefined"==typeof document)return null;const e=document.createElement("div");e.style.cssText="position:fixed;left:0;top:0;padding-top:env(safe-area-inset-top,0px);padding-bottom:env(safe-area-inset-bottom,0px);padding-left:env(safe-area-inset-left,0px);padding-right:env(safe-area-inset-right,0px);visibility:hidden;pointer-events:none;width:0;height:0;overflow:hidden",document.body.appendChild(e);const t=getComputedStyle(e);parseFloat(t.paddingTop),parseFloat(t.paddingBottom),parseFloat(t.paddingLeft),parseFloat(t.paddingRight);document.body.removeChild(e)})(),window.innerHeight,r.bottom,null!=s.visualViewport&&"number"==typeof s.visualBottomY&&(s.visualBottomY,r.bottom)};requestAnimationFrame(()=>{requestAnimationFrame(()=>n())});const r=window.setTimeout(()=>n(),320),i=window.visualViewport,o=()=>(null!=t&&clearTimeout(t),void(t=window.setTimeout(()=>{t=null,n()},80)));return i&&(i.addEventListener("resize",o),i.addEventListener("scroll",o)),()=>{e=!1,clearTimeout(r),null!=t&&clearTimeout(t),i&&(i.removeEventListener("resize",o),i.removeEventListener("scroll",o))}},[ie,S,z]),(0,Ge.jsxs)(dt,{ref:O,$hide:oe&&m,children:[(0,Ge.jsx)(mt,{ref:D,show:w&&!d&&"icon_only"!==s,$isLong:z,children:(0,Ge.jsxs)(ft,{ref:L,children:[(0,Ge.jsx)(gt,{onClick:e=>{e.stopPropagation(),k(!1),p?p():console.warn("[Teaser Debug] onChatTeaserClose is not defined in props")},children:(0,Ge.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"52",height:"52",viewBox:"0 0 52 52",fill:"none",children:[(0,Ge.jsx)("circle",{cx:"26",cy:"25",r:"10",fill:"white"}),(0,Ge.jsx)("path",{d:"M18 17L34 33",stroke:"#7B7B7B",strokeWidth:"4.25",strokeLinecap:"round"}),(0,Ge.jsx)("path",{d:"M34 17L18 33",stroke:"#7B7B7B",strokeWidth:"4.25",strokeLinecap:"round"})]})}),(0,Ge.jsx)(ht,{ref:R,$isLong:z,children:o})]})},o),(0,Ge.jsx)(ut,{isOpen:d,onClick:V,className:"aizen-toggle-button "+(d?"active":""),children:(0,Ge.jsx)(xt,{children:d?(0,Ge.jsxs)("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",children:[(0,Ge.jsx)("path",{d:"M6 6L18 18",stroke:"white",strokeWidth:"2",strokeLinecap:"round"}),(0,Ge.jsx)("path",{d:"M18 6L6 18",stroke:"white",strokeWidth:"2",strokeLinecap:"round"})]}):(0,Ge.jsx)("img",{src:"lesson"===q?"https://cdn.prod.website-files.com/64420a3911d6832c7ba8b105/69d760d87077677230a6f928_Aire%20%E9%A0%AD%E8%B2%BC-%E9%96%89%E7%9C%BC%E8%A1%A8%E6%83%85.png":"https://cdn.prod.website-files.com/64420a3911d6832c7ba8b105/69c600991a72bee63d16eb8c_1ab9ceaacf41248951a6b857106e7ed6_Aire%20%E9%A0%AD%E8%B2%BC.png",alt:"Aire"})})}),(0,Ge.jsxs)(yt,{background:h,isOpen:d,children:[(0,Ge.jsx)(Xe,{onReset:X,onClose:Z,onBackgroundChange:e=>{g(e),localStorage.setItem("aizen-chat-background",e)},currentBackground:h,isAiTyping:K,animationState:K?"thinking":"idle"}),(0,Ge.jsxs)(_t,{children:[(0,Ge.jsx)(Et,{ref:_,"data-chat-scroll-container":"true",children:H?(0,Ge.jsxs)(Bt,{children:[(0,Ge.jsx)(Tt,{children:[1,2,3].map(e=>(0,Ge.jsx)(Rt,{},e))}),(0,Ge.jsx)(Mt,{children:"載入對話中..."})]}):(0,Ge.jsxs)(It,{ref:A,children:[F&&(0,Ge.jsx)("div",{ref:E,style:{height:"20px",width:"100%",opacity:0}}),ne.map((e,n,r)=>{const i=r[n-1],o=!i||!((e,t)=>{if(!e||!t)return!1;const n=new Date(e),r=new Date(t);return n.getFullYear()===r.getFullYear()&&n.getMonth()===r.getMonth()&&n.getDate()===r.getDate()})(i.timestamp,e.timestamp),a=!r[n+1]||r[n+1].sender!==e.sender;return(0,Ge.jsxs)(t().Fragment,{children:[o&&e.timestamp&&(0,Ge.jsx)(Dt,{children:(0,Ge.jsx)(zt,{children:re(e.timestamp)})}),(0,Ge.jsx)(xn,{message:e,isLastMessage:n===r.length-1,isFirstInGroup:!r[n-1]||r[n-1].sender!==e.sender,isLastInGroup:a,onQuickAction:te,hasUserRepliedOnce:I,isLatestBotGroup:n>=Q,isBotActive:J})]},`${e.id}-${n}`)}),(0,Ge.jsx)("div",{ref:M})]})}),d&&I&&(0,Ge.jsx)($t,{ref:ee,show:J,children:(0,Ge.jsx)("img",{src:a,alt:"冥想教練"})})]}),(0,Ge.jsx)(Pt,{onSend:te})]})]})},bn="aizen-chat-container";let vn=null;const wn={init:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(vn)return;if(!e.getTokenFn||"function"!=typeof e.getTokenFn)throw new Error("AIZEN Widget initialization failed: getTokenFn function is required");if(r.setGetToken(e.getTokenFn),!e.conversationId)throw new Error("AIZEN Widget initialization failed: conversationId is required");e.apiHost&&r.setBaseURL(e.apiHost);const i={...e,teaserText:e.teaserText||"需要幫助嗎?",displayMode:e.displayMode||"icon_with_teaser",demoMode:!0===e.demoMode},o=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:bn,t=document.getElementById(e);return t||(t=document.createElement("div"),t.id=e,document.body.appendChild(t)),t}(e.containerId||bn);vn=(0,n.H)(o),vn.render(t().createElement(yn,i))},destroy:function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!vn)return;vn.unmount(),vn=null;const t=e.containerId||bn,n=document.getElementById(t);n&&n.parentNode&&n.parentNode.removeChild(n)},show:()=>{if(vn){const e=document.getElementById(bn);e&&(e.style.display="block")}},hide:()=>{if(vn){const e=document.getElementById(bn);e&&(e.style.display="none")}}};"undefined"!=typeof window&&(window.AizenWidget=window.AizenWidget||wn,window.AizenWidget.version="v1.0.80-FIXLEFT");const kn=wn})(),o.default})());