

#import "BrownViewController.h"
#import "Route.h"
#import "VortexSumSequencesAffectingEscapedPositions.h"
#import "PeopleBoundingEndKeyEcho.h"
#import "ManDidWarnConfig.h"

@interface BrownViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) VortexSumSequencesAffectingEscapedPositions *disablesGradeClearMaleAnonymous;
@property (nonatomic, strong) PeopleBoundingEndKeyEcho *promptMixLockingTryRank;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static PeopleBoundingEndKeyEcho *wristMailFunReuseAdditionDone = nil;
static VortexSumSequencesAffectingEscapedPositions *muteWrappersAdjustPrincipalHueCorners = nil;

@implementation BrownViewController

+ (void)wasMoireMin {
    
    [Route deciliterRecordedLemmaRatingsClampCervical];

    muteWrappersAdjustPrincipalHueCorners = [[VortexSumSequencesAffectingEscapedPositions alloc] init];
    muteWrappersAdjustPrincipalHueCorners.fatZipLevel = BankPanRetryAnonymousEncoded;

    [Route driveQualifiedGracefulBuffersNumeric:muteWrappersAdjustPrincipalHueCorners];

    wristMailFunReuseAdditionDone = [[PeopleBoundingEndKeyEcho alloc] init];
    wristMailFunReuseAdditionDone.fatZipLevel = OurBusMeasure;
    wristMailFunReuseAdditionDone.decibel = 7;
    wristMailFunReuseAdditionDone.collapsedAlbanianRecentlyIdiomCheckout = YES;
    [Route driveQualifiedGracefulBuffersNumeric:wristMailFunReuseAdditionDone];

    [wristMailFunReuseAdditionDone wasDryRunStore];
}

+ (PeopleBoundingEndKeyEcho *)issueForwardAllocateStoppedSurfaceDigest {
    return wristMailFunReuseAdditionDone;
}
+ (VortexSumSequencesAffectingEscapedPositions *)escapesConsumedExpiredHyphensBeatMin {
    return muteWrappersAdjustPrincipalHueCorners;
}

- (VortexSumSequencesAffectingEscapedPositions *)disablesGradeClearMaleAnonymous {
    return muteWrappersAdjustPrincipalHueCorners;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = badgeRunIts.clinicalAchievedTruncateAsleepHasLate;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(artLossAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(miterAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(willBundleAction)]
    ];
    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.promptMixLockingTryRank = [BrownViewController issueForwardAllocateStoppedSurfaceDigest];

    [self mainUnit];
}

- (void)mainUnit {
    if (!self.promptMixLockingTryRank) {
        _textView.text = badgeRunIts.moodPivotPatternFallbackHangOldest;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.promptMixLockingTryRank putFallbackDate:self.selectedDate];
        } else {
            logs = [self.promptMixLockingTryRank ageTraverse];
        }

        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 = badgeRunIts.muteNetRotorYearsBrokenExpecting;
            }

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

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

- (void)artLossAction {
    [self mainUnit];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *flightDry = [[NSDateFormatter alloc] init];
        flightDry.dateFormat = badgeRunIts.encryptAcquirePinkSoftballBundlesSigmaChunk;
        NSString *markDirect = [flightDry stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = badgeRunIts.zipWayWarpParticleSubRoom;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = badgeRunIts.ropeEmailBendRemoveRegionsIcelandicGuide;
        } else {
            self.title = markDirect;
        }
    } else {
        self.title = badgeRunIts.beganRawIconDirectRestPitch;
    }
}

- (void)willBundleAction {
    if (!self.promptMixLockingTryRank) {
        return;
    }

    NSArray<NSDate *> *takeFatUsedTry = [self.promptMixLockingTryRank ourBriefRun];
    if (takeFatUsedTry.count == 0) {
        UIAlertController *stack = [UIAlertController alertControllerWithTitle:badgeRunIts.adverbStrokeBookmarkMattingIntegralPortion
                                                                       message:badgeRunIts.muteNetRotorYearsBrokenExpecting
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [stack addAction:[UIAlertAction actionWithTitle:badgeRunIts.overPutEndpointsCervicalCardGrow style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:stack animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:badgeRunIts.blinkDecayDogUtilitiesEggStyleDone
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:badgeRunIts.beganRawIconDirectRestPitch
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self mainUnit];
    }]];

    NSDateFormatter *flightDry = [[NSDateFormatter alloc] init];
    flightDry.dateFormat = badgeRunIts.encryptAcquirePinkSoftballBundlesSigmaChunk;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in takeFatUsedTry) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = badgeRunIts.zipWayWarpParticleSubRoom;
        } else if ([calendar isDateInYesterday:date]) {
            title = badgeRunIts.ropeEmailBendRemoveRegionsIcelandicGuide;
        } else {
            title = [flightDry stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:badgeRunIts.separateCoalescedAbortedUsedIterateMolar style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)miterAction {
    if (!self.promptMixLockingTryRank) {
        return;
    }

    NSArray *playFree = [self.promptMixLockingTryRank sunPlaceEar];
    if (playFree.count == 0) {
        UIAlertController *stack = [UIAlertController alertControllerWithTitle:badgeRunIts.adverbStrokeBookmarkMattingIntegralPortion
                                                                       message:badgeRunIts.pageAdvisoryOptWarningCharacterDescend
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [stack addAction:[UIAlertAction actionWithTitle:badgeRunIts.overPutEndpointsCervicalCardGrow style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:stack animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:badgeRunIts.sigmoidUbiquityCommentAvailSlopePrintDetail
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:badgeRunIts.estonianCalorieAddressesTexturedAddressPlacementInternet
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self intervalWarp];
    }]];

    for (NSURL *fileURL in playFree) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:badgeRunIts.looseMarkScriptIconFadeExportedSpeakers, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self peakBankFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:badgeRunIts.separateCoalescedAbortedUsedIterateMolar style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)intervalWarp {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *awayFar = [self.promptMixLockingTryRank suchTildeMoire];

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

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

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

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

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

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

@end
