#import "FGTheme.h"

@implementation FGTheme

+ (UIColor *)accent {
    return [UIColor colorWithRed:0.180 green:0.396 blue:0.965 alpha:1.0]; // #2E65F6
}

+ (UIColor *)success { return [UIColor systemGreenColor]; }
+ (UIColor *)warning { return [UIColor systemOrangeColor]; }
+ (UIColor *)danger  { return [UIColor systemRedColor]; }

+ (UIColor *)screenBackground { return [UIColor systemGroupedBackgroundColor]; }
+ (UIColor *)cardBackground   { return [UIColor secondarySystemGroupedBackgroundColor]; }
+ (UIColor *)primaryText      { return [UIColor labelColor]; }
+ (UIColor *)secondaryText    { return [UIColor secondaryLabelColor]; }
+ (UIColor *)separator        { return [UIColor separatorColor]; }

+ (UIFont *)titleFont        { return [UIFont systemFontOfSize:21 weight:UIFontWeightBold]; }
+ (UIFont *)sectionTitleFont { return [UIFont systemFontOfSize:13 weight:UIFontWeightSemibold]; }
+ (UIFont *)bodyFont         { return [UIFont systemFontOfSize:15 weight:UIFontWeightRegular]; }
+ (UIFont *)bodyBoldFont     { return [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold]; }
+ (UIFont *)captionFont      { return [UIFont systemFontOfSize:12 weight:UIFontWeightRegular]; }
+ (UIFont *)monoFontOfSize:(CGFloat)size { return [UIFont monospacedDigitSystemFontOfSize:size weight:UIFontWeightMedium]; }

+ (UIButton *)filledButtonWithTitle:(NSString *)title target:(id)target action:(SEL)action {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];
    button.backgroundColor = [self accent];
    button.layer.cornerRadius = 13.0;
    button.layer.cornerCurve = kCACornerCurveContinuous;
    button.contentEdgeInsets = UIEdgeInsetsMake(0, 16, 0, 16);
    if (target && action) [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return button;
}

+ (UIButton *)tintedButtonWithTitle:(NSString *)title target:(id)target action:(SEL)action {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[self accent] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold];
    button.backgroundColor = [[self accent] colorWithAlphaComponent:0.12];
    button.layer.cornerRadius = 13.0;
    button.layer.cornerCurve = kCACornerCurveContinuous;
    button.contentEdgeInsets = UIEdgeInsetsMake(0, 14, 0, 14);
    if (target && action) [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return button;
}

+ (UIButton *)iconButtonNamed:(NSString *)symbolName size:(CGFloat)size target:(id)target action:(SEL)action {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    UIImage *image = [self symbolNamed:symbolName size:size * 0.42 weight:UIFontWeightSemibold];
    [button setImage:image forState:UIControlStateNormal];
    button.tintColor = [self accent];
    button.backgroundColor = [self cardBackground];
    button.layer.cornerRadius = size / 2.0;
    button.layer.cornerCurve = kCACornerCurveContinuous;
    button.layer.shadowColor = UIColor.blackColor.CGColor;
    button.layer.shadowOpacity = 0.12;
    button.layer.shadowRadius = 10;
    button.layer.shadowOffset = CGSizeMake(0, 4);
    if (target && action) [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return button;
}

+ (UILabel *)labelWithText:(NSString *)text font:(UIFont *)font color:(UIColor *)color {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.text = text;
    label.font = font;
    label.textColor = color;
    label.numberOfLines = 0;
    return label;
}

+ (void)applyCardStyle:(UIView *)view {
    view.backgroundColor = [self cardBackground];
    view.layer.cornerRadius = 18.0;
    view.layer.cornerCurve = kCACornerCurveContinuous;
    view.layer.shadowColor = UIColor.blackColor.CGColor;
    view.layer.shadowOpacity = 0.10;
    view.layer.shadowRadius = 16.0;
    view.layer.shadowOffset = CGSizeMake(0, 6);
}

+ (UIImage *)symbolNamed:(NSString *)name size:(CGFloat)pointSize weight:(UIFontWeight)weight {
    UIImageSymbolConfiguration *configuration =
        [UIImageSymbolConfiguration configurationWithPointSize:pointSize weight:weight];
    UIImage *image = [UIImage systemImageNamed:name withConfiguration:configuration];
    return image ?: [UIImage systemImageNamed:@"mappin" withConfiguration:configuration];
}

@end
