//
//  MVMCoreUIUtility.h
//  MVMCoreUI
//
//  Created by Scott Pfeil on 1/10/19.
//  Copyright © 2019 Verizon Wireless. All rights reserved.
//

#import <UIKit/UIKit.h>

#define fequalwiththreshold(a,b,c) (fabs((a) - (b)) < c)

NS_ASSUME_NONNULL_BEGIN

@interface MVMCoreUIUtility : NSObject

#pragma mark - Getters

// Returns localized imageName
+ (nullable NSString *)localizedImageName:(nullable NSString *)imageName;

// The bundle for this framework
+ (nullable NSBundle *)bundleForMVMCoreUI;

// Returns the hardcoded string from the string file.
+ (nullable NSString *)hardcodedStringWithKey:(nonnull NSString *)key;

// Returns an image from this framework's bundle
+ (nullable UIImage *)imageNamed:(nullable NSString *)imageName;

// Returns the margins for a view.
+ (UIEdgeInsets)getMarginsForView:(nullable UIView *)view;

/// Gets the current visible view controller. Checks presented view controllers first, and then it checks on the NavigationController in the session object.
+ (nullable UIViewController *)getCurrentVisibleController;

/// Gets the first non manager controller.
+ (nullable UIViewController *)getViewControllerTraversingManagers:(UIViewController *)viewController;

/// Checks if the view or any descendents of the view is currently focused for voice over.
+ (BOOL)viewContainsAccessiblityFocus:(nonnull UIView *)view;

+ (BOOL)isView:(nonnull UIView *)view visibleIn:(nonnull UIView *)rootView;

+ (BOOL)isViewVisibleInParent:(nonnull UIView *)view;

+ (BOOL)doesView:(nonnull UIView *)overlappingView cover:(nonnull UIView *)view;

+ (BOOL)isViewTransparent:(nonnull UIView *)view;

#pragma mark - Setters

+ (void)setMarginsForView:(nullable UIView *)view leading:(CGFloat)leading top:(CGFloat)top trailing:(CGFloat)trailing bottom:(CGFloat)bottom;

#pragma mark - Formatting

// Formats the given mdn.
+ (nullable NSString *)formatMdn:(nullable NSString *)mdn;

// Removes any format.
+ (nullable NSString *)removeMdnFormat:(nullable NSString *)mdn;

/// Returns an ordinal formatted string for a number.
+ (nullable NSString *)getOrdinalStringForIndex:(nonnull NSNumber *)number;

#pragma mark - Validations

// Will validate passed string on corresponding regular expression
+ (BOOL)validateString:(nonnull NSString *)string withRegularExpression:(nonnull NSString *)regExpression;

// Validates the given mdn.
+ (BOOL)validateMDNString:(nullable NSString *)mdn;

// Validates the given internation mdn.
+ (BOOL)validateInternationalMDNString:(nullable NSString *)mdn;

#pragma mark - Sizing

// Grabs the width from the available container.
+ (CGFloat)getWidth;

// Gets the space needed at the top of the view for the status bar.
+ (CGFloat)getTopSpaceWithStatusBarForView:(UIView *_Nonnull)view;

// Returns the height of the view. If nil is passed for the width, it will use the detail view width.
+ (CGFloat)getHeightOfView:(nonnull UIView *)view forWidth:(nullable NSNumber *)width;

// Returns the space between the content and the frame. Can use this to get the space for items to fill out the screen.
+ (CGFloat)getRemainingSpaceBetweenContentAndFrame:(nonnull UIScrollView *)scrollview;

// Gets the constraint height to be whatever space is left in the scroll view.
+ (CGFloat)getVariableConstraintHeight:(CGFloat)currentConstant inScrollView:(nonnull UIScrollView *)scrollView minimumHeight:(CGFloat)minimumHeight;

/// Sets the view's frame according to constraints.
+ (void)sizeViewToFit:(nullable UIView *)view;
+ (void)sizeViewToFit:(UIView *)view forWidth:(nullable NSNumber *)width;

#pragma mark - Keyboard

/** Handles setting the content inset for a passed in scroll view.
 * @param notification - pass in the notification from the UIKeyboardWillShowNotification.
 * @param scrollView - the scroll view to set the content inset.
 * @param viewController - Pass in the main view that the scroll view is in for calculations.
 * @param rectToScrollTo  - Pass in a block that returns the rectangle. **/
+ (void)setScrollViewInsetForKeyboardShow:(nonnull NSNotification *)notification scrollView:(nonnull UIScrollView *)scrollView viewController:(nonnull UIViewController *)viewController rectToScrollTo:(nonnull CGRect (^)(void))rectToScrollTo;

/** Handles setting the content inset for a passed in scroll view.
 * @param notification - pass in the notification from the UIKeyboardWillShowNotification.
 * @param scrollView - the scroll view to set the content inset.
 * @param contentInset - The pre-keyboard inset to set after hiding. **/
+ (void)setScrollViewInsetForKeyboardHide:(nonnull NSNotification *)notification scrollView:(nonnull UIScrollView *)scrollView viewController:(nonnull UIViewController *)viewController contentInset:(UIEdgeInsets)contentInset;


@end

NS_ASSUME_NONNULL_END
