import{a as e,n as t}from"./lit-xS7RrYW6.js";import{$ as n,K as r}from"./index-Bt8RaTD0.js";var i=e=>n(`/api/sealclaw/share/${encodeURIComponent(e)}`,{method:`GET`}),a=e=>n(`/api/sealclaw/share/${encodeURIComponent(e)}/claim`,{method:`POST`}),o=e=>n(`/api/sealclaw/share/my`,{method:`GET`,params:e}),s=e=>n(`/api/sealclaw/share/${encodeURIComponent(e)}`,{method:`DELETE`}),c=e=>n(`/api/sealclaw/enterprise/skills`,{method:`GET`,params:e}),l=e=>n(`/api/sealclaw/enterprise/skills/${e}/install`,{method:`POST`});function u(){return{sharePreview:null,sharePreviewLoading:!1,sharePreviewCode:``,shareClaimLoading:!1,shareClaimResult:null,myShares:[],mySharesLoading:!1,enterpriseSkills:[],enterpriseSkillsLoading:!1,enterpriseInstallLoading:null,sharingError:null}}function d(e){e==null||e()}async function f(e,t,n){e.sharePreviewCode=t,e.sharePreviewLoading=!0,e.sharePreview=null,e.shareClaimResult=null,e.sharingError=null,d(n);try{let n=await i(t);e.sharePreview=(n==null?void 0:n.data)??null}catch(t){e.sharingError=String(t)}finally{e.sharePreviewLoading=!1,d(n)}}async function p(e,t){if(e.sharePreviewCode){e.shareClaimLoading=!0,e.shareClaimResult=null,e.sharingError=null,d(t);try{await a(e.sharePreviewCode),e.shareClaimResult=`领取成功！技能已加入您的技能库，桌面/CLI 同步后可用。`}catch(t){e.sharingError=String(t)}finally{e.shareClaimLoading=!1,d(t)}}}async function m(e,t){e.mySharesLoading=!0,d(t);try{var n;let t=await o({page:1,size:50});e.myShares=(t==null||(n=t.data)==null?void 0:n.data)??[]}catch{e.myShares=[]}finally{e.mySharesLoading=!1,d(t)}}async function h(e,t,n){e.sharingError=null;try{await s(t),e.myShares=e.myShares.filter(e=>e.shareCode!==t)}catch(t){e.sharingError=String(t)}d(n)}async function g(e,t,n){e.enterpriseSkillsLoading=!0,d(n);try{var r;let n=await c({keyword:t,page:1,size:50});e.enterpriseSkills=(n==null||(r=n.data)==null?void 0:r.data)??[]}catch{e.enterpriseSkills=[]}finally{e.enterpriseSkillsLoading=!1,d(n)}}async function _(e,t,n){e.enterpriseInstallLoading=t,e.sharingError=null,d(n);try{await l(t);let n=e.enterpriseSkills.find(e=>e.skillId===t);n&&(n.owned=!0)}catch(t){e.sharingError=String(t)}finally{e.enterpriseInstallLoading=null,d(n)}}function v(n){let{state:r}=n;return e`
    <div
      class="skill-sharing-panel"
      style="display:flex;flex-direction:column;gap:24px;padding:16px;"
    >
      ${y(n)} ${b(n)}
      ${x(n)}
      ${r.sharingError?e`<div
            class="sharing-error"
            style="color:var(--color-error, #e53e3e);font-size:13px;margin-top:8px;"
          >
            ${r.sharingError}
          </div>`:t}
    </div>
  `}function y(n){let{state:r}=n,i=r.sharePreviewCode;return e`
    <section class="sharing-section">
      <h3 style="margin:0 0 12px;font-size:15px;font-weight:600;">导入分享技能</h3>
      <div style="display:flex;gap:8px;align-items:center;">
        <input
          type="text"
          placeholder="输入分享码或链接"
          .value=${i}
          @input=${e=>{i=e.target.value}}
          style="flex:1;padding:6px 10px;border:1px solid var(--color-border);border-radius:6px;font-size:13px;"
        />
        <button
          @click=${()=>n.onPreviewShare(i)}
          ?disabled=${r.sharePreviewLoading}
          style="padding:6px 14px;border-radius:6px;background:var(--color-primary, #3182ce);color:#fff;border:none;cursor:pointer;font-size:13px;"
        >
          ${r.sharePreviewLoading?`查询中...`:`预览`}
        </button>
      </div>
      ${r.sharePreview?e`
            <div
              style="margin-top:12px;padding:12px;border:1px solid var(--color-border);border-radius:8px;background:var(--color-bg-secondary);"
            >
              <div style="font-weight:500;">${r.sharePreview.title??`未知技能`}</div>
              ${r.sharePreview.description?e`<div
                    style="font-size:12px;color:var(--color-text-secondary);margin-top:4px;"
                  >
                    ${r.sharePreview.description}
                  </div>`:t}
              ${r.sharePreview.version?e`<div
                    style="font-size:12px;color:var(--color-text-secondary);margin-top:2px;"
                  >
                    版本：${r.sharePreview.version}
                  </div>`:t}
              ${r.sharePreview.claimable?e`<button
                    @click=${()=>n.onClaimShare()}
                    ?disabled=${r.shareClaimLoading}
                    style="margin-top:8px;padding:6px 14px;border-radius:6px;background:var(--color-success, #38a169);color:#fff;border:none;cursor:pointer;font-size:13px;"
                  >
                    ${r.shareClaimLoading?`领取中...`:`导入到我的技能库`}
                  </button>`:e`<div
                    style="margin-top:8px;font-size:12px;color:var(--color-error, #e53e3e);"
                  >
                    ${r.sharePreview.unclaimableReason??`不可领取`}
                  </div>`}
            </div>
          `:t}
      ${r.shareClaimResult?e`<div style="margin-top:8px;font-size:13px;color:var(--color-success, #38a169);">
            ${r.shareClaimResult}
          </div>`:t}
    </section>
  `}function b(n){let{state:i}=n;return e`
    <section class="sharing-section">
      <div
        style="display:flex;align-items:center;justify-content:space-between;margin-bottom:12px;"
      >
        <h3 style="margin:0;font-size:15px;font-weight:600;">我的分享</h3>
        <button
          @click=${()=>n.onLoadMyShares()}
          ?disabled=${i.mySharesLoading}
          style="padding:4px 10px;border-radius:6px;border:1px solid var(--color-border);background:transparent;cursor:pointer;font-size:12px;"
        >
          ${i.mySharesLoading?`加载中...`:`刷新`}
        </button>
      </div>
      ${i.myShares.length===0&&!i.mySharesLoading?e`<div style="font-size:13px;color:var(--color-text-secondary);">暂无分享记录</div>`:t}
      ${r(i.myShares,e=>e.shareCode,r=>e`
          <div
            style="display:flex;align-items:center;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--color-border);"
          >
            <div>
              <span style="font-weight:500;font-size:13px;">${r.skillTitle??r.shareCode}</span>
              <span style="font-size:11px;color:var(--color-text-secondary);margin-left:8px;">
                ${r.status===1?`已领${r.claimedCount}${r.maxClaims?`/${r.maxClaims}`:``}`:`已撤销`}
              </span>
            </div>
            <div style="display:flex;gap:6px;">
              <button
                @click=${()=>n.onCopyShareUrl(r.shareCode)}
                style="padding:3px 8px;border-radius:4px;border:1px solid var(--color-border);background:transparent;cursor:pointer;font-size:11px;"
              >
                复制链接
              </button>
              ${r.status===1?e`<button
                    @click=${()=>n.onRevokeShare(r.shareCode)}
                    style="padding:3px 8px;border-radius:4px;border:1px solid var(--color-error, #e53e3e);color:var(--color-error, #e53e3e);background:transparent;cursor:pointer;font-size:11px;"
                  >
                    撤销
                  </button>`:t}
            </div>
          </div>
        `)}
    </section>
  `}function x(n){let{state:i}=n;return e`
    <section class="sharing-section">
      <div
        style="display:flex;align-items:center;justify-content:space-between;margin-bottom:12px;"
      >
        <h3 style="margin:0;font-size:15px;font-weight:600;">企业技能</h3>
        <button
          @click=${()=>n.onLoadEnterpriseSkills()}
          ?disabled=${i.enterpriseSkillsLoading}
          style="padding:4px 10px;border-radius:6px;border:1px solid var(--color-border);background:transparent;cursor:pointer;font-size:12px;"
        >
          ${i.enterpriseSkillsLoading?`加载中...`:`刷新`}
        </button>
      </div>
      ${i.enterpriseSkills.length===0&&!i.enterpriseSkillsLoading?e`<div style="font-size:13px;color:var(--color-text-secondary);">
            本企业暂无共享技能
          </div>`:t}
      ${r(i.enterpriseSkills,e=>e.skillId,t=>e`
          <div
            style="display:flex;align-items:center;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--color-border);"
          >
            <div>
              <span style="font-weight:500;font-size:13px;">${t.title}</span>
              <span style="font-size:11px;color:var(--color-text-secondary);margin-left:8px;">
                ${t.name} ${t.version?`v${t.version}`:``}
              </span>
            </div>
            <div>
              ${t.owned?e`<span style="font-size:12px;color:var(--color-success, #38a169);"
                    >✓ 已安装</span
                  >`:e`<button
                    @click=${()=>n.onInstallEnterpriseSkill(t.skillId)}
                    ?disabled=${i.enterpriseInstallLoading===t.skillId}
                    style="padding:3px 10px;border-radius:4px;background:var(--color-primary, #3182ce);color:#fff;border:none;cursor:pointer;font-size:12px;"
                  >
                    ${i.enterpriseInstallLoading===t.skillId?`安装中...`:`安装`}
                  </button>`}
            </div>
          </div>
        `)}
    </section>
  `}export{p as claimShareAction,u as createInitialSharingState,_ as installEnterpriseSkillAction,g as loadEnterpriseSkills,m as loadMyShares,f as previewShare,v as renderSkillSharingPanel,h as revokeShareAction};
//# sourceMappingURL=skill-sharing-PPFmxi-D.js.map