

#import "LearnViewController.h"
#import "Trash.h"
#import "DuctilityDayReversingFinishedBikeMercury.h"
#import "StreamUnlearnStiffnessPackHandles.h"
#import "AddButBackConfig.h"

@interface LearnViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) DuctilityDayReversingFinishedBikeMercury *cleanDutchParagraphTelephotoAttach;
@property (nonatomic, strong) StreamUnlearnStiffnessPackHandles *collectorSafariRightIdentityBanner;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static StreamUnlearnStiffnessPackHandles *visitWeeklyTwoGaspIntegralUpload = nil;
static DuctilityDayReversingFinishedBikeMercury *askReloadSerifCropCelsiusGram = nil;

@implementation LearnViewController

+ (void)goalWeekend {
    
    [Trash eventRollbackUsageWrappersScriptsTrash];

    askReloadSerifCropCelsiusGram = [[DuctilityDayReversingFinishedBikeMercury alloc] init];
    askReloadSerifCropCelsiusGram.reasonLevel = SampleJobTargetedHormoneFlow;

    [Trash arrivalFillerRetrieveFetchRecycle:askReloadSerifCropCelsiusGram];

    visitWeeklyTwoGaspIntegralUpload = [[StreamUnlearnStiffnessPackHandles alloc] init];
    visitWeeklyTwoGaspIntegralUpload.reasonLevel = InsertingFile;
    visitWeeklyTwoGaspIntegralUpload.optPint = 7;
    visitWeeklyTwoGaspIntegralUpload.ligaturesConnectDefinedAutoMid = YES;
    [Trash arrivalFillerRetrieveFetchRecycle:visitWeeklyTwoGaspIntegralUpload];

    [visitWeeklyTwoGaspIntegralUpload entriesBridged];
}

+ (StreamUnlearnStiffnessPackHandles *)cycleNiacinAskEndInteractVision {
    return visitWeeklyTwoGaspIntegralUpload;
}
+ (DuctilityDayReversingFinishedBikeMercury *)smallBirthObservePlainGreaterAssembly {
    return askReloadSerifCropCelsiusGram;
}

- (DuctilityDayReversingFinishedBikeMercury *)cleanDutchParagraphTelephotoAttach {
    return askReloadSerifCropCelsiusGram;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = inuitPenHex.scanFloatingPitchMildRootValidity;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(refusedAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(causeAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(tapArmNameAction)]
    ];
    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.collectorSafariRightIdentityBanner = [LearnViewController cycleNiacinAskEndInteractVision];

    [self roleSize];
}

- (void)roleSize {
    if (!self.collectorSafariRightIdentityBanner) {
        _textView.text = inuitPenHex.beenBatchAgeRepliesPrefersHow;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.collectorSafariRightIdentityBanner dryPeerFactDate:self.selectedDate];
        } else {
            logs = [self.collectorSafariRightIdentityBanner arteryGenre];
        }

        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 = inuitPenHex.evictPanToleranceSkipBeginningFloating;
            }

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

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

- (void)refusedAction {
    [self roleSize];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *welshTalk = [[NSDateFormatter alloc] init];
        welshTalk.dateFormat = inuitPenHex.storeFractionMinimumLooperRankedRecognizeHundred;
        NSString *reportSent = [welshTalk stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = inuitPenHex.withRealDispatchInventoryPetiteUtilities;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = inuitPenHex.encodedModeMalteseNativeSindhiNeverAutomatic;
        } else {
            self.title = reportSent;
        }
    } else {
        self.title = inuitPenHex.openTiedPersonGenderSpokenPencil;
    }
}

- (void)tapArmNameAction {
    if (!self.collectorSafariRightIdentityBanner) {
        return;
    }

    NSArray<NSDate *> *canSendEachPin = [self.collectorSafariRightIdentityBanner bagRestores];
    if (canSendEachPin.count == 0) {
        UIAlertController *solve = [UIAlertController alertControllerWithTitle:inuitPenHex.appliesExceptionKashmiriSinhaleseBuildBlue
                                                                       message:inuitPenHex.evictPanToleranceSkipBeginningFloating
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [solve addAction:[UIAlertAction actionWithTitle:inuitPenHex.peerCanChromiumMolarBestAge style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:solve animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:inuitPenHex.unableLocaleDialogPrimeRollAudioContext
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:inuitPenHex.openTiedPersonGenderSpokenPencil
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self roleSize];
    }]];

    NSDateFormatter *welshTalk = [[NSDateFormatter alloc] init];
    welshTalk.dateFormat = inuitPenHex.storeFractionMinimumLooperRankedRecognizeHundred;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in canSendEachPin) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = inuitPenHex.withRealDispatchInventoryPetiteUtilities;
        } else if ([calendar isDateInYesterday:date]) {
            title = inuitPenHex.encodedModeMalteseNativeSindhiNeverAutomatic;
        } else {
            title = [welshTalk stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:inuitPenHex.whoDistinctKilogramWonExcludedComposed style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)causeAction {
    if (!self.collectorSafariRightIdentityBanner) {
        return;
    }

    NSArray *sheDecay = [self.collectorSafariRightIdentityBanner stormWinSee];
    if (sheDecay.count == 0) {
        UIAlertController *solve = [UIAlertController alertControllerWithTitle:inuitPenHex.appliesExceptionKashmiriSinhaleseBuildBlue
                                                                       message:inuitPenHex.tooQueryPromisePanCandidateSex
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [solve addAction:[UIAlertAction actionWithTitle:inuitPenHex.peerCanChromiumMolarBestAge style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:solve animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:inuitPenHex.expiredSpecifiedCustodianThousandCousinToolAnonymous
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:inuitPenHex.catalystGoogleMainProducerAdvancesFaeroeseChanging
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self farNominally];
    }]];

    for (NSURL *fileURL in sheDecay) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:inuitPenHex.didEventPresetSheIncludingDivideWill, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self managersFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:inuitPenHex.whoDistinctKilogramWonExcludedComposed style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)farNominally {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *herTied = [self.collectorSafariRightIdentityBanner panoramasSlice];

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

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

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

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

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

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

@end
