//import UIKit
//import Flutter
//
//class PenguinViewController: UIViewController {
//    override func viewDidLoad() {
//        super.viewDidLoad()
//        setupPenguinView()
//    }
//
//    private func setupPenguinView() {
//        guard let appDelegate = UIApplication.shared.delegate as? AppDelegate,
//              let flutterEngine = appDelegate.flutterEngine else {
//            print("Error: Flutter engine is not available.")
//            return
//        }
//
//        let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
//        let penguinView = PenguinView(frame: self.view.bounds, viewIdentifier: 0, arguments: nil, binaryMessenger: flutterViewController.binaryMessenger)
//        let penguinUIView = penguinView.view()
//        penguinUIView.frame = self.view.bounds
//        penguinUIView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
//        self.view.addSubview(penguinUIView)
//    }
//}


import UIKit
import Flutter
class PenguinViewController: UIViewController {
    var flutterEngine: FlutterEngine?
    var arguments: [String: Any]  = [:]

    // Custom initializer
    init(flutterEngine: FlutterEngine?, arguments: [String: Any]) {
        self.flutterEngine = flutterEngine
        self.arguments = arguments
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        print("======== My Values =============")
        print(arguments)
        setupPenguinView()
    }

    private func setupPenguinView() {
        guard let flutterEngine = flutterEngine else {
            print("Error: Flutter engine is not available.")
            return
        }

        let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
        let penguinView = PenguinView(frame: self.view.bounds, viewIdentifier: 0, arguments: arguments, binaryMessenger: flutterViewController.binaryMessenger)
        let penguinUIView = penguinView.view()
        penguinUIView.frame = self.view.bounds
        penguinUIView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        self.view.addSubview(penguinUIView)
    }
    
    func setProperties(flutterEngine: FlutterEngine, arguments: [String: Any]) {
         self.flutterEngine = flutterEngine
         self.arguments = arguments
     }
}
