
#import "YMIMBaseMessageCell.h"
#import "SLMikeSegment.h"
#import "SLMessageViewController.h"
#import "SLMikeSegmentModel.h"

@interface YMIMBaseMessageCell()

@property (nonatomic, strong) MessageModel *msgModel;

@end

@implementation YMIMBaseMessageCell

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

- (void)confignMessageView
{
    
    [self.msgHeaderView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(0);
        make.width.height.mas_equalTo(52);
    }];

    [self.mikeLabelBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.msgHeaderView.mas_left).offset(-10);
        make.left.mas_greaterThanOrEqualTo(16);
        make.top.mas_equalTo(6);
        make.height.mas_equalTo(46);
        make.width.mas_equalTo(100);
    }];

    [self.mikeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mikeLabelBgView);
        make.left.mas_equalTo(12);
    }];

    [self.mikeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.mikeLabelBgView);
        make.left.equalTo(self.mikeImageView.mas_right);
    }];


    [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.msgHeaderView.mas_left).offset(-10);
        make.left.mas_greaterThanOrEqualTo(16);
        make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
    }];
    [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.right.bottom.mas_equalTo(-12);
    }];
    
    [self timeLabel];
}

- (void)removeAllConstViewHierarchy:(UIView *)superView
{
    for (UIView *subview in superView.subviews)
    {
        [self removeAllConstViewHierarchy:subview];
        NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:subview];
        for (MASConstraint *constraint in installedConstraints) {
            [constraint uninstall];
        }
    }
}

