//
//  UIView+YSMASAdditions.h
//  Masonry
//
//  Created by Jonas Budelmann on 20/07/13.
//  Copyright (c) 2013 cloudling. All rights reserved.
//

#import "YSMASUtilities.h"
#import "YSMASConstraintMaker.h"
#import "YSMASViewAttribute.h"

/**
 *	Provides constraint maker block
 *  and convience methods for creating YSMASViewAttribute which are view + NSLayoutAttribute pairs
 */
@interface YSMAS_VIEW (YSMASAdditions)

/**
 *	following properties return a new YSMASViewAttribute with current view and appropriate NSLayoutAttribute
 */
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_left;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_top;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_right;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_bottom;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_leading;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_trailing;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_width;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_height;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_centerX;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_centerY;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_baseline;
@property (nonatomic, strong, readonly) YSMASViewAttribute *(^ysmas_attribute)(NSLayoutAttribute attr);

#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)

@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_firstBaseline;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_lastBaseline;

#endif

#if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)

@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_leftMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_rightMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_topMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_bottomMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_leadingMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_trailingMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_centerXWithinMargins;
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_centerYWithinMargins;

#endif

#if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 110000) || (__TV_OS_VERSION_MAX_ALLOWED >= 110000)

@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_safeAreaLayoutGuide API_AVAILABLE(ios(11.0),tvos(11.0));
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_safeAreaLayoutGuideTop API_AVAILABLE(ios(11.0),tvos(11.0));
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_safeAreaLayoutGuideBottom API_AVAILABLE(ios(11.0),tvos(11.0));
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_safeAreaLayoutGuideLeft API_AVAILABLE(ios(11.0),tvos(11.0));
@property (nonatomic, strong, readonly) YSMASViewAttribute *ysmas_safeAreaLayoutGuideRight API_AVAILABLE(ios(11.0),tvos(11.0));

#endif

/**
 *	a key to associate with this view
 */
@property (nonatomic, strong) id ysmas_key;

/**
 *	Finds the closest common superview between this view and another view
 *
 *	@param	view	other view
 *
 *	@return	returns nil if common superview could not be found
 */
- (instancetype)ysmas_closestCommonSuperview:(YSMAS_VIEW *)view;

/**
 *  Creates a YSMASConstraintMaker with the callee view.
 *  Any constraints defined are added to the view or the appropriate superview once the block has finished executing
 *
 *  @param block scope within which you can build up the constraints which you wish to apply to the view.
 *
 *  @return Array of created YSMASConstraints
 */
- (NSArray *)ysmas_makeConstraints:(void(NS_NOESCAPE ^)(YSMASConstraintMaker *make))block;

/**
 *  Creates a YSMASConstraintMaker with the callee view.
 *  Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
 *  If an existing constraint exists then it will be updated instead.
 *
 *  @param block scope within which you can build up the constraints which you wish to apply to the view.
 *
 *  @return Array of created/updated YSMASConstraints
 */
- (NSArray *)ysmas_updateConstraints:(void(NS_NOESCAPE ^)(YSMASConstraintMaker *make))block;

/**
 *  Creates a YSMASConstraintMaker with the callee view.
 *  Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
 *  All constraints previously installed for the view will be removed.
 *
 *  @param block scope within which you can build up the constraints which you wish to apply to the view.
 *
 *  @return Array of created/updated YSMASConstraints
 */
- (NSArray *)ysmas_remakeConstraints:(void(NS_NOESCAPE ^)(YSMASConstraintMaker *make))block;

@end
