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

#import "XVDispatchOrderAlter.h"
#import "XVGetOrderAlterSliderView.h"
#import "XVGetOrderAlterButtonView.h"

@interface XVDispatchOrderAlter()

@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UILabel *orderTypeLabel;
@property (nonatomic, strong) UILabel *goodsTypeLabel;

@property (nonatomic, strong) UILabel *distanceLabel;

@property (nonatomic, strong) UILabel *timeLabel;

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

@property (nonatomic, strong) UILabel *deliveryLabel;
// 送货距离
@property (nonatomic, strong) UILabel *deliveryDistanceLabel;
// 送货地址
@property (nonatomic, strong) UILabel *deliveryAddressLabel;
// 收货人
@property (nonatomic, strong) UILabel *deliveryNameLabel;
// 备注
@property (nonatomic, strong) YYLabel *remarkLabel;


@property (nonatomic, strong) XVGetOrderAlterSliderView *silderToolView;
@property (nonatomic, strong) XVGetOrderAlterButtonView *buttonToolView;



@end

@implementation XVDispatchOrderAlter

+ (void)show {
    
    XVDispatchOrderAlter *view = [[XVDispatchOrderAlter alloc]init];
    // 计算alter的高度
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-16, SCREEN_HEIGHT)];
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(bgView);
    }];
    [bgView layoutIfNeeded];
    bgView.height = view.height;
    
    [LEEAlert alert].config
        .LeeCustomView(bgView)
        .LeeMaxWidth(SCREEN_WIDTH-16)
        .LeeMaxHeight(SCREEN_HEIGHT)
        .LeeHeaderInsets(UIEdgeInsetsMake(0, 0, 0, 0))
        .LeeItemInsets(UIEdgeInsetsMake(0, 0, 0, 0))
        .LeeClickBackgroundClose(NO)
        .LeeShow();
    
}

- (instancetype)initWithFrame:(CGRect)frame {
    if(self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {


    [self addSubview:self.topView];
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(self);
    }];
    
    [self.topView addSubview:self.priceLabel];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(self.topView).mas_offset(33);
        
    }];
        
    [self.topView addSubview:self.orderTypeLabel];
    [self.orderTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.priceLabel);
        make.right.mas_equalTo(self.topView).mas_offset(-28);
    }];
    
    [self.topView addSubview:self.distanceLabel];
    [self.distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.priceLabel);
        make.top.mas_equalTo(self.priceLabel.mas_bottom).mas_offset(15);
    }];
    
    [self.topView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.priceLabel);
        make.top.mas_equalTo(self.distanceLabel.mas_bottom).mas_offset(15);
        make.bottom.mas_equalTo(self.topView).mas_offset(-15);
    }];
    
    

    [self addSubview:self.pickupLabel];
    [self.pickupLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topView.mas_bottom).mas_offset(25);
        make.left.mas_equalTo(self).mas_offset(14);
        make.size.mas_equalTo(CGSizeMake(28, 28));
    }];
    kViewBorderRadius(self.pickupLabel, 14, 1, COLOR_THEMEGRENN);
    

    [self addSubview:self.pickupDistanceLabel];
    [self.pickupDistanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.pickupLabel);
        make.left.mas_equalTo(self.pickupLabel.mas_right);
        make.width.mas_equalTo(45);
    }];


    [self addSubview:self.pickupAddressLabel];
    [self.pickupAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.pickupDistanceLabel.mas_right);
        make.top.mas_equalTo(self.pickupLabel);
        make.right.mas_equalTo(self).mas_offset(-14);
    }];

    [self addSubview:self.pickupDetailAddressLabel];
    [self.pickupDetailAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.pickupAddressLabel.mas_bottom);
        make.right.left.mas_equalTo(self.pickupAddressLabel);
    }];



    [self addSubview:self.deliveryLabel];
    [self.deliveryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.pickupDetailAddressLabel.mas_bottom).mas_offset(32);
        make.left.mas_equalTo(self).mas_offset(14);
        make.size.mas_equalTo(CGSizeMake(28, 28));
    }];
    kViewBorderRadius(self.deliveryLabel, 14, 0, [UIColor clearColor]);

    [self addSubview:self.deliveryDistanceLabel];
    [self.deliveryDistanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.deliveryLabel);
        make.left.mas_equalTo(self.deliveryLabel.mas_right);
        make.width.mas_equalTo(45);
    }];

    [self addSubview:self.deliveryAddressLabel];
    [self.deliveryAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(self.pickupAddressLabel);
        make.top.mas_equalTo(self.deliveryLabel);

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

    [self addSubview:self.remarkLabel];
    [self.remarkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).mas_offset(12);
        make.right.mas_equalTo(self).mas_offset(-12);
        make.top.mas_equalTo(self.deliveryNameLabel.mas_bottom).mas_offset(52);

    }];

