import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{er as t}from"./control-ui-foundation-CeFMP1Ly.js";import{fl as n,fs as r,ml as i,ms as a}from"./control-ui-core-pH6nakZ-.js";import{G as o,J as s,W as c,Z as l,at as u,rt as d}from"./lit-runtime-BEtFSUCp.js";import{Ht as f,Lt as p,Rt as m,qt as h}from"./control-ui-core-Br5DB0Zj.js";import{F as g,I as _,L as v,z as y}from"./control-ui-boot-wpHCbPL9.js";import{Da as b,Ea as x,Oa as S,Ta as C,co as w,do as T,lo as E}from"./control-ui-boot-Cdpgu1Gm.js";function D(e){if(!e?.trim())return null;try{let t=new URL(e);return t.protocol===`https:`||t.protocol===`http:`?t.href:null}catch{return null}}function O(e){let t=D(e);if(!t)return null;let n=new URL(t);if(n.origin===window.location.origin)return null;if(n.searchParams.get(`openclawHostTheme`)!==`1`||!/^\/embed\/(?:channel|thread)\/[^/]+\/[^/]+\/?$/u.test(n.pathname))return n.href;n.searchParams.set(`theme`,document.documentElement.dataset.themeMode===`light`?`light`:`dark`),n.searchParams.set(`hostOrigin`,window.location.origin);let r=w().tokens;return Object.keys(r).length>0&&n.searchParams.set(`themeTokens`,JSON.stringify(r)),n.href}var k;function A(){return(A=e((()=>{g(),c(),l(),m(),b(),C(),f(),a(),E(),i(),k=class extends n{constructor(...e){super(...e),this.sessionKey=``,this.loadInfo=null,this.openDiscussion=null,this.onStateChange=null,this.canOpen=!0,this.sourceGeneration=0,this.openingDiscussion=null,this.themeObserver=null,this.discussionTask=new _(this,{args:()=>[this.sessionKey.trim(),this.loadInfo,this.openDiscussion,this.sourceGeneration,this.canOpen],task:async([e,t,n,r,i],{signal:a})=>{if(!t||!e)return null;let o=await t(e);a.throwIfAborted();let s={sessionKey:e,loader:t,opener:n,sourceGeneration:r,canOpen:i};if(!this.isOpeningCurrent(s))return v;let c=o;if(o.state===`available`&&i&&n){if(this.openingDiscussion=s,this.publish(e,o),!this.isOpeningCurrent(s))return v;c=await n(e)??o}return a.throwIfAborted(),this.isOpeningCurrent(s)?{sessionKey:e,info:c}:v},onComplete:e=>{this.openingDiscussion=null,e&&this.publish(e.sessionKey,e.info)},onError:()=>{this.openingDiscussion=null}}),this.handleDiscussionFrameLoad=e=>{let t=e.currentTarget;t instanceof HTMLIFrameElement&&this.postDiscussionTheme(t)}}isOpeningCurrent(e){return e.sessionKey===this.sessionKey.trim()&&e.loader===this.loadInfo&&e.opener===this.openDiscussion&&e.sourceGeneration===this.sourceGeneration&&e.canOpen===this.canOpen}connectedCallback(){super.connectedCallback(),!(typeof MutationObserver>`u`)&&(this.themeObserver=new MutationObserver(()=>this.postDiscussionTheme()),this.themeObserver.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`,`data-theme-mode`,`style`]}))}disconnectedCallback(){this.themeObserver?.disconnect(),this.themeObserver=null,super.disconnectedCallback()}postDiscussionTheme(e=this.querySelector(`.session-discussion__frame`)){e?.isConnected&&T(e,new URL(e.src).origin)}publish(e,t){e===this.sessionKey.trim()&&this.onStateChange?.(e,t.state,D(t.openUrl))}renderOpen(e){let t=O(e.embedUrl),n=D(e.openUrl);return s`
      <div class="session-discussion__open">
        ${t?s`
              <iframe
                class="session-discussion__frame"
                src=${t}
                title=${h(`chat.sessionDiscussion.frameTitle`)}
                sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"
                @load=${this.handleDiscussionFrameLoad}
              ></iframe>
            `:S({icon:p.messageSquare,heading:h(`chat.sidePanel.discussion`),description:h(`chat.sessionDiscussion.unavailable`),action:n?s`<a class="session-link" href=${n} target="_blank" rel="noopener">
                    ${h(`chat.sessionDiscussion.openExternal`)}
                  </a>`:o})}
      </div>
    `}render(){if(this.discussionTask.status===y.ERROR){let e=this.discussionTask.error;return s`<div class="session-discussion__empty">
        <div class="callout danger">${r(e)}</div>
      </div>`}let e=this.discussionTask.value,t=!!(this.loadInfo&&this.sessionKey.trim())&&this.discussionTask.status===y.PENDING;if(t&&this.openingDiscussion&&this.isOpeningCurrent(this.openingDiscussion))return x(`discussion`,h(`chat.sessionDiscussion.opening`));if(t)return x(`discussion`,h(`chat.sessionDiscussion.loading`));if(this.discussionTask.status!==y.COMPLETE||!e)return o;let{info:n}=e;return n.state===`none`?o:n.state===`available`?this.canOpen?S({icon:p.messageSquare,heading:h(`chat.sidePanel.discussion`),description:h(`chat.sessionDiscussion.unavailable`)}):S({icon:p.messageSquare,heading:h(`chat.sidePanel.discussion`),description:h(`chat.sessionDiscussion.requiresWriteAccess`)}):this.renderOpen(n)}},t([u()],k.prototype,`sessionKey`,void 0),t([u({attribute:!1})],k.prototype,`loadInfo`,void 0),t([u({attribute:!1})],k.prototype,`openDiscussion`,void 0),t([u({attribute:!1})],k.prototype,`onStateChange`,void 0),t([u({type:Boolean})],k.prototype,`canOpen`,void 0),t([u({type:Number})],k.prototype,`sourceGeneration`,void 0),t([d()],k.prototype,`openingDiscussion`,void 0),customElements.get(`openclaw-session-discussion`)||customElements.define(`openclaw-session-discussion`,k)})))()}A();
//# sourceMappingURL=session-discussion-panel-3-zZr__N.js.map