//
//  LogoSelectView.m
//  双子星云手机
//
//  Created by APPLE on 2023/8/18.
//

#import "LogoSelectView.h"
#import <Masonry.h>
#import "iPhone.h"

@interface LogoSelectView()
{
    UIButton *claBtn;
    UIButton *bowserBtn;
}
@end

@implementation LogoSelectView
@synthesize selectIndex;
@synthesize delegate;

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    [self drawAnyView];
    
    return self;
}

- (void)drawAnyView{
    [self setBackgroundColor:[UIColor clearColor]];
    /*标签*/
    UILabel *upLabel = [[UILabel alloc] init];
    [upLabel setTextColor:HW0A132BColor];
    [upLabel setFont:[UIFont boldSystemFontOfSize:16.f]];
    [upLabel setText:NSLocalizedString(@"logo_select_login",nil)];
    [self addSubview:upLabel];
    [upLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(22);
    }];
    
    /*提示*/
    UILabel *upTipLabel = [[UILabel alloc] init];
    [upTipLabel setTextColor:COLOR_PACEHOLDER];
    [upTipLabel setFont:[UIFont boldSystemFontOfSize:14.f]];
    NSString *curStr = NSLocalizedString(@"logo_change_login_tip",nil);
    [upTipLabel setText:curStr];
    upTipLabel.numberOfLines = 0;
    [self addSubview:upTipLabel];
    
    CGFloat curHeight = [curStr boundingRectWithSize:CGSizeMake(SCREEN_W -16 -16, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:14.f]} context:nil].size.height;
    
    if(curHeight >= 20){
        curHeight += 10;
    }
    
    [upTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(upLabel.mas_bottom).offset(10.0);
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        //make.height.mas_equalTo(22);
        make.height.mas_equalTo(curHeight);
    }];
    
    /*掩盖视图类型*/
    NSInteger maskModel = [HWDataManager getIntegerWithKey:Const_Mask_View_Model];
    
    /*按钮选择*/
    UIView *bgView = [[UIView alloc] init];
    [bgView setBackgroundColor:[UIColor whiteColor]];
    [bgView.layer setCornerRadius:8.f];
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(upTipLabel.mas_bottom).offset(12.f);
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(180);
    }];
    
    claBtn = [[UIButton alloc] init];
    [claBtn setBackgroundColor:HWF7F7F7Color];
    claBtn.clipsToBounds = YES;
    claBtn.layer.cornerRadius = 16.f;
    [claBtn addTarget:self
               action:@selector(claBtnPressed)
     forControlEvents:(UIControlEventTouchUpInside)];
    [bgView addSubview:claBtn];
    [claBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(34.f);
        make.left.mas_equalTo(52*AUTOSCALE);
        make.width.mas_equalTo(112);
        make.height.mas_equalTo(112);
    }];
    
    [claBtn.layer setBorderWidth:2];
    if (maskModel == 1){
        selectIndex = 1;
        [claBtn.layer setBorderColor:HW13B2EBColor.CGColor];
    }else{
        [claBtn.layer setBorderColor:[UIColor clearColor].CGColor];
    }
    [claBtn setTitle:NSLocalizedString(@"logo_calculator",nil) forState:(UIControlStateNormal)];
    [claBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
    [claBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [claBtn setImage:[UIImage imageNamed:@"calculator_icon"] forState:(UIControlStateNormal)];
    [claBtn setTitleEdgeInsets:UIEdgeInsetsMake(claBtn.imageView.frame.size.height+10,-claBtn.imageView.frame.size.width, 0.0,0.0)];
    [claBtn setImageEdgeInsets:UIEdgeInsetsMake(-claBtn.bounds.size.width/4+15, claBtn.bounds.size.width/4-10, claBtn.titleLabel.bounds.size.height, -claBtn.bounds.size.width/4)];
    
    bowserBtn = [[UIButton alloc] init];
    [bowserBtn setBackgroundColor:HWF7F7F7Color];
    bowserBtn.clipsToBounds = YES;
    bowserBtn.layer.cornerRadius = 16.f;
    [bowserBtn addTarget:self
                  action:@selector(bowserBtnPressed)
        forControlEvents:(UIControlEventTouchUpInside)];
    [bgView addSubview:bowserBtn];
    [bowserBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(34.f);
        make.right.mas_equalTo(-52*AUTOSCALE);
        make.width.mas_equalTo(112);
        make.height.mas_equalTo(112);
    }];
    
    [bowserBtn.layer setBorderWidth:2];
    if (maskModel == 2){
        selectIndex = 2;
        [bowserBtn.layer setBorderColor:HW13B2EBColor.CGColor];
    }else{
        [bowserBtn.layer setBorderColor:[UIColor clearColor].CGColor];
    }
    [bowserBtn setTitle:NSLocalizedString(@"logo_bowser",nil) forState:(UIControlStateNormal)];
    [bowserBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
    [bowserBtn.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [bowserBtn setImage:[UIImage imageNamed:@"web_icon"] forState:(UIControlStateNormal)];
    [bowserBtn setTitleEdgeInsets:UIEdgeInsetsMake(bowserBtn.imageView.frame.size.height+10,-bowserBtn.imageView.frame.size.width, 0.0,0.0)];
    [bowserBtn setImageEdgeInsets:UIEdgeInsetsMake(-bowserBtn.bounds.size.width/4+15, bowserBtn.bounds.size.width/4-10, bowserBtn.titleLabel.bounds.size.height, -bowserBtn.bounds.size.width/4)];
}

- (void)claBtnPressed{
    [claBtn.layer setBorderColor:HW13B2EBColor.CGColor];
    [bowserBtn.layer setBorderColor:[UIColor clearColor].CGColor];
    selectIndex = 1;
    if ([delegate respondsToSelector:@selector(logoSelectViewHaveSelect)]){
        [delegate logoSelectViewHaveSelect];
    }
}

- (void)bowserBtnPressed{
    [bowserBtn.layer setBorderColor:HW13B2EBColor.CGColor];
    [claBtn.layer setBorderColor:[UIColor clearColor].CGColor];
    selectIndex = 2;
    if ([delegate respondsToSelector:@selector(logoSelectViewHaveSelect)]){
        [delegate logoSelectViewHaveSelect];
    }
}

@end
