import { esc, pluginText as text } from "/assets/js/shared.js"; import { bytes, meter } from "/assets/js/overview.js"; const states = {mounted:["已挂载","Mounted"],unmounted:["未挂载","Unmounted"],missing:["设备未连接","Device disconnected"],unknown:["状态未确认","Unconfirmed"]}; export function storageCards(system, resources) { if(!Array.isArray(system.storage_inventory))return ""; const inventory=new Map(system.storage_inventory.map(d=>["storage-"+d.id,d])); const presented=resources?.filter(r=>inventory.has(r.id)); const disks=presented?.length?presented.map(r=>({...inventory.get(r.id),name:r.name,visible:!r.hidden})):system.storage_inventory; return disks.filter(d=>d.visible!==false).map(d=>{ const percent=Number.isFinite(d.used_percent)&&d.state==="mounted"?d.used_percent:null; const label=text(...(states[d.state]||states.unknown)); const detail=percent===null?label:`${bytes(d.used_bytes)} / ${bytes(d.capacity_bytes)} · ${text("剩余","Free")} ${bytes(d.free_bytes)}`; const location=d.mountpoint?`${text("挂载点","Mount point")}: ${d.mountpoint}`:d.device?`${text("设备","Device")}: ${d.device}`:""; return `