//
//  UIButton+DDCategory.h
//  DDCategoryKit_Private
//  Created by DDIsFriend on 2022/7/29.

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSUInteger, DDCustomButtonState) {
    DDCustomButtonStateNormal,
    DDCustomButtonStateSelected,
    DDCustomButtonStateHighlight,
};

typedef NS_ENUM(NSInteger, DDCustomButtonStyle) {
    /**
     * image is left of the button,title is right, image and title is whole center.
     */
    ImageLeftPaddingTitleRightWithWholeCenter = 0,
    /**
     * image is right of the button, title is left , image and title is whole center.
     */
    ImageRightPaddingTitleLeftWithWholeCenter,
    /**
     * image is top of the button,title is bottom, image and title is whole center.
     */
    ImageTopPaddingTitleBottomWithWholeCenter,
    /**
     *image is bottom of the button,title is top, image and title is whole center.
     */
    ImageBottomPaddingTitleTopWithWholeCenter,
};

@interface UIButton (DDCategory)
/**
 * return a instance of custom button
 */
+ (instancetype)dd_initCustomButton;

- (instancetype)dd_addTarget:(nullable id)target action:(nonnull SEL)action forControlEvents:(UIControlEvents)controlEvents;

@end

typedef NSString * DDCustomButtonAttributedStringKey NS_TYPED_EXTENSIBLE_ENUM;

FOUNDATION_EXPORT const DDCustomButtonAttributedStringKey DDCustomButtonAttributedStringState;
FOUNDATION_EXPORT const DDCustomButtonAttributedStringKey DDCustomButtonAttributedStringAttributedText;
FOUNDATION_EXPORT const DDCustomButtonAttributedStringKey DDCustomButtonAttributedStringImage;

@interface UIButton (AttributedString)
+ (instancetype)dd_initWithAttributedTitles:(NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)attributedTitles;

+ (instancetype)dd_initWithImages:(nullable NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)images;

+ (instancetype)dd_initWithBackgroundColor:(UIColor *)backgroundColor;
/**
 * return a instance of custom button
 * @param attributedTitles button attributedTitle example: @[@{DDCustomButtonAttributedStringStateName : @(DDCustomButtonStateNormal.rawValue),DDCustomButtonAttributedStringTextName : attributedString}]
 * @param images button images
 * @param backgroundColor button backgroundColor
 */
+ (instancetype)dd_initWithAttributedTitles:(nullable NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)attributedTitles images:(nullable NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)images backgroundColor:(nullable UIColor *)backgroundColor;

/**
 * return a instance of custom button
 * @param buttonType button type
 * @param attributedTitles button attributedTitle example: @[@{DDCustomButtonAttributedStringStateName : @(DDCustomButtonStateNormal.rawValue),DDCustomButtonAttributedStringTextName : attributedString}]
 * @param images button images
 * @param backgroundColor button backgroundColor
 */
+ (instancetype)dd_initWithType:(UIButtonType)buttonType attributedTitles:(nullable NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)attributedTitles images:(nullable NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)images backgroundColor:(nullable UIColor *)backgroundColor;

/**
 * return a instance of custom button
 * @param attributedTitles button attributedTitle example: @[@{DDCustomButtonAttributedStringStateName : @(DDCustomButtonStateNormal.rawValue),DDCustomButtonAttributedStringTextName : attributedString}]
 * @param images button images
 * @param backgroundColor button backgroundColor
 */
- (instancetype)dd_setAttributedTitles:(nullable NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)attributedTitles images:(nullable NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)images backgroundColor:(nullable UIColor *)backgroundColor;

- (instancetype)dd_setAttributedTitles:(nullable NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)attributedTitles;
- (instancetype)dd_setImages:(nullable NSArray<NSDictionary<DDCustomButtonAttributedStringKey,id> *> *)images;
- (instancetype)dd_setBackgroundColor:(nullable UIColor *)backgroundColor;

@end

@interface UIButton (Placement)
/**
 * layout image and title position.
 * @param style ButtonImageTitleStyle
 * @param padding image and title padding
 * @warning use this function after button already has frame,  image and title is not nil,such as user use masonry to constraint button, you should transfer layoutIfNeeded before to sure button has already bounds, example:sizeToFit().
 */
- (instancetype)dd_customizeWithStyle:(DDCustomButtonStyle)style padding:(CGFloat)padding;
@end
NS_ASSUME_NONNULL_END
