//
//  ViewConstrainingView.h
//  mobilefirst
//
//  Created by Scott Pfeil on 2/22/16.
//  Copyright © 2016 Verizon Wireless. All rights reserved.
//

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

@interface ViewConstrainingView : MFView

// Dont set these directly.
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *leftPin;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *rightPin;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *topPin;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *bottomPin;

@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterPin;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterLeftPin;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterRightPin;

@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterVerticalPin;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterTopPin;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *alignCenterBottomPin;

@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *leftPinLow;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *rightPinLow;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *topPinLow;
@property (nullable, strong, nonatomic) IBOutlet NSLayoutConstraint *bottomPinLow;

/// In updateView, will set horizontal padding to default.
@property (nonatomic) BOOL updateViewHorizontalDefaults;
@property (nonatomic) BOOL updateViewVerticalDefaults;

/// A molecule if we constrain one.
@property (weak, nullable, nonatomic) UIView <MVMCoreUIMoleculeViewProtocol>*molecule;

/// A flag for if we should add a molecule from json.
@property (nonatomic) BOOL shouldSetupMoleculeFromJSON;

// Returns an empty view
+ (nonnull ViewConstrainingView *)emptyView;
    
// Returns a view with the provided view as a subview, pinned.
+ (nonnull ViewConstrainingView *)viewConstrainingView:(nonnull UIView *)view;

// Can be initialized with a molecule to constrain
- (nullable instancetype)initWithMolecule:(nonnull UIView <MVMCoreUIMoleculeViewProtocol>*)molecule alignment:(UIStackViewAlignment)alignment;

#pragma mark - Constraining

// Use these to sets the constants, because subclasses may align differently.
- (void)setPinConstantsWithInsets:(UIEdgeInsets)insets;
- (void)setTopPinConstant:(CGFloat)top left:(CGFloat)left bottom:(CGFloat)bottom right:(CGFloat)right;
- (void)setLeftPinConstant:(CGFloat)constant;
- (void)setRightPinConstant:(CGFloat)constant;
- (void)setTopPinConstant:(CGFloat)constant;
- (void)setBottomPinConstant:(CGFloat)constant;

// Displaying/hiding
- (void)show;
- (void)hide;

// Pins all edges to its super. 0 constant
- (void)pinToSuperView;
- (void)pinViewToSuperView:(nonnull UIView *)view;

// Resets all the constraints to default.
- (void)resetConstraints;

// Add a view to be constrained in this view.
- (void)addConstrainedView:(nonnull UIView *)view;

// Change the alignment of the label
- (void)alignLeft;
- (void)alignCenterHorizontal;
- (void)alignRight;
- (void)alignFillHorizontal;
- (void)alignTop;
- (void)alignCenterVertical;
- (void)alignBottom;
- (void)alignFillVertical;

/// Convenience function for getting the alignment from a map.
+ (UIStackViewAlignment)getAlignmentForString:(nullable NSString *)alignmentString defaultAlignment:(UIStackViewAlignment)defaultAlignment;

/// Makes the view isAccessibilityElement false and adds molecule elements to accessbilityElements.
- (void)setMoleculeAccessibility;

@end