//    [self addSubview:self.buttonToolView];
//    [self.buttonToolView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.bottom.mas_equalTo(self).mas_offset(-15);
//        make.width.mas_equalTo(SCREEN_WIDTH-16);
//        make.centerX.mas_equalTo(self);
//        make.top.mas_equalTo(self.remarkLabel.mas_bottom).mas_offset(45);
//        make.height.mas_equalTo(75);
//
//    }];
    
    
    [self addSubview:self.silderToolView];
    
    [self.silderToolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.width.mas_equalTo(SCREEN_WIDTH-16);
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.remarkLabel.mas_bottom).mas_offset(45);
        make.height.mas_equalTo(51);
    }];

}

- (UIView *)topView {
    if(_topView == nil) {
        _topView = [[UIView alloc]init];
        _topView.backgroundColor = COLOR_THEMEGRENN;
    }
    return _topView;
}

- (UILabel *)priceLabel {
    if(_priceLabel == nil) {
        
        _priceLabel = [[UILabel alloc]init];
        NSMutableAttributedString *text = [NSMutableAttributedString new];
        UIFont *font = [UIFont systemFontOfSize:36];
        UIColor *color = [UIColor colorWithHexString:@"#F0EFEF"];
        [text appendAttributedString:[[NSAttributedString alloc] initWithString:@"8.65" attributes:@{NSFontAttributeName : font,NSForegroundColorAttributeName:color}]];
        [text appendAttributedString:[[NSAttributedString alloc] initWithString:@"（指派单）" attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14],NSForegroundColorAttributeName:color}]];
        _priceLabel.attributedText = text;
                       
    }
    return _priceLabel;
}

- (UILabel *)orderTypeLabel {
    if(_orderTypeLabel == nil) {
        _orderTypeLabel = [[UILabel alloc]initWithText:@"文件" textColor:[UIColor colorWithHexString:@"#F0EFEF"] textAlignment:(NSTextAlignmentCenter) fontSize:14];
    }
    return _orderTypeLabel;
}
- (UILabel *)distanceLabel {
    if(_distanceLabel == nil) {
        _distanceLabel = [[UILabel alloc]initWithText:@"3.45公里/距你1.71公里" textColor:[UIColor whiteColor] textAlignment:(NSTextAlignmentCenter) fontSize:14];
    }
    return _distanceLabel;
}


- (UILabel *)timeLabel {
    if(_timeLabel == nil) {
        _timeLabel = [[UILabel alloc]initWithText:@"17:00前送达" textColor:[UIColor whiteColor] textAlignment:(NSTextAlignmentCenter) fontSize:14];
    }
    return _timeLabel;
}

- (UILabel *)pickupLabel {
    if(_pickupLabel == nil) {
        _pickupLabel = [[UILabel alloc]initWithText:@"取" textColor:[UIColor whiteColor] textAlignment:(NSTextAlignmentCenter) fontSize:14];
        _pickupLabel.backgroundColor = COLOR_THEMEGRENN;
    }
    return _pickupLabel;
}

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

- (UILabel *)deliveryLabel {
    if(_deliveryLabel == nil) {
        _deliveryLabel = [[UILabel alloc]initWithText:@"收" textColor:[UIColor whiteColor] textAlignment:(NSTextAlignmentCenter) fontSize:14];
        _deliveryLabel.backgroundColor = [UIColor colorWithHexString:@"#FF7C61"];

    }
    return _deliveryLabel;
}


- (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;
}

- (XVGetOrderAlterSliderView *)silderToolView {
    if(_silderToolView == nil) {
        _silderToolView = [[XVGetOrderAlterSliderView alloc]init];
    }
    return _silderToolView;
}
- (XVGetOrderAlterButtonView *)buttonToolView {
    if(_buttonToolView == nil) {
        _buttonToolView = [[XVGetOrderAlterButtonView alloc]init];
    }
    return _buttonToolView;
}


@end
