import{a as e,n as t}from"./lit-xS7RrYW6.js";import{R as n}from"./index-Bt8RaTD0.js";function r(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function i(e){let t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return`刚刚`;if(n<60)return`${n} 分钟前`;let r=Math.floor(n/60);if(r<24)return`${r} 小时前`;let i=Math.floor(r/24);if(i<7)return`${i} 天前`;let a=new Date(e);return`${a.getMonth()+1}/${a.getDate()}`}function a(e){let t=e.lastIndexOf(`.`),n=t>=0?e.slice(t+1).toLowerCase():``;return[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`,`bmp`].includes(n)?`filespace__file-icon--image`:[`ts`,`tsx`,`js`,`jsx`].includes(n)?`filespace__file-icon--js`:[`py`].includes(n)?`filespace__file-icon--py`:[`md`,`txt`].includes(n)?`filespace__file-icon--doc`:[`json`,`yaml`,`yml`,`toml`].includes(n)?`filespace__file-icon--config`:[`csv`].includes(n)?`filespace__file-icon--csv`:[`rs`,`go`,`sh`,`bash`,`zsh`].includes(n)?`filespace__file-icon--code`:`filespace__file-icon--default`}function o(e){let t=e.lastIndexOf(`.`),r=t>=0?e.slice(t+1).toLowerCase():``;return[`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`ico`,`bmp`].includes(r)?n.image:[`ts`,`tsx`,`js`,`jsx`,`py`,`rs`,`go`,`sh`,`bash`,`json`,`yaml`,`yml`,`toml`].includes(r)?n.fileCode:n.fileText}function s(s){let{loading:c,error:l,data:u,search:d,collapsed:f,connected:p}=s,m=d.trim().toLowerCase(),h=m?(u??[]).map(e=>({...e,files:e.files.filter(t=>t.name.toLowerCase().includes(m)||t.path.toLowerCase().includes(m)||e.sessionLabel.toLowerCase().includes(m))})).filter(e=>e.files.length>0):u??[],g=h.reduce((e,t)=>e+t.files.length,0),_=()=>e`
    <div class="filespace__empty">
      <div class="filespace__empty-icon-wrap">
        <span class="filespace__empty-icon">${n.folder}</span>
      </div>
      <p class="filespace__empty-title">${m?`没有匹配的文件`:`暂无项目文件`}</p>
      <p class="filespace__empty-desc">
        ${m?`尝试更换关键词，或清除搜索条件查看全部文件`:`AI 在会话中生成或修改的工作区文件将在这里显示`}
      </p>
      ${m?e`<button class="filespace__clear-btn" @click=${()=>s.onSearchChange(``)}>
            清除搜索
          </button>`:t}
    </div>
  `,v=(n,c)=>{let l=a(c.name),u=o(c.name),d=c.size==null?null:r(c.size),f=c.updatedAtMs==null?null:i(c.updatedAtMs);return e`
      <div
        class="filespace__file"
        @click=${()=>s.onOpenFile(n.agentId,c.path)}
        title=${c.path}
      >
        <div class="filespace__file-icon ${l}">${u}</div>
        <div class="filespace__file-info">
          <span class="filespace__file-name">${c.name}</span>
          <div class="filespace__file-meta">
            ${d?e`<span class="filespace__file-size">${d}</span>`:t}
            ${f?e`<span class="filespace__file-time">${f}</span>`:t}
            <span class="filespace__file-path">${c.path}</span>
          </div>
        </div>
        <div class="filespace__file-actions">
          <button
            class="filespace__action-btn filespace__action-btn--primary"
            @click=${e=>{e.stopPropagation(),s.onOpenFile(n.agentId,c.path)}}
          >
            打开文件
          </button>
          <button
            class="filespace__action-btn"
            @click=${e=>{e.stopPropagation(),s.onRevealFile(n.agentId,c.path)}}
          >
            打开目录
          </button>
        </div>
      </div>
    `};return e`
    <div class="filespace">
      <div class="filespace__search-wrap">
        <span class="filespace__search-icon">${n.search}</span>
        <input
          class="filespace__search"
          type="text"
          placeholder="搜索文件名、会话名..."
          .value=${d}
          @input=${e=>s.onSearchChange(e.target.value)}
        />
        ${d?e`<button
              class="filespace__search-clear"
              @click=${()=>s.onSearchChange(``)}
              title="清除搜索"
            >
              ${n.x}
            </button>`:t}
      </div>

      ${!c&&u!==null?e`<p class="filespace__stats">${g} 个文件，来自 ${h.length} 个会话</p>`:t}

      <div class="filespace__content">
        ${c?e`
              <div class="filespace__loading">
                <span class="filespace__spinner"></span>
                <span class="filespace__loading-text">加载中…</span>
              </div>
            `:l?e`
                <div class="filespace__error">
                  <p>加载失败：${l}</p>
                  <button class="filespace__clear-btn" @click=${s.onRefresh}>重试</button>
                </div>
              `:p?h.length===0?_():e`<div class="filespace__groups">${h.map(r=>{let i=f.includes(r.sessionKey);return e`
      <div class="filespace__group">
        <button
          class="filespace__group-header"
          @click=${()=>s.onToggleCollapse(r.sessionKey)}
          aria-expanded=${!i}
        >
          <span
            class="filespace__group-chevron ${i?``:`filespace__group-chevron--open`}"
          >
            ${n.chevronRight}
          </span>
          <span class="filespace__group-folder">${n.messageSquare}</span>
          <span class="filespace__group-label">${r.sessionLabel}</span>
          <span class="filespace__group-count">${r.files.length} 个文件</span>
        </button>
        ${i?t:e`<div class="filespace__group-files">
              ${r.files.map(e=>v(r,e))}
            </div>`}
      </div>
    `})}</div>`:e`
                  <div class="filespace__empty">
                    <span class="filespace__empty-icon">${n.folder}</span>
                    <p class="filespace__empty-title">未连接到网关</p>
                    <p class="filespace__empty-desc">请先连接到 OpenClaw 网关</p>
                  </div>
                `}
      </div>
    </div>
  `}export{s as renderFileSpace};
//# sourceMappingURL=filespace-BFoqOTyc.js.map