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`