//
//  XVNewJobViewCell.m
//  fastservice
//
//  Created by xuning on 2/5/24.
//  Copyright © 2024 FastService. All rights reserved.
//

#import "XVNewJobViewCell.h"
#import "HBLockSliderView.h"

@interface XVNewJobViewCell()<HBLockSliderDelegate>

@property (nonatomic, strong) UIView *bgView;


// 直送
@property (nonatomic, strong) UILabel *orderTypeLabel;
// 18:00 立即取货
@property (nonatomic, strong) UILabel *timeLabel;

// ¥5.5
@property (nonatomic, strong) UILabel *priceLabel;

// 新订单标识
@property (nonatomic, strong) UIImageView *newOrderImageView;

// 小费
@property (nonatomic, strong) UIButton *tipButton;

// tagView
@property (nonatomic, strong) UIView *tagView;
// 取货距离
@property (nonatomic, strong) UILabel *pickupDistanceLabel;
// 取货地址
@property (nonatomic, strong) UILabel *pickupAddressLabel;
// 取货详细地址
@property (nonatomic, strong) UILabel *pickupDetailAddressLabel;

@property (nonatomic, strong) UIView *lineView;

// 送货距离
@property (nonatomic, strong) UILabel *deliveryDistanceLabel;
// 送货地址
@property (nonatomic, strong) UILabel *deliveryAddressLabel;
// 收货人
@property (nonatomic, strong) UILabel *deliveryNameLabel;
// 备注
@property (nonatomic, strong) YYLabel *remarkLabel;
// 抢单
@property (nonatomic, strong) UIButton *orderButton;
// 滑动
@property (nonatomic, strong) HBLockSliderView *sliderView;

// 预约标记
@property (nonatomic, strong) UIView *preOrderView;


@end

@implementation XVNewJobViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = DEFAULT_BACKGROUND_COLOR;
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    
    [self.contentView addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 6, 6, 6));
    }];
    kViewBorderRadius(self.bgView, 10, 0, [UIColor whiteColor]);
    
    [self.bgView addSubview:self.orderTypeLabel];
    [self.orderTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bgView).mas_offset(9);
        make.left.mas_equalTo(self.bgView).mas_offset(17);
        make.size.mas_equalTo(CGSizeMake(62, 25));
    }];
    kViewBorderRadius(self.orderTypeLabel, 5, 0, [UIColor clearColor]);
    
    [self.bgView addSubview:self.newOrderImageView];
    [self.newOrderImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.mas_equalTo(self.bgView);
        make.size.mas_equalTo(CGSizeMake(29, 27));
    }];
    
    [self.bgView addSubview:self.priceLabel];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.bgView).mas_offset(-17);
        make.top.mas_equalTo(self.bgView).mas_offset(14);
    }];
    
    [self.bgView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.orderTypeLabel.mas_right).mas_offset(19);
        make.centerY.mas_equalTo(self.orderTypeLabel);
    }];
    
    [self.bgView addSubview:self.tagView];
    [self.tagView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.bgView).mas_offset(50);
        make.left.mas_equalTo(self.bgView).mas_offset(17);
        make.right.mas_equalTo(self.bgView).mas_offset(-17);
        make.height.mas_equalTo(20);
    }];
    [self.bgView addSubview:self.pickupDistanceLabel];
    [self.pickupDistanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.bgView).mas_offset(0);
        make.top.mas_equalTo(self.tagView.mas_bottom).mas_offset(14);
        make.width.mas_equalTo(50);
    }];

    
    [self.bgView addSubview:self.pickupAddressLabel];
    [self.pickupAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.tagView.mas_bottom).mas_offset(14);
        make.left.mas_equalTo(self.pickupDistanceLabel.mas_right).mas_offset(0);
        make.right.mas_equalTo(self.bgView).mas_offset(-17);
    }];
    
    [self.bgView addSubview:self.pickupDetailAddressLabel];
    [self.pickupDetailAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.pickupAddressLabel.mas_bottom).mas_offset(0);
        make.left.right.mas_equalTo(self.pickupAddressLabel);
    }];
    
    [self.bgView addSubview:self.deliveryDistanceLabel];
    [self.deliveryDistanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.bgView).mas_offset(0);
        make.width.mas_equalTo(50);
        make.top.mas_equalTo(self.pickupAddressLabel.mas_bottom).mas_offset(31);
    }];
    
    [self.bgView addSubview:self.lineView];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(2);
        make.centerX.mas_equalTo(self.pickupDistanceLabel);
        make.top.mas_equalTo(self.pickupDistanceLabel.mas_bottom).mas_offset(12);
        make.bottom.mas_equalTo(self.deliveryDistanceLabel.mas_top).mas_offset(-12);
    }];
    
    [self.bgView addSubview:self.deliveryAddressLabel];
    [self.deliveryAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.deliveryDistanceLabel);
        make.left.right.mas_equalTo(self.pickupAddressLabel);
        
    }];

    [self.bgView addSubview:self.deliveryNameLabel];
    [self.deliveryNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.deliveryAddressLabel.mas_bottom).mas_offset(0);
        make.left.right.mas_equalTo(self.pickupAddressLabel);
    }];

    [self.bgView addSubview:self.remarkLabel];
    [self.remarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.deliveryAddressLabel);
        make.top.mas_equalTo(self.deliveryNameLabel.mas_bottom).mas_offset(20);
    }];
    
    [self.bgView addSubview:self.orderButton];

    
    [self.orderButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.bgView).mas_offset(15);
        make.right.mas_equalTo(self.bgView).mas_offset(-15);
        make.top.mas_equalTo(self.remarkLabel.mas_bottom).mas_offset(15);
        make.bottom.mas_equalTo(self.bgView.mas_bottom).mas_offset(-8);
        make.height.mas_equalTo(44);

    }];
    kViewBorderRadius(self.orderButton, 5, 0, [UIColor clearColor]);
    
    
    
}
- (void)orderButtonClick {
    
}
- (UIView *)bgView {
    if(_bgView == nil) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UILabel *)orderTypeLabel {
    if(_orderTypeLabel == nil) {
        _orderTypeLabel = [[UILabel alloc]initWithText:@"直送" textColor:[UIColor whiteColor] textAlignment:(NSTextAlignmentCenter) fontSize:10];
        _orderTypeLabel.backgroundColor = COLOR_THEMEGRENN;
    }
    return _orderTypeLabel;
}

