

#import "CheckViewController.h"
#import "Press.h"
#import "VowelWrittenAttitudeWorkoutsSpecialFriction.h"
#import "ObserversThickSmileSerifCalorie.h"
#import "CubePosterConfig.h"

@interface CheckViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) VowelWrittenAttitudeWorkoutsSpecialFriction *gallonsZeroRaceRetainInside;
@property (nonatomic, strong) ObserversThickSmileSerifCalorie *twoUnderRefreshedMediaWalk;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static ObserversThickSmileSerifCalorie *requiringPastIslamicGainCropBayer = nil;
static VowelWrittenAttitudeWorkoutsSpecialFriction *repliesLongitudeObserversExactMinRectified = nil;

@implementation CheckViewController

+ (void)curlNodeMan {
    
    [Press verifyCustomParagraphCivilAnchorsSedentary];

    repliesLongitudeObserversExactMinRectified = [[VowelWrittenAttitudeWorkoutsSpecialFriction alloc] init];
    repliesLongitudeObserversExactMinRectified.searchLevel = RomanMileRetriedReturningConclude;

    [Press hardAuthorMakeLowerSquare:repliesLongitudeObserversExactMinRectified];

    requiringPastIslamicGainCropBayer = [[ObserversThickSmileSerifCalorie alloc] init];
    requiringPastIslamicGainCropBayer.searchLevel = ForScopeBuild;
    requiringPastIslamicGainCropBayer.handoff = 7;
    requiringPastIslamicGainCropBayer.minHardConvertedLogRet = YES;
    [Press hardAuthorMakeLowerSquare:requiringPastIslamicGainCropBayer];

    [requiringPastIslamicGainCropBayer bitOffHeavyAll];
}

+ (ObserversThickSmileSerifCalorie *)haveKilobitsSandboxAmpereLoseHard {
    return requiringPastIslamicGainCropBayer;
}
+ (VowelWrittenAttitudeWorkoutsSpecialFriction *)topSugarPutOvulationQuietNet {
    return repliesLongitudeObserversExactMinRectified;
}

- (VowelWrittenAttitudeWorkoutsSpecialFriction *)gallonsZeroRaceRetainInside {
    return repliesLongitudeObserversExactMinRectified;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = eraWasMiles.everyStereoSupportSwitchErrorPoint;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(youRopeAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(matchAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(fairBinFaxAction)]
    ];
    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.twoUnderRefreshedMediaWalk = [CheckViewController haveKilobitsSandboxAmpereLoseHard];

    [self hexPanel];
}

- (void)hexPanel {
    if (!self.twoUnderRefreshedMediaWalk) {
        _textView.text = eraWasMiles.lossSomaliPlaceMakeCombiningHover;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.twoUnderRefreshedMediaWalk flipMathDidDate:self.selectedDate];
        } else {
            logs = [self.twoUnderRefreshedMediaWalk helperStale];
        }

        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 = eraWasMiles.mantissaEraThicknessHandoverProducingPrevious;
            }

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

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

- (void)youRopeAction {
    [self hexPanel];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *golfDepth = [[NSDateFormatter alloc] init];
        golfDepth.dateFormat = eraWasMiles.vowelHandoffSkipFlashSelectorsLocatorAudible;
        NSString *gravityBed = [golfDepth stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = eraWasMiles.thiaminFunCertProblemIcelandicEldest;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = eraWasMiles.mildPrematureCursorPanoramaHaveTitleHex;
        } else {
            self.title = gravityBed;
        }
    } else {
        self.title = eraWasMiles.airOpticalContainedGaspTaggerCap;
    }
}

- (void)fairBinFaxAction {
    if (!self.twoUnderRefreshedMediaWalk) {
        return;
    }

    NSArray<NSDate *> *forkUnsafeShot = [self.twoUnderRefreshedMediaWalk plainSumAny];
    if (forkUnsafeShot.count == 0) {
        UIAlertController *agent = [UIAlertController alertControllerWithTitle:eraWasMiles.forkIncorrectBloodDeletingFourHectares
                                                                       message:eraWasMiles.mantissaEraThicknessHandoverProducingPrevious
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [agent addAction:[UIAlertAction actionWithTitle:eraWasMiles.waistSwapPinchYetFailureTry style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:agent animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:eraWasMiles.stringAdaptiveTabRevealedUnboundedDistortedTwist
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:eraWasMiles.airOpticalContainedGaspTaggerCap
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self hexPanel];
    }]];

    NSDateFormatter *golfDepth = [[NSDateFormatter alloc] init];
    golfDepth.dateFormat = eraWasMiles.vowelHandoffSkipFlashSelectorsLocatorAudible;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in forkUnsafeShot) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = eraWasMiles.thiaminFunCertProblemIcelandicEldest;
        } else if ([calendar isDateInYesterday:date]) {
            title = eraWasMiles.mildPrematureCursorPanoramaHaveTitleHex;
        } else {
            title = [golfDepth stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:eraWasMiles.veryRemembersMegabytesPrefersOtherSupply style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)matchAction {
    if (!self.twoUnderRefreshedMediaWalk) {
        return;
    }

    NSArray *batchSaw = [self.twoUnderRefreshedMediaWalk splatFixAnd];
    if (batchSaw.count == 0) {
        UIAlertController *agent = [UIAlertController alertControllerWithTitle:eraWasMiles.forkIncorrectBloodDeletingFourHectares
                                                                       message:eraWasMiles.priorShowStartCloseVarianceCompleted
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [agent addAction:[UIAlertAction actionWithTitle:eraWasMiles.waistSwapPinchYetFailureTry style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:agent animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:eraWasMiles.didJouleCharacterItsIslamicDefineHas
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:eraWasMiles.hasEpsilonDeliverTextCountryWayWorkflow
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self ignoreDecide];
    }]];

    for (NSURL *fileURL in batchSaw) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:eraWasMiles.bestMusicMostOrdinalSearchPublicProcesses, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self systolicFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:eraWasMiles.veryRemembersMegabytesPrefersOtherSupply style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)ignoreDecide {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *badHeap = [self.twoUnderRefreshedMediaWalk vignetteCourse];

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

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

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

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

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

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

@end
