import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Ei as t,Fi as n,er as r}from"./control-ui-foundation-CeFMP1Ly.js";import{U as i,cs as a,is as o}from"./control-ui-core-pH6nakZ-.js";import{G as s,J as c,W as l,Z as u,at as d,rt as f}from"./lit-runtime-BEtFSUCp.js";import{Cn as p,Gn as m,Sn as h,bn as g,cn as _,gn as v,ln as y,mn as ee,on as te,pn as b,qn as x,vn as S,wn as ne,yn as re,zn as C}from"./control-ui-core-DGVkFhVB.js";import{Ht as w,K as ie,Lt as T,Rt as E,q as ae,qt as D}from"./control-ui-core-Br5DB0Zj.js";import{Hl as oe,Ul as O,wr as k}from"./control-ui-boot-Cdpgu1Gm.js";import{a as A,c as j,g as M,h as N,i as P,n as F,t as I}from"./config-form.tiers-DLXolKGz.js";import{d as L,o as R,p as z,r as B}from"./memory-schema-3MkJhUhF.js";import{a as V,i as H}from"./settings-targets-GAGqNu16.js";function U(e){let t=D(e.labelKey);return{routeId:e.routeId,...e.search===void 0?{}:{search:e.search},hash:e.hash,label:t,searchText:[t,...e.searchKeys.map(e=>D(e)),e.aliases??``].join(` `)}}function W(e,t){let n=q[e],r=t.properties;if(!n||!r)return t;let i=new Set(n());return{...t,properties:Object.fromEntries(Object.entries(r).filter(([e])=>i.has(e)))}}function G(e){if(!e.query.trim())return[];let t=j(e.query),n=t.tags.length===0&&t.text?K.filter(t=>(e.identityAvailable||!t.requiresIdentity)&&b(t.routeId,e.canAdmin!==!1)).map(U).filter(e=>g(e.searchText,t.text)):[],r=e.schema&&typeof e.schema==`object`&&!Array.isArray(e.schema)?e.schema:null;if(!r||a(r)!==`object`||!r.properties)return n;let i=e.value??{};for(let[t,a]of Object.entries(r.properties)){let r=L(t);if(!b(r,e.canAdmin!==!1))continue;let o=W(r,a),s=N[t],c=F({schema:o,path:[t],hints:e.uiHints}),l=n=>!!(n&&A({key:t,schema:n,value:i[t],hints:e.uiHints,query:e.query,label:s?.label,description:s?.description,textMatcher:g})),u=l(c.common),d=l(c.advanced);if(!u&&!d)continue;let f=encodeURIComponent(t),p={search:``,hash:`#config-section-${f}`};n.push(r===`memory`?{routeId:r,label:s?.label??o.title??t,pathname:m(`settings`,e.basePath),hash:p.hash}:{routeId:r,label:s?.label??o.title??t,search:`?section=${f}${d?`&advanced=1`:``}`,hash:p.hash})}return n}var K,q;function J(){return(J=e((()=>{y(),C(),M(),P(),I(),w(),o(),z(),B(),V(),K=Object.values(H),q={memory:R,updates:()=>[`channel`,`auto`]}})))()}var Y,X;function Z(){return(Z=e((()=>{l(),u(),w(),E(),Y=2e3,X=class extends n{constructor(...e){super(...e),this.savedVisible=!1}createRenderRoot(){return this}willUpdate(){let e=this.props?.status;this.previousStatus===`saving`&&e===`saved`?(this.clearSavedTimer(),this.savedVisible=!0,this.savedTimer=globalThis.setTimeout(()=>{this.savedTimer=void 0,this.savedVisible=!1},Y)):e!==`saved`&&(this.clearSavedTimer(),this.savedVisible=!1),this.previousStatus=e}disconnectedCallback(){this.clearSavedTimer(),super.disconnectedCallback()}clearSavedTimer(){globalThis.clearTimeout(this.savedTimer),this.savedTimer=void 0}renderClaw(e){return c`<span class="settings-save-indicator__claw ${e}" aria-hidden="true"
      >${T.claw}</span
    >`}render(){let e=this.props;if(!e)return s;let t,n=``,r=``,i=``;if(e.applying)t=c` <span class="settings-save-indicator__spinner" aria-hidden="true"
          >${T.loader}</span
        >
        <span>${D(`configView.applying`)}</span>`;else if(e.status===`saving`)t=c` ${this.renderClaw(`settings-save-indicator__claw--saving`)}
        <span>${D(`configView.autoSaveSaving`)}</span>`;else if(e.status===`error`)i=e.lastError?.trim()??``,r=i?`${D(`configView.autoSaveFailed`)}: ${i}`:``,n=` settings-save-indicator--danger`,t=c` <span>${D(`configView.autoSaveFailed`)}</span>
        <button
          class="btn btn--xs settings-save-indicator__action"
          type="button"
          @click=${e.onRetry}
        >
          ${D(`configView.retry`)}
        </button>`;else if(e.status===`paused`)t=c` <span>${D(`configView.autoSavePaused`)}</span>
        <button
          class="btn btn--xs settings-save-indicator__action"
          type="button"
          @click=${e.onRetry}
        >
          ${D(`configView.saveNow`)}
        </button>`;else if(e.status===`conflict`)n=` settings-save-indicator--danger`,t=c` <span>${D(`configView.autoSaveConflict`)}</span>
        <button
          class="btn btn--xs settings-save-indicator__action"
          type="button"
          @click=${e.onReload}
        >
          ${D(`common.reload`)}
        </button>`;else if(this.savedVisible)n=` settings-save-indicator--saved`,t=c` ${this.renderClaw(`settings-save-indicator__claw--saved`)}
        <span class="settings-save-indicator__check" aria-hidden="true">${T.check}</span>
        <span>${D(`configView.autoSaveSaved`)}</span>`;else if(e.needsApply)t=c` <button
        class="btn btn--xs settings-save-indicator__apply"
        type="button"
        ?disabled=${e.applyDisabled}
        @click=${e.onApply}
      >
        ${D(`configView.applyChanges`)}
      </button>`;else return s;return c`<div
      class="settings-save-indicator${n}"
      role="status"
      aria-live="polite"
      aria-label=${r||s}
      title=${i||s}
    >
      ${t}
    </div>`}},r([d({attribute:!1})],X.prototype,`props`,void 0),r([f()],X.prototype,`savedVisible`,void 0),customElements.get(`openclaw-settings-save-indicator`)||customElements.define(`openclaw-settings-save-indicator`,X)})))()}function se(e,n){if(n.pathname)return!1;let r=t(n.label);return[S(e),p(e)].some(e=>t(e)===r)}function ce(e,n,r){let i=ne(r),a=n.filter(e=>b(e.routeId,r)),o=t(e);if(!o)return i.map(e=>({labelKey:e.labelKey,items:e.routes.map(e=>({routeId:e,blocks:[]}))}));let s=i.flatMap(e=>e.routes),c=[...new Set([...s,...te.filter(e=>b(e,r)),...a.map(e=>e.routeId)])],l=c.filter(e=>[S(e),p(e),h(e)].some(e=>g(e,o))),u=new Set(l),d=i.flatMap(e=>e.labelKey&&g(D(e.labelKey),o)?e.routes.filter(e=>!u.has(e)&&(u.add(e),!0)):[]),f=new Map,m=new Set;for(let e of a){let t=`${e.routeId}\u0000${e.pathname??``}\u0000${e.search??``}\u0000${e.hash}`;if(m.has(t))continue;m.add(t);let n=f.get(e.routeId)??[];n.push(e),f.set(e.routeId,n)}let _=[...l,...d];return[..._.length>0?[{labelKey:null,items:_.map(e=>({routeId:e,blocks:(f.get(e)??[]).filter(t=>!se(e,t))}))}]:[],...c.filter(e=>!u.has(e)&&f.has(e)).map(e=>({labelKey:null,items:[{routeId:e,blocks:f.get(e)??[]}]}))]}function le(e,t,n){let r=re(e.activeRouteId)===t;return c`
    <a
      href=${x(t,e.basePath)}
      class="settings-sidebar__item ${r?`settings-sidebar__item--active`:``}"
      aria-current=${r?`page`:s}
      @focus=${n=>v(e.preloadTimers,t,n,e.onPreload,r)}
      @blur=${t=>_(e.preloadTimers,t)}
      @pointerenter=${n=>v(e.preloadTimers,t,n,e.onPreload,r)}
      @pointerleave=${t=>_(e.preloadTimers,t)}
      @touchstart=${n=>v(e.preloadTimers,t,n,e.onPreload,r,!0)}
      @click=${n=>{i(n)&&(n.preventDefault(),e.onNavigate(t))}}
    >
      <span class="settings-sidebar__item-icon" aria-hidden="true"
        >${T[ee(t)]}</span
      >
      <span class="settings-sidebar__item-label"
        >${n??S(t)}</span
      >
    </a>
  `}function ue(e,t){let n=(t.pathname??x(t.routeId,e.basePath))+(t.search??``)+t.hash,r=e.activeRouteId===t.routeId&&(t.pathname===void 0||e.activePathname===t.pathname)&&e.activeHash===t.hash&&(t.search===void 0||e.activeSearch===t.search);return c`
    <a
      href=${n}
      class="settings-sidebar__subitem ${r?`settings-sidebar__subitem--active`:``}"
      aria-current=${r?`location`:s}
      @click=${n=>{i(n)&&(n.preventDefault(),e.onNavigate(t.routeId,{...t.pathname?{pathname:t.pathname}:{},...t.search?{search:t.search}:{},hash:t.hash}))}}
    >
      <span class="settings-sidebar__subitem-label">${t.label}</span>
    </a>
  `}function Q(e){e.closest(`.settings-sidebar`)?.querySelector(`.settings-sidebar__search`)?.classList.toggle(`settings-sidebar__search--scrolled`,e.scrollTop>0)}function de(e){let t=D(`connection.reconnecting`),n=e.searchBlockMatches??(e.searchParams?G(e.searchParams):[]),r=ce(e.searchQuery,n,e.canAdmin!==!1);return c`
    <aside class="settings-sidebar">
      <header class="settings-sidebar__header">
        <button type="button" class="settings-sidebar__back" @click=${()=>e.onExit()}>
          <span class="settings-sidebar__back-icon" aria-hidden="true">${T.arrowLeft}</span>
          ${D(`nav.exitSettings`)}
          <kbd class="settings-sidebar__esc" aria-hidden="true">esc</kbd>
        </button>
        <h1 class="settings-sidebar__title">${D(`nav.settings`)}</h1>
      </header>
      <div class="settings-sidebar__search" role="search">
        <span class="settings-sidebar__search-icon" aria-hidden="true">${T.search}</span>
        <input
          class="settings-sidebar__search-input"
          type="search"
          autocomplete="off"
          spellcheck="false"
          aria-label=${D(`nav.settingsSearchLabel`)}
          placeholder=${D(`nav.settingsSearchPlaceholder`)}
          .value=${e.searchQuery}
          @input=${t=>e.onSearchQueryChange(t.currentTarget.value)}
          @keydown=${t=>{if(t.key===`Escape`){if(t.preventDefault(),e.searchQuery){e.onSearchQueryChange(``);return}e.onExit()}}}
        />
        ${e.searchQuery?c`
              <button
                type="button"
                class="settings-sidebar__search-clear"
                aria-label=${D(`nav.settingsSearchClear`)}
                @click=${t=>{let n=t.currentTarget.parentElement?.querySelector(`input`);e.onSearchQueryChange(``),n?.focus()}}
              >
                ${T.x}
              </button>
            `:s}
      </div>
      <nav
        class="settings-sidebar__nav"
        aria-label=${D(`common.settingsSections`)}
        @scroll=${e=>Q(e.currentTarget)}
      >
        ${r.length===0?c`<p class="settings-sidebar__empty" role="status">
              ${D(`nav.settingsSearchNoResults`)}
            </p>`:r.map(t=>c`
                <div class="settings-sidebar__group">
                  ${t.labelKey?c`<div class="settings-sidebar__group-label">${D(t.labelKey)}</div>`:s}
                  ${t.items.map(t=>c`
                      ${le(e,t.routeId)}
                      ${t.blocks.map(t=>ue(e,t))}
                    `)}
                </div>
              `)}
      </nav>
      <footer class="settings-sidebar__footer">
        ${e.restartPending||e.offline?O({kind:e.restartPending?`restarting`:`offline`,queuedOutboxCount:e.queuedOutboxCount??0,title:e.lastError?ae(e.lastError):t,onRetry:e.onRetryConnect}):c`<openclaw-settings-save-indicator
              .props=${e.saveIndicator}
            ></openclaw-settings-save-indicator>`}
        <openclaw-sidebar-build-chip
          .basePath=${e.basePath}
          .gatewayVersion=${e.gatewayVersion||null}
          .variant=${`settings`}
          .onNavigate=${()=>e.onNavigate(`about`)}
        ></openclaw-sidebar-build-chip>
      </footer>
    </aside>
  `}function $(){return($=e((()=>{l(),y(),C(),w(),J(),E(),ie(),oe(),Z(),k()})))()}$();export{de as renderSettingsSidebar};
//# sourceMappingURL=settings-sidebar-C0XMfym-.js.map