//
//  UIColor+YSColor.m
//  C_TTHcNetAPI
//
//  Created by yuxiangxiang on 2020/3/30.
//

#import "UIColor+YSColor.h"
#import "UIColor+Gradient.h"
  
#define YS_UIColorFromRGB(rgbValue, alp)    [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 \
green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 \
blue:((float)(rgbValue & 0xFF)) / 255.0 \
alpha:alp]
#define YSRGB(rgb) YS_UIColorFromRGB(rgb,1)
#define YSRGBA(rgb,a) YS_UIColorFromRGB(rgb,a)

@implementation UIColor (YSColor)


+ (UIColor *)customColorWithType:(YSColorNewType)colorType
{
    if (@available(iOS 13.0, *))
    {
        return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            
            switch (UITraitCollection.currentTraitCollection.userInterfaceStyle)
            {
                case UIUserInterfaceStyleUnspecified:
                case UIUserInterfaceStyleLight:
                    return [self getLightColorValue:colorType];
                case UIUserInterfaceStyleDark:
                    return [self getDarkColorValue:colorType];
                default:
                    return [self getLightColorValue:colorType];
            }
            
        }];
    }
    else
    {
        return [self getLightColorValue:colorType];
    }
}




+ (UIColor *)customColorWithlightColor:(UIColor *)lightColor andDarkColor:(UIColor *)darkColor
{
    if (@available(iOS 13.0, *))
    {
        return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            
            switch (UITraitCollection.currentTraitCollection.userInterfaceStyle)
            {
                case UIUserInterfaceStyleUnspecified:
                case UIUserInterfaceStyleLight:
                    return lightColor;
                case UIUserInterfaceStyleDark:
                    return darkColor;
                default:
                    return lightColor;
            }
            
        }];
    }
    else
    {
        return lightColor;
    }
}










//系统默认黑色
+ (UIColor *)YSSystemBlackColor
{
    if (@available(iOS 13.0, *))
    {
        return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            
            switch (UITraitCollection.currentTraitCollection.userInterfaceStyle)
            {
                case UIUserInterfaceStyleUnspecified:
                case UIUserInterfaceStyleLight:
                    return [UIColor blackColor];
                case UIUserInterfaceStyleDark:
                    return [UIColor whiteColor];
                default:
                    return [UIColor blackColor];
            }
            
        }];
    }
    else
    {
        return [UIColor blackColor];
    }
}

//系统默认白色
+ (UIColor *)YSSystemWhiteColor
{
    if (@available(iOS 13.0, *))
    {
        return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            
            switch (UITraitCollection.currentTraitCollection.userInterfaceStyle)
            {
                case UIUserInterfaceStyleUnspecified:
                case UIUserInterfaceStyleLight:
                    return [UIColor whiteColor];
                case UIUserInterfaceStyleDark:
                    return [UIColor blackColor];
                default:
                    return [UIColor whiteColor];
            }
            
        }];
    }
    else
    {
        return [UIColor whiteColor];
    }
}

//系统默认白色背景色
+ (UIColor *)YSSystemBackgroundWhiteColor
{
    if (@available(iOS 13.0, *))
    {
        return UIColor.systemBackgroundColor;
    }
    else
    {
        return [UIColor whiteColor];
    }
}

+ (UIColor *)YSBrandColor{
    return [self customColorWithType:YSColorTypeBrand];
}

+ (UIColor *)YSBrandColorSecondary{
    return [self customColorWithType:YSColorTypeBrandSecondary];
}


+ (UIColor *)YSLinkColor{
    return [self customColorWithType:YSColorTypeLink];
}

+ (UIColor *)YSIncorrectColor{
    return [self customColorWithType:YSColorTypeIncorrect];
}

+ (UIColor *)YSCorrectColor{
    return [self customColorWithType:YSColorTypeCorrect];
}


+ (UIColor *)YSLabelColorPrimary{
    return [self customColorWithType:YSColorTypeLabelPrimary];
}

+ (UIColor *)YSLabelColorSecondary{
    return [self customColorWithType:YSColorTypeLabelSecondary];
}


+ (UIColor *)YSLabelColorTertiary{
    return [self customColorWithType:YSColorTypeLabelTertiary];
}


+ (UIColor *)YSLabelColorQuarternary{
    return [self customColorWithType:YSColorTypeLabelQuarternary];
}

+ (UIColor *)YSLabelColorInverse{
    return [self customColorWithType:YSColorTypeLabelInverse];
}


+ (UIColor *)YSLabelColorDisable{
    return [self customColorWithType:YSColorTypeLabelDisable];
}


+ (UIColor *)YSInputColor{
    return [self customColorWithType:YSColorTypeInput];
}


+ (UIColor *)YSSeparatorColor{
    return [self customColorWithType:YSColorTypeSeparator];
}


+ (UIColor *)YSPopupColor{
    return [self customColorWithType:YSColorTypePopup];
}


+ (UIColor *)YSSystemBackgroundPrimaryColor{
    return [self customColorWithType:YSColorTypeBackgroundPrimary];
}


+ (UIColor *)YSSystemBackgroundSecondaryColor{
    return [self customColorWithType:YSColorTypeBackgroundSecondary];
}

+(UIColor *)YSSystemBackgroundTertiaryColor{
    return [self customColorWithType:YSColorTypeBackgroundTertiary];
}

+(UIColor *)YSSystemBackgroundQuarternary{
    return [self customColorWithType:YSColorTypeBackgroundQuarternary];
}


+(UIColor *)YSFillColorSecondary{
    return [self customColorWithType:YSColorTypeFill];
}


+(UIColor *)YSPopupMaskingOutColor{
    return [self customColorWithType:YSColorTypePopupMaskOut];
}


