import{f as e,i as t,o as n,p as r}from"./lit-runtime-DA0-mbwP.js";import{o as i,t as a}from"./string-coerce-kcFITeCw.js";import{F as o,g as s,h as c,j as l}from"./index-x7xgmgRf.js";import{i as u,n as d,r as f,t as p}from"./skills-shared-CXH5_9Ow.js";function m(e){return e?c(e,window.location.href):null}function h(e){!(e instanceof HTMLDialogElement)||e.open||(e.isConnected?e.showModal():queueMicrotask(()=>{e.isConnected&&!e.open&&e.showModal()}))}var g=[{id:`all`,label:`All`},{id:`ready`,label:`Ready`},{id:`needs-setup`,label:`Needs Setup`},{id:`disabled`,label:`Disabled`}];function _(e,t){switch(t){case`all`:return!0;case`ready`:return!e.disabled&&e.eligible;case`needs-setup`:return!e.disabled&&!e.eligible;case`disabled`:return e.disabled}throw Error(`Unsupported skills status filter`)}function v(e){return e.disabled?`muted`:e.eligible?`ok`:`warn`}function y(e,t){let n=e.clawhub;return!n||n.status!==`linked`||!n.valid?null:t[l({registry:n.registry,slug:n.slug,version:n.installedVersion})]??null}function b(e){if(!e)return`Unavailable`;let t=e.securityStatus?.trim()||null;return e.ok&&e.decision===`pass`?t===`clean`||!t?`Clean`:t:t===`pending`||t===`not-run`?`Pending`:t===`malicious`?`Blocked`:t===`suspicious`?`Review`:`Unavailable`}function x(e){if(!e)return`chip-warn`;if(e.ok&&e.decision===`pass`)return`chip-ok`;let t=e.securityStatus?.trim()||null;return t===`pending`||t===`not-run`?`chip`:`chip-warn`}function S(t){let n=t.report?.skills??[],o={all:n.length,ready:0,"needs-setup":0,disabled:0};for(let e of n)e.disabled?o.disabled++:e.eligible?o.ready++:o[`needs-setup`]++;let s=t.statusFilter===`all`?n:n.filter(e=>_(e,t.statusFilter)),c=a(t.filter),l=c?s.filter(e=>a([e.name,e.description,e.source].join(` `)).includes(c)):s,d=u(l),f=t.detailKey?n.find(e=>e.skillKey===t.detailKey)??null:null;return r`
    <section class="card">
      <div class="row" style="justify-content: space-between;">
        <div>
          <div class="card-title">Skills</div>
          <div class="card-sub">Installed skills and their status.</div>
        </div>
        <button
          class="btn"
          ?disabled=${t.loading||!t.connected}
          @click=${t.onRefresh}
        >
          ${t.loading?i(`common.loading`):i(`common.refresh`)}
        </button>
      </div>

      <div class="agent-tabs" style="margin-top: 14px;">
        ${g.map(e=>r`
            <button
              class="agent-tab ${t.statusFilter===e.id?`active`:``}"
              @click=${()=>t.onStatusFilterChange(e.id)}
            >
              ${e.label}<span class="agent-tab-count">${o[e.id]}</span>
            </button>
          `)}
      </div>

      <div
        class="filters"
        style="display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 12px;"
      >
        <label class="field" style="flex: 1; min-width: 180px;">
          <input
            .value=${t.filter}
            @input=${e=>t.onFilterChange(e.target.value)}
            placeholder="Filter installed skills"
            autocomplete="off"
            name="skills-filter"
          />
        </label>
        <div class="muted">${l.length} shown</div>
      </div>

      <div style="margin-top: 16px; border-top: 1px solid var(--border); padding-top: 16px;">
        <div style="display: flex; align-items: center; gap: 12px; margin-bottom: 12px;">
          <div style="font-weight: 600;">ClawHub</div>
          <div class="muted" style="font-size: 13px;">
            Search and install skills from the registry
          </div>
        </div>
        <div style="display: flex; align-items: center; gap: 12px; flex-wrap: wrap;">
          <label class="field" style="flex: 1; min-width: 180px;">
            <input
              .value=${t.clawhubQuery}
              @input=${e=>t.onClawHubQueryChange(e.target.value)}
              placeholder="Search ClawHub skills…"
              autocomplete="off"
              name="clawhub-search"
            />
          </label>
          ${t.clawhubSearchLoading?r`<span class="muted">Searching…</span>`:e}
        </div>
        ${t.clawhubSearchError?r`<div class="callout danger" style="margin-top: 8px;">
              ${t.clawhubSearchError}
            </div>`:e}
        ${t.clawhubInstallMessage?r`<div
              class="callout ${t.clawhubInstallMessage.kind===`error`?`danger`:`success`}"
              style="margin-top: 8px;"
            >
              ${t.clawhubInstallMessage.text}
            </div>`:e}
        ${C(t)}
      </div>

      ${t.error?r`<div class="callout danger" style="margin-top: 12px;">${t.error}</div>`:e}
      ${l.length===0?r`
            <div class="muted" style="margin-top: 16px">
              ${!t.connected&&!t.report?`Not connected to gateway.`:`No skills found.`}
            </div>
          `:r`
            <div class="agent-skills-groups" style="margin-top: 16px;">
              ${d.map(e=>r`
                  <details class="agent-skills-group" open>
                    <summary class="agent-skills-header">
                      <span>${e.label}</span>
                      <span class="muted">${e.skills.length}</span>
                    </summary>
                    <div class="list skills-grid">
                      ${e.skills.map(e=>T(e,t))}
                    </div>
                  </details>
                `)}
            </div>
          `}
    </section>

    ${f?E(f,t):e}
    ${t.clawhubDetailSlug?w(t):e}
  `}function C(t){let n=t.clawhubResults;return n?n.length===0?r`<div class="muted" style="margin-top: 8px;">No skills found on ClawHub.</div>`:r`
    <div class="list" style="margin-top: 8px;">
      ${n.map(n=>r`
          <div
            class="list-item list-item-clickable"
            @click=${()=>t.onClawHubDetailOpen(n.slug)}
          >
            <div class="list-main">
              <div class="list-title">${n.displayName}</div>
              <div class="list-sub">${n.summary?o(n.summary,120):n.slug}</div>
            </div>
            <div class="list-meta" style="display: flex; align-items: center; gap: 8px;">
              ${n.version?r`<span class="muted" style="font-size: 12px;">v${n.version}</span>`:e}
              <button
                class="btn btn--sm"
                ?disabled=${t.clawhubInstallSlug!==null}
                @click=${e=>{e.stopPropagation(),t.onClawHubInstall(n.slug)}}
              >
                ${t.clawhubInstallSlug===n.slug?`Installing…`:`Install`}
              </button>
            </div>
          </div>
        `)}
    </div>
  `:e}function w(t){let a=t.clawhubDetail;return r`
    <dialog
      class="md-preview-dialog"
      ${n(h)}
      @click=${e=>{let t=e.currentTarget;e.target===t&&t.close()}}
      @close=${t.onClawHubDetailClose}
    >
      <div class="md-preview-dialog__panel">
        <div class="md-preview-dialog__header">
          <div class="md-preview-dialog__title">
            ${a?.skill?.displayName??t.clawhubDetailSlug}
          </div>
          <button
            class="btn btn--sm"
            @click=${e=>{e.currentTarget.closest(`dialog`)?.close()}}
          >
            Close
          </button>
        </div>
        <div class="md-preview-dialog__body" style="display: grid; gap: 16px;">
          ${t.clawhubDetailLoading?r`<div class="muted">${i(`common.loading`)}</div>`:t.clawhubDetailError?r`<div class="callout danger">${t.clawhubDetailError}</div>`:a?.skill?r`
                    <div style="font-size: 14px; line-height: 1.5;">
                      ${a.skill.summary??``}
                    </div>
                    ${a.owner?.displayName?r`<div class="muted" style="font-size: 13px;">
                          By
                          ${a.owner.displayName}${a.owner.handle?r` (@${a.owner.handle})`:e}
                        </div>`:e}
                    ${a.latestVersion?r`<div class="muted" style="font-size: 13px;">
                          Latest: v${a.latestVersion.version}
                        </div>`:e}
                    ${a.latestVersion?.changelog?r`<div
                          style="font-size: 13px; border-top: 1px solid var(--border); padding-top: 12px; white-space: pre-wrap;"
                        >
                          ${a.latestVersion.changelog}
                        </div>`:e}
                    ${a.metadata?.os?r`<div class="muted" style="font-size: 12px;">
                          Platforms: ${a.metadata.os.join(`, `)}
                        </div>`:e}
                    <button
                      class="btn primary"
                      ?disabled=${t.clawhubInstallSlug!==null}
                      @click=${()=>{t.clawhubDetailSlug&&t.onClawHubInstall(t.clawhubDetailSlug)}}
                    >
                      ${t.clawhubInstallSlug===t.clawhubDetailSlug?`Installing…`:`Install ${a.skill.displayName}`}
                    </button>
                  `:r`<div class="muted">Skill not found.</div>`}
        </div>
      </div>
    </dialog>
  `}function T(t,n){let i=n.busyKey===t.skillKey,a=v(t),s=y(t,n.clawhubVerdicts);return r`
    <div class="list-item list-item-clickable" @click=${()=>n.onDetailOpen(t.skillKey)}>
      <div class="list-main">
        <div class="list-title" style="display: flex; align-items: center; gap: 8px;">
          <span class="statusDot ${a}"></span>
          ${t.emoji?r`<span>${t.emoji}</span>`:e}
          <span>${t.name}</span>
        </div>
        <div class="list-sub">${o(t.description,140)}</div>
      </div>
      <div
        class="list-meta"
        style="display: flex; align-items: center; justify-content: flex-end; gap: 10px;"
      >
        ${t.clawhub?.status===`linked`?r`<span class="chip ${x(s)}">${b(s)}</span>`:t.clawhub?.status===`invalid`?r`<span class="chip chip-warn">ClawHub link invalid</span>`:e}
        <label class="skill-toggle-wrap" @click=${e=>e.stopPropagation()}>
          <input
            type="checkbox"
            class="skill-toggle"
            .checked=${!t.disabled}
            ?disabled=${i}
            @change=${e=>{e.stopPropagation(),n.onToggle(t.skillKey,t.disabled)}}
          />
        </label>
      </div>
    </div>
  `}function E(t,i){let a=i.busyKey===t.skillKey,o=i.edits[t.skillKey]??``,s=i.messages[t.skillKey]??null,c=t.install.length>0&&t.missing.bins.length>0,l=!!(t.bundled&&t.source!==`nodmix-bundled`),u=p(t),g=d(t),_=y(t,i.clawhubVerdicts),b=i.detailTab===`card`&&t.skillCard?.present?`card`:`overview`;return r`
    <dialog
      class="md-preview-dialog"
      ${n(h)}
      @click=${e=>{let t=e.currentTarget;e.target===t&&t.close()}}
      @close=${i.onDetailClose}
    >
      <div class="md-preview-dialog__panel">
        <div class="md-preview-dialog__header">
          <div
            class="md-preview-dialog__title"
            style="display: flex; align-items: center; gap: 8px;"
          >
            <span class="statusDot ${v(t)}"></span>
            ${t.emoji?r`<span style="font-size: 18px;">${t.emoji}</span>`:e}
            <span>${t.name}</span>
          </div>
          <button
            class="btn btn--sm"
            @click=${e=>{e.currentTarget.closest(`dialog`)?.close()}}
          >
            Close
          </button>
        </div>
        <div class="md-preview-dialog__body" style="display: grid; gap: 16px;">
          <div>
            <div style="font-size: 14px; line-height: 1.5; color: var(--text);">
              ${t.description}
            </div>
            ${f({skill:t,showBundledBadge:l})}
          </div>

          ${t.clawhub||t.skillCard?.present?r`
                <div class="agent-tabs">
                  <button
                    class="agent-tab ${b===`overview`?`active`:``}"
                    @click=${()=>i.onDetailTabChange(`overview`)}
                  >
                    Overview
                  </button>
                  ${t.skillCard?.present?r`<button
                        class="agent-tab ${b===`card`?`active`:``}"
                        @click=${()=>i.onDetailTabChange(`card`)}
                      >
                        Skill Card
                      </button>`:e}
                </div>
              `:e}
          ${b===`overview`?D(t,i,_):O(t,i)}
          ${u.length>0?r`
                <div
                  class="callout"
                  style="border-color: var(--warn-subtle); background: var(--warn-subtle); color: var(--warn);"
                >
                  <div style="font-weight: 600; margin-bottom: 4px;">Missing requirements</div>
                  <div>${u.join(`, `)}</div>
                </div>
              `:e}
          ${g.length>0?r`
                <div class="muted" style="font-size: 13px;">Reason: ${g.join(`, `)}</div>
              `:e}

          <div style="display: flex; align-items: center; gap: 12px;">
            <label class="skill-toggle-wrap">
              <input
                type="checkbox"
                class="skill-toggle"
                .checked=${!t.disabled}
                ?disabled=${a}
                @change=${()=>i.onToggle(t.skillKey,t.disabled)}
              />
            </label>
            <span style="font-size: 13px; font-weight: 500;">
              ${t.disabled?`Disabled`:`Enabled`}
            </span>
            ${c?r`<button
                  class="btn"
                  ?disabled=${a}
                  @click=${()=>i.onInstall(t.skillKey,t.name,t.install[0].id)}
                >
                  ${a?`Installing…`:t.install[0].label}
                </button>`:e}
          </div>

          ${s?r`<div class="callout ${s.kind===`error`?`danger`:`success`}">
                ${s.message}
              </div>`:e}
          ${t.primaryEnv?r`
                <div style="display: grid; gap: 8px;">
                  <div class="field">
                    <span
                      >API key
                      <span class="muted" style="font-weight: normal; font-size: 0.88em;"
                        >(${t.primaryEnv})</span
                      ></span
                    >
                    <input
                      type="password"
                      .value=${o}
                      @input=${e=>i.onEdit(t.skillKey,e.target.value)}
                    />
                  </div>
                  ${(()=>{let n=m(t.homepage);return n?r`<div class="muted" style="font-size: 13px;">
                          Get your key:
                          <a href="${n}" target="_blank" rel="noopener noreferrer"
                            >${t.homepage}</a
                          >
                        </div>`:e})()}
                  <button
                    class="btn primary"
                    ?disabled=${a}
                    @click=${()=>i.onSaveKey(t.skillKey)}
                  >
                    Save key
                  </button>
                </div>
              `:e}

          <div
            style="border-top: 1px solid var(--border); padding-top: 12px; display: grid; gap: 6px; font-size: 12px; color: var(--muted);"
          >
            <div><span style="font-weight: 600;">Source:</span> ${t.source}</div>
            <div style="font-family: var(--mono); word-break: break-all;">${t.filePath}</div>
            ${(()=>{let n=m(t.homepage);return n?r`<div>
                    <a href="${n}" target="_blank" rel="noopener noreferrer"
                      >${t.homepage}</a
                    >
                  </div>`:e})()}
          </div>
        </div>
      </div>
    </dialog>
  `}function D(t,n,i){let a=t.clawhub;if(!a)return e;if(a.status===`invalid`)return r`<div class="callout danger">
      <div style="font-weight: 600; margin-bottom: 4px;">ClawHub link invalid</div>
      <div>${a.reason}</div>
    </div>`;let o=m(i?.securityAuditUrl??void 0),s=i?.reasons?.length?i.reasons.join(`, `):null;return r`
    <div
      class="callout"
      style="display: grid; gap: 8px; border-color: var(--border); background: var(--panel-2);"
    >
      <div style="display: flex; align-items: center; gap: 8px; flex-wrap: wrap;">
        <span class="chip ${x(i)}">${b(i)}</span>
        <span class="muted" style="font-size: 12px;">${a.slug}@${a.installedVersion}</span>
        ${n.clawhubVerdictsLoading?r`<span class="muted">Refreshing…</span>`:e}
      </div>
      ${n.clawhubVerdictsError?r`<div class="muted" style="font-size: 13px;">${n.clawhubVerdictsError}</div>`:s?r`<div class="muted" style="font-size: 13px;">${s}</div>`:e}
      ${o?r`<div style="font-size: 13px;">
            <a href="${o}" target="_blank" rel="noopener noreferrer"
              >Full security report</a
            >
          </div>`:e}
    </div>
  `}function O(n,i){if(!n.skillCard?.present)return e;let a=i.skillCardContents[n.skillKey];if(a===void 0){let e=i.skillCardErrors[n.skillKey];return e?r`<div class="callout danger">${e}</div>`:r`<div class="muted" style="font-size: 13px;">
      ${i.skillCardLoadingKey===n.skillKey?`Loading Skill Card...`:`Skill Card not loaded.`}
    </div>`}return r`
    <article class="sidebar-markdown" style="max-width: 100%; overflow-wrap: anywhere;">
      ${t(s(a))}
    </article>
  `}export{S as renderSkills};
//# sourceMappingURL=skills-Dfkm7c13.js.map