//
//  MFTextField.h
//  myverizon
//
//  Created by Suresh, Kamlesh on 11/24/15.
//  Copyright © 2015 Verizon Wireless. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <MVMCoreUI/ViewConstrainingView.h>

@class PrimaryButton;
@class MFTextField;
@class Label;

@protocol MFTextFieldDelegate <NSObject>

@optional

// Called when the entered text becomes valid based on the validation block
- (void)entryIsValid:(nullable MFTextField *)textfield;

// Called when the entered text becomes invalid based on the validation block
- (void)entryIsInvalid:(nullable MFTextField *)textfield;

// Dismisses the keyboard.
- (void)dismissFieldInput:(nullable id)sender;

@end

@interface MFTextField : ViewConstrainingView <MVMCoreUIMoleculeViewProtocol>

@property (nullable, weak, nonatomic) UIView *view;

@property (nullable, weak, nonatomic) IBOutlet UIView *textFieldContainerView;
@property (nullable, weak, nonatomic) IBOutlet UITextField *textField;
@property (nullable, weak, nonatomic) IBOutlet Label *formLabel;
@property (nullable, weak, nonatomic) IBOutlet UIView *separatorView;//make it public so outsider class can know the posistion of it.

@property (nullable, weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;
@property (weak, nonatomic, nullable) IBOutlet NSLayoutConstraint *formLabelRightPin;

@property (nonatomic,getter=isEnabled) BOOL enabled;

// To set the placeholder and text
@property (nullable, weak, nonatomic) NSString *text;
@property (nullable, weak, nonatomic) NSString *formText;
@property (nullable, weak, nonatomic) NSString *fieldKey;

@property (nullable, weak, nonatomic) NSString *placeholder; // will move out in Feb release

@property (assign, nonatomic) BOOL hideBorder;

//accesories
@property (nullable, weak, nonatomic) UIDatePicker *datePicker;
@property (nullable, weak, readonly, nonatomic) UIToolbar *toolbar;

//helper
@property (nullable, strong, nonatomic) NSDateFormatter *formatter;

// If you're using a MFViewController, you must set this to it
@property (nullable, weak, nonatomic) id<UITextFieldDelegate> uiTextFieldDelegate;

// The delegate and block for validation. Validates if the text that the user has entered is valid or not. Checked after each change if there is a delegate.
@property (nullable, weak, nonatomic) id<MFTextFieldDelegate> mfTextFieldDelegate;
@property (nonatomic, getter=isValid) BOOL valid;
@property (nullable, copy, nonatomic) BOOL (^validationBlock)(NSString *_Nullable enteredValue);

// custom text colors
@property (nullable, strong, nonatomic) UIColor *customEnabledTextColor;
@property (nullable, strong, nonatomic) UIColor *customDisabledTextColor;

//default error message
@property (nullable, strong, nonatomic) NSString *errMessage;

@property (nullable, copy, nonatomic) void (^editCompleteAction)(NSString * _Nullable text);

// Returns the actual MFTextfield object from XIB. Should only be called from the main thread.
+ (nullable instancetype)mfTextField;
+ (nullable instancetype)mfTextFieldWithBothDelegates:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate;
+ (nullable instancetype)mfTextFieldWithMap:(nullable NSDictionary *)map bothDelegates:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate;


// Returns the actual MFTextfield object from XIB. Has dropdown carrot. Should only be called from the main thread.
+ (nullable instancetype)mfTextFieldForDropDown;
+ (nullable instancetype)mfTextFieldForDropDownWithBothDelegates:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate;

// Sets both
- (void)setBothTextFieldDelegates:(id<UITextFieldDelegate,MFTextFieldDelegate> _Nullable)delegate;
// Sets the place holder and text according to the map
- (void)setWithMap:(nullable NSDictionary *)map bothDelegates:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>) delegate;


// set place holder with custom colors
- (void)setPlaceholder:(nullable NSString *)placeholder withColor:(nullable UIColor *)color;

//show the dropDown carrot
- (void)showDropDown:(BOOL)show;

// Show error
- (void)setErrorMessage:(nonnull NSString *)errorMessage;

// Hide Error
- (void)hideError;

//push notificaiton of accessibility
- (void)pushAccessibilityNotification;

// disable textfield
- (void)enable:(BOOL)enable;

// Default validation block
- (void)setDefaultValidationBlock;

//add date picker as inputView for the textfield, default done action is to set the textfield input
- (void)inputFromDatePickerFromDate:(nullable NSDate *)fromDate toDate:(nullable NSDate *)toDate showFromDateAsDefaultInput:(BOOL)show;
- (void)setDatePickerFromDate:(nullable NSDate *)fromDate toDate:(nullable NSDate *)toDate;
- (nonnull NSDate *)dismissDatePicker;
- (void)dismissPicker;

//get all enabled textfields, can be pairly used with the primary button's handleEnablingWithTextFields if you only want the enable testfield's validation to be tested
+ (nullable NSArray *)getEnabledTextfields:(nullable NSArray <MFTextField *>*)textFieldToDetermine;

- (void)showLabel:(BOOL)show;

//By default, the validation block is validated only on textfield value changed. This method is added to validate explicitly if the block is dependent on any other variables and will update the isValid accordingly.
- (void)validateBlock;

- (void)setAccessibilityString:(nullable NSString *)accessibilityString;

// For Validator Protocol
- (nullable NSString *)formFieldName;
- (nullable id)formFieldValue;

@end