+(UIColor *)YSGuideMaskingOutColor{
    return [self customColorWithType:YSColorTypeGuideMaskOut];
}


+(UIColor *)YSToastColor{
    return [self customColorWithType:YSColorTypeToastMask];
}


+ (UIColor *)YSButtonColorWithSize:(CGSize)size{
    return [UIColor colorGradientChangeWithSize:size direction:GradientChangeDirectionVertical startColor:YSRGBA(0xFFBE59,1.0) endColor:YSRGBA(0xFF8F42,1.0)];
}

+ (UIColor *)YSButtonDisableColor{
    return [self customColorWithType:YSColorTypeButtonDisable];
}

+ (UIColor *)YSButtonColorUnselectColor{
    return [self customColorWithType:YSColorTypeButtonUnselect];
}


+ (UIColor *)getLightColorValue:(YSColorNewType)colorType
{
    switch (colorType) //todo read from configfile
    {
        case YSColorTypeBrand:
            return YSRGB(0x3E80FF);
        case YSColorTypeBrandSecondary:
            return YSRGB(0xFFAE63);
        case YSColorTypeLink:
            return YSRGB(0x128EE9);
        case YSColorTypeIncorrect:
            return YSRGB(0xFB4848);
        case YSColorTypeCorrect:
            return YSRGB(0x52C41B);
            
            
        case YSColorTypeLabelPrimary:
            return YSRGB(0x333333);
        case YSColorTypeLabelSecondary:
            return YSRGB(0x666666);
        case YSColorTypeLabelTertiary:
            return YSRGB(0x999999);
        case YSColorTypeLabelQuarternary:
            return YSRGB(0xCCCCCC);
        case YSColorTypeLabelInverse:
            return YSRGB(0xFFFFFF);
        case YSColorTypeLabelDisable:
            return YSRGB(0xFFFFFF);
            
            
        case YSColorTypeInput:
            return YSRGB(0xEAEAEA);
        case YSColorTypeSeparator:
            return YSRGB(0xEDEDED);
        case YSColorTypePopup:
            return YSRGB(0xF1F1F1);
        case YSColorTypeBackgroundPrimary:
            return YSRGB(0xF8F8F8);
        case YSColorTypeBackgroundSecondary:
            return YSRGB(0xFFFFFF);
            
        case YSColorTypeBackgroundTertiary:
            return YSRGB(0xFFFFFF);
        case YSColorTypeBackgroundQuarternary:
            return YSRGB(0xFFFFFF);
        case YSColorTypeFill:
            return YSRGB(0xF8F8F8);
            
            
        case YSColorTypePopupMaskOut:
            return YSRGBA(000000, 0.7);
        case YSColorTypeGuideMaskOut:
            return YSRGBA(000000, 0.8);
        case YSColorTypeToastMask:
            return YSRGBA(000000, 0.8);
        case YSColorTypeButtonPrimary:
            return YSRGB(0xFFAE63);
        case YSColorTypeButtonSecondary:
            return YSRGB(0xFFAE63);
            
            
        case YSColorTypeButtonDisable:
            return YSRGB(0xCCCCCC);
        case YSColorTypeButtonUnselect:
            return YSRGB(0xCCCCCC);

        default:
            return YSRGB(0xFFAE63);
    }
}


+ (UIColor *)getDarkColorValue:(YSColorNewType)colorType
{
    switch (colorType) //todo read from configfile
    {
        case YSColorTypeBrand:
            return YSRGB(0x3E80FF);
        case YSColorTypeBrandSecondary:
            return YSRGB(0xFFAE63);
        case YSColorTypeLink:
            return YSRGB(0x6090FF);
        case YSColorTypeIncorrect:
            return YSRGB(0xFF5656);
        case YSColorTypeCorrect:
            return YSRGB(0x75C151);
            
            
        case YSColorTypeLabelPrimary:
            return YSRGB(0xD3D3D3);
        case YSColorTypeLabelSecondary:
            return YSRGB(0xA6A6A6);
        case YSColorTypeLabelTertiary:
            return YSRGBA(0xFFFFFF, 0.45);
        case YSColorTypeLabelQuarternary:
            return YSRGB(0x595959);
        case YSColorTypeLabelInverse:
            return YSRGB(0xFFFFFF);
        case YSColorTypeLabelDisable:
            return YSRGBA(0xFFFFFF, 0.25);
            
        case YSColorTypeInput:
            return YSRGB(0x4B4B4B);
        case YSColorTypeSeparator:
            return YSRGB(0x38383A);
        case YSColorTypePopup:
            return YSRGB(0x38383A);
        case YSColorTypeBackgroundPrimary:
            return YSRGB(0x121212);
        case YSColorTypeBackgroundSecondary:
            return YSRGB(0x1C1C1E);
            
        case YSColorTypeBackgroundTertiary:
            return YSRGB(0x2C2C2E);
        case YSColorTypeBackgroundQuarternary:
            return YSRGB(0x3A3A3C);
        case YSColorTypeFill:
            return YSRGB(0x2C2C2E);
            
            
        case YSColorTypePopupMaskOut:
            return YSRGBA(000000, 0.7);
        case YSColorTypeGuideMaskOut:
            return YSRGBA(000000, 0.8);
        case YSColorTypeToastMask:
            return YSRGBA(000000, 0.8);
            
            
        case YSColorTypeButtonPrimary:
            return YSRGB(0xFF954D);
        case YSColorTypeButtonSecondary:
            return YSRGB(0xFF954D);
        case YSColorTypeButtonDisable:
            return YSRGB(0x38383A);
        case YSColorTypeButtonUnselect:
            return YSRGB(0x38383A);

        default:
            return YSRGB(0xFFAE63);
    }
}




@end
