//
//  HomeHelperHeaderView.m
//  Open
//
//  Created by 雷俊博 on 2021/7/23.
//  Copyright © 2021 黄江涛 . All rights reserved.
//

#import "HomeHelperHeaderView.h"

@implementation HomeHelperHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self setupUI];
    }
    return self;
}

- (void)setupUI
{
    
    UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), 45 * WIDTHRADIU)];
    blueView.backgroundColor = K_MainColor;
    [self addSubview:blueView];
    UIBezierPath *maskPath;
    maskPath = [UIBezierPath bezierPathWithRoundedRect:blueView.bounds

                                        byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)

                                              cornerRadii:CGSizeMake(8.0, 8.0)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = blueView.bounds;
    maskLayer.path = maskPath.CGPath;
    blueView.layer.mask = maskLayer;
    
    
    //阴历
    UILabel *lb_date = [UILabel new];
    lb_date.text = @"今日签到";
    lb_date.textColor = [UIColor whiteColor];
    lb_date.font = [UIFont boldSystemFontOfSize:14 * WIDTHRADIU];
    [blueView addSubview:lb_date];
    [lb_date mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15 * WIDTHRADIU);
        make.centerY.equalTo(blueView);
    }];
    
    self.lb_lunDate = lb_date;
    
    //温度
    UILabel *lb_weather = [UILabel new];
    lb_weather.text = @"连续签到拿更多金币奖励";
    lb_weather.textColor = [UIColor whiteColor];
    lb_weather.font = [UIFont systemFontOfSize:13 * WIDTHRADIU];
    [blueView addSubview:lb_weather];
    [lb_weather mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lb_date.mas_right).offset(20 * WIDTHRADIU);
        make.centerY.equalTo(blueView);
    }];
    
    self.lb_dateAndWeather = lb_weather;
    
    
    //日期按钮
    UIButton *dateBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    dateBtn.tag = 200;
    [dateBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [blueView addSubview:dateBtn];
    [dateBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.offset(0);
        make.right.equalTo(lb_weather);
    }];
    
    
    //按钮
    UIButton *targetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    targetBtn.frame = CGRectMake(CGRectGetWidth(self.bounds) - 95 * WIDTHRADIU, 8.5 * WIDTHRADIU, 80 * WIDTHRADIU, 28 * WIDTHRADIU);
    [targetBtn setTitle:@"领取金币" forState:UIControlStateNormal];
    [targetBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    targetBtn.titleLabel.font = [UIFont systemFontOfSize:12 * WIDTHRADIU];
    targetBtn.layer.cornerRadius = 14 * WIDTHRADIU;
    targetBtn.layer.borderWidth = 0.5;
    targetBtn.layer.borderColor = [UIColor whiteColor].CGColor;
    targetBtn.tag = 201;
    [targetBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [blueView addSubview:targetBtn];
    
    self.signBtn = targetBtn;
    
    
    
   
}

#pragma mark - event response
- (void)btnClick:(UIButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(HomeHelperHeaderViewBtnClickWithIndex:)]) {
        [self.delegate HomeHelperHeaderViewBtnClickWithIndex:sender.tag];
    }
}

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

@end
