

#import "ClusterPenView.h"
#import "HueThinDustPanCell.h"
#import "UIImageView+WebCache.h"
#import "UIView+WebCache.h"

@interface ClusterPenView ()
@property (nonatomic, strong) UIImageView *netAllCreditsImageView;
@end

@implementation ClusterPenView

- (void)stretchLighterQuoteSkippedStylizeLawModel:(OpenSubLocalInfo *)model {

    NSMutableArray *began = [NSMutableArray new];
    for (int i = 0; i<model.overlayAge; i++) {
        HueThinDustPanCell *arts = [[HueThinDustPanCell alloc]init];
        arts.pageWatchBar = model.planeInset;
        arts.channelCount = 1;
        arts.didFor = 6;
        arts.applyLawManSub = CGFLOAT_MIN;
        CGRect swapRect = [model.focalWatched boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:model.clientsOrdinarySessionWorkoutEntropyDay] forKey:NSFontAttributeName] context:nil];
        arts.nameTopSize = CGSizeMake(swapRect.size.width+8, swapRect.size.height+4);
        arts.model = model;
        [began addObject:arts];
    }
    [self currentlyUpper:began];
}

- (void)collisionAdjustsSlovakEffectFixingPetabytesTypeModel:(OpenSubLocalInfo *)model {
    NSString *url = model.callingMomentaryAnimatedRenewCocoaMillion;

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

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

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

- (void)molePortSolveImageView:(UIImageView *)was image:(UIImage *)image {
    CGFloat width = self.bounds.size.width;
    CGFloat height = self.bounds.size.height;
    if (image.size.width > 0) {
        CGFloat gaspScale = image.size.height / image.size.width * width;
        
        CGFloat cutBusy = (height - gaspScale) * 0.5;
        was.frame = CGRectMake(0, cutBusy, width, gaspScale);
    } else {
        was.frame = self.bounds;
    }
}

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


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

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

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

@end
