 import SnapKit
 import FontAwesome
 
-struct GSNavigationInfo {
-    
-    static func height(state: GSState) -> CGFloat {
-        var height = 0
-        if state == .InactiveRegular || state == .ActiveRegular {
-            height = 64
-        } else {
-            height = 32
-        }
-        return CGFloat(height)
-    }
-    
-    static func topMargin(state: GSState) -> CGFloat {
-        var topMargin = 0
-        switch state {
-        case .InactiveRegular:
-            topMargin = 44
-        case .InactiveCompact:
-            topMargin = 32
-        default:
-            topMargin = 0
-        }
-        return CGFloat(topMargin)
-    }
-}
-
-struct GSVLayoutInfo {
-    
-    static let ContentHeight = CGFloat(80)
-    static let ContentFontSize = CGFloat(12)
-    static let ContentPadding = CGFloat(5)
-    
-    static func topMargin(state: GSState) -> CGFloat {
-        var topMargin = 0
-        switch state {
-        case .InactiveRegular:
-            topMargin = 144
-        case .InactiveCompact:
-            topMargin = 112
-        case .ActiveRegular:
-            topMargin = 100
-        case .ActiveCompact:
-            topMargin = 68
-        }
-        return CGFloat(topMargin)
-    }
-}
-
-enum GSButtonTag : Int {
-    case Unknown = 0
-    case Timeline = 1
-    case Article = 2
-    case Celebrity = 3
-}
-
-enum GSState : Int {
-    case InactiveRegular
-    case InactiveCompact
-    case ActiveRegular
-    case ActiveCompact
-}
-
 class GlobalSearchViewController: UISearchController, UISearchBarDelegate, UIGestureRecognizerDelegate {
+    
+    struct NavigationInfo {
+        
+        static func height(state: State) -> CGFloat {
+            var height = 0
+            if state == .InactiveRegular || state == .ActiveRegular {
+                height = 64
+            } else {
+                height = 32
+            }
+            return CGFloat(height)
+        }
+        
+        static func topMargin(state: State) -> CGFloat {
+            var topMargin = 0
+            switch state {
+            case .InactiveRegular:
+                topMargin = 44
+            case .InactiveCompact:
+                topMargin = 32
+            default:
+                topMargin = 0
+            }
+            return CGFloat(topMargin)
+        }
+    }
+    
+    struct LayoutInfo {
+        
+        static let ContentHeight = CGFloat(80)
+        static let ContentFontSize = CGFloat(12)
+        static let ContentPadding = CGFloat(5)
+        
+        static func topMargin(state: State) -> CGFloat {
+            var topMargin = 0
+            switch state {
+            case .InactiveRegular:
+                topMargin = 144
+            case .InactiveCompact:
+                topMargin = 112
+            case .ActiveRegular:
+                topMargin = 100
+            case .ActiveCompact:
+                topMargin = 68
+            }
+            return CGFloat(topMargin)
+        }
+    }
+    
+    enum ButtonTag : Int {
+        case Unknown = 0
+        case Timeline = 1
+        case Article = 2
+        case Celebrity = 3
+    }
+    
+    enum State : Int {
+        case InactiveRegular
+        case InactiveCompact
+        case ActiveRegular
+        case ActiveCompact
+    }
     
     struct TitlePlaceholder {
         static let Timeline = NSLocalizedString("朋友圈", comment: "Timeline")

        button.addTarget(self, action: "buttonTapped:", forControlEvents: .TouchUpInside)
        let label = UILabel()
        label.text = text
        label.font = UIFont.systemFontOfSize(GSVLayoutInfo.ContentFontSize)
        label.textColor = UIColor.grayColor()
        let stackView = UIStackView()
        stackView.axis = .Vertical
        stackView.alignment = .Center
        stackView.spacing = GSVLayoutInfo.ContentPadding
        stackView.addArrangedSubview(button)
        stackView.addArrangedSubview(label)
        
        return stackView
    }
    
    private func _transitionToState(state: GSState) {
        
        _contextTopMarginConstraint!.updateOffset(GSVLayoutInfo.topMargin(state))
        _navigationBarTopConstraint!.updateOffset(GSNavigationInfo.topMargin(state))
        UIView.animateWithDuration(0.25) { () -> Void in
            self.view.layoutIfNeeded()
        }
    }
    
    private func _fetchCurrentState(active: Bool) -> GSState {
        
        var state: GSState
        if tq_isMinimumWindowHeight() {
            state = active ? .ActiveCompact : .InactiveCompact
        } else {

        
        _scrollContentView.addSubview(_stackView)
        _stackView.snp_makeConstraints { (make) -> Void in
            let top = LayoutInfo.topMargin(_fetchCurrentState(false))
            _contextTopMarginConstraint = make.top.equalTo(_scrollContentView).offset(top).constraint
            make.leading.trailing.bottom.equalTo(_scrollContentView)
            make.height.equalTo(LayoutInfo.ContentHeight)
        }
    }
    private func _setupNavigationBar() {
