//
//  NSColorHelpers.h
//  GlyphsKit
//
//  Created by Georg Seifert
//  Copyright 2024 Georg Seifert. All rights reserved.
//

typedef NS_ENUM(NSInteger, GSControlAccentColor) {
	GSControlAccentColorMulticolor = -1,
	GSControlAccentColorBlue = 0,
	GSControlAccentColorPurple = 1,
	GSControlAccentColorPink = 2,
	GSControlAccentColorRed = 3,
	GSControlAccentColorOrange = 4,
	GSControlAccentColorYellow = 5,
	GSControlAccentColorGreen = 6,
	GSControlAccentColorGraphite = 7,
};

typedef NSString *GSSyntaxColorRole NS_TYPED_EXTENSIBLE_ENUM;
extern GSSyntaxColorRole const GSSyntaxColorRoleComment;
extern GSSyntaxColorRole const GSSyntaxColorRoleKeyword;
extern GSSyntaxColorRole const GSSyntaxColorRoleModifierKeyword;
extern GSSyntaxColorRole const GSSyntaxColorRoleLookupFlag;
extern GSSyntaxColorRole const GSSyntaxColorRoleTag;
extern GSSyntaxColorRole const GSSyntaxColorRoleLookupName;
extern GSSyntaxColorRole const GSSyntaxColorRoleGlyphName;
extern GSSyntaxColorRole const GSSyntaxColorRoleClassName;
extern GSSyntaxColorRole const GSSyntaxColorRoleNumber;
extern GSSyntaxColorRole const GSSyntaxColorRoleString;
extern GSSyntaxColorRole const GSSyntaxColorRoleDirective;
extern GSSyntaxColorRole const GSSyntaxColorRoleVariable;
extern GSSyntaxColorRole const GSSyntaxColorRoleFilePath;
extern GSSyntaxColorRole const GSSyntaxColorRoleWhitespace;

@interface NSColor (Helper)

- (NSColor *)contrastingLabelColor;

- (BOOL)isDark;

+ (NSColor *)colorWithString:(NSString *)string;

- (BOOL)isRGBColor;

- (NSColor *)sRGBColor;

- (NSColor *)safeRGBColor;

- (void)getSafeRed:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha;

- (void)getSafeHue:(CGFloat *)hue saturation:(CGFloat *)saturation brightness:(CGFloat *)brightness alpha:(CGFloat *)alpha;

- (NSColor *)colorByAddingHue:(CGFloat)addHue addSaturation:(CGFloat)addSaturation addBrightness:(CGFloat)addBrightness;

- (NSColor *)componentBasedColor;

+ (NSColor *)colorWithHexString:(NSString *)hexString;

- (NSString *)hexString;

- (NSString *)rgbString;

- (NSString *)hsbString;

@property (class, nonatomic, readonly) NSColor *dividerColor;
@property (class, nonatomic, readonly) NSColor *darkContentBackgroundColor;
@property (class, nonatomic, readonly) NSColor *menuHighlightColor;
/// A color value that represents an error instead of a real color value.
///
/// The color components are RGBA = (x, y, x, x) where x is the smallest float larger than 0xFE and y is the smallest float larger than 0x01.
/// That is an almost fully opaque bright pink color that that will round to an 8-bit value of 0xFE01FEFE.
///
/// The components are chosen to not collide with normal usage colors:
/// - Bright pink is rarely used.
/// - All components are off-by-one from pure pink (0xFF00FFFF).
/// - When not rounded to 8-bit, the components are irreducibly offset from integer values for further differentiation.
///
/// The color uses the sRGB color space.
@property (class, nonatomic, readonly) NSColor *errorReplacementColor;

/// Returns whether the given color is a value representing an error (``errorReplacementColor``).
///
/// - Parameter isLenient: When `YES`, also accepts color values that match when rounded to an 8-bit representation.
+ (BOOL)isErrorReplacementColor:(NSColor *)color lenient:(BOOL)isLenient;

#pragma mark code colors

+ (GSControlAccentColor)syntaxAccentColorFromSystemAccentColor;

+ (NSDictionary<GSSyntaxColorRole, NSColor *> *)syntaxColorsForDarkMode:(BOOL)isDarkMode;

@end
