//
//  NativeModule.swift
//  AwesomeProject3
//
//  Created by Macbook Pro on 02/07/2023.
//

import Foundation
import React


@objc(NativeModule)
class NativeModule: NSObject, RCTBridgeModule {
  
  static func moduleName() -> String! {
    return "NativeModule"
  }
  
  // Optional: Implement the supportedEvents() method if you want to send events from the native module to React Native.
  
  // Optional: Implement the constantsToExport() method if you want to expose constants to React Native.
  
  @objc
  func nativeMethod(_ input: String) {
    // Perform the native method logic
    print("Native method called with input:", input)
    showAlert()
  }
  
  
  func showAlert() {
      let alertController = UIAlertController(title: "Alert", message: "This is a simple alert.", preferredStyle: .alert)
      
      let okayAction = UIAlertAction(title: "Okay", style: .default) { _ in
          // Handle okay action
      }
      
      alertController.addAction(okayAction)
      
      // If you want to add more actions, you can do so by creating additional UIAlertAction objects and adding them to the alertController.
      
      // Present the alert controller
      if let viewController = UIApplication.shared.keyWindow?.rootViewController {
          viewController.present(alertController, animated: true, completion: nil)
      }
  }
  
  // Optional: Implement other methods you want to call from React Native
  
}

@objc(NativeModuleManager)
class NativeModuleManager: RCTViewManager {
  override static func requiresMainQueueSetup() -> Bool {
    return true
  }

  override func view() -> UIView! {
    return UIView()
  }

  @objc
  override func constantsToExport() -> [AnyHashable: Any] {
    return ["myConstant": "Hello from native"]
  }

  @objc
  override static func moduleName() -> String! {
    return "NativeModule"
  }

}
