//
//  SLMoentsChatView.m
//  SLAiELTS
//
//  Created by Gusont on 2023/4/10.
//

#import "SLMoentsChatView.h"

@interface SLMoentsChatView()

@property (nonatomic, strong) UIButton *rightSendBtn;

@property (nonatomic, strong) UIView *textBgView;

@end


@implementation SLMoentsChatView

static const NSInteger btnTag = 20000;

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

- (void)confignUI
{
    self.backgroundColor = [[UIColor colorFormString:@"#273F66"] colorWithAlphaComponent:0.3];
    [self.textBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];

    [self.rightSendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.textBgView);
        make.right.equalTo(self.textBgView.mas_right).offset(-12 * KScaleW);
        make.width.mas_equalTo(64);
        make.height.mas_equalTo(32);
    }];
    
    [self.nextGrowingTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(24);
        make.centerY.equalTo(self.textBgView).priority(500);
        make.top.greaterThanOrEqualTo(self.textBgView).offset(8).priority(1000);
        make.right.equalTo(self.rightSendBtn.mas_left).offset(-12);
    }];
}

- (void)btnClick:(UIButton *)btn
{
    switch (btn.tag - btnTag) {
        case 2:
            if (self.sendTextBlock) {
                self.sendTextBlock(self.nextGrowingTextView.textView.text);
            }
            break;
        default:
            break;
    }
}

- (UIButton *)rightSendBtn
{
    if (!_rightSendBtn) {
        _rightSendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightSendBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [_rightSendBtn setTitleColor:SL333Color forState:UIControlStateNormal];
        [_rightSendBtn setTitle:@"评论" forState:UIControlStateNormal];
        [_rightSendBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        _rightSendBtn.tag = btnTag + 2;
        [self.textBgView addSubview:_rightSendBtn];
    }
    return _rightSendBtn;
}

- (YMNextGrowingTextView *)nextGrowingTextView
{
    if (!_nextGrowingTextView) {
        _nextGrowingTextView = [[YMNextGrowingTextView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH - 160, 40)];
        _nextGrowingTextView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:1];
        _nextGrowingTextView.placeholderAttributedText = [[NSAttributedString alloc] initWithString:@"请输入关键词" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 16], NSForegroundColorAttributeName : [UIColor whiteColor]}];
        _nextGrowingTextView.layer.cornerRadius = 4.0;
        _nextGrowingTextView.maxNumberOfLines = 6;
        [self.textBgView addSubview:_nextGrowingTextView];
    }
    return _nextGrowingTextView;
}

- (UIView *)textBgView
{
    if (!_textBgView) {
        _textBgView = [[UIView alloc] initWithFrame:CGRectZero];
        [self addSubview:_textBgView];
    }
    return _textBgView;
}

@end
