<commit_before>//
//  ValidatedAnimatedTextInput.swift
//  GISTFramework
//
//  Created by <NAME> on 12/07/2017.
//  Copyright © 2017 Social Cubix. All rights reserved.
//

import UIKit
import PhoneNumberKit

open class ValidatedAnimatedTextInput: AnimatedTextInput, ValidatedTextInput {
    
    //MARK: - Properties
    
    /// Bool flag for validating an empty text.
    @IBInspectable open var validateEmpty:Bool = false;
    
    /// Bool flag for validating a valid email text.
    @IBInspectable open var validateEmail:Bool = false;
    
    /// Bool flag for validating a valid phone number text.
    @IBInspectable open var validatePhone:Bool = false;
    
    /// Bool flag for validating a valid email or phone number text.
    @IBInspectable open var validateEmailOrPhone:Bool = false;
    
    /// Bool flag for validating a valid email, phone or non empty number text.
    @IBInspectable open var validateEmailPhoneOrUserName:Bool = false;
    
    /// Bool flag for validating a valid url text.
    @IBInspectable open var validateURL:Bool = false;
    
    /// Bool flag for validating a valid numaric input.
    @IBInspectable open var validateNumeric:Bool = false;
    
    /// Bool flag for validating a valid alphabetic input.
    @IBInspectable open var validateAlphabetic:Bool = false;
    
    /// Bool flag for validating a valid alphabetic input.
    @IBInspectable open var validateRegex:String = "";
    
    /// Validats minimum character limit.
    @IBInspectable open var minChar:Int = 0;
    
    /// Validats maximum character limit.
    @IBInspectable open var maxChar:Int = 0;
    
