//  CustomRedPacketMessageCell.m
//


#import "CustomRedPacketMessageCell.h"
#define Message_Height 147
#define Message_Width 240

@interface CustomRedPacketMessageCell()
@property (nonatomic, strong) UIImageView *imageView;
@end

@implementation CustomRedPacketMessageCell

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

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initialize];
    }
    return self;
}

- (void)initialize {
    [self showBubbleBackgroundView:YES];
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.messageContentView addSubview:self.imageView];

}

+ (CGSize)sizeForMessageModel:(RCMessageModel *)model
      withCollectionViewWidth:(CGFloat)collectionViewWidth
         referenceExtraHeight:(CGFloat)extraHeight {
    return CGSizeMake(collectionViewWidth, extraHeight + Message_Height);
}

- (void)setDataModel:(RCMessageModel *)model {
    [super setDataModel:model];
    [self setAutoLayout];
}

- (void)setAutoLayout {
    RCMessage *msg = [[RCCoreClient sharedCoreClient] getMessage:self.model.messageId];
    [self setImageViewState:msg.expansionDic];

}

- (void)setImageViewState:(NSDictionary *) expansionDic{
    CGSize bubbleBackgroundViewSize = CGSizeMake(Message_Width + 5, Message_Height + 5);
    self.imageView.frame = CGRectMake(2.5, 2.5, Message_Width, Message_Height);
    self.messageContentView.contentSize = bubbleBackgroundViewSize;
    if ([expansionDic[@"open"] isEqualToString:@"true" ]) {
        self.imageView.image = [UIImage imageNamed:@"open"];
    }
    else{
        self.imageView.image = [UIImage imageNamed:@"close"];
    }
}
@end
