import Foundation


@objc(RNVntelCCCDMRZViewManager)
class VntelCCCDViewManager: RCTViewManager {

  override func view() -> (VntelCccdView) {
    return VntelCccdView()
  }

  @objc override static func requiresMainQueueSetup() -> Bool {
    return false
  }
}

protocol VntelCccdViewDelegate: AnyObject {
    /// TODO change mrz type
    func onRecognizedMRZ(_ mrz: MRZResult)
}
class VntelCccdView : UIView, MRZScannerViewDelegate {
    weak var delegate: VntelCccdViewDelegate?
    
    
    @objc var layout: NSArray = [] {
        didSet {
            
        }
    }
    
    let scanController = MRZScannerViewController()
    
    init() {
        super.init(frame: .zero)
        self.addSubview(scanController.view)
        scanController.view.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            scanController.view.topAnchor.constraint(equalTo: self.topAnchor),
            scanController.view.bottomAnchor.constraint(equalTo: self.bottomAnchor),
            scanController.view.leadingAnchor.constraint(equalTo: self.leadingAnchor),
            scanController.view.trailingAnchor.constraint(equalTo: self.trailingAnchor),
        ])
        scanController.delegate = self
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func onScan() {
        
    }
    //QKMRZScannerViewDelegate - Delegate
    func mrzScannerView(_ mrzScannerView: LiveMRZScanner, didFind scanResult: ParsedResult) {
        if let dob = scanResult.birthdate, let doe = scanResult.expiryDate {
            self.delegate?.onRecognizedMRZ(scanResult)
          
        }
    }
    
        
}