- (void)confignBaseMessageContentWith:(MessageModel *)msgModel receiveHeardImg:(NSString *)img {
    self.msgModel = msgModel;
    self.messageLabel.text = msgModel.sendText;
    [self removeAllConstViewHierarchy:self.contentView];
    CGFloat topTimeHeight = 0.f;
    if (msgModel.showTime) {
        NSString *timeStr = [NSString stringWithFormat:@"%f",msgModel.sendTime * 1000];
         
        CGFloat nowDate = [[NSDate date] timeIntervalSince1970];
        if (nowDate - msgModel.sendTime > 60 * 60 * 24) {
            self.timeLabel.text = [NSString timeFromFormatter:@"M月d日 H:m" timeString:timeStr];
        }else {
            self.timeLabel.text = [NSString timeFromFormatter:@"H:m" timeString:timeStr];
        }
        topTimeHeight = 23.f;
        [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self.contentView);
            make.height.mas_equalTo(topTimeHeight);
        }];
    }else {
        self.timeLabel.text = @"";
        [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.equalTo(self.contentView);
            make.height.mas_equalTo(0);
        }];
    }
    if (_sendFailImageView) {
        [_sendFailImageView removeFromSuperview];
        _sendFailImageView = nil;
    }
    
    CGFloat topHeight = msgModel.showMike ? 46 : 0;
    CGFloat topMikeBg = (topHeight ? 6 : 0) + topTimeHeight;
    if (msgModel.isReceive) {
        NSArray *msgArr = [msgModel.sendText componentsSeparatedByString:@" "];
//        __block CGFloat m = 0;
//        [msgArr enumerateObjectsUsingBlock:^(NSString *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            NSInteger l = obj.length;
//            CGFloat x = 0;
//            if (l > 12) {
//                x = 20.0;
//            }else if (l > 9 && l < 12) {
//                x = 18.0;
//            }else if (l > 5 && l < 10) {
//                x = 14.0;
//            }else if (l > 3 && l < 6) {
//                x = 12.0;
//            }else {
//                x = 9.0;
//            }
//            m += MIN(obj.length / x, 0.6);
//
//        }];
        NSInteger timeLong = ceil(msgArr.count / 2.5);
        {//你有多少数据量
            self.messageLabel.text = msgModel.showTrans ? msgModel.sendTextTrans : msgModel.sendText;
            if (!msgModel.showMike) {
                self.messageLabel.text = msgModel.sendText;
            }
//            self.messageLabel.textAlignment = NSTextAlignmentLeft;
            self.messageLabel.textColor = [UIColor blackColor];
            self.mikeLabel.textColor = [UIColor blackColor];
            self.mikeLabelBgView.backgroundColor = [UIColor whiteColor];
            self.messageLabelBgView.backgroundColor = [UIColor whiteColor];
            self.mikeImageView.image = ImageName(@"icon_msg_yy");
            NSString *headUrl = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl, img];
            [self.msgHeaderView sd_setImageWithURL:[NSURL URLWithString:headUrl] placeholderImage:ImageName(@"icon_ellipse")];
            self.mikeLabel.text = [NSString stringWithFormat:@"%ld″",timeLong];
            if (!msgModel.showText) {
                [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.top.left.equalTo(self.messageLabelBgView).offset(10);
//                    make.right.bottom.equalTo(self.messageLabelBgView).offset(-12);
                    
                }];
                [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self.msgHeaderView.mas_right).offset(10);
                    make.right.mas_lessThanOrEqualTo(self).offset(-16);
                    make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
                    make.height.mas_lessThanOrEqualTo(0.01);
                }];
            }else {
                [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self.msgHeaderView.mas_right).offset(10);
                    make.right.mas_lessThanOrEqualTo(self).offset(-16);
                    make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
                }];
                [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.top.left.equalTo(self.messageLabelBgView).offset(10);
                    make.right.bottom.equalTo(self.messageLabelBgView).offset(-12);
                    
                }];
            }
        }
        {
            [self.mikeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.mikeLabelBgView);
                make.left.mas_equalTo(12);
            }];

            [self.mikeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.mikeLabelBgView);
                make.left.equalTo(self.mikeImageView.mas_right);
            }];
            CGFloat mikeLabelWidth = 70.0f;
            if (timeLong > 0) {
                mikeLabelWidth = mikeLabelWidth + log(timeLong) * log(timeLong) * log(timeLong) * 4;
                mikeLabelWidth = MIN(kSCREEN_WIDTH * 3 / 5.0, mikeLabelWidth);
//                NSLog(@"--%f--%f--%f--%f--%f--%f--%f--%f--%f--%f",log(1),log(2),log(5),log(10),log(20),log(30),log(40),log(50),log(100),mikeLabelWidth);
            }
            [self.mikeLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.msgHeaderView.mas_right).offset(10);
                make.right.mas_lessThanOrEqualTo(self).offset(-16);
                make.top.mas_equalTo(topMikeBg);
                make.height.mas_equalTo(topHeight);
                make.width.mas_equalTo(mikeLabelWidth);
            }];
        }
        {
            if (self.msgModel.showTrans && !self.msgModel.showMike) {
                [self.msgTransLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.left.equalTo(self.msgHeaderView.mas_right).offset(10);
                    make.right.mas_lessThanOrEqualTo(self).offset(-16);
                    make.top.equalTo(self.messageLabelBgView.mas_bottom).offset(8);
                }];
                [self.msgTransLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.top.left.equalTo(self.msgTransLabelBgView).offset(10);
                    make.right.bottom.equalTo(self.msgTransLabelBgView).offset(-12);
                    
                }];
                self.msgTransLabel.text = msgModel.sendTextTrans;
            }
        }
        [self.msgHeaderView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(16);
            make.top.mas_equalTo(topTimeHeight);
            make.width.height.mas_equalTo(52);
        }];
    }else {
//        self.messageLabel.textAlignment = NSTextAlignmentRight;
        self.messageLabel.textColor = [UIColor whiteColor];
        self.mikeLabel.textColor = [UIColor whiteColor];
        self.mikeLabelBgView.backgroundColor = SLColor(@"#448AF7");
        self.messageLabelBgView.backgroundColor = SLColor(@"#448AF7");
        self.mikeImageView.image = ImageName(@"icon_msg_yy_w");
        NSString *headUrl = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl, [SLGlobalInfo SharedInstance].loginInfo.user.userHead];
        [self.msgHeaderView sd_setImageWithURL:[NSURL URLWithString:headUrl] placeholderImage:ImageName(@"icon_ellipse")];
        NSInteger timeLong = ceil(msgModel.audioDuration);
        self.mikeLabel.text = [NSString stringWithFormat:@"%ld″",timeLong];
        {
            if (!msgModel.showText) {
                [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.top.left.equalTo(self.messageLabelBgView).offset(10);
//                    make.right.bottom.equalTo(self.messageLabelBgView).offset(-10);
                }];
                [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.right.equalTo(self.msgHeaderView.mas_left).offset(-10);
                    make.left.mas_greaterThanOrEqualTo(16);
                    make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
                    make.height.mas_lessThanOrEqualTo(0.01);
                }];
               
            }else {
                CGFloat msgLeft = msgModel.sendFailure ? 24 : 16;
                [self.messageLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.right.equalTo(self.msgHeaderView.mas_left).offset(-10);
                    make.left.mas_greaterThanOrEqualTo(msgLeft);
                    make.top.equalTo(self.mikeLabelBgView.mas_bottom).offset(8);
                }];
                [self.messageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                    make.top.left.equalTo(self.messageLabelBgView).offset(10);
                    make.right.bottom.equalTo(self.messageLabelBgView).offset(-10);
                }];
            }
        }
        
        {
            [self.mikeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.mikeLabelBgView);
                make.right.equalTo(self.mikeImageView.mas_left);
            }];
            [self.mikeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.centerY.equalTo(self.mikeLabelBgView);
                make.right.equalTo(self.mikeLabelBgView.mas_right).offset(-12);
            }];
            
            
            CGFloat mikeLabelWidth = 70.0f;
            if (timeLong > 0) {
                mikeLabelWidth = mikeLabelWidth + log(timeLong) * log(timeLong) * log(timeLong) * 4;
                mikeLabelWidth = MIN(kSCREEN_WIDTH * 3 / 5.0, mikeLabelWidth);
//                NSLog(@"--%f--%f--%f--%f--%f--%f--%f--%f--%f--%f",log(1),log(2),log(5),log(10),log(20),log(30),log(40),log(50),log(100),mikeLabelWidth);
            }
            [self.mikeLabelBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(self.msgHeaderView.mas_left).offset(-10);
                make.left.mas_greaterThanOrEqualTo(self).offset(16);
                make.top.mas_equalTo(topMikeBg);
                make.height.mas_equalTo(topHeight);
                make.width.mas_equalTo(mikeLabelWidth);
            }];
            if (msgModel.sendFailure) {
                if (topHeight) {
                    [self.sendFailImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
                        make.centerY.equalTo(self.mikeLabelBgView);
                        make.right.equalTo(self.mikeLabelBgView.mas_left).offset(-2);
                        make.width.height.mas_equalTo(20);
                    }];
                }else {
                    [self.sendFailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
                        make.centerY.equalTo(self.messageLabelBgView);
                        make.right.equalTo(self.messageLabelBgView.mas_left).offset(-2);
                        make.width.height.mas_equalTo(20);
                    }];
                }
            }
            
        }
        {
            [self.msgHeaderView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-16);
                make.top.mas_equalTo(topTimeHeight);
                make.width.height.mas_equalTo(52);
            }];
        }
    }
}

