        
     }
 }
+
+// MARK: Importing Reading Lists
+
+private extension CreateReadingListViewController {
+
+    func articlesFromEncodedPageIds(_ encodedPageIds: String, completion: @escaping (Result<[WMFArticle], Error>) -> Void) {
+
+        guard let importedReadingList = decodedReadingListFromEncodedPageIds(encodedPageIds) else {
+            completion(.failure(ImportReadingListError.failureDecodingPayload))
+            return
+        }
+        
+        self.importedReadingList = importedReadingList
+
+        pageURLsFromImportedReadingList(importedReadingList) { [weak self] result in
+            switch result {
+            case .success(let urls):
+                self?.articleObjectsFromArticleURLs(urls, completion: completion)
+            case .failure(let error):
+                completion(.failure(error))
+            }
+        }
+    }
+    
+    func decodedReadingListFromEncodedPageIds(_ encodedPageIds: String) -> ImportedReadingList? {
+        guard let data = Data(base64Encoded: encodedPageIds),
+              let result = try? JSONDecoder().decode(ImportedReadingList.self, from: data) else {
+            return nil
+        }
+        
+        return result
+    }
+    
+    func pageURLsFromImportedReadingList(_ importedReadingList: ImportedReadingList, completion: @escaping ((Result<[URL], Error>) -> Void)) {
+        
+        // https://phabricator.wikimedia.org/T316822#8366987
+        // Has the format:
+        // {
+        //     "en":[59874,31883,24868,14381],
+        //     "ru":[59874,31883,24868,14381]
+        // }
+        let listDict = importedReadingList.list
+
+        // Turn into format:
+        // {
+        //     https://en.wikipedia.org: [59874,31883,24868,14381],
+        //     https://ru.wikipedia.org: [59874,31883,24868,14381]
+        // }
+        var siteURLDict: [URL: [Int]] = [:]
+        for (key, value) in listDict {
+            if let siteURL = NSURL.wmf_URL(withDefaultSiteAndLanguageCode: key) {
+                siteURLDict[siteURL] = value
+            }
+        }
+
+        // Fetch page URLs for each site, combine into single array of page URLs
+        let group = DispatchGroup()
+        var finalPageURLs: [URL] = []
+        var errors: [Error] = []
+        for (key, value) in siteURLDict {
+            group.enter()
+            pageIdsFetcher.fetchPageURLs(key, pageIDs: value) { error in
+                DispatchQueue.main.async {
+                    errors.append(error)
+                    group.leave()
+                }
+            } success: { urls in
+                DispatchQueue.main.async {
+                    finalPageURLs.append(contentsOf: urls)
+                    group.leave()
+                }
+            }
+        }
+
+        group.notify(queue: .main) {
+
+            if let error = errors.first {
+                completion(.failure(error))
+                return
+            }
+
+            guard !finalPageURLs.isEmpty else {
+                completion(.failure(ImportReadingListError.failureFetchingPageURLs))
+                return
+            }
+
+            completion(.success(finalPageURLs))
+        }
+    }
+
+    func articleObjectsFromArticleURLs(_ articleURLs: [URL], completion: @escaping ((Result<[WMFArticle], Error>) -> Void)) {
+        
+        guard let dataStore = dataStore else {
+            completion(.failure(ImportReadingListError.missingDataStore))
+            return
+        }
+
+        let keys = articleURLs.compactMap { $0.wmf_inMemoryKey }
+
+        let articleFetcher = ArticleFetcher()
+        articleFetcher.fetchArticleSummaryResponsesForArticles(withKeys: keys) { result in
+
+            DispatchQueue.main.async {
+                var articles: [WMFArticle] = []
+                do {
+                    let articleSummaries = try dataStore.viewContext.wmf_createOrUpdateArticleSummmaries(withSummaryResponses: result)
+
+                    for (_, value) in articleSummaries {
+                        articles.append(value)
+                    }
+
+                    guard !articles.isEmpty else {
+                        completion(.failure(ImportReadingListError.failureFetchingArticleObjects))
+                        return
+                    }
+
+                    completion(.success(articles))
+                } catch let error {
+                    completion(.failure(error))
+                }
+            }
+        }
+    }
+}

        self.title = WMFLocalizedString("import-shared-reading-list-title", value: "Import shared reading list", comment: "Title of screen that imports a shared reading list.")
        let closeButton = UIBarButtonItem.wmf_buttonType(WMFButtonType.X, target: self, action: #selector(closeButtonTapped(_:)))
        navigationItem.leftBarButtonItem = closeButton
    }
    
    private func hideReadingListError() {

    @IBOutlet weak var createReadingListButton: WMFAuthButton!
    
    fileprivate var theme: Theme = Theme.standard
    fileprivate var articles: [WMFArticle]
    public let moveFromReadingList: ReadingList?
    
    weak var delegate: CreateReadingListDelegate?
    
    // Import shared reading list properties
    private let encodedPageIds: String?
    private var importedReadingList: ImportedReadingList?
    private let dataStore: MWKDataStore?
    private let pageIdsFetcher = PageIDToURLFetcher()
    
    var isInImportingMode: Bool {
        encodedPageIds != nil
    }
    
    lazy var importLoadingView: UIView = {
        let view = UIView(frame: .zero)
        view.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(importSpinner)
        view.backgroundColor = theme.colors.paperBackground
        NSLayoutConstraint.activate([
            importSpinner.centerXAnchor.constraint(equalTo: view.centerXAnchor),
            importSpinner.centerYAnchor.constraint(equalTo: view.centerYAnchor)
        ])
        view.isHidden = true
        return view
    }()

    lazy var importSpinner: UIActivityIndicatorView = {
        let activityIndicator = UIActivityIndicatorView(style: .medium)
        activityIndicator.translatesAutoresizingMaskIntoConstraints = false
        activityIndicator.hidesWhenStopped = true
        activityIndicator.color = theme.colors.primaryText
        return activityIndicator
    }()
    
    // MARK: Lifecycle
    
