

#import "SpeedCaretView.h"
#import "MagnitudeDigitCell.h"
#import "UIImageView+WebCache.h"
#import "UIView+WebCache.h"

@interface SpeedCaretView ()
@property (nonatomic, strong) UIImageView *funTopSubjectImageView;
@end

@implementation SpeedCaretView

- (void)prefersFourStringStiffnessAcceptedIllModel:(IgnoredTotalInfo *)model {

    NSMutableArray *infer = [NSMutableArray new];
    for (int i = 0; i<model.sinFreeMix; i++) {
        MagnitudeDigitCell *pace = [[MagnitudeDigitCell alloc]init];
        pace.wordCritical = model.commentWon;
        pace.channelCount = 1;
        pace.driven = 6;
        pace.eggTalkFadeTry = CGFLOAT_MIN;
        CGRect forkRect = [model.mobileOldSix boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:model.organizeExportedAttachSatisfiedNumericTwo] forKey:NSFontAttributeName] context:nil];
        pace.transitSize = CGSizeMake(forkRect.size.width+8, forkRect.size.height+4);
        pace.model = model;
        [infer addObject:pace];
    }
    [self animatorIodine:infer];
}

- (void)replacedCalendarShowInnerDecideRegionForkModel:(IgnoredTotalInfo *)model {
    NSString *url = model.discountEightLawHueCellRate;

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

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

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

- (void)mightGoalCardImageView:(UIImageView *)bag image:(UIImage *)image {
    CGFloat width = self.bounds.size.width;
    CGFloat height = self.bounds.size.height;
    if (image.size.width > 0) {
        CGFloat telephone = image.size.height / image.size.width * width;
        
        CGFloat jobLoss = (height - telephone) * 0.5;
        bag.frame = CGRectMake(0, jobLoss, width, telephone);
    } else {
        bag.frame = self.bounds;
    }
}

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


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

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

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

@end
