import Foundation
import UIKit
import WebKit

@objc public class PreventCapture: NSObject {
    
    @objc public func screenCapturePrevent(view: UIView, completion: @escaping (Bool) -> Void) {
        view.makeSecure()
        completion(true)
    }
}

extension UIView {
    @objc public func makeSecure() {
        DispatchQueue.main.async {
            let textField = UITextField()
            textField.isSecureTextEntry = true
            self.addSubview(textField)
        
            if UIDevice.current.userInterfaceIdiom == .phone {
                textField.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
                textField.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
            }
            
            self.layer.superlayer?.insertSublayer(textField.layer, at: 0)
            textField.layer.sublayers?.last?.addSublayer(self.layer)
          
        }
    }
}