- (void)setCellLayerCornerRadiusWith:(MessageModel *)msgModel {
    [self setNeedsLayout];
    [self layoutIfNeeded];
    // Drawing code
    CGFloat cornerRadius = 12;
    //设置所需的圆角位置以及大小
    UIBezierPath *maskPath;
    UIBezierPath *maskPath1;
    UIBezierPath *maskPath2;
    if (msgModel.isReceive) {
        maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageLabelBgView.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];
        maskPath1 = [UIBezierPath bezierPathWithRoundedRect:self.mikeLabelBgView.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];
        maskPath2 = [UIBezierPath bezierPathWithRoundedRect:self.msgTransLabelBgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];
    }else {
        maskPath = [UIBezierPath bezierPathWithRoundedRect:self.messageLabelBgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];
        maskPath1 = [UIBezierPath bezierPathWithRoundedRect:self.mikeLabelBgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(cornerRadius , cornerRadius)];

    }
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.messageLabelBgView.bounds;
    maskLayer.path = maskPath.CGPath;
    self.messageLabelBgView.layer.mask = maskLayer;
    
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = self.mikeLabelBgView.bounds;
    maskLayer1.path = maskPath1.CGPath;
    self.mikeLabelBgView.layer.mask = maskLayer1;
    
    CAShapeLayer *maskLayer2 = [[CAShapeLayer alloc] init];
    maskLayer2.frame = self.msgTransLabelBgView.bounds;
    maskLayer2.path = maskPath2.CGPath;
    self.msgTransLabelBgView.layer.mask = maskLayer2;
}

- (void)drawRect:(CGRect)rect
{
    
}

- (void)mikeHandleTap:(UITapGestureRecognizer *)tap {
    SLMikeSegmentModel *model = [SLMikeSegmentModel initWithSegTitle:@"播放" segImage:@"icon_mike_translate" mikeType:SLMikeInputBroadcast];
    if (self.segmentBlock) {
        self.segmentBlock(model);
    }
}

- (void)mikeHandleLongPressGestures:(UILongPressGestureRecognizer *)paramSender {
    if (paramSender.state == UIGestureRecognizerStateBegan) {
        [self showMsgSegmentWith:self.mikeLabelBgView];
    }
}

- (void)msgHandleLongPressGestures:(UILongPressGestureRecognizer *)paramSender {
    if (paramSender.state == UIGestureRecognizerStateBegan) {
        [self showMsgSegmentWith:self.messageLabelBgView];
    }
}

- (void)msgTransHandleLongPressGestures:(UILongPressGestureRecognizer *)paramSender {
    if (paramSender.state == UIGestureRecognizerStateBegan) {
        [self showMsgSegmentWith:self.msgTransLabelBgView];
    }
}

- (void)showMsgSegmentWith:(UIView *)bgView {
    UIViewController *vc = self.viewController;
    if ([vc isKindOfClass:SLMessageViewController.class]) {
        CGRect rect = [self convertRect:bgView.frame toView:self.viewController.view];
        //加一个蒙层
        __block UIView *bView = [[UIView alloc] initWithFrame:vc.view.frame];
        bView.backgroundColor = [UIColor clearColor];
        bView.tag = SLMikeSegMentBgTag;
        [vc.view addSubview:bView];
        NSMutableArray *arr = [NSMutableArray new];
        if (self.msgModel.showMike && !self.msgModel.showText) {
            [arr addObjectsFromArray:@[
                [SLMikeSegmentModel initWithSegTitle:@"查看" segImage:@"icon_eyes_on" mikeType:SLMikeInputLook],
                [SLMikeSegmentModel initWithSegTitle:@"删除" segImage:@"icon_mike_delete" mikeType:SLMikeInputDelete]]];
            if (self.msgModel.isReceive) {
                [arr insertObject:[SLMikeSegmentModel initWithSegTitle:@"翻译" segImage:@"icon_mike_translate" mikeType:SLMikeInputTrans] atIndex:1];
            }
        }else if (!self.msgModel.showMike && self.msgModel.showText) {
            [arr addObjectsFromArray:@[
                            [SLMikeSegmentModel initWithSegTitle:@"删除" segImage:@"icon_mike_delete" mikeType:SLMikeInputDelete]]];
            if (self.msgModel.isReceive && !self.msgModel.showTrans) {
                [arr insertObject:[SLMikeSegmentModel initWithSegTitle: @"翻译" segImage:@"icon_mike_translate" mikeType:SLMikeInputTrans] atIndex:0];
            }
            if (self.msgModel.isReceive) {
                [arr insertObject:[SLMikeSegmentModel initWithSegTitle: @"播放" segImage:@"icon_filled_talk" mikeType:SLMikeInputBroadcast] atIndex:0];
            }
            [arr addObject:[SLMikeSegmentModel initWithSegTitle: @"复制" segImage:@"icon_mike_copy" mikeType:SLMsgCopy]];
        }else if (self.msgModel.showMike && self.msgModel.showText) {
            if (bgView == self.mikeLabelBgView) {
                [arr addObject:[SLMikeSegmentModel initWithSegTitle:@"删除" segImage:@"icon_mike_delete" mikeType:SLMikeInputDelete]];
                if (self.msgModel.isReceive) {
                    [arr insertObject:[SLMikeSegmentModel initWithSegTitle:!self.msgModel.showTrans ? @"翻译" : @"原文" segImage:@"icon_mike_translate" mikeType:SLMikeInputTrans] atIndex:0];
                }
            }
            if (bgView == self.messageLabelBgView) {
                [arr addObject:[SLMikeSegmentModel initWithSegTitle:@"隐藏" segImage:@"icon_mike_delete" mikeType:SLMikeInputHidden]];
                [arr addObject:[SLMikeSegmentModel initWithSegTitle: @"复制" segImage:@"icon_mike_copy" mikeType:SLMsgCopy]];
            }
        }
        if (self.msgModel.showTrans && bgView == self.msgTransLabelBgView) {
            [arr removeAllObjects];
            [arr addObject:[SLMikeSegmentModel initWithSegTitle: @"复制" segImage:@"icon_mike_copy" mikeType:SLMsgCopy]];
        }
        
        CGFloat width = arr.count * 45 + 20;
        CGFloat x = self.msgModel.isReceive ? rect.origin.x : rect.origin.x + rect.size.width - width;
        SLMikeSegment *mikeSegment = [[SLMikeSegment alloc] initWithFrame:CGRectMake(x, rect.origin.y - 59, width, 50) titleArray:arr];
        WS(weakSelf);
        mikeSegment.mikeSegmentBlock = ^(SLMikeSegmentModel *model) {
            [bView removeFromSuperview];
            if (weakSelf.segmentBlock) {
                weakSelf.segmentBlock(model);
            }
        };
        [bView addSubview:mikeSegment];
        SLMessageViewController *msgVc = (SLMessageViewController *)vc;
        msgVc.hiddenMikeSegment = YES;
        UIImageView *imgView = [[UIImageView alloc] initWithImage:ImageName(@"icon_dsjx")];
        [bView addSubview:imgView];
        [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(mikeSegment);
            make.top.equalTo(mikeSegment.mas_bottom).offset(0);
            make.width.mas_equalTo(16);
            make.height.mas_equalTo(8);
        }];
    }
}