    @IBInspectable public var maskFormat: String? {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.maskFormat;
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.maskFormat = newValue;
        }
    } //P.E.
    
    @IBInspectable public var sendMaskedText:Bool {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.sendMaskedText ?? false;
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.sendMaskedText = newValue;
        }
    } //P.E.
    
    @IBInspectable public var maskPhone: Bool {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.maskPhone ?? false;
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.maskPhone = newValue;
        }
    } //P.E.
    
    @IBInspectable public var phonePrefix: Bool {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.phonePrefix ?? true;
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.phonePrefix = newValue;
        }
    } //P.E.
    
    @IBInspectable public var prefix: String? {
        get {
            return (self.textInput as? AnimatedTextField)?.prefix;
        }
        
        set {
            (self.textInput as? AnimatedTextField)?.prefix = newValue;
        }
    } //P.E.
    
    
    @IBInspectable public var defaultRegion:String {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.defaultRegion ?? PhoneNumberKit.defaultRegionCode();
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.defaultRegion = newValue;
        }
    } //P.E.
    
    open var planText:String? {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.planText;
        }
    } //P.E
    
    internal var curText: String? {
        get {
            return (self.maskFormat != nil || self.prefix != nil || maskPhone) ? self.planText:self.text;
        }
    } //P.E.
    
    open var isValidMask:Bool {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.isValidMask ?? false;
        }
    } //P.E.
    
    /**
     Validity msg for invalid input text. - Default text is 'Invalid'
     The msg can be a key of SyncEngine with a prefix '#'
     */
    @IBInspectable open var validityMsg:String? = nil;
    
    private var _isEmpty:Bool = false;
    
    private var _isValid:Bool = false;
    
    public var phoneNumber:PhoneNumber?;
    
    open override var text: String? {
        get {
            return super.text;
        }
        set {
            super.text = newValue;
            
            if (!self.isFirstResponder) {
                
                if maskFormat != nil {
                    (self.textInput as? AnimatedInputMaskTextField)?.applyMaskFormat();
                } else if maskPhone {
                    (self.textInput as? AnimatedInputMaskTextField)?.applyPhoneMaskFormat();
                }
                
                if (self.prefix != nil) {
                    (self.textInput as? AnimatedTextField)?.addPrefix();
                }
                
                self.validateText();
            }
        }
    } //P.E.
    
    open var forcedInvalid:Bool {
        get {
            return false;
        }
        
        set {
            _isValid = newValue;
        }
    }
    
    open var validText: String?;
    
    /// Flag for whether the input is valid or not.
    open var isValid:Bool {
        get {
            if (self.isFirstResponder) {
                self.validateText();
            }
            
            let cValid:Bool = (_isValid && (!validateEmpty || !_isEmpty));
            
            self.isInvalidMsgHidden = cValid;<commit_msg>Fixed issue<commit_after>//
//  ValidatedAnimatedTextInput.swift
//  GISTFramework
//
//  Created by <NAME> on 12/07/2017.
//  Copyright © 2017 Social Cubix. All rights reserved.
//

import UIKit
import PhoneNumberKit

open class ValidatedAnimatedTextInput: AnimatedTextInput, ValidatedTextInput {
    
    //MARK: - Properties
    
    /// Bool flag for validating an empty text.
    @IBInspectable open var validateEmpty:Bool = false;
    
    /// Bool flag for validating a valid email text.
    @IBInspectable open var validateEmail:Bool = false;
    
    /// Bool flag for validating a valid phone number text.
    @IBInspectable open var validatePhone:Bool = false;
    
    /// Bool flag for validating a valid email or phone number text.
    @IBInspectable open var validateEmailOrPhone:Bool = false;
    
    /// Bool flag for validating a valid email, phone or non empty number text.
    @IBInspectable open var validateEmailPhoneOrUserName:Bool = false;
    
    /// Bool flag for validating a valid url text.
    @IBInspectable open var validateURL:Bool = false;
    
    /// Bool flag for validating a valid numaric input.
    @IBInspectable open var validateNumeric:Bool = false;
    
    /// Bool flag for validating a valid alphabetic input.
    @IBInspectable open var validateAlphabetic:Bool = false;
    
    /// Bool flag for validating a valid alphabetic input.
    @IBInspectable open var validateRegex:String = "";
    
    /// Validats minimum character limit.
    @IBInspectable open var minChar:Int = 0;
    
    /// Validats maximum character limit.
    @IBInspectable open var maxChar:Int = 0;
    
    @IBInspectable public var maskFormat: String? {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.maskFormat;
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.maskFormat = newValue;
        }
    } //P.E.
    
    @IBInspectable public var sendMaskedText:Bool {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.sendMaskedText ?? false;
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.sendMaskedText = newValue;
        }
    } //P.E.
    
    @IBInspectable public var maskPhone: Bool {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.maskPhone ?? false;
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.maskPhone = newValue;
        }
    } //P.E.
    
    @IBInspectable public var phonePrefix: Bool {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.phonePrefix ?? true;
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.phonePrefix = newValue;
        }
    } //P.E.
    
    @IBInspectable public var prefix: String? {
        get {
            return (self.textInput as? AnimatedTextField)?.prefix;
        }
        
        set {
            (self.textInput as? AnimatedTextField)?.prefix = newValue;
        }
    } //P.E.
    
    
    @IBInspectable public var defaultRegion:String {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.defaultRegion ?? PhoneNumberKit.defaultRegionCode();
        }
        
        set {
            (self.textInput as? AnimatedInputMaskTextField)?.defaultRegion = newValue;
        }
    } //P.E.
    
    open var planText:String? {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.planText;
        }
    } //P.E
    
    internal var curText: String? {
        get {
            return (self.maskFormat != nil || self.prefix != nil || maskPhone) ? self.planText:self.text;
        }
    } //P.E.
    
    open var isValidMask:Bool {
        get {
            return (self.textInput as? AnimatedInputMaskTextField)?.isValidMask ?? false;
        }
    } //P.E.
    
    /**
     Validity msg for invalid input text. - Default text is 'Invalid'
     The msg can be a key of SyncEngine with a prefix '#'
     */
    @IBInspectable open var validityMsg:String? = nil;
    
    private var _isEmpty:Bool = false;
    
    private var _isValid:Bool = false;
    
    public var phoneNumber:PhoneNumber?;
    
    open override var text: String? {
        get {
            return super.text;
        }
        set {
            super.text = newValue;
            
            if (!self.isFirstResponder) {
                
                if maskFormat != nil {
                    (self.textInput as? AnimatedInputMaskTextField)?.applyMaskFormat();
                } else if maskPhone {
                    (self.textInput as? AnimatedInputMaskTextField)?.applyPhoneMaskFormat();
                }
                
                if (self.prefix != nil) {
                    (self.textInput as? AnimatedTextField)?.addPrefix();
                }
                
                self.validateText();
            }
        }
    } //P.E.
    
    open var forcedInvalid:Bool {
        get {
            return false;
        }
        
        set {
            _isValid = !newValue;
        }
    }
    
    open var validText: String?;
    
    /// Flag for whether the input is valid or not.
    open var isValid:Bool {
        get {
            if (self.isFirstResponder) {
                self.validateText();
            }
            
            let cValid:Bool = (_isValid && (!validateEmpty || !_isEmpty));
            
            self.isInvalidMsgHidden = cValid;
{'fraction_non_alphanumeric': 0.09020175517958925, 'fraction_numerical': 0.00253324889170361, 'mean_word_length': 1.734784760019792, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6964309', 'n_tokens_mistral': 3129, 'n_tokens_neox': 3059, 'n_words': 810}