//
//  ShoeStyleSelectView.m
//  Open
//
//  Created by 雷俊博 on 2019/12/6.
//  Copyright © 2019 黄江涛 . All rights reserved.
//

#import "ShoeStyleSelectView.h"

#import "LineTextFiled.h"

@interface ShoeStyleSelectView ()
{
    UIButton* lastBtn;
    
    UIButton*manBtn;
    UIButton*womanBtn;
}

@property (nonatomic, strong)UILabel* lb_title;

@property (nonatomic, strong)NSMutableArray *btnArray;



@end

@implementation ShoeStyleSelectView
#pragma mark - life cycle
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.btnArray = [[NSMutableArray alloc]init];
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    //添加title
    UILabel *lb_title = [[UILabel alloc]init];
    lb_title.text = @"款        式:";
    lb_title.textColor = [UIColor colorWithHex:0x666666];
    lb_title.font = [UIFont systemFontOfSize:17];
    [self addSubview:lb_title];
    
    [lb_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.offset(20);
        make.width.offset(80);
    }];
    
    CGFloat btnW = 17;

    //男款
    UIButton *btn_man = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn_man setImage:[UIImage imageNamed:@"prizedetail_btn_unselected"] forState:UIControlStateNormal];
    [btn_man addTarget:self action:@selector(SelectSexBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    manBtn = btn_man;
     [self addSubview:btn_man];
    [self.btnArray addObject:btn_man];
    [btn_man mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lb_title.mas_right).offset(4);
        make.width.height.offset(btnW);
        make.centerY.equalTo(lb_title);
    }];
    
   
    
   UILabel* lb_manTitle = [[UILabel alloc]init];
   lb_manTitle.text = @"男款";
   lb_manTitle.textColor = [UIColor colorWithHex:0x666666];
   lb_manTitle.font = [UIFont systemFontOfSize:17];
   [self addSubview:lb_manTitle];
    
    [lb_manTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(btn_man.mas_right);
        make.centerY.equalTo(btn_man);
    }];
    
    LineTextFiled *tf_manSize = [[LineTextFiled alloc]initWithFrame:CGRectZero];
    tf_manSize.borderStyle =  UITextBorderStyleNone;
    tf_manSize.keyboardType = UIKeyboardTypeNumberPad;
    
    self.tf_man = tf_manSize;
    
    [self addSubview:tf_manSize];
    
    [tf_manSize mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lb_manTitle.mas_right).offset(2);
        make.top.offset(0);
        make.height.offset(18);
        make.width.offset(30);
    }];
    
    UILabel* lb_manUnit = [[UILabel alloc]init];
    lb_manUnit.text = @"码";
    lb_manUnit.textColor = [UIColor colorWithHex:0x666666];
    lb_manUnit.font = [UIFont systemFontOfSize:17];
    [self addSubview:lb_manUnit];
    
    [lb_manUnit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tf_manSize.mas_right).offset(2);
        make.centerY.equalTo(tf_manSize);
    }];
    
    //女款
    UIButton *btn_woman = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn_woman addTarget:self action:@selector(SelectSexBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [btn_woman setImage:[UIImage imageNamed:@"prizedetail_btn_unselected"] forState:UIControlStateNormal];
    womanBtn = btn_woman;
    [self addSubview:btn_woman];
    [self.btnArray addObject:btn_woman];
    
     [btn_woman mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.equalTo(btn_man);
         make.width.height.offset(btnW);
         make.top.equalTo(btn_man.mas_bottom).offset(10);
     }];
     
    UILabel* lb_womanTitle = [[UILabel alloc]init];
    lb_womanTitle.text = @"女款";
    lb_womanTitle.textColor = [UIColor colorWithHex:0x666666];
    lb_womanTitle.font = [UIFont systemFontOfSize:17];
    [self addSubview:lb_womanTitle];
     
     [lb_womanTitle mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.equalTo(btn_woman.mas_right);
         make.centerY.equalTo(btn_woman);
     }];
     
     LineTextFiled *tf_womanSize = [[LineTextFiled alloc]init];
     tf_womanSize.borderStyle =  UITextBorderStyleNone;
     tf_womanSize.keyboardType = UIKeyboardTypeNumberPad;
     self.tf_woman = tf_womanSize;
    
    [self addSubview:tf_womanSize];
     
     [tf_womanSize mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.equalTo(lb_womanTitle.mas_right).offset(2);
         make.top.equalTo(lb_womanTitle);
         make.height.offset(18);
         make.width.offset(30);
     }];
     
     UILabel* lb_womanUnit = [[UILabel alloc]init];
     lb_womanUnit.text = @"码";
     lb_womanUnit.textColor = [UIColor colorWithHex:0x666666];
     lb_womanUnit.font = [UIFont systemFontOfSize:17];
     [self addSubview:lb_womanUnit];
     
     [lb_womanUnit mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.equalTo(tf_womanSize.mas_right).offset(2);
         make.centerY.equalTo(tf_womanSize);
     }];
    
    
    
    
    [self SelectSexBtnClick:manBtn];

    
    
}


#pragma mark - event response
- (void)SelectSexBtnClick:(UIButton *)sender
{
    if (lastBtn == sender && lastBtn) {
        return;
    }
    
    
    self.isWoman = sender == womanBtn ? YES : NO;
   
    
    if (lastBtn) {
        [lastBtn setImage:[UIImage imageNamed:@"prizedetail_btn_unselected"] forState:UIControlStateNormal];
    }
    
    [sender setImage:[UIImage imageNamed:@"prizedetail_btn_selected"] forState:UIControlStateNormal];
    
    lastBtn = sender;
}

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

@end
