import{i as e,n as t}from"./lit-BZwq2xLD.js";import{l as n}from"./format-DeRVtGzv.js";import{A as r,O as i,s as a}from"./index-BID6wkBZ.js";var o=[``,`off`,`minimal`,`low`,`medium`,`high`,`xhigh`],s=[``,`off`,`on`],c=[{value:``,label:`inherit`},{value:`off`,label:`off (explicit)`},{value:`on`,label:`on`},{value:`full`,label:`full`}],l=[{value:``,label:`inherit`},{value:`on`,label:`on`},{value:`off`,label:`off`}],u=[``,`off`,`on`,`stream`],d=[10,25,50,100];function f(e){if(!e)return``;let t=e.trim().toLowerCase();return t===`z.ai`||t===`z-ai`?`zai`:t}function p(e){return f(e)===`zai`}function m(e){return p(e)?s:o}function h(e,t){return!t||e.includes(t)?[...e]:[...e,t]}function g(e,t){return!t||e.some(e=>e.value===t)?[...e]:[...e,{value:t,label:`${t} (custom)`}]}function _(e,t){return!t||!e||e===`off`?e:`on`}function v(e,t){return e?t&&e===`on`?`low`:e:null}function y(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>{let t=(e.key??``).toLowerCase(),r=(e.label??``).toLowerCase(),i=(e.kind??``).toLowerCase(),a=(e.displayName??``).toLowerCase();return t.includes(n)||r.includes(n)||i.includes(n)||a.includes(n)}):e}function b(e,t,n){let r=n===`asc`?1:-1;return[...e].toSorted((e,n)=>{let i=0;switch(t){case`key`:i=(e.key??``).localeCompare(n.key??``);break;case`kind`:i=(e.kind??``).localeCompare(n.kind??``);break;case`updated`:i=(e.updatedAt??0)-(n.updatedAt??0);break;case`tokens`:i=(e.totalTokens??e.inputTokens??e.outputTokens??0)-(n.totalTokens??n.inputTokens??n.outputTokens??0);break}return i*r})}function x(e,t,n){let r=t*n;return e.slice(r,r+n)}function S(n){let r=b(y(n.result?.sessions??[],n.searchQuery),n.sortColumn,n.sortDir),a=r.length,o=Math.max(1,Math.ceil(a/n.pageSize)),s=Math.min(n.page,o-1),c=x(r,s,n.pageSize),l=(t,r)=>{let a=n.sortColumn===t,o=a&&n.sortDir===`asc`?`desc`:`asc`;return e`
      <th
        data-sortable
        data-sort-dir=${a?n.sortDir:``}
        @click=${()=>n.onSortChange(t,a?o:`desc`)}
      >
        ${r}
        <span class="data-table-sort-icon">${i.arrowUpDown}</span>
      </th>
    `};return e`
    ${n.actionsOpenKey?e`
            <div
              class="data-table-overlay"
              @click=${()=>n.onActionsOpenChange(null)}
              aria-hidden="true"
            ></div>
          `:t}
    <section class="card" style=${n.actionsOpenKey?`position: relative; z-index: 41;`:``}>
      <div class="row" style="justify-content: space-between; margin-bottom: 12px;">
        <div>
          <div class="card-title">Sessions</div>
          <div class="card-sub">${n.result?`Store: ${n.result.path}`:`Active session keys and per-session overrides.`}</div>
        </div>
        <button class="btn" ?disabled=${n.loading} @click=${n.onRefresh}>
          ${n.loading?`Loading…`:`Refresh`}
        </button>
      </div>

      <div class="filters" style="margin-bottom: 12px;">
        <label class="field-inline">
          <span>Active</span>
          <input
            style="width: 72px;"
            placeholder="min"
            .value=${n.activeMinutes}
            @input=${e=>n.onFiltersChange({activeMinutes:e.target.value,limit:n.limit,includeGlobal:n.includeGlobal,includeUnknown:n.includeUnknown})}
          />
        </label>
        <label class="field-inline">
          <span>Limit</span>
          <input
            style="width: 64px;"
            .value=${n.limit}
            @input=${e=>n.onFiltersChange({activeMinutes:n.activeMinutes,limit:e.target.value,includeGlobal:n.includeGlobal,includeUnknown:n.includeUnknown})}
          />
        </label>
        <label class="field-inline checkbox">
          <input
            type="checkbox"
            .checked=${n.includeGlobal}
            @change=${e=>n.onFiltersChange({activeMinutes:n.activeMinutes,limit:n.limit,includeGlobal:e.target.checked,includeUnknown:n.includeUnknown})}
          />
          <span>Global</span>
        </label>
        <label class="field-inline checkbox">
          <input
            type="checkbox"
            .checked=${n.includeUnknown}
            @change=${e=>n.onFiltersChange({activeMinutes:n.activeMinutes,limit:n.limit,includeGlobal:n.includeGlobal,includeUnknown:e.target.checked})}
          />
          <span>Unknown</span>
        </label>
      </div>

      ${n.error?e`<div class="callout danger" style="margin-bottom: 12px;">${n.error}</div>`:t}

      <div class="data-table-wrapper">
        <div class="data-table-toolbar">
          <div class="data-table-search">
            <input
              type="text"
              placeholder="Filter by key, label, kind…"
              .value=${n.searchQuery}
              @input=${e=>n.onSearchChange(e.target.value)}
            />
          </div>
        </div>

        <div class="data-table-container">
          <table class="data-table">
            <thead>
              <tr>
                ${l(`key`,`Key`)}
                <th>Label</th>
                ${l(`kind`,`Kind`)}
                ${l(`updated`,`Updated`)}
                ${l(`tokens`,`Tokens`)}
                <th>Thinking</th>
                <th>Fast</th>
                <th>Verbose</th>
                <th>Reasoning</th>
                <th style="width: 60px;"></th>
              </tr>
            </thead>
            <tbody>
              ${c.length===0?e`
                      <tr>
                        <td colspan="10" style="text-align: center; padding: 48px 16px; color: var(--muted)">
                          No sessions found.
                        </td>
                      </tr>
                    `:c.map(e=>C(e,n.basePath,n.onPatch,n.onDelete,n.onActionsOpenChange,n.actionsOpenKey,n.loading))}
            </tbody>
          </table>
        </div>

        ${a>0?e`
                <div class="data-table-pagination">
                  <div class="data-table-pagination__info">
                    ${s*n.pageSize+1}-${Math.min((s+1)*n.pageSize,a)}
                    of ${a} row${a===1?``:`s`}
                  </div>
                  <div class="data-table-pagination__controls">
                    <select
                      style="height: 32px; padding: 0 8px; font-size: 13px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--card);"
                      .value=${String(n.pageSize)}
                      @change=${e=>n.onPageSizeChange(Number(e.target.value))}
                    >
                      ${d.map(t=>e`<option value=${t}>${t} per page</option>`)}
                    </select>
                    <button
                      ?disabled=${s<=0}
                      @click=${()=>n.onPageChange(s-1)}
                    >
                      Previous
                    </button>
                    <button
                      ?disabled=${s>=o-1}
                      @click=${()=>n.onPageChange(s+1)}
                    >
                      Next
                    </button>
                  </div>
                </div>
              `:t}
      </div>
    </section>
  `}function C(o,s,d,f,y,b,x){let S=o.updatedAt?n(o.updatedAt):`n/a`,C=o.thinkingLevel??``,w=p(o.modelProvider),T=_(C,w),E=h(m(o.modelProvider),T),D=o.fastMode===!0?`on`:o.fastMode===!1?`off`:``,O=g(l,D),k=o.verboseLevel??``,A=g(c,k),j=o.reasoningLevel??``,M=h(u,j),N=typeof o.displayName==`string`&&o.displayName.trim().length>0?o.displayName.trim():null,P=!!(N&&N!==o.key&&N!==(typeof o.label==`string`?o.label.trim():``)),F=o.kind!==`global`,I=F?`${r(`chat`,s)}?session=${encodeURIComponent(o.key)}`:null,L=b===o.key,R=o.kind===`direct`?`data-table-badge--direct`:o.kind===`group`?`data-table-badge--group`:o.kind===`global`?`data-table-badge--global`:`data-table-badge--unknown`;return e`
    <tr>
      <td>
        <div class="mono session-key-cell">
          ${F?e`<a href=${I} class="session-link">${o.key}</a>`:o.key}
          ${P?e`<span class="muted session-key-display-name">${N}</span>`:t}
        </div>
      </td>
      <td>
        <input
          .value=${o.label??``}
          ?disabled=${x}
          placeholder="(optional)"
          style="width: 100%; max-width: 140px; padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);"
          @change=${e=>{let t=e.target.value.trim();d(o.key,{label:t||null})}}
        />
      </td>
      <td>
        <span class="data-table-badge ${R}">${o.kind}</span>
      </td>
      <td>${S}</td>
      <td>${a(o)}</td>
      <td>
        <select
          ?disabled=${x}
          style="padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 90px;"
          @change=${e=>{let t=e.target.value;d(o.key,{thinkingLevel:v(t,w)})}}
        >
          ${E.map(t=>e`<option value=${t} ?selected=${T===t}>
                ${t||`inherit`}
              </option>`)}
        </select>
      </td>
      <td>
        <select
          ?disabled=${x}
          style="padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 90px;"
          @change=${e=>{let t=e.target.value;d(o.key,{fastMode:t===``?null:t===`on`})}}
        >
          ${O.map(t=>e`<option value=${t.value} ?selected=${D===t.value}>
                ${t.label}
              </option>`)}
        </select>
      </td>
      <td>
        <select
          ?disabled=${x}
          style="padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 90px;"
          @change=${e=>{let t=e.target.value;d(o.key,{verboseLevel:t||null})}}
        >
          ${A.map(t=>e`<option value=${t.value} ?selected=${k===t.value}>
                ${t.label}
              </option>`)}
        </select>
      </td>
      <td>
        <select
          ?disabled=${x}
          style="padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 90px;"
          @change=${e=>{let t=e.target.value;d(o.key,{reasoningLevel:t||null})}}
        >
          ${M.map(t=>e`<option value=${t} ?selected=${j===t}>
                ${t||`inherit`}
              </option>`)}
        </select>
      </td>
      <td>
        <div class="data-table-row-actions">
          <button
            type="button"
            class="data-table-row-actions__trigger"
            aria-label="Open menu"
            @click=${e=>{e.stopPropagation(),y(L?null:o.key)}}
          >
            ${i.moreHorizontal}
          </button>
          ${L?e`
                  <div class="data-table-row-actions__menu">
                    ${F?e`
                            <a
                              href=${I}
                              style="display: block; padding: 8px 12px; font-size: 13px; text-decoration: none; color: var(--text); border-radius: var(--radius-sm);"
                              @click=${()=>y(null)}
                            >
                              Open in Chat
                            </a>
                          `:t}
                    <button
                      type="button"
                      class="danger"
                      @click=${()=>{y(null),f(o.key)}}
                    >
                      Delete
                    </button>
                  </div>
                `:t}
        </div>
      </td>
    </tr>
  `}export{S as renderSessions};
//# sourceMappingURL=sessions-CU0vzUWF.js.map