

#import "WordIndoorView.h"
#import "DidTopHardLookCell.h"
#import "UIImageView+WebCache.h"
#import "UIView+WebCache.h"

@interface WordIndoorView ()
@property (nonatomic, strong) UIImageView *livePointOverImageView;
@end

@implementation WordIndoorView

- (void)quietCivilToneGradeFillSoftnessModel:(HeadReplyNetInfo *)model {

    NSMutableArray *space = [NSMutableArray new];
    for (int i = 0; i<model.markPanSaw; i++) {
        DidTopHardLookCell *dust = [[DidTopHardLookCell alloc]init];
        dust.jobJobObject = model.costDueNet;
        dust.channelCount = 1;
        dust.barShe = 6;
        dust.fillCityPubOld = CGFLOAT_MIN;
        CGRect handRect = [model.danceNetwork boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:model.wayExitsKindBlueMillNorth] forKey:NSFontAttributeName] context:nil];
        dust.theBendSize = CGSizeMake(handRect.size.width+8, handRect.size.height+4);
        dust.model = model;
        [space addObject:dust];
    }
    [self outLoadRuleLaw:space];
}

- (void)includingEndpointSupportsAnimatorLessSigningTabModel:(HeadReplyNetInfo *)model {
    NSString *url = model.relationsVersionFiveBoxMakerStart;

    if (url.length == 0) {
        _livePointOverImageView.hidden = YES;
        _livePointOverImageView.image = nil;
        return;
    }

    UIImageView *son = self.livePointOverImageView;
    son.hidden = NO;
    if (son.superview != self) {
        [self insertSubview:son atIndex:0];
    } else {
        [self sendSubviewToBack:son];
    }

    [son sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if (image) [self ubiquityQuietImageView:son image:image];
    }];
}

- (void)ubiquityQuietImageView:(UIImageView *)son image:(UIImage *)image {
    CGFloat width = self.bounds.size.width;
    CGFloat height = self.bounds.size.height;
    if (image.size.width > 0) {
        CGFloat callBelow = image.size.height / image.size.width * width;
        
        CGFloat textBit = (height - callBelow) * 0.5;
        son.frame = CGRectMake(0, textBit, width, callBelow);
    } else {
        son.frame = self.bounds;
    }
}

- (UIImageView *)livePointOverImageView {
    if (!_livePointOverImageView) {
        _livePointOverImageView = [[UIImageView alloc] init];
        _livePointOverImageView.contentMode = UIViewContentModeScaleToFill;
        _livePointOverImageView.userInteractionEnabled = NO;
        _livePointOverImageView.clipsToBounds = NO;
    }
    return _livePointOverImageView;
}


- (void)spellImpliedBetweenSlashedDisposeReusable {
    if (_livePointOverImageView) {
        [_livePointOverImageView sd_cancelLatestImageLoad];
        [_livePointOverImageView removeFromSuperview];
        _livePointOverImageView.image = nil;
        _livePointOverImageView = nil;
    }
}

- (void)stop {
    [super stop];
    [self spellImpliedBetweenSlashedDisposeReusable];
}

- (void)removeFromSuperview {
    [self spellImpliedBetweenSlashedDisposeReusable];
    [super removeFromSuperview];
}

@end
