// __mocks__/chrome.js — Mock Chrome APIs for Node.js testing

global.chrome = {
  storage: {
    local: {
      get: jest.fn(async (keys) => {
        const store = {};
        if (typeof keys === 'string') keys = [keys];
        for (const key of keys) {
          store[key] = global.__chromeStore?.[key] ?? null;
        }
        return store;
      }),
      set: jest.fn(async (items) => {
        global.__chromeStore = { ...global.__chromeStore, ...items };
      }),
      remove: jest.fn(async (keys) => {
        if (typeof keys === 'string') keys = [keys];
        for (const key of keys) delete global.__chromeStore?.[key];
      }),
      clear: jest.fn(async () => {
        global.__chromeStore = {};
      })
    }
  },
  runtime: {
    getManifest: jest.fn(() => ({ version: '1.0.0' }))
  },
  action: {
    setBadgeText: jest.fn(async () => {}),
    setBadgeBackgroundColor: jest.fn(async () => {})
  }
};

global.__chromeStore = {};
