const mockStorage: Record<string, unknown> = {};

const chromeMock = {
  storage: {
    local: {
      set: async (data: Record<string, unknown>) => {
        Object.assign(mockStorage, data);
      },
      get: async (key: string | string[]) => {
        if (Array.isArray(key)) {
          const result: Record<string, unknown> = {};
          for (const k of key) result[k] = mockStorage[k];
          return result;
        }
        return { [key]: mockStorage[key] };
      },
      remove: async (key: string | string[]) => {
        const keys = Array.isArray(key) ? key : [key];
        for (const k of keys) delete mockStorage[k];
      },
      clear: async () => {
        Object.keys(mockStorage).forEach((k) => delete mockStorage[k]);
      },
    },
  },
};

(global as any).chrome = chromeMock;
