//
//  CustomPicker.swift
//  OrderScheduling
//
//  Created by 中道 on 2023/9/4.
//

import Foundation
import BRPickerView

public let CP = CustomPicker.default

open class CustomPicker {
    public static let `default` = CustomPicker()
    
    func showItems(items:[String],selectedIndex:Int? = nil,selectedItem:String? = nil,resultHandler:@escaping ((BRResultModel?) -> Void)) {
        let pickerView = BRStringPickerView()
        if selectedItem != nil {
            pickerView.selectValue = selectedItem!
        }
        if selectedIndex != nil {
            pickerView.selectIndex = selectedIndex!
        }
        
        pickerView.dataSourceArr = items
        pickerView.resultModelBlock = { result in
            resultHandler(result)
        }
        pickerView.show()
    }
    
    func showDate(minDate: Date? = nil,maxDate: Date? = nil,selectDate: Date? = nil,resultHandler:@escaping ((Date?, String?) -> Void)) {
        let pickerView = BRDatePickerView()
        pickerView.pickerMode = .YMDHMS
        pickerView.minDate = minDate
        pickerView.maxDate = maxDate
        pickerView.selectDate = selectDate
        pickerView.resultBlock = { date,dateString in
            resultHandler(date,dateString)
        }
        pickerView.show()
    }
}
