

#import "AliveViewController.h"
#import "Print.h"
#import "HeavyQueryGreekNewsstandMouthFollow.h"
#import "TerabytesPortraitsTiedNonceReflect.h"
#import "DegreeNearConfig.h"

@interface AliveViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) HeavyQueryGreekNewsstandMouthFollow *eventSendMirroredThemeBold;
@property (nonatomic, strong) TerabytesPortraitsTiedNonceReflect *characterBigReturnedExecParsecs;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static TerabytesPortraitsTiedNonceReflect *itemGaspTraitTruncateOperationDevices = nil;
static HeavyQueryGreekNewsstandMouthFollow *textDiscoverSlightCapturingStrokedSeeking = nil;

@implementation AliveViewController

+ (void)mapThirdDry {
    
    [Print partAppleSpousesGoogleKilobytesAlpha];

    textDiscoverSlightCapturingStrokedSeeking = [[HeavyQueryGreekNewsstandMouthFollow alloc] init];
    textDiscoverSlightCapturingStrokedSeeking.allForLevel = ModerateReportDissolvePlaybackStack;

    [Print relayCatalystQuechuaStarItalics:textDiscoverSlightCapturingStrokedSeeking];

    itemGaspTraitTruncateOperationDevices = [[TerabytesPortraitsTiedNonceReflect alloc] init];
    itemGaspTraitTruncateOperationDevices.allForLevel = DryReplaceUse;
    itemGaspTraitTruncateOperationDevices.areRoot = 7;
    itemGaspTraitTruncateOperationDevices.preferredHighRowBothIntrinsic = YES;
    [Print relayCatalystQuechuaStarItalics:itemGaspTraitTruncateOperationDevices];

    [itemGaspTraitTruncateOperationDevices rootSinkRetain];
}

+ (TerabytesPortraitsTiedNonceReflect *)sumWrappingRankGlyphAccuracyPromised {
    return itemGaspTraitTruncateOperationDevices;
}
+ (HeavyQueryGreekNewsstandMouthFollow *)illKinAveragePhaseDueAvailable {
    return textDiscoverSlightCapturingStrokedSeeking;
}

- (HeavyQueryGreekNewsstandMouthFollow *)eventSendMirroredThemeBold {
    return textDiscoverSlightCapturingStrokedSeeking;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = awayWrapShe.hyphenDissolveTrialCloseAmbientHer;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(barEasyAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(buildAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(hangOxygenAction)]
    ];
    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.characterBigReturnedExecParsecs = [AliveViewController sumWrappingRankGlyphAccuracyPromised];

    [self pickText];
}

- (void)pickText {
    if (!self.characterBigReturnedExecParsecs) {
        _textView.text = awayWrapShe.furlongsFlashBitFocusesSparseDays;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.characterBigReturnedExecParsecs focusingTabDate:self.selectedDate];
        } else {
            logs = [self.characterBigReturnedExecParsecs closureItem];
        }

        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 = awayWrapShe.hourlyEscapesHealthSubsetOperatorSee;
            }

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

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

- (void)barEasyAction {
    [self pickText];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *loudReady = [[NSDateFormatter alloc] init];
        loudReady.dateFormat = awayWrapShe.bedLateBreakFlagLayerDiscardsApplies;
        NSString *dogDestroy = [loudReady stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = awayWrapShe.personOneSheMinuteHasClose;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = awayWrapShe.updatingPartnerLocationHourIconPrivilegeYet;
        } else {
            self.title = dogDestroy;
        }
    } else {
        self.title = awayWrapShe.tripleIllPoloCarNecessaryCity;
    }
}

- (void)hangOxygenAction {
    if (!self.characterBigReturnedExecParsecs) {
        return;
    }

    NSArray<NSDate *> *rebusHurricane = [self.characterBigReturnedExecParsecs delayOurOwn];
    if (rebusHurricane.count == 0) {
        UIAlertController *greek = [UIAlertController alertControllerWithTitle:awayWrapShe.cloudBlurStickyVitaminFarthestTable
                                                                       message:awayWrapShe.hourlyEscapesHealthSubsetOperatorSee
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [greek addAction:[UIAlertAction actionWithTitle:awayWrapShe.menstrualBypassFamilyDuePatchBed style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:greek animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:awayWrapShe.buddhistPositionReplaceObserveResumeOldFive
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:awayWrapShe.tripleIllPoloCarNecessaryCity
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self pickText];
    }]];

    NSDateFormatter *loudReady = [[NSDateFormatter alloc] init];
    loudReady.dateFormat = awayWrapShe.bedLateBreakFlagLayerDiscardsApplies;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in rebusHurricane) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = awayWrapShe.personOneSheMinuteHasClose;
        } else if ([calendar isDateInYesterday:date]) {
            title = awayWrapShe.updatingPartnerLocationHourIconPrivilegeYet;
        } else {
            title = [loudReady stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:awayWrapShe.finalizeAgreementSigningHasJustifiedOccurred style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)buildAction {
    if (!self.characterBigReturnedExecParsecs) {
        return;
    }

    NSArray *eggMight = [self.characterBigReturnedExecParsecs netCocoaBox];
    if (eggMight.count == 0) {
        UIAlertController *greek = [UIAlertController alertControllerWithTitle:awayWrapShe.cloudBlurStickyVitaminFarthestTable
                                                                       message:awayWrapShe.badFootersGallonsReturnControlsStand
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [greek addAction:[UIAlertAction actionWithTitle:awayWrapShe.menstrualBypassFamilyDuePatchBed style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:greek animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:awayWrapShe.verboseRaceMillEncodedNarrativeAchievedRegions
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:awayWrapShe.schedulerExtractKernelsForceWithLaunchingMax
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self danceEyeLate];
    }]];

    for (NSURL *fileURL in eggMight) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:awayWrapShe.routerGramCardComposeExtrinsicLikeWorkspace, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self speakCapFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:awayWrapShe.finalizeAgreementSigningHasJustifiedOccurred style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)danceEyeLate {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *seeking = [self.characterBigReturnedExecParsecs menButAnyTilde];

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

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

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

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

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

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

@end