- (UILabel *)messageLabel
{
    if (!_messageLabel) {
        _messageLabel = [[UILabel alloc] init];
        _messageLabel.textAlignment = NSTextAlignmentLeft;
        _messageLabel.numberOfLines = 0;
        _messageLabel.textColor = [UIColor whiteColor];
        _messageLabel.font = [UIFont systemFontOfSize:17];
        _messageLabel.userInteractionEnabled = YES;
        [self.messageLabelBgView addSubview:_messageLabel];
    }
    return _messageLabel;
}

- (UIView *)messageLabelBgView
{
    if (!_messageLabelBgView) {
        _messageLabelBgView = [[UIView alloc] initWithFrame:CGRectZero];
        _messageLabelBgView.backgroundColor = SLColor(@"#448AF7");
        _messageLabelBgView.clipsToBounds = YES;
        _messageLabelBgView.userInteractionEnabled = YES;
        UILongPressGestureRecognizer *gesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(msgHandleLongPressGestures:)];
        gesture.minimumPressDuration= 0.5f;
        [_messageLabelBgView addGestureRecognizer:gesture];
        [self.contentView addSubview:_messageLabelBgView];
    }
    return _messageLabelBgView;
}

- (UILabel *)msgTransLabel
{
    if (!_msgTransLabel) {
        _msgTransLabel = [[UILabel alloc] init];
        _msgTransLabel.textAlignment = NSTextAlignmentLeft;
        _msgTransLabel.numberOfLines = 0;
        _msgTransLabel.textColor = [UIColor blackColor];
        _msgTransLabel.font = [UIFont systemFontOfSize:17];
        _msgTransLabel.userInteractionEnabled = YES;
        [self.msgTransLabelBgView addSubview:_msgTransLabel];
    }
    return _msgTransLabel;
}

