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

import Foundation


public extension UIDatePicker {
    
    class func addDatePicker(to textField: UITextField) -> UIDatePicker {
        
        let datePicker = UIDatePicker()
        datePicker.backgroundColor = .mvmWhite
        datePicker.datePickerMode = .date
        
        let locale = NSLocale.current as NSLocale
        datePicker.locale = locale as Locale
        datePicker.calendar = locale.object(forKey: .calendar) as? Calendar
        //To support old style wheel
        if #available(iOS 13.4, *) {
            datePicker.preferredDatePickerStyle = .wheels
        }
        textField.inputView = datePicker
        
        return datePicker
    }

    class func addTimeAndDatePicker(to textField: UITextField) -> UIDatePicker {
        
        let datePicker = UIDatePicker()
        datePicker.backgroundColor = .mvmWhite
        datePicker.datePickerMode = .time
        //To support old style wheel
        if #available(iOS 13.4, *) {
            datePicker.preferredDatePickerStyle = .wheels
        }
        textField.inputView = datePicker

        return datePicker
    }
}
