

#import "QuietViewController.h"
#import "Block.h"
#import "ChannelsTenMasteringEnumerateBarSpeaking.h"
#import "AggregateQuoteAtomLocalStorm.h"
#import "FailKitEndConfig.h"

@interface QuietViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) ChannelsTenMasteringEnumerateBarSpeaking *artworkBarStayIntervalsFinger;
@property (nonatomic, strong) AggregateQuoteAtomLocalStorm *serializeSpanMakerClampedAudit;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static AggregateQuoteAtomLocalStorm *kilogramsFarsiInstallsOneGeneratorPan = nil;
static ChannelsTenMasteringEnumerateBarSpeaking *endsModelInviteJumpLaterLeave = nil;

@implementation QuietViewController

+ (void)partStepson {
    
    [Block permanentOddCanonicalHisLaunchDrag];

    endsModelInviteJumpLaterLeave = [[ChannelsTenMasteringEnumerateBarSpeaking alloc] init];
    endsModelInviteJumpLaterLeave.tryAskLevel = AnimatedFileEulerFindBit;

    [Block importantSleepPaymentsRenamingTrash:endsModelInviteJumpLaterLeave];

    kilogramsFarsiInstallsOneGeneratorPan = [[AggregateQuoteAtomLocalStorm alloc] init];
    kilogramsFarsiInstallsOneGeneratorPan.tryAskLevel = SerialFooters;
    kilogramsFarsiInstallsOneGeneratorPan.bitAway = 7;
    kilogramsFarsiInstallsOneGeneratorPan.unlockSoftwareDaysHectaresToo = YES;
    [Block importantSleepPaymentsRenamingTrash:kilogramsFarsiInstallsOneGeneratorPan];

    [kilogramsFarsiInstallsOneGeneratorPan smallRankOcean];
}

+ (AggregateQuoteAtomLocalStorm *)alignedOldLemmaCalendarLinearlyResource {
    return kilogramsFarsiInstallsOneGeneratorPan;
}
+ (ChannelsTenMasteringEnumerateBarSpeaking *)axialTargetConnectFlippedBarCup {
    return endsModelInviteJumpLaterLeave;
}

- (ChannelsTenMasteringEnumerateBarSpeaking *)artworkBarStayIntervalsFinger {
    return endsModelInviteJumpLaterLeave;
}

+ (void)showFromViewController:(UIViewController *)parentVC {
    QuietViewController *glyph = [[QuietViewController alloc] init];
    UINavigationController *won = [[UINavigationController alloc] initWithRootViewController:glyph];
    won.modalPresentationStyle = UIModalPresentationFullScreen;
    [parentVC presentViewController:won animated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = tabUploaded.irregularSamplerGallonHerExternalSplat;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
                                            initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
                                            target:self
                                            action:@selector(touchAction)];

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(silenceAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(chainAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(chainAlongAction)]
    ];
    self.navigationController.navigationBar.layoutMargins = UIEdgeInsetsMake(0, 0, 0, -10);

    _textView = [[UITextView alloc] init];
    _textView.font = [UIFont systemFontOfSize:11];
    _textView.editable = NO;
    _textView.backgroundColor = [UIColor systemBackgroundColor];
    _textView.textColor = [UIColor labelColor];
    _textView.translatesAutoresizingMaskIntoConstraints = NO;
    _textView.showsVerticalScrollIndicator = YES;
    _textView.showsHorizontalScrollIndicator = YES;
    _textView.alwaysBounceVertical = YES;
    
    _textView.scrollEnabled = YES;
    [self.view addSubview:_textView];

    [NSLayoutConstraint activateConstraints:@[
        [_textView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor],
        [_textView.leadingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.leadingAnchor constant:8],
        [_textView.trailingAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor constant:-8],
        [_textView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
    ]];

    self.serializeSpanMakerClampedAudit = [QuietViewController alignedOldLemmaCalendarLinearlyResource];

    [self forkItem];
}

- (void)forkItem {
    if (!self.serializeSpanMakerClampedAudit) {
        _textView.text = tabUploaded.invitedAgreementMediaGreatDetachCentered;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.serializeSpanMakerClampedAudit fiveCapableDate:self.selectedDate];
        } else {
            logs = [self.serializeSpanMakerClampedAudit millPairBad];
        }

        dispatch_async(dispatch_get_main_queue(), ^{
            if (logs.length > 0) {
                self.textView.text = logs;
                
                [self.textView scrollRangeToVisible:NSMakeRange(logs.length - 1, 1)];
            } else {
                self.textView.text = tabUploaded.tenLowerWetAlternateRollPretty;
            }

            [self updateTitle];
        });
    });
}

- (void)touchAction {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)silenceAction {
    [self forkItem];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *learnRing = [[NSDateFormatter alloc] init];
        learnRing.dateFormat = tabUploaded.bondShakeEggStandForwardDomainsHourly;
        NSString *tooNominal = [learnRing stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = tabUploaded.displaysConstantSpeakStableModernDiscovery;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = tabUploaded.kindCounterArtsRemembersVisibleCapturingOxygen;
        } else {
            self.title = tooNominal;
        }
    } else {
        self.title = tabUploaded.learnNetworkIcyChromaticTabularNotation;
    }
}

- (void)chainAlongAction {
    if (!self.serializeSpanMakerClampedAudit) {
        return;
    }

    NSArray<NSDate *> *eyeCutFilmWalk = [self.serializeSpanMakerClampedAudit policyMight];
    if (eyeCutFilmWalk.count == 0) {
        UIAlertController *space = [UIAlertController alertControllerWithTitle:tabUploaded.exactDenseCloseTryTerminalRear
                                                                       message:tabUploaded.tenLowerWetAlternateRollPretty
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [space addAction:[UIAlertAction actionWithTitle:tabUploaded.mayFunCosmicBypassOverlapFun style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:space animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:tabUploaded.golfNetResponseParentalWayDaysPassword
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:tabUploaded.learnNetworkIcyChromaticTabularNotation
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self forkItem];
    }]];

    NSDateFormatter *learnRing = [[NSDateFormatter alloc] init];
    learnRing.dateFormat = tabUploaded.bondShakeEggStandForwardDomainsHourly;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in eyeCutFilmWalk) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = tabUploaded.displaysConstantSpeakStableModernDiscovery;
        } else if ([calendar isDateInYesterday:date]) {
            title = tabUploaded.kindCounterArtsRemembersVisibleCapturingOxygen;
        } else {
            title = [learnRing stringFromDate:date];
        }

        [actionSheet addAction:[UIAlertAction actionWithTitle:title
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            self.selectedDate = date;
            [self forkItem];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:tabUploaded.tipGrantingInsertingPulseShipmentHas style:UIAlertActionStyleCancel handler:nil]];

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        actionSheet.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItems.lastObject;
    }

    [self presentViewController:actionSheet animated:YES completion:nil];
}

- (void)chainAction {
    if (!self.serializeSpanMakerClampedAudit) {
        return;
    }

    NSArray *wayRatio = [self.serializeSpanMakerClampedAudit funWaxChina];
    if (wayRatio.count == 0) {
        UIAlertController *space = [UIAlertController alertControllerWithTitle:tabUploaded.exactDenseCloseTryTerminalRear
                                                                       message:tabUploaded.bestHasAdverbStalledFrenchBlob
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [space addAction:[UIAlertAction actionWithTitle:tabUploaded.mayFunCosmicBypassOverlapFun style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:space animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:tabUploaded.icySyntaxSawRemoteOutBadgeOrdered
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:tabUploaded.outMixerHalfDecisionAnimationLongitudeUtilities
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self cookieTenRed];
    }]];

    for (NSURL *fileURL in wayRatio) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:tabUploaded.trackMinorBlindingFootersCentralRefreshedCube, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self bandLeftFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:tabUploaded.tipGrantingInsertingPulseShipmentHas style:UIAlertActionStyleCancel handler:nil]];

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        actionSheet.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItems.lastObject;
    }

    [self presentViewController:actionSheet animated:YES completion:nil];
}

- (void)cookieTenRed {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *descent = [self.serializeSpanMakerClampedAudit carScenePopOne];

        dispatch_async(dispatch_get_main_queue(), ^{
            if (descent.length > 0) {
                UIActivityViewController *maskFunWay = [[UIActivityViewController alloc]
                                                       initWithActivityItems:@[descent]
                                                       applicationActivities:nil];

                if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
                    maskFunWay.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItems.lastObject;
                }

                [self presentViewController:maskFunWay animated:YES completion:nil];
            }
        });
    });
}

- (void)bandLeftFile:(NSURL *)fileURL {
    UIActivityViewController *maskFunWay = [[UIActivityViewController alloc]
                                           initWithActivityItems:@[fileURL]
                                           applicationActivities:nil];

    if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
        maskFunWay.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItems.lastObject;
    }

    [self presentViewController:maskFunWay animated:YES completion:nil];
}

@end