- (UILabel *)timeLabel {
    if(_timeLabel == nil) {
        _timeLabel = [[UILabel alloc]initWithText:@"18:00 立即取货" textColor:[UIColor colorWithHexString:@"#585858"] textAlignment:(NSTextAlignmentCenter) fontSize:18];
    }
    return _timeLabel;
}

- (UILabel *)priceLabel {
    if(_priceLabel == nil) {
        _priceLabel = [[UILabel alloc]initWithText:@"¥5.5" textColor:[UIColor colorWithHexString:@"##FF461F"] textAlignment:(NSTextAlignmentCenter) fontSize:18];
    }
    return _priceLabel;
}

- (UIImageView *)newOrderImageView {
    if(_newOrderImageView == nil) {
        _newOrderImageView = [[UIImageView alloc]initWithImageName:@"new_order"];
        UILabel *text = [[UILabel alloc]initWithText:@"新" textColor:[UIColor whiteColor] textAlignment:(NSTextAlignmentCenter) fontSize:12];
        [_newOrderImageView addSubview:text];
        [text mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(_newOrderImageView).mas_offset(1);
            make.top.mas_equalTo(_newOrderImageView);
            make.height.mas_equalTo(17);
        }];
    }
    return _newOrderImageView;
}



- (UIView *)tagView {
    if (_tagView == nil) {
        _tagView = [[UIView alloc]init];
        
    }
    return _tagView;
}

- (UILabel *)pickupDistanceLabel {
    if (_pickupDistanceLabel == nil) {
        _pickupDistanceLabel = [[UILabel alloc]initWithText:@"1.9" textColor:F_101010_COLOR textAlignment:(NSTextAlignmentCenter) fontSize:12];
        _pickupDistanceLabel.numberOfLines = 0;
    }
    return _pickupDistanceLabel;
}

- (UIView *)lineView {
    if (_lineView == nil) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = F_BBBBBB_COLOR;
    }
    return _lineView;
}

