1 // Copyright 2015-present 650 Industries. All rights reserved.
2 
3 import Foundation
4 
5 @objc
6 public class DevMenuItemsContainer: NSObject, DevMenuItemsContainerProtocol {
7   private var items: [DevMenuScreenItem] = []
8 
getRootItemsnull9   public func getRootItems() -> [DevMenuScreenItem] {
10     return items.sorted { $0.importance > $1.importance }
11   }
12 
getAllItemsnull13   public func getAllItems() -> [DevMenuScreenItem] {
14     var result: [DevMenuScreenItem] = []
15     for item in items {
16       result.append(item)
17       if let container = item as? DevMenuItemsContainerProtocol {
18         result.append(contentsOf: container.getAllItems())
19       }
20     }
21     return result.sorted { $0.importance > $1.importance }
22   }
23 
24   @objc
addItemnull25   public func addItem(_ item: DevMenuScreenItem) {
26     items.append(item)
27   }
28 
serializeItemsnull29   func serializeItems() -> [[String: Any]] {
30     return getRootItems().map({ $0.serialize() })
31   }
32 }
33