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

#import "XVOrderSortView.h"
@interface XVOrderSortView()

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIButton *systemButton;

@property (nonatomic, strong) UILabel *distanceLabel;
@property (nonatomic, strong) UILabel *timeLabel;


@property (nonatomic, strong) UIButton *distanceAscButton;
@property (nonatomic, strong) UIButton *distanceDescButton;

@property (nonatomic, strong) UIButton *timeAscButton;
@property (nonatomic, strong) UIButton *timeDescButton;

@property (nonatomic, strong) UIView *maskView;

@property (nonatomic, strong) UIView *alertView;


@end

@implementation XVOrderSortView

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

- (void)setupUI {
    
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.3];


//    [self addSubview:self.maskView];
    
    [self addSubview:self.alertView];
    
    [self.alertView addSubview:self.titleLabel];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.alertView).mas_offset(9);
        make.left.mas_equalTo(self.alertView).mas_offset(16);
    }];
    
    
    [self.alertView addSubview:self.systemButton];
    [self.systemButton sizeToFit];
    [self.systemButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.titleLabel);
        make.left.mas_equalTo(self.titleLabel.mas_right).mas_offset(15);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(15);
    }];

    
    kViewBorderRadius(self.systemButton, 4, 0, [UIColor clearColor]);
    
    [self.alertView addSubview:self.distanceLabel];
    [self.distanceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(20);
    }];
    
    [self.alertView addSubview:self.timeLabel];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(self.distanceLabel.mas_bottom).mas_offset(18);
    }];
    
    [self.alertView addSubview:self.distanceAscButton];
    [self.alertView addSubview:self.distanceDescButton];
    
    [self.distanceAscButton sizeToFit];
    [self.distanceDescButton sizeToFit];
    [self.distanceAscButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.distanceLabel);
        make.left.mas_equalTo(self.distanceLabel.mas_right).mas_offset(33);
        make.size.mas_equalTo(CGSizeMake(94, 17));
    }];
    [self.distanceDescButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.distanceLabel);
        make.left.mas_equalTo(self.distanceAscButton.mas_right).mas_offset(18);
        make.size.mas_equalTo(CGSizeMake(94, 17));
    }];

    
    [self.alertView addSubview:self.timeAscButton];
    [self.alertView addSubview:self.timeDescButton];
    
    [self.timeAscButton sizeToFit];
    [self.timeDescButton sizeToFit];
    [self.timeAscButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.timeLabel);
        make.left.mas_equalTo(self.timeLabel.mas_right).mas_offset(33);
        make.size.mas_equalTo(CGSizeMake(94, 17));
    }];
    [self.timeDescButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.timeLabel);
        make.left.mas_equalTo(self.timeAscButton.mas_right).mas_offset(18);
        make.size.mas_equalTo(CGSizeMake(94, 17));
    }];
    
    
    self.userInteractionEnabled = YES;
    UITapGestureRecognizer *myTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapMaskView)];
    [self addGestureRecognizer:myTap];


}

- (UILabel *)titleLabel {
    if(_titleLabel == nil) {
        _titleLabel = [[UILabel alloc]initWithText:@"订单排序" textColor:F_3D3B4F_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:12];
    }
    return _titleLabel;
}

- (UIButton *)systemButton {
    if(_systemButton == nil) {
        _systemButton = [[UIButton alloc]initWithTitle:@"系统推荐" fontSize:12 titleColor:[UIColor whiteColor] bgColor:COLOR_THEMEGRENN];
    }
    return _systemButton;
}
- (UILabel *)distanceLabel {
    if(_distanceLabel == nil) {
        _distanceLabel = [[UILabel alloc]initWithText:@"按距离排序" textColor:F_606060_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:12];
    }
    return _distanceLabel;
}

- (UILabel *)timeLabel {
    if(_timeLabel == nil) {
        _timeLabel = [[UILabel alloc]initWithText:@"按时间排序" textColor:F_606060_COLOR textAlignment:(NSTextAlignmentLeft) fontSize:12];
    }
    return _timeLabel;
}

- (UIButton *)distanceAscButton {
    if(_distanceAscButton == nil) {
        _distanceAscButton = [[UIButton alloc]initWithTitle:@"取货地由近及远" fontSize:12 titleColor:[UIColor colorWithHexString:@"#737272"] bgColor:F7_3_COLOR];
    }
    return _distanceAscButton;
}

- (UIButton *)distanceDescButton {
    if(_distanceDescButton == nil) {
        _distanceDescButton = [[UIButton alloc]initWithTitle:@"取货地由远及近" fontSize:12 titleColor:[UIColor colorWithHexString:@"#737272"] bgColor:F7_3_COLOR];
    }
    return _distanceDescButton;
}

- (UIButton *)timeAscButton {
    if(_timeAscButton == nil) {
        _timeAscButton = [[UIButton alloc]initWithTitle:@"取货时间最近" fontSize:12 titleColor:[UIColor colorWithHexString:@"#737272"] bgColor:F7_3_COLOR];
    }
    return _timeAscButton;
}

- (UIButton *)timeDescButton {
    if(_timeDescButton == nil) {
        _timeDescButton = [[UIButton alloc]initWithTitle:@"取货时间最远" fontSize:12 titleColor:[UIColor colorWithHexString:@"#737272"] bgColor:F7_3_COLOR];
    }
    return _timeDescButton;
}

- (UIView *)alertView {
    if (!_alertView) {
        _alertView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 115)];
        _alertView.backgroundColor = [UIColor whiteColor];
        [_alertView addRoundedCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) withRadii:CGSizeMake(10, 10)];
    }
    return _alertView;
}

#pragma mark - 蒙层视图
- (UIView *)maskView {
    if (!_maskView) {
        _maskView = [[UIView alloc]initWithFrame:self.bounds];
        _maskView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.3];;
        // 设置子视图的大小随着父视图变化
        _maskView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    }
    return _maskView;
}
- (void)didTapMaskView {
    self.hidden = YES;
}

@end
