

#import "NoiseViewController.h"
#import "Bleed.h"
#import "ShiftFigurePlugDiscardsSuitableCompact.h"
#import "SecurityOvulationAgeTrailingPut.h"
#import "RestWhoEarConfig.h"

@interface NoiseViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) ShiftFigurePlugDiscardsSuitableCompact *swedishBlinkAsleepFlexibleHelp;
@property (nonatomic, strong) SecurityOvulationAgeTrailingPut *unpluggedZeroArterySubsetBurmese;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static SecurityOvulationAgeTrailingPut *leapBasicLatitudeKindExceptionAppend = nil;
static ShiftFigurePlugDiscardsSuitableCompact *presetEndProceedFilteringSystolicCut = nil;

@implementation NoiseViewController

+ (void)persistGolf {
    
    [Bleed hourCircularHelloSchemeIndianFavorite];

    presetEndProceedFilteringSystolicCut = [[ShiftFigurePlugDiscardsSuitableCompact alloc] init];
    presetEndProceedFilteringSystolicCut.resignLevel = TimeBookmarkSuddenKinPolicy;

    [Bleed sawSlashReferentOverhangSense:presetEndProceedFilteringSystolicCut];

    leapBasicLatitudeKindExceptionAppend = [[SecurityOvulationAgeTrailingPut alloc] init];
    leapBasicLatitudeKindExceptionAppend.resignLevel = DistanceTrial;
    leapBasicLatitudeKindExceptionAppend.license = 7;
    leapBasicLatitudeKindExceptionAppend.esperantoMouthPresetBusCap = YES;
    [Bleed sawSlashReferentOverhangSense:leapBasicLatitudeKindExceptionAppend];

    [leapBasicLatitudeKindExceptionAppend siteDidCurlUse];
}

+ (SecurityOvulationAgeTrailingPut *)placementSatisfiedIncrementStillLegibleSender {
    return leapBasicLatitudeKindExceptionAppend;
}
+ (ShiftFigurePlugDiscardsSuitableCompact *)swahiliSegueReduceKilowattOfferSubtitles {
    return presetEndProceedFilteringSystolicCut;
}

- (ShiftFigurePlugDiscardsSuitableCompact *)swedishBlinkAsleepFlexibleHelp {
    return presetEndProceedFilteringSystolicCut;
}

+ (void)preventsViewController:(UIViewController *)parentVC {
    NoiseViewController *spine = [[NoiseViewController alloc] init];
    UINavigationController *how = [[UINavigationController alloc] initWithRootViewController:spine];
    how.modalPresentationStyle = UIModalPresentationFullScreen;
    [parentVC presentViewController:how animated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = awayEntropy.impliedBarCatalystStrideSameSerial;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(songDueAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(earlyAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(carInvitedAction)]
    ];
    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.unpluggedZeroArterySubsetBurmese = [NoiseViewController placementSatisfiedIncrementStillLegibleSender];

    [self thatHost];
}

- (void)thatHost {
    if (!self.unpluggedZeroArterySubsetBurmese) {
        _textView.text = awayEntropy.identicalDraftMixAfterMoireResign;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.unpluggedZeroArterySubsetBurmese pongWeekdayDate:self.selectedDate];
        } else {
            logs = [self.unpluggedZeroArterySubsetBurmese yearWaxRoom];
        }

        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 = awayEntropy.tapsFunNicknameBurnPrefixTrack;
            }

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

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

- (void)songDueAction {
    [self thatHost];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *factorDog = [[NSDateFormatter alloc] init];
        factorDog.dateFormat = awayEntropy.cardBarriersDelayCleanupImpactGigahertzAre;
        NSString *splatReuse = [factorDog stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = awayEntropy.indexingDaysHandleMayNearToggle;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = awayEntropy.ageShuffleIssueFileGracefulSlopeResponds;
        } else {
            self.title = splatReuse;
        }
    } else {
        self.title = awayEntropy.useOfficialCurlThousandsSmallerReorder;
    }
}

- (void)carInvitedAction {
    if (!self.unpluggedZeroArterySubsetBurmese) {
        return;
    }

    NSArray<NSDate *> *flagBagJobZero = [self.unpluggedZeroArterySubsetBurmese napIncludes];
    if (flagBagJobZero.count == 0) {
        UIAlertController *found = [UIAlertController alertControllerWithTitle:awayEntropy.routeFemaleSoundNordicOriginsWeekend
                                                                       message:awayEntropy.tapsFunNicknameBurnPrefixTrack
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [found addAction:[UIAlertAction actionWithTitle:awayEntropy.trackingArrayExpectsYearLatvianBrowse style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:found animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:awayEntropy.tallMustUpperBoundBoxDiacriticInitial
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:awayEntropy.useOfficialCurlThousandsSmallerReorder
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self thatHost];
    }]];

    NSDateFormatter *factorDog = [[NSDateFormatter alloc] init];
    factorDog.dateFormat = awayEntropy.cardBarriersDelayCleanupImpactGigahertzAre;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in flagBagJobZero) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = awayEntropy.indexingDaysHandleMayNearToggle;
        } else if ([calendar isDateInYesterday:date]) {
            title = awayEntropy.ageShuffleIssueFileGracefulSlopeResponds;
        } else {
            title = [factorDog stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:awayEntropy.threeDitherTransferReversedDeferredConsumer style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)earlyAction {
    if (!self.unpluggedZeroArterySubsetBurmese) {
        return;
    }

    NSArray *panUsage = [self.unpluggedZeroArterySubsetBurmese lineOpenMix];
    if (panUsage.count == 0) {
        UIAlertController *found = [UIAlertController alertControllerWithTitle:awayEntropy.routeFemaleSoundNordicOriginsWeekend
                                                                       message:awayEntropy.decayMinimalEnsureSwapFilenamesScanner
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [found addAction:[UIAlertAction actionWithTitle:awayEntropy.trackingArrayExpectsYearLatvianBrowse style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:found animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:awayEntropy.typeFootballJustifiedCubeHandshakeHangYoungest
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:awayEntropy.applyChooseButterflySlashedViewAnnotatedSmallest
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self zoneDelayCar];
    }]];

    for (NSURL *fileURL in panUsage) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:awayEntropy.anchoredEarlyEchoDefineCombineFaxVisitor, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self lightNapFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:awayEntropy.threeDitherTransferReversedDeferredConsumer style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)zoneDelayCar {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *youMode = [self.unpluggedZeroArterySubsetBurmese trackSelectors];

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

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

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

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

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

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

@end
