class c{constructor(e=globalThis.chrome??d()){this.api=e}async listWindows(){return(await s("windows.getAll",()=>this.api.windows.getAll({populate:!0}),[])).map(i=>({id:i.id,focused:i.focused,tabs:(i.tabs??[]).map(o)}))}async listGroups(){if(!this.api.tabGroups)return[];const e=await s("tabGroups.query",()=>this.api.tabGroups.query({}),[]),i=await this.listWindows();return e.map(r=>({id:r.id,windowId:r.windowId,title:r.title,color:r.color,tabs:i.flatMap(a=>a.tabs).filter(a=>a.groupId===r.id)}))}async listBookmarks(){return this.api.bookmarks?(await s("bookmarks.getTree",()=>this.api.bookmarks.getTree(),[])).map(n):[]}async openUrl(e,i){if(i?.newWindow){const a=await this.api.windows.create({url:e,focused:!0});return{url:e,title:e,windowId:a.id}}const r=await this.api.tabs.create({url:e,pinned:i?.pinned});return o(r)}}function o(t){return{id:t.id,windowId:t.windowId,groupId:t.groupId,index:t.index,url:t.url??t.pendingUrl??"",title:t.title??"",favicon:t.favIconUrl,active:t.active,pinned:t.pinned,lastAccessed:t.lastAccessed!=null?new Date(t.lastAccessed).toISOString():void 0}}function n(t){return{id:t.id,parentId:t.parentId,title:t.title??"",url:t.url,dateAdded:t.dateAdded!=null?new Date(t.dateAdded).toISOString():void 0,children:t.children?.map(n)}}async function s(t,e,i){try{return await e()}catch(r){return console.warn(`[wkms.chrome_tabs] ${t} failed`,r),i}}function d(){throw new Error("ChromeTabs: globalThis.chrome is missing — this adapter is only valid in the MV3 service worker. Use MemoryTabs for tests or popup/sidepanel surfaces.")}export{c as ChromeTabs};
//# sourceMappingURL=chrome_tabs-haoxWPlB.js.map