- (UILabel *)deliveryDistanceLabel {
    if (_deliveryDistanceLabel == nil) {
        _deliveryDistanceLabel = [[UILabel alloc]initWithText:@"3.9" textColor:F_101010_COLOR textAlignment:(NSTextAlignmentCenter) fontSize:12];
        _deliveryDistanceLabel.numberOfLines = 0;
    }
    return _deliveryDistanceLabel;
}
- (UILabel *)pickupAddressLabel {
    if (_pickupAddressLabel == nil) {
        _pickupAddressLabel = [[UILabel alloc]initWithText:@"小鱼的测试店铺(花园桥店) " textColor:F_101010_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:20];
        _pickupAddressLabel.numberOfLines = 0;
        _pickupAddressLabel.font = [UIFont boldSystemFontOfSize:20];
    }
    return _pickupAddressLabel;
}
- (UILabel *)pickupDetailAddressLabel {
    if (_pickupDetailAddressLabel == nil) {
        _pickupDetailAddressLabel = [[UILabel alloc]initWithText:@"北京动物园大猩猩馆000000000" textColor:F_101010_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:12];
        _pickupDetailAddressLabel.numberOfLines = 0;
    }
    return _pickupDetailAddressLabel;
}
- (UILabel *)deliveryAddressLabel {
    if (_deliveryAddressLabel == nil) {
        _deliveryAddressLabel = [[UILabel alloc]initWithText:@"白石桥南地铁站" textColor:F_101010_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:18];
        _deliveryAddressLabel.numberOfLines = 0;
        _deliveryAddressLabel.font = [UIFont boldSystemFontOfSize:20];
    }
    return _deliveryAddressLabel;
}

- (UILabel *)deliveryNameLabel {
    if (_deliveryNameLabel == nil) {
        _deliveryNameLabel = [[UILabel alloc]initWithText:@"收货人:嫦娥仙子" textColor:F_101010_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:14];
        _deliveryNameLabel.numberOfLines = 0;
        
    }
    return _deliveryNameLabel;

}

- (YYLabel *)remarkLabel {
    if (_remarkLabel == nil) {
        _remarkLabel = [[YYLabel alloc]init];
        _remarkLabel.text = @"这里是备注";
        _remarkLabel.font = [UIFont systemFontOfSize:14];
        _remarkLabel.backgroundColor = [UIColor whiteColor];
        _remarkLabel.textColor = kHexRGB(0x808080);
        _remarkLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 84;
        _remarkLabel.textTapAction = ^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
            //点击展开

        };
    }
    return _remarkLabel;
}
- (UIButton *)orderButton {
    if (_orderButton == nil) {
        _orderButton = [[UIButton alloc]initWithTitle:@"抢单" fontSize:16 titleColor:[UIColor whiteColor] bgColor:COLOR_THEMEGRENN];
        [_orderButton addTarget:self action:@selector(orderButtonClick) forControlEvents:UIControlEventTouchUpInside];
        _orderButton.cs_acceptEventInterval = 1;
    }
    return _orderButton;
}

- (UIView *)preOrderView {
    if (_preOrderView == nil) {
        _preOrderView = [[UIView alloc]init];
        _preOrderView.backgroundColor = [UIColor colorWithHexString:@"#1393EC"];
        UIImageView *imageView = [[UIImageView alloc]initWithImage:IMG(@"闹钟")];
        [_preOrderView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(_preOrderView);
            make.size.mas_equalTo(CGSizeMake(15, 15));
            make.left.mas_equalTo(_preOrderView).mas_offset(8);
        }];
        UILabel *label = [[UILabel alloc]initWithText:@"预" textColor:[UIColor whiteColor] textAlignment:(NSTextAlignmentCenter) fontSize:12];
        [_preOrderView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(imageView.mas_right);
            make.right.mas_equalTo(_preOrderView);
            make.centerY.mas_equalTo(_preOrderView);
        }];
    }
    return _preOrderView;
}
- (HBLockSliderView *)sliderView {
    if (_sliderView == nil) {
        _sliderView = [[HBLockSliderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 40, 44)];
        _sliderView.text = @"滑动抢单";
        [_sliderView setColorForBackgroud:COLOR_THEMEGRENN
                               foreground:COLOR_THEMEGRENN
                                    thumb:COLOR_THEMEGRENN
                                   border:[UIColor clearColor]
                                textColor:[UIColor whiteColor]];
        _sliderView.thumbBack = YES;
        [_sliderView setThumbBeginImage:[UIImage imageNamed:@"huadong"] finishImage:[UIImage imageNamed:@"huadong"]];
        [_sliderView setRoundCorners:5];
        _sliderView.delegate = self;
        
    }
    return _sliderView;
}

@end