- (UIView *)msgTransLabelBgView
{
    if (!_msgTransLabelBgView) {
        _msgTransLabelBgView = [[UIView alloc] initWithFrame:CGRectZero];
        _msgTransLabelBgView.backgroundColor = [UIColor whiteColor];
        _msgTransLabelBgView.clipsToBounds = YES;
        _msgTransLabelBgView.userInteractionEnabled = YES;
        UILongPressGestureRecognizer *gesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(msgTransHandleLongPressGestures:)];
        gesture.minimumPressDuration= 0.5f;
        [_msgTransLabelBgView addGestureRecognizer:gesture];
        [self.contentView addSubview:_msgTransLabelBgView];
    }
    return _msgTransLabelBgView;
}
//如何学习ChatGPT开发
- (UIImageView *)msgHeaderView {
    if (!_msgHeaderView) {
        _msgHeaderView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _msgHeaderView.image = ImageName(@"icon_ellipse");
        _msgHeaderView.layer.cornerRadius = 26.0f;
        _msgHeaderView.contentMode = UIViewContentModeScaleAspectFill;
        _msgHeaderView.clipsToBounds = YES;
        [self.contentView addSubview:_msgHeaderView];
    }
    return _msgHeaderView;
}

- (UIView *)mikeLabelBgView {
    if (!_mikeLabelBgView) {
        _mikeLabelBgView = [[UIView alloc] initWithFrame:CGRectZero];
        _mikeLabelBgView.backgroundColor = SLColor(@"#448AF7");
        _mikeLabelBgView.clipsToBounds = YES;
        UILongPressGestureRecognizer *gesture=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(mikeHandleLongPressGestures:)];
        gesture.minimumPressDuration= 0.5f;
        [_mikeLabelBgView addGestureRecognizer:gesture];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(mikeHandleTap:)];
        [_mikeLabelBgView addGestureRecognizer:tap];
        [self.contentView addSubview:_mikeLabelBgView];
    }
    return _mikeLabelBgView;
}

- (UIImageView *)mikeImageView {
    if (!_mikeImageView) {
        _mikeImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _mikeImageView.image = ImageName(@"icon_msg_yy");
        _mikeImageView.userInteractionEnabled = YES;
        [self.mikeLabelBgView addSubview:_mikeImageView];
    }
    return _mikeImageView;
}

- (UILabel *)mikeLabel
{
    if (!_mikeLabel) {
        _mikeLabel = [[UILabel alloc] init];
        _mikeLabel.text = @"30″";
        _mikeLabel.textAlignment = NSTextAlignmentRight;
        _mikeLabel.numberOfLines = 0;
        _mikeLabel.textColor = [UIColor whiteColor];
        _mikeLabel.font = [UIFont systemFontOfSize:17];
        _mikeLabel.userInteractionEnabled = YES;
        [self.mikeLabelBgView addSubview:_mikeLabel];
    }
    return _mikeLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.textAlignment = NSTextAlignmentCenter;
        _timeLabel.textColor = [UIColor colorFormString:@"#3C3C43"];
        _timeLabel.font = [UIFont systemFontOfSize:11];
        [self.contentView addSubview:_timeLabel];
    }
    return _timeLabel;
}

- (UIImageView *)sendFailImageView {
    if (!_sendFailImageView) {
        _sendFailImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
        _sendFailImageView.image = ImageName(@"icon_sendFail");
        WS(weakSelf);
        [_sendFailImageView addTapWithBlock:^{
            SLMikeSegmentModel *model = [SLMikeSegmentModel initWithSegTitle:@"重发" segImage:@"" mikeType:SLMsgRepeat];
            if (weakSelf.segmentBlock) {
                weakSelf.segmentBlock(model);
            }
        }];
        [self.contentView addSubview:_sendFailImageView];
    }
    return _sendFailImageView;
}

@end
