import{n as e}from"./rolldown-runtime-DkW27tQK.js";import{S as t,g as n,ms as r,ps as i,w as a}from"./control-ui-core-pH6nakZ-.js";import{G as o,J as s,W as c,i as l,n as u}from"./lit-runtime-BEtFSUCp.js";import{Ht as d,Lt as f,Rt as p,qt as m}from"./control-ui-core-Br5DB0Zj.js";import{$i as h,ea as g}from"./control-ui-boot-Cdpgu1Gm.js";import{a as _,c as v,d as y,i as b,l as x,n as S,o as C,r as w,s as T,t as E,u as D}from"./logbook-controller-CNu_bIUT.js";function O(e,n){return t(e,{hour:`2-digit`,minute:`2-digit`,timeZone:n},``)}function k(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)%360}function A(e){let t=e.captureEnabled&&!e.capturePaused&&!e.lastCaptureError,n=e.capturePaused?m(`logbook.status.paused`):e.captureEnabled?m(`logbook.status.capturing`,{seconds:String(e.captureIntervalSeconds)}):m(`logbook.status.disabled`);return s`
    <div class="logbook__chips">
      <span class="logbook__chip ${t?`logbook__chip--ok`:`logbook__chip--warn`}">
        <span class="logbook__chip-dot"></span>
        ${n}
      </span>
      ${e.nodeName||e.nodeId?s`<span class="logbook__chip" title=${m(`logbook.status.nodeHelp`)}>
            ${f.monitor} ${e.nodeName??e.nodeId}
          </span>`:o}
      ${e.pendingFrames>0?s`<span class="logbook__chip" title=${m(`logbook.status.pendingHelp`)}>
            ${m(`logbook.status.pending`,{count:String(e.pendingFrames)})}
          </span>`:o}
      ${e.analysisRunning?s`<span class="logbook__chip logbook__chip--busy"
            >${m(`logbook.status.analyzing`)}</span
          >`:o}
      ${e.lastCaptureError?s`<span
            class="logbook__chip logbook__chip--error"
            title=${i(e.lastCaptureError)}
          >
            ${m(`logbook.status.captureError`)}
          </span>`:o}
      ${e.lastBatch?.status===`error`?s`<span
            class="logbook__chip logbook__chip--error"
            title=${i(e.lastBatch.error)}
          >
            ${m(`logbook.status.batchError`)}
          </span>`:o}
      ${e.visionModelSource===`missing`?s`<span
            class="logbook__chip logbook__chip--warn"
            title=${m(`logbook.status.modelMissingHelp`)}
          >
            ${m(`logbook.status.modelMissing`)}
          </span>`:o}
    </div>
  `}function j(e,t,r,a){let c=e.expandedCardIds.has(r.id),l=k(r.category),u=r.keyframeId!==void 0&&!e.framePreviewFailed.has(r.keyframeId)?r.keyframeId:void 0,d=u===void 0?void 0:e.framePreviews.get(u);return c&&u!==void 0&&!d&&C(e,t,u),s`
    <article
      class="logbook-card ${c?`logbook-card--expanded`:``}"
      style="--logbook-hue: ${l}"
    >
      <button
        class="logbook-card__header"
        type="button"
        @click=${()=>{let t=new Set(e.expandedCardIds);c?t.delete(r.id):t.add(r.id),e.expandedCardIds=t,e.requestUpdate?.()}}
      >
        <span class="logbook-card__time">
          ${O(r.startMs,a)}<span class="logbook-card__time-sep">–</span
          >${O(r.endMs,a)}
        </span>
        <span class="logbook-card__stripe" aria-hidden="true"></span>
        <span class="logbook-card__heading">
          <span class="logbook-card__title">${r.title}</span>
          <span class="logbook-card__summary">${r.summary}</span>
        </span>
        <span class="logbook-card__meta">
          <span class="logbook-card__category">${r.category}</span>
          ${r.appPrimary?s`<span class="logbook-card__app">${r.appPrimary}</span>`:o}
          <span class="logbook-card__duration"
            >${n(r.endMs-r.startMs)??`0s`}</span
          >
        </span>
      </button>
      ${c?s`
            <div class="logbook-card__body">
              ${d?s`<img
                    class="logbook-card__keyframe"
                    src=${d}
                    alt=${m(`logbook.card.keyframeAlt`)}
                  />`:u===void 0?o:s`<div class="logbook-card__keyframe logbook-card__keyframe--loading">
                      ${m(`common.loading`)}
                    </div>`}
              ${r.detail?s`<p class="logbook-card__detail">${i(r.detail)}</p>`:o}
              ${r.distractions.length>0?s`
                    <div class="logbook-card__distractions">
                      <span class="logbook-card__distractions-label">
                        ${m(`logbook.card.distractions`)}
                      </span>
                      ${r.distractions.map(e=>s`
                          <span class="logbook-card__distraction">
                            ${O(e.startMs,a)} · ${e.title}
                          </span>
                        `)}
                    </div>
                  `:o}
            </div>
          `:o}
    </article>
  `}function M(e){let t=e.timeline?.stats;if(!t||t.trackedMs<=0)return o;let r=Math.max(0,t.trackedMs-t.distractionMs),i=Math.round(r/t.trackedMs*100),a=t.categories[0]?.ms??1;return s`
    <section class="card logbook-side__card">
      <div class="card-title">${m(`logbook.stats.title`)}</div>
      <div class="logbook-stats__focus">
        <div class="logbook-stats__focus-bar">
          <div class="logbook-stats__focus-fill" style="width: ${i}%"></div>
        </div>
        <div class="logbook-stats__focus-legend">
          <span>${m(`logbook.stats.focus`,{pct:String(i)})}</span>
          <span
            >${m(`logbook.stats.tracked`,{duration:n(t.trackedMs)??`0s`})}</span
          >
        </div>
      </div>
      <div class="logbook-stats__categories">
        ${t.categories.slice(0,6).map(e=>s`
            <div
              class="logbook-stats__category"
              style="--logbook-hue: ${k(e.category)}"
            >
              <span class="logbook-stats__category-name">${e.category}</span>
              <span class="logbook-stats__category-bar">
                <span
                  class="logbook-stats__category-fill"
                  style="width: ${Math.max(6,Math.round(e.ms/a*100))}%"
                ></span>
              </span>
              <span class="logbook-stats__category-time"
                >${n(e.ms)??`0s`}</span
              >
            </div>
          `)}
      </div>
      ${t.apps.length>0?s`
            <div class="logbook-stats__apps">
              ${t.apps.slice(0,5).map(e=>s`<span class="logbook-stats__app">${e.domain}</span>`)}
            </div>
          `:o}
    </section>
  `}function N(e,t){return s`
    <section class="card logbook-side__card">
      <div class="logbook-side__card-header">
        <div class="card-title">${m(`logbook.standup.title`)}</div>
        <button
          class="btn btn--small"
          type="button"
          ?disabled=${e.standupLoading}
          @click=${()=>void T(e,t,e.standup!==null)}
        >
          ${e.standupLoading?m(`common.loading`):e.standup?m(`logbook.standup.refresh`):m(`logbook.standup.generate`)}
        </button>
      </div>
      ${e.standup?s`<div class="logbook-standup__body markdown-body">
            ${l(g(e.standup.text))}
          </div>`:s`<div class="card-sub">${m(`logbook.standup.empty`)}</div>`}
    </section>
  `}function P(e,t){return s`
    <section class="card logbook-side__card">
      <div class="card-title">${m(`logbook.ask.title`)}</div>
      <form
        class="logbook-ask__form"
        @submit=${n=>{n.preventDefault(),E(e,t)}}
      >
        <input
          class="logbook-ask__input"
          type="text"
          .value=${e.askQuestion}
          placeholder=${m(`logbook.ask.placeholder`)}
          @input=${t=>{e.askQuestion=t.target.value}}
        />
        <button class="btn btn--small" type="submit" ?disabled=${e.askLoading}>
          ${e.askLoading?m(`common.loading`):m(`logbook.ask.submit`)}
        </button>
      </form>
      ${e.askAnswer?s`<p class="logbook-ask__answer">${e.askAnswer}</p>`:o}
    </section>
  `}function F(e){let t=w(e.host);t.requestUpdate=e.onRequestUpdate??null;let n=e.connected;S(t,n?e.client:null,n),n&&!t.timeline&&!t.loading&&!t.error&&_(t,e.client);let r=t.status?.today??v(),i=t.day===r,a=t.status,c=t.timeline?.cards??[];return s`
    <section class="logbook">
      <header class="logbook__header">
        <div class="logbook__daynav">
          <button
            class="btn btn--small"
            type="button"
            aria-label=${m(`logbook.nav.previousDay`)}
            @click=${()=>void _(t,e.client,{day:y(t.day,-1)})}
          >
            ‹
          </button>
          <span class="logbook__day">${t.day}</span>
          <button
            class="btn btn--small"
            type="button"
            aria-label=${m(`logbook.nav.nextDay`)}
            ?disabled=${i}
            @click=${()=>void _(t,e.client,{day:y(t.day,1)})}
          >
            ›
          </button>
          ${i?o:s`<button
                class="btn btn--small"
                type="button"
                @click=${()=>void _(t,e.client,{today:!0})}
              >
                ${m(`logbook.nav.today`)}
              </button>`}
        </div>
        ${t.status?A(t.status):o}
        <div class="logbook__actions">
          ${t.status?s`<button
                class="btn btn--small"
                type="button"
                ?disabled=${t.actionPending||!t.status.captureEnabled}
                @click=${()=>void D(t,e.client,!t.status?.capturePaused)}
              >
                ${t.status.capturePaused?m(`logbook.actions.resume`):m(`logbook.actions.pause`)}
              </button>`:o}
          <button
            class="btn btn--small"
            type="button"
            ?disabled=${t.actionPending}
            @click=${()=>void x(t,e.client)}
          >
            ${m(`logbook.actions.analyzeNow`)}
          </button>
          <button
            class="btn btn--small"
            type="button"
            ?disabled=${t.loading}
            @click=${()=>void _(t,e.client)}
          >
            ${f.refresh}
          </button>
        </div>
      </header>
      ${t.error?s`<div class="callout danger" role="alert">${t.error}</div>`:o}
      <div class="logbook__layout">
        <div class="logbook__timeline">
          ${t.loading&&c.length===0?s`<div class="card-sub">${m(`common.loading`)}</div>`:o}
          ${!t.loading&&c.length===0&&!t.error?s`
                <div class="logbook__empty">
                  <div class="logbook__empty-title">${m(`logbook.empty.title`)}</div>
                  <div class="logbook__empty-sub">${m(`logbook.empty.subtitle`)}</div>
                </div>
              `:o}
          ${a?c.map(n=>j(t,e.client,n,a.timeZone)):o}
        </div>
        <aside class="logbook__side">
          ${M(t)} ${N(t,e.client)}
          ${P(t,e.client)}
        </aside>
      </div>
    </section>
  `}function I(){return(I=e((()=>{c(),u(),p(),h(),d(),r(),a(),b()})))()}I();export{F as renderLogbook};
//# sourceMappingURL=logbook-view-C3X0A817.js.map