import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{Zr as t,er as n}from"./control-ui-foundation-CeFMP1Ly.js";import{$t as r,Aa as i,An as a,Cn as o,Da as s,Hr as c,Ur as l,Vr as ee,Xr as u,dn as d,fl as f,fn as p,ja as m,ml as h,qr as g,un as _,vr as v,wr as y,yr as b}from"./control-ui-core-pH6nakZ-.js";import{G as x,J as S,W as C,Z as w,at as te}from"./lit-runtime-BEtFSUCp.js";import{Cn as T,Jn as ne,Jt as re,Yt as E,ln as ie,m as D,p as O,qn as k,zn as ae}from"./control-ui-core-DGVkFhVB.js";import{Dt as oe,Ft as se,Ht as A,Lt as j,Nt as ce,Ot as le,Rt as M,qt as N}from"./control-ui-core-Br5DB0Zj.js";import{In as ue,Ln as de}from"./control-ui-boot-wpHCbPL9.js";import{n as P,t as F}from"./workboard-board-glyph-f8SLNsbu.js";import{_ as I,a as L,b as R,c as z,d as B,f as V,g as H,h as fe,i as pe,l as me,m as he,n as ge,o as _e,p as ve,r as ye,s as be,t as xe,u as Se,v as U,x as Ce,y as we}from"./view-card-DMysdVMQ.js";import{i as Te}from"./mutations-BYbn2CZG.js";import{c as Ee,g as De,h as Oe,m as ke,o as Ae,s as je,t as W,u as G,v as Me}from"./workboard-D4DxP9hk.js";import{t as Ne}from"./agent-select-registration-Bgp9CYzQ.js";import{n as Pe,t as Fe}from"./agent-scope-control-C6P46hJO.js";function Ie(e){let t=e.lastDispatchSummary;if(!t)return x;let n=Object.values(t).reduce((e,t)=>e+t,0)===0?`workboard.dispatchSummaryEmpty`:`workboard.dispatchSummary`;return S`
    <div class="callout">
      ${N(n,{started:String(t.started),failures:String(t.failures),promoted:String(t.promoted),blocked:String(t.blocked),reclaimed:String(t.reclaimed),orchestrated:String(t.orchestrated)})}
    </div>
  `}function Le(e,t,n){let r=[[`running`,N(`workboard.healthRunning`),t.running],[`blocked`,N(`workboard.healthBlocked`),t.blocked],[`stale`,N(`workboard.healthStale`),t.stale],[`readyUnassigned`,N(`workboard.healthReadyUnassigned`),t.readyUnassigned],[`missingProof`,N(`workboard.healthMissingProof`),t.missingProof],[`failedAttempts`,N(`workboard.healthFailedAttempts`),t.failedAttempts]];return S`
    <div class="workboard-health" aria-label=${N(`workboard.healthLabel`)}>
      ${r.map(([t,r,i])=>S`
          <button
            class="workboard-health__item workboard-health__item--${t} ${e.activeHealthHighlight===t?`workboard-health__item--active`:``} ${i===0?`workboard-health__item--empty`:``}"
            type="button"
            aria-pressed=${e.activeHealthHighlight===t}
            aria-label=${`${i} ${r}`}
            @click=${()=>{e.activeHealthHighlight=e.activeHealthHighlight===t?null:t,n?.()}}
          >
            <strong>${i}</strong>${r}
          </button>
        `)}
    </div>
  `}function K(e){return e.lastRefreshAt?S`<span
      class="workboard-refresh-status ${e.lastRefreshError?`workboard-refresh-status--error`:``}"
      title=${e.lastRefreshError?N(`workboard.refreshError`):``}
    >
      ${N(`workboard.lastRefreshed`,{time:he(e.lastRefreshAt)})}
    </span>`:e.lastRefreshError?S`<span class="workboard-refresh-status workboard-refresh-status--error">
        ${N(`workboard.refreshError`)}
      </span>`:x}function Re(e){let n=r(e.host);if(e.pluginEnabled===null)return e.pluginEnablementError?S`
        <section class="workboard">
          <div class="callout danger" role="alert">${e.pluginEnablementError}</div>
          ${e.onReloadConfig?S`<button class="btn" type="button" @click=${e.onReloadConfig}>
                ${N(`lazyView.retry`)}
              </button>`:x}
        </section>
      `:le();if(!e.pluginEnabled)return S`
      <section class="workboard">
        <div class="callout">
          ${N(`workboard.disabledHelpStart`)}
          <code>${N(`workboard.enableConfigKey`)}</code>${N(`workboard.disabledHelpEnd`)}
        </div>
      </section>
    `;let i=I(e.agentsList,n.cards);n.agentFilter=Ce(i,n.agentFilter);let a=ee(n.boards,n.cards),o=n.boardFilter,s=t=>t.filter(e=>n.showArchived||!e.metadata?.archivedAt).filter(e=>u(e,o)).filter(t=>R(t,e.agentsList,e.scopeAgentId)).filter(t=>we(t,e.agentsList,n.agentFilter)).filter(e=>H(e,{query:n.query,priority:n.priorityFilter})),c=t=>s(De({cards:n.cards,preset:t,tasksByCardId:n.tasksByCardId,sessions:e.sessions,defaultAgentId:e.agentsList?.defaultId})),l=c(n.viewPreset),d=Me({cards:l,tasksByCardId:n.tasksByCardId,sessions:e.sessions}),f=n.error??n.lifecycleTaskRefreshError,m=V(e),h=new Map;for(let e of n.statuses)h.set(e,[]);for(let e of l)h.get(e.status)?.push(e);let g=n.emptyColumnMode===`hide`||n.viewPreset!==`all`?n.statuses.filter(e=>(h.get(e)?.length??0)>0):n.statuses,_=n.viewPreset!==`all`||n.query.trim()!==``||n.priorityFilter!==`all`||n.agentFilter!==`all`||o!==`__all__`||!n.showArchived&&n.cards.some(e=>e.metadata?.archivedAt),v=q.map(e=>{let t=c(e.value).length;return{value:e.value,label:N(e.labelKey),description:e.value===`all`?void 0:N(`workboard.viewPresetCount`,{count:String(t)}),disabled:e.value!==`all`&&t===0}}),y=[{value:`all`,label:N(`workboard.allPriorities`)},...t.map(e=>({value:e,label:ve(e)}))],b=Y.map(([e,t])=>({value:e,label:N(t)})),C=i.map(t=>({value:t.id,label:t.label,description:t.description,agent:t.id===`all`||t.id==="default"?void 0:e.agentsList?.agents.find(e=>e.id===t.id)??{id:t.id},icon:t.id===`all`?j.users:t.id==="default"?j.bot:void 0})),w=n.draftOpen||!!ye(n);return S`
    <section class="workboard">
      <div class="workboard-main" ?inert=${w} aria-hidden=${w?`true`:x}>
        <div class="workboard-toolbar">
          <div class="workboard-toolbar__filters">
            <input
              class="input"
              type="search"
              title=${N(`workboard.searchPlaceholder`)}
              placeholder=${N(`workboard.searchPlaceholder`)}
              .value=${n.query}
              @input=${t=>{n.query=t.currentTarget.value,e.onRequestUpdate?.()}}
            />
            ${B({value:n.viewPreset,options:v,label:N(`workboard.viewPreset`),onChange:e=>{n.viewPreset=e},requestUpdate:e.onRequestUpdate,className:`workboard-select--toolbar`,showLabel:!1})}
            ${B({value:n.priorityFilter,options:y,label:N(`workboard.allPriorities`),onChange:e=>{n.priorityFilter=e},requestUpdate:e.onRequestUpdate,className:`workboard-select--toolbar`,showLabel:!1})}
            ${a.length>=3?B({value:o,options:a,label:N(`workboard.boardFilter`),onChange:t=>{n.boardFilter=t,e.onBoardFilterChange?.(t)},requestUpdate:e.onRequestUpdate,className:`workboard-select--toolbar workboard-select--toolbar-board`,showLabel:!1}):x}
            ${e.showAgentFilter===!1?x:S`
                  <openclaw-agent-select
                    class="workboard-agent-select workboard-agent-select--toolbar"
                    .options=${C}
                    .value=${n.agentFilter}
                    .accessibleLabel=${N(`workboard.agentFilter`)}
                    .onSelect=${t=>{let r=i.find(e=>e.id===t);r&&(n.agentFilter=r.id,e.onRequestUpdate?.())}}
                  ></openclaw-agent-select>
                `}
            <button
              class="btn workboard-archive-toggle ${n.showArchived?`active`:``}"
              type="button"
              aria-pressed=${n.showArchived}
              @click=${()=>{n.showArchived=!n.showArchived,e.onRequestUpdate?.()}}
            >
              ${n.showArchived?j.eye:j.eyeOff}
              ${n.showArchived?N(`workboard.hideArchivedShort`):N(`workboard.showArchivedShort`)}
            </button>
            <div class="workboard-layout-controls">
              <div class="workboard-layout-toggle" role="group" aria-label=${N(`workboard.layout`)}>
                ${J.map(([t,r,i])=>S`
                    <openclaw-tooltip .content=${N(r)}>
                      <button
                        class="btn btn--icon ${n.layout===t?`active`:``}"
                        type="button"
                        aria-label=${N(r)}
                        aria-pressed=${n.layout===t}
                        @click=${()=>{n.layout=t,e.onRequestUpdate?.()}}
                      >
                        ${i}
                      </button>
                    </openclaw-tooltip>
                  `)}
              </div>
              ${K(n)}
            </div>
            ${B({value:n.emptyColumnMode,options:b,label:N(`workboard.emptyColumns`),onChange:e=>{n.emptyColumnMode=e,n.expandedEmptyStatuses.clear()},requestUpdate:e.onRequestUpdate,className:`workboard-select--toolbar workboard-select--empty-columns`,showLabel:!1})}
          </div>
          <div class="workboard-toolbar__actions">
            <button
              class="btn"
              type="button"
              ?disabled=${n.loading||n.dispatching||p(n)}
              @click=${()=>Oe({host:e.host,client:e.client,requestUpdate:e.onRequestUpdate,source:`manual`,refreshDiagnostics:e.canWrite!==!1})}
            >
              ${n.loading?N(`common.refreshing`):N(`common.refresh`)}
            </button>
            ${m?S`
                  <button
                    class="btn"
                    type="button"
                    ?disabled=${n.dispatching||p(n)}
                    @click=${()=>Te({host:e.host,client:e.client,requestUpdate:e.onRequestUpdate})}
                  >
                    ${j.zap} ${N(`workboard.dispatch`)}
                  </button>
                `:x}
            ${m?S`
                  <button
                    class="btn primary"
                    type="button"
                    aria-haspopup="dialog"
                    aria-expanded=${n.draftOpen?`true`:`false`}
                    aria-controls=${me}
                    ?disabled=${n.dispatching}
                    @click=${()=>{be(n,e),e.onRequestUpdate?.()}}
                  >
                    ${j.plus} ${N(`workboard.newCard`)}
                  </button>
                `:x}
          </div>
        </div>
        ${Le(n,d,e.onRequestUpdate)}
        ${f?S`<div class="callout danger">${f}</div>`:x}
        ${Ie(n)}
        ${l.length===0&&_||g.length===0?S`
              <div class="workboard-empty-state" role="status">
                <strong>${N(`workboard.emptyFilteredTitle`)}</strong>
                <span>${N(`workboard.emptyFilteredHint`)}</span>
              </div>
            `:S`
              <div
                class="workboard-board workboard-board--page workboard-board--${n.layout} ${g.length===1?`workboard-board--single-column`:``}"
              >
                ${g.map(t=>ge(e,t,h.get(t)??[]))}
              </div>
            `}
      </div>
      ${z(e)} ${L(e)}
    </section>
  `}var q,J,Y;function X(){return(X=e((()=>{C(),Ne(),M(),oe(),ce(),se(),A(),W(),U(),c(),pe(),_e(),xe(),fe(),Se(),q=[{value:`all`,labelKey:`workboard.viewAll`},{value:`default_agent`,labelKey:`workboard.viewDefaultAgent`},{value:`ready`,labelKey:`workboard.viewReady`},{value:`running`,labelKey:`workboard.viewRunning`},{value:`blocked`,labelKey:`workboard.viewBlocked`},{value:`review`,labelKey:`workboard.viewReview`},{value:`stale`,labelKey:`workboard.viewStale`},{value:`missing_proof`,labelKey:`workboard.viewMissingProof`},{value:`recently_done`,labelKey:`workboard.viewRecentlyDone`}],J=[[`compact`,`workboard.layoutCompact`,j.layoutCompact],[`comfortable`,`workboard.layoutComfortable`,j.layoutComfortable]],Y=[[`show`,`workboard.showEmptyColumns`],[`collapse`,`workboard.collapseEmptyColumns`],[`hide`,`workboard.hideEmptyColumns`]]})))()}function Z(e,t){let n=n=>{let r=e.cards.find(e=>e.id===n);return!!(r&&t(r))};e.detailCardId&&!n(e.detailCardId)&&(e.detailCardId=null,e.detailCommentBody=``),e.editingCardId&&!n(e.editingCardId)&&a(e)}var Q;function $(){return($=e((()=>{de(),C(),w(),ie(),ae(),D(),re(),Fe(),M(),F(),A(),s(),l(),o(),W(),h(),b(),U(),c(),X(),Q=class extends f{constructor(...e){super(...e),this.requestPageUpdate=()=>this.context?.workboard.notify(),this.canonicalizedLocation=``,this.redirectedMissingBoardId=``,this.subscriptions=new v(this).watch(()=>this.context?.agents,(e,t)=>e.subscribe(t)).effect(()=>this.context?.agentSelection,e=>{let t=()=>this.syncWorkboardAgentScope();return t(),e.subscribe(t)}).effect(()=>this.context?.runtimeConfig,e=>{let t=()=>{this.requestUpdate(),this.ensureInitialData()};return t(),e.subscribe(t)}).watch(()=>this.context?.sessions,(e,t)=>e.subscribe(t)).effect(()=>this.context?.workboard,e=>{this.syncWorkboardAgentScope();let t=e.subscribe(()=>{this.syncWorkboardBoardRoute(),this.requestUpdate()});return()=>{t(),d(e),_(e)}}).effect(()=>this.context?.gateway,e=>{let t=t=>{this.context?.gateway===e&&(t.phase===`connected`&&t.client?this.ensureInitialData():this.context?.workboard&&(d(this.context.workboard),_(this.context.workboard)),this.requestUpdate())};return t(e.snapshot),e.subscribe(t)}).effect(()=>this.context?.gateway,e=>e.subscribeEvents(t=>{let n=this.context?.workboard;n&&this.context?.gateway===e&&e.snapshot.phase===`connected`&&t.event===`plugin.workboard.changed`&&Ee(n,t.payload)})),this.handleVisibilityChange=()=>{document.visibilityState===`visible`&&this.context?.workboard&&G(this.context.workboard)}}connectedCallback(){super.connectedCallback(),this.ensureInitialData(),this.syncWorkboardBoardFilter(),this.syncCanonicalLocation(),this.syncWorkboardBoardRoute(),this.syncWorkboardRuntime(),document.addEventListener(`visibilitychange`,this.handleVisibilityChange)}updated(e){e.has(`routeData`)&&(this.syncWorkboardBoardFilter(),this.syncCanonicalLocation(),this.syncWorkboardBoardRoute()),this.syncWorkboardRuntime(),this.context?.workboard&&G(this.context.workboard)}disconnectedCallback(){document.removeEventListener(`visibilitychange`,this.handleVisibilityChange),this.subscriptions.clear(),super.disconnectedCallback()}ensureInitialData(){let e=this.context,t=e?.gateway.snapshot;!e||t?.phase!==`connected`||!t.client||(!e.runtimeConfig.state.configSnapshot&&!e.runtimeConfig.state.configLoading&&e.runtimeConfig.ensureLoaded(),!e.agents.state.agentsList&&!e.agents.state.agentsLoading&&e.agents.ensureList(),!e.sessions.state.result&&!e.sessions.state.loading&&e.sessions.refresh())}pluginEnabled(){let e=this.context?.runtimeConfig.state.configSnapshot;return e?y(e):null}syncWorkboardRuntime(){let e=this.context,t=e?.gateway.snapshot,n=this.pluginEnabled();if(!e||t?.phase!==`connected`||!t.client||n!==!0){e&&(d(e.workboard),_(e.workboard));return}let r=e.workboard.state,i=E(t),a=je({host:e.workboard,client:t.client,requestUpdate:this.requestPageUpdate});ke({host:e.workboard,client:t.client,requestUpdate:this.requestPageUpdate,force:a,refreshDiagnostics:i.canWrite}),r.dispatching||Ae({host:e.workboard,client:t.client,requestUpdate:this.requestPageUpdate})}reloadConfig(){let e=this.context;e&&e.runtimeConfig.refresh({discardPendingChanges:!0})}syncWorkboardAgentScope(){let e=this.context;if(!e)return;let t=e.agentSelection.state.scopeId;if(this.observedAgentScopeId!==t){this.observedAgentScopeId=t;let n=e.workboard.state,r=e.agents.state.agentsList;n.agentFilter=`all`,Z(n,e=>R(e,r,t)),e.workboard.notify()}}syncWorkboardBoardFilter(){let e=this.context,t=this.routeData?.boardFilter;if(!e||!t||e.workboard.state.boardFilter===t)return;let n=e.workboard.state;Z(n,e=>u(e,t)),n.boardFilter=t,e.workboard.notify()}syncCanonicalLocation(){let e=this.routeData?.canonicalLocation,t=this.context;if(!e){this.canonicalizedLocation=``;return}if(!t)return;let n=`${e.pathname}${e.search}${e.hash}`;this.canonicalizedLocation!==n&&(this.canonicalizedLocation=n,t.replace(`workboard`,e))}setWorkboardBoardFilter(e){let t=this.context;t&&t.replace(`workboard`,{pathname:e===`__all__`?k(`workboard`,t.basePath):ne(e,t.basePath),search:this.routeData?.search??``})}syncWorkboardBoardRoute(){let e=this.context,t=this.routeData?.boardFilter;if(!e||!t||t===`__all__`||!e.workboard.boardsReady){this.redirectedMissingBoardId=``;return}if(e.workboard.state.boards.some(e=>e.id===t)){this.redirectedMissingBoardId=``;return}this.redirectedMissingBoardId!==t&&(this.redirectedMissingBoardId=t,e.replace(`workboard`,{pathname:k(`workboard`,e.basePath),search:this.routeData?.search??``}))}selectedBoard(){let e=this.context,t=this.routeData?.boardFilter;if(!e||!t||t===`__all__`)return null;let n=e.workboard.state.boards.find(e=>e.id===t);return n||e.workboard.boardsReady?n??null:{id:t,total:0,active:0,archived:0,byStatus:{}}}render(){let e=this.context;if(!e)return x;let t=e.gateway.snapshot,n=e.runtimeConfig.state,r=E(t),a=this.pluginEnabled(),o=this.selectedBoard();return S`
      <section class="content-header content-header--page">
        <div>
          <div class="page-title workboard-page-title">
            ${o?P(o,`workboard-board-glyph--header`):x}
            <span
              >${o?g(o):T(`workboard`)}</span
            >
            ${o?.automationJobId?S`<a
                  class="chip workboard-automation-chip"
                  href=${k(`cron`,e.basePath)}
                  title=${N(`workboard.automationAttachedTitle`)}
                  aria-label=${N(`workboard.automationAttachedTitle`)}
                >
                  ${j.calendarClock}<span>${N(`workboard.automationAttached`)}</span>
                </a>`:x}
          </div>
          ${o?S`<div class="page-subtitle">${T(`workboard`)}</div>`:x}
        </div>
        ${Pe({agents:e.agents.state.agentsList?.agents??[],selection:e.agentSelection})}
      </section>
      ${Re({host:e.workboard,client:t.client,connected:t.phase===`connected`,canWrite:r.canWrite,canGrant:r.canGrantApprovals,canModelOverride:r.canAdmin,pluginEnabled:a,pluginEnablementError:!n.configSnapshot&&!n.configLoading?n.lastError:null,agentsList:e.agents.state.agentsList,defaultAgentId:t.assistantAgentId,sessions:e.sessions.state.result?.sessions??[],scopeAgentId:e.agentSelection.state.scopeId,showAgentFilter:e.agentSelection.state.scopeId===null,onOpenSession:t=>{let n=i(e,t);e.navigate(n,{...m({context:e,face:n,sessionKey:t,preferenceDerivedFace:!0}).options,hash:``})},onReloadConfig:()=>this.reloadConfig(),onBoardFilterChange:e=>this.setWorkboardBoardFilter(e),onRequestUpdate:this.requestPageUpdate})}
    `}},n([ue({context:O,subscribe:!0})],Q.prototype,`context`,void 0),n([te({attribute:!1})],Q.prototype,`routeData`,void 0),customElements.get(`openclaw-workboard-page`)||customElements.define(`openclaw-workboard-page`,Q)})))()}$();
//# sourceMappingURL=workboard-page-80zGXgRV.js.map