//
//  GSLayer+MetricsKeysUI.h
//  GlyphsCore
//
//  Created by Georg Seifert on 31.08.15.
//  Copyright (c) 2015 schriftgestaltung.de. All rights reserved.
//

#import <GlyphsCore/GSLayer.h>

/// State flags for metrics key display.
typedef NS_OPTIONS(uint8_t, GSMetricsKeysUI) {
	/// The metrics key is valid and synchronized.
	GSMetricsKeysOK = 0,
	/// The metrics key is valid but the current metric value does not match it.
	GSMetricsKeysOutOfSync = 1 << 0,
	/// The metrics key cannot be resolved.
	GSMetricsKeysInvalid = 1 << 1,
	/// The displayed value is a placeholder inherited from another source.
	GSMetricsKeysPlaceholder = 1 << 2,
};

NS_ASSUME_NONNULL_BEGIN

@interface GSLayer (MetricsKeysUI)

/// Numeric offset encoded in an aligned metrics key.
///
/// Returns `0` when no offset is encoded.
+ (NSInteger)alignedMetricsValueForKey:(nullable NSString *)key;

/// Attributed display string for a metrics key.
///
/// - Parameter side: The metric side whose key should be displayed.
/// - Parameter fontSize: The display font size.
/// - Parameter metricsKeyState: On return, the state flags for the displayed key.
- (NSAttributedString *)attributedMetricsKey:(GSMetricNumbers)side fontSize:(CGFloat)fontSize state:(nullable GSMetricsKeysUI *)metricsKeyState;

/// Whether any horizontal metrics key is out of sync.
- (BOOL)metricsKeysOutOfSync;

/// Whether any horizontal metrics key is invalid.
- (BOOL)metricsKeysInvalid;

/// Localized label for a metric side.
+ (NSString *)metricsLabelForSide:(GSMetricNumbers)side;

- (NSString *)_metricsKey:(GSMetricNumbers)side state:(nullable GSMetricsKeysUI *)state annotation:(NSString *_Nullable*_Nullable)annotation defaultKey:(nullable NSString *)defaultKey;

/// Plain metrics key for display and editing.
///
/// This resolves the effective key for the metric side without annotations.
///
/// - Parameter side: The metric side whose key should be returned.
- (nullable NSString *)plainMetricsKeyUI:(GSMetricNumbers)side;

/// Display color for metrics key state flags.
+ (NSColor *)colorForMetricsState:(GSMetricsKeysUI)state;

#pragma mark Left
/// Display and editing string for the left metrics key.
@property (nonatomic, unsafe_unretained, nullable) NSString *leftMetricsKeyUI;
/// State flags for the left metrics key.
- (GSMetricsKeysUI)leftMetricsKeyState;
/// Display string for the left metrics key and its state.
///
/// - Parameter state: On return, the state flags for the displayed key.
- (NSString *)leftMetricsKeyState:(nullable GSMetricsKeysUI *)state;
/// Plain effective metrics key for the left side bearing.
- (nullable NSString *)leftPlainMetricsKey;

#pragma mark Width
/// Display and editing string for the width metrics key.
@property (nonatomic, unsafe_unretained, nullable) NSString *widthMetricsKeyUI;
/// Fast display string for the width metrics key.
- (NSString *)widthMetricsKeyUIFast;
/// State flags for the width metrics key.
- (GSMetricsKeysUI)widthMetricsKeyState;
/// Display string for the width metrics key and its state.
///
/// - Parameter state: On return, the state flags for the displayed key.
- (NSString *)widthMetricsKeyState:(nullable GSMetricsKeysUI *)state;
/// Plain effective metrics key for the advance width.
- (nullable NSString *)widthPlainMetricsKey;

#pragma mark Right
/// Display and editing string for the right metrics key.
@property (nonatomic, unsafe_unretained, nullable) NSString *rightMetricsKeyUI;
/// State flags for the right metrics key.
- (GSMetricsKeysUI)rightMetricsKeyState;
/// Display string for the right metrics key and its state.
///
/// - Parameter state: On return, the state flags for the displayed key.
- (NSString *)rightMetricsKeyState:(nullable GSMetricsKeysUI *)state;
/// Plain effective metrics key for the right side bearing.
- (nullable NSString *)rightPlainMetricsKey;

#pragma mark Top
/// Display and editing string for the top metrics key.
@property (nonatomic, unsafe_unretained, nullable) NSString *topMetricsKeyUI;
/// State flags for the top metrics key.
- (GSMetricsKeysUI)topMetricsKeyState;
/// Display string for the top metrics key and its state.
///
/// - Parameter state: On return, the state flags for the displayed key.
- (NSString *)topMetricsKeyState:(nullable GSMetricsKeysUI *)state;
/// Plain effective metrics key for the top side bearing.
- (nullable NSString *)topPlainMetricsKey;

#pragma mark Bottom
/// Display and editing string for the bottom metrics key.
@property (nonatomic, unsafe_unretained, nullable) NSString *bottomMetricsKeyUI;
/// State flags for the bottom metrics key.
- (GSMetricsKeysUI)bottomMetricsKeyState;
/// Display string for the bottom metrics key and its state.
///
/// - Parameter state: On return, the state flags for the displayed key.
- (NSString *)bottomMetricsKeyState:(nullable GSMetricsKeysUI *)state;
/// Plain effective metrics key for the bottom side bearing.
- (nullable NSString *)bottomPlainMetricsKey;

#pragma mark Vert Width
/// Vertical advance width for display.
///
/// Returns the master height when no explicit vertical width is set.
- (CGFloat)vertWidthUI;
/// Display and editing string for the vertical width metrics key.
@property (nonatomic, unsafe_unretained, nullable) NSString *vertWidthMetricsKeyUI;
/// State flags for the vertical width metrics key.
- (GSMetricsKeysUI)vertWidthMetricsKeyState;
/// Display string for the vertical width metrics key and its state.
///
/// - Parameter state: On return, the state flags for the displayed key.
/// - Parameter defaultKey: The fallback display key when no explicit key exists.
- (NSString *)vertWidthMetricsKeyState:(nullable GSMetricsKeysUI *)state defaultKey:(nullable NSString *)defaultKey;
/// Plain effective metrics key for the vertical advance width.
- (nullable NSString *)vertWidthPlainMetricsKey;

#pragma mark Vert Origin
/// Display and editing string for the vertical origin metrics key.
@property (nonatomic, unsafe_unretained, nullable) NSString *vertOriginMetricsKeyUI;
/// State flags for the vertical origin metrics key.
- (GSMetricsKeysUI)vertOriginMetricsKeyState;
/// Display string for the vertical origin metrics key and its state.
///
/// - Parameter state: On return, the state flags for the displayed key.
- (NSString *)vertOriginMetricsKeyState:(nullable GSMetricsKeysUI *)state;
/// Plain effective metrics key for the vertical origin.
- (nullable NSString *)vertOriginPlainMetricsKey;

@end

NS_ASSUME_NONNULL_END
