//
//  RDSBarButtonItem.m
//  RuiYuRealEstate
//
//  Created by coderYK on 2018/9/6.
//  Copyright © 2018年 coderYK. All rights reserved.
//

#import "RDSBarButtonItem.h"
#import "UIImage+Extension.h"

@implementation RDSBarButtonItem

+ (instancetype)p_fixSpace:(CGFloat)width {
    
    RDSBarButtonItem *sapce = [[RDSBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                                                             target:nil action:nil];
    sapce.width = width;
    return sapce;
}

+ (instancetype)fixSpaceReduce5 {
    return [self p_fixSpace:-5];
}

+ (instancetype)fixSpaceReduce10 {
    return [self p_fixSpace:-10];
}

+ (instancetype)fixSpace15 {
    return [self p_fixSpace:15];
}

+ (instancetype)menuBarButtonItemWithTarget:(id)target action:(SEL)action {
    
    return [self barButtonItemWithImage:@"menu" target:target action:action];
}

+ (instancetype)messageBarButtonItemWithTarget:(id)target action:(SEL)action {
    
    return [self barButtonItemWithImage:@"message" target:target action:action];
}

+ (instancetype)moreBarButtonItemWithTarget:(id)target action:(SEL)action {
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.tintColor = kTextColor;
    UIImage *more = [[UIImage imageNamed:@"more"] imageWithRenderingMode:(UIImageRenderingModeAlwaysTemplate)];
    [button setBackgroundImage:more forState:UIControlStateNormal];
    [button setBackgroundImage:more forState:UIControlStateHighlighted];
    //[button sizeToFit];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    RDSBarButtonItem *item = [[RDSBarButtonItem alloc] initWithCustomView:button];
    return item;
}

+ (instancetype)addBarButtonItemWithTarget:(id)target action:(SEL)action {
    
    return [self barButtonItemWithImage:@"nav_add_ic" target:target action:action];
}

+ (instancetype)barButtonItemWithImage:(NSString *)imageName target:(id)target action:(SEL)action {
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateHighlighted];
    //[button sizeToFit];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    RDSBarButtonItem *item = [[RDSBarButtonItem alloc] initWithCustomView:button];
    return item;
}

+ (instancetype)saveBarButtonItemWithTarget:(id)target action:(SEL)action {
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [saveBtn setTitleColor:RDSThemeColor forState:UIControlStateNormal];
    saveBtn.titleLabel.font = [UIFont boldSystemFontOfSize:18];
    //[saveBtn sizeToFit];
    [saveBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    RDSBarButtonItem *item = [[RDSBarButtonItem alloc] initWithCustomView:saveBtn];
    return item;
}

+ (instancetype)barButtonItemWithTitle:(NSString *)title target:(id)target action:(SEL)action {
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [saveBtn setTitle:title forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    
    saveBtn.frame = CGRectMake(0, 0, 50, 32);
    saveBtn.layer.cornerRadius = 5;
    saveBtn.layer.masksToBounds = YES;
    saveBtn.backgroundColor = RDSGreenColor;
    //[saveBtn setBackgroundImage:[UIImage rds_imageWithColor:RDSPinkColor toColor:RDSBlueColor imgSize:saveBtn.rds_size] forState:UIControlStateNormal];
    //[saveBtn sizeToFit];
    [saveBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    RDSBarButtonItem *item = [[RDSBarButtonItem alloc] initWithCustomView:saveBtn];
    return item;
}

+ (instancetype)barButtonItemWithTitle:(NSString *)title bgColor:(UIColor *)bgColor target:(id)target action:(SEL)action {
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [saveBtn setTitle:title forState:UIControlStateNormal];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    saveBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    
    saveBtn.frame = CGRectMake(0, 0, 50, 32);
    saveBtn.layer.cornerRadius = 5;
    saveBtn.layer.masksToBounds = YES;
    saveBtn.backgroundColor = bgColor;
    //[saveBtn setBackgroundImage:[UIImage rds_imageWithColor:RDSPinkColor toColor:RDSBlueColor imgSize:saveBtn.rds_size] forState:UIControlStateNormal];
    //[saveBtn sizeToFit];
    [saveBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    RDSBarButtonItem *item = [[RDSBarButtonItem alloc] initWithCustomView:saveBtn];
    return item;
}

+ (instancetype)barButtonItemWithTitle:(NSString *)title color:(UIColor *)color target:(id)target action:(SEL)action{
    
    UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [saveBtn setTitle:title forState:UIControlStateNormal];
    [saveBtn setTitleColor:color forState:UIControlStateNormal];
    saveBtn.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    //[saveBtn sizeToFit];
    [saveBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    RDSBarButtonItem *item = [[RDSBarButtonItem alloc] initWithCustomView:saveBtn];
    return item;
}

@end
