//
//  ProgrammaticScrollViewController.swift
//  MVMCoreUI
//
//  Created by Scott Pfeil on 3/12/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//


open class ProgrammaticScrollViewController: ScrollingViewController {
    //--------------------------------------------------
    // MARK: - Constraints
    //--------------------------------------------------
    
    public var topConstraint: NSLayoutConstraint?
    public var bottomConstraint: NSLayoutConstraint?
    
    //--------------------------------------------------
    // MARK: - Initializers
    //--------------------------------------------------
    
    public override init(with scrollView: UIScrollView) {
        super.init(with: scrollView)
    }
    
    public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    }
    
    required public init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    //--------------------------------------------------
    // MARK: - Lifecycle
    //--------------------------------------------------
    
    open override func loadView() {
        
        let view = UIView()
        view.backgroundColor = .white
        
        let scrollView = UIScrollView()
        scrollView.backgroundColor = .clear
        scrollView.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(scrollView)
        
        // Sets the constraints for the scroll view
        scrollView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
        view.rightAnchor.constraint(equalTo: scrollView.rightAnchor).isActive = true
        topConstraint = scrollView.topAnchor.constraint(equalTo: view.topAnchor)
        topConstraint?.isActive = true
        bottomConstraint = view.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor)
        bottomConstraint?.isActive = true

        // Sets the constraints for the content view
        let contentView = MVMCoreUICommonViewsUtility.commonView()
        scrollView.addSubview(contentView)
        contentView.leftAnchor.constraint(equalTo: scrollView.safeAreaLayoutGuide.leftAnchor).isActive = true
        scrollView.safeAreaLayoutGuide.rightAnchor.constraint(equalTo: contentView.rightAnchor).isActive = true
        contentView.topAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true
        scrollView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
        
        self.contentView = contentView
        self.scrollView = scrollView
        self.view = view
    }
}
