//
//  TourSearchOptionCell.m
//  TakeTours
//
//  Created by Vae on 2019/3/5.
//

#import "TourSearchOptionCell.h"
#import "Lang.h"
#import "CocoaUtils.h"
#import "AllConfig.h"

@interface TourSearchOptionCell()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;
@property (weak, nonatomic) IBOutlet UILabel *optionTitleLabel;
@property (weak, nonatomic) IBOutlet UILabel *optionContentLabel;
@property (weak, nonatomic) IBOutlet UILabel *optionErrorLabel;
@end

@implementation TourSearchOptionCell

- (void)awakeFromNib {
    [super awakeFromNib];
	self.optionErrorLabel.hidden = YES;
	self.optionContentLabel.hidden = YES;
	
	self.optionTitleLabel.font = [UIFont systemFontOfSize:16];
	self.optionContentLabel.font = [UIFont systemFontOfSize:16];
	self.optionErrorLabel.font = [UIFont systemFontOfSize:12];
	
	self.optionTitleLabel.textColor = [CocoaUtils colorWithRGBs:0x999999];
	self.optionContentLabel.textColor = [CocoaUtils colorWithRGBs:0x333333];
	self.optionErrorLabel.textColor = [CocoaUtils colorWithRGBs:StandardColorOrange];
	
}

-(void)setTitleText:(NSString *)titleText{
	_titleText = titleText;
	self.optionTitleLabel.text = _titleText;
	[self changeTopAndBottomConstraintValue];
}

-(void)setContentText:(NSString *)contentText{
	if ([StringUtils isEmpty:contentText]) {
		self.optionContentLabel.hidden = YES;
		return;
	}
	_contentText = contentText;
	self.optionTitleLabel.font = [UIFont systemFontOfSize:12];
	self.optionContentLabel.text = _contentText;
	self.optionErrorLabel.hidden = YES;
	self.optionContentLabel.hidden = NO;
	[self changeTopAndBottomConstraintValue];
}

- (void)setErrorText:(NSString *)errorText{
	if ([StringUtils isEmpty:errorText]) {
		self.optionErrorLabel.hidden = YES;
		return;
	}
	self.optionTitleLabel.font = [UIFont systemFontOfSize:16];
	_errorText = errorText;
	self.optionErrorLabel.text = _errorText;
	self.optionContentLabel.hidden = YES;
	self.optionErrorLabel.hidden = NO;
	[self changeTopAndBottomConstraintValue];
}

- (void)setAllowContentWrapping:(BOOL)allowContentWrapping{
	_allowContentWrapping = allowContentWrapping;
	if (allowContentWrapping) {
		self.optionContentLabel.numberOfLines = 0;
	}else{
		self.optionContentLabel.numberOfLines = 1;
	}
}

-(void)changeTopAndBottomConstraintValue{
	if ([self.optionErrorLabel isHidden] && [self.optionContentLabel isHidden]) {
		self.topConstraint.constant = 15;
		self.topConstraint.constant = 15;
	}else{
		self.topConstraint.constant = 10;
		self.bottomConstraint.constant = 10;
	}
}


@end
