//
//  UIPickerView.swift
//  MVMCoreUI
//
//  Created by Kevin Christiano on 4/14/20.
//  Copyright © 2020 Verizon Wireless. All rights reserved.
//

import Foundation


public extension UIPickerView {
    
    class func createPickerView() -> UIPickerView {
        
        let picker = UIPickerView(frame: .zero)
        picker.backgroundColor = .mvmWhite
        picker.showsSelectionIndicator = true
        return picker
    }
    
    class func addPicker(to textField: UITextField, delegate: TextFieldAndPickerDelegate?, dismissAction: Selector?) -> UIPickerView {

        // Sets up the picker (same tag as the textfield)
        let picker = createPickerView()
        picker.delegate = delegate
        picker.dataSource = delegate
        picker.tag = textField.tag
        textField.inputView = picker

        // Adds a dismiss toolbar, since all fields with pickers should have one.
        if let dismissAction = dismissAction {
            UIToolbar.addDismissToolbar(to: textField, delegate: delegate, action: dismissAction)
        }
        
        return picker
    }
}
