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

#import "View+YSMASAdditions.h"

#ifdef YSMAS_SHORTHAND

/**
 *	Shorthand view additions without the 'ysmas_' prefixes,
 *  only enabled if YSMAS_SHORTHAND is defined
 */
@interface YSMAS_VIEW (YSMASShorthandAdditions)

@property (nonatomic, strong, readonly) YSMASViewAttribute *left;
@property (nonatomic, strong, readonly) YSMASViewAttribute *top;
@property (nonatomic, strong, readonly) YSMASViewAttribute *right;
@property (nonatomic, strong, readonly) YSMASViewAttribute *bottom;
@property (nonatomic, strong, readonly) YSMASViewAttribute *leading;
@property (nonatomic, strong, readonly) YSMASViewAttribute *trailing;
@property (nonatomic, strong, readonly) YSMASViewAttribute *width;
@property (nonatomic, strong, readonly) YSMASViewAttribute *height;
@property (nonatomic, strong, readonly) YSMASViewAttribute *centerX;
@property (nonatomic, strong, readonly) YSMASViewAttribute *centerY;
@property (nonatomic, strong, readonly) YSMASViewAttribute *baseline;
@property (nonatomic, strong, readonly) YSMASViewAttribute *(^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 *firstBaseline;
@property (nonatomic, strong, readonly) YSMASViewAttribute *lastBaseline;

#endif

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

@property (nonatomic, strong, readonly) YSMASViewAttribute *leftMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *rightMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *topMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *bottomMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *leadingMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *trailingMargin;
@property (nonatomic, strong, readonly) YSMASViewAttribute *centerXWithinMargins;
@property (nonatomic, strong, readonly) YSMASViewAttribute *centerYWithinMargins;

#endif

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

@property (nonatomic, strong, readonly) YSMASViewAttribute *safeAreaLayoutGuideTop API_AVAILABLE(ios(11.0),tvos(11.0));
@property (nonatomic, strong, readonly) YSMASViewAttribute *safeAreaLayoutGuideBottom API_AVAILABLE(ios(11.0),tvos(11.0));
@property (nonatomic, strong, readonly) YSMASViewAttribute *safeAreaLayoutGuideLeft API_AVAILABLE(ios(11.0),tvos(11.0));
@property (nonatomic, strong, readonly) YSMASViewAttribute *safeAreaLayoutGuideRight API_AVAILABLE(ios(11.0),tvos(11.0));

#endif

- (NSArray *)makeConstraints:(void(^)(YSMASConstraintMaker *make))block;
- (NSArray *)updateConstraints:(void(^)(YSMASConstraintMaker *make))block;
- (NSArray *)remakeConstraints:(void(^)(YSMASConstraintMaker *make))block;

@end

#define YSMAS_ATTR_FORWARD(attr)  \
- (YSMASViewAttribute *)attr {    \
    return [self ysmas_##attr];   \
}

@implementation YSMAS_VIEW (YSMASShorthandAdditions)

YSMAS_ATTR_FORWARD(top);
YSMAS_ATTR_FORWARD(left);
YSMAS_ATTR_FORWARD(bottom);
YSMAS_ATTR_FORWARD(right);
YSMAS_ATTR_FORWARD(leading);
YSMAS_ATTR_FORWARD(trailing);
YSMAS_ATTR_FORWARD(width);
YSMAS_ATTR_FORWARD(height);
YSMAS_ATTR_FORWARD(centerX);
YSMAS_ATTR_FORWARD(centerY);
YSMAS_ATTR_FORWARD(baseline);

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

YSMAS_ATTR_FORWARD(firstBaseline);
YSMAS_ATTR_FORWARD(lastBaseline);

#endif

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

YSMAS_ATTR_FORWARD(leftMargin);
YSMAS_ATTR_FORWARD(rightMargin);
YSMAS_ATTR_FORWARD(topMargin);
YSMAS_ATTR_FORWARD(bottomMargin);
YSMAS_ATTR_FORWARD(leadingMargin);
YSMAS_ATTR_FORWARD(trailingMargin);
YSMAS_ATTR_FORWARD(centerXWithinMargins);
YSMAS_ATTR_FORWARD(centerYWithinMargins);

#endif

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

YSMAS_ATTR_FORWARD(safeAreaLayoutGuideTop);
YSMAS_ATTR_FORWARD(safeAreaLayoutGuideBottom);
YSMAS_ATTR_FORWARD(safeAreaLayoutGuideLeft);
YSMAS_ATTR_FORWARD(safeAreaLayoutGuideRight);

#endif

- (YSMASViewAttribute *(^)(NSLayoutAttribute))attribute {
    return [self ysmas_attribute];
}

- (NSArray *)makeConstraints:(void(NS_NOESCAPE ^)(YSMASConstraintMaker *))block {
    return [self ysmas_makeConstraints:block];
}

- (NSArray *)updateConstraints:(void(NS_NOESCAPE ^)(YSMASConstraintMaker *))block {
    return [self ysmas_updateConstraints:block];
}

- (NSArray *)remakeConstraints:(void(NS_NOESCAPE ^)(YSMASConstraintMaker *))block {
    return [self ysmas_remakeConstraints:block];
}

@end

#endif
