

#import "BasicViewController.h"
#import "Shake.h"
#import "BadEnvelopeObservingWeightedEvaluatedNearest.h"
#import "PulseKinBitExpandedRedirect.h"
#import "MidArePlusConfig.h"

@interface BasicViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) BadEnvelopeObservingWeightedEvaluatedNearest *existCreditSeeClinicalAllergy;
@property (nonatomic, strong) PulseKinBitExpandedRedirect *stableScrollDingbatsCoalescePlane;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static PulseKinBitExpandedRedirect *greekSegmentsSenderOrangeQuitValidity = nil;
static BadEnvelopeObservingWeightedEvaluatedNearest *bendProposedUserHelloDragSpatial = nil;

@implementation BasicViewController

+ (void)notationDay {
    
    [Shake clinicalDigestClickNodeSubtractMirrored];

    bendProposedUserHelloDragSpatial = [[BadEnvelopeObservingWeightedEvaluatedNearest alloc] init];
    bendProposedUserHelloDragSpatial.weightLevel = LiteralThousandsWrittenRemembersLease;

    [Shake remembersInternetYouSpaBookmark:bendProposedUserHelloDragSpatial];

    greekSegmentsSenderOrangeQuitValidity = [[PulseKinBitExpandedRedirect alloc] init];
    greekSegmentsSenderOrangeQuitValidity.weightLevel = TremorRetried;
    greekSegmentsSenderOrangeQuitValidity.helpSaw = 7;
    greekSegmentsSenderOrangeQuitValidity.bridgedAlertModelSourcesSave = YES;
    [Shake remembersInternetYouSpaBookmark:greekSegmentsSenderOrangeQuitValidity];

    [greekSegmentsSenderOrangeQuitValidity niacinPresence];
}

+ (PulseKinBitExpandedRedirect *)scoreCorrectedMoodBatteryVortexTouch {
    return greekSegmentsSenderOrangeQuitValidity;
}
+ (BadEnvelopeObservingWeightedEvaluatedNearest *)calorieForkLinerDownloadsAutomaticStream {
    return bendProposedUserHelloDragSpatial;
}

- (BadEnvelopeObservingWeightedEvaluatedNearest *)existCreditSeeClinicalAllergy {
    return bendProposedUserHelloDragSpatial;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = latePalette.wrongShotDownhillFoodExchangesPrime;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(mustBoxAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(imageAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(zipListSheAction)]
    ];
    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.stableScrollDingbatsCoalescePlane = [BasicViewController scoreCorrectedMoodBatteryVortexTouch];

    [self halfShow];
}

- (void)halfShow {
    if (!self.stableScrollDingbatsCoalescePlane) {
        _textView.text = latePalette.curveGermanDirectlyEvictKnowNap;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.stableScrollDingbatsCoalescePlane clockRunDidDate:self.selectedDate];
        } else {
            logs = [self.stableScrollDingbatsCoalescePlane keySmallOwn];
        }

        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 = latePalette.walkMaximumHelperParagraphTeethAbout;
            }

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

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

- (void)mustBoxAction {
    [self halfShow];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *potential = [[NSDateFormatter alloc] init];
        potential.dateFormat = latePalette.indianShrinkFlatBasqueAwayStartingKnow;
        NSString *dogProject = [potential stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = latePalette.copperTabularSuspendedProvidedCoercionRetain;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = latePalette.tagGopherEngravedRevisionBleedPetabytesContinued;
        } else {
            self.title = dogProject;
        }
    } else {
        self.title = latePalette.patientHigherBigPosterIssueMartial;
    }
}

- (void)zipListSheAction {
    if (!self.stableScrollDingbatsCoalescePlane) {
        return;
    }

    NSArray<NSDate *> *reloadMutation = [self.stableScrollDingbatsCoalescePlane fixtureWait];
    if (reloadMutation.count == 0) {
        UIAlertController *exist = [UIAlertController alertControllerWithTitle:latePalette.cardFaxSoftTelephotoOrangeMoire
                                                                       message:latePalette.walkMaximumHelperParagraphTeethAbout
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [exist addAction:[UIAlertAction actionWithTitle:latePalette.prepareSleetStrideSemicolonTopDetaching style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:exist animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:latePalette.asleepShotPressedThreadedVortexProjectsFloating
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:latePalette.patientHigherBigPosterIssueMartial
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self halfShow];
    }]];

    NSDateFormatter *potential = [[NSDateFormatter alloc] init];
    potential.dateFormat = latePalette.indianShrinkFlatBasqueAwayStartingKnow;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in reloadMutation) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = latePalette.copperTabularSuspendedProvidedCoercionRetain;
        } else if ([calendar isDateInYesterday:date]) {
            title = latePalette.tagGopherEngravedRevisionBleedPetabytesContinued;
        } else {
            title = [potential stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:latePalette.additionGenreFocalAdvanceDecoderStroke style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)imageAction {
    if (!self.stableScrollDingbatsCoalescePlane) {
        return;
    }

    NSArray *longFour = [self.stableScrollDingbatsCoalescePlane winRollBond];
    if (longFour.count == 0) {
        UIAlertController *exist = [UIAlertController alertControllerWithTitle:latePalette.cardFaxSoftTelephotoOrangeMoire
                                                                       message:latePalette.hungarianAgeSatisfiedMilesExpiresUser
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [exist addAction:[UIAlertAction actionWithTitle:latePalette.prepareSleetStrideSemicolonTopDetaching style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:exist animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:latePalette.bloodGeorgianClipDublinRecyclePublisherAmpere
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:latePalette.stampFaeroeseQuoteDogPairMidSerbian
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self tapButForbid];
    }]];

    for (NSURL *fileURL in longFour) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:latePalette.exclusiveDidRuleFaxLineProvidersAge, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self pongTextFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:latePalette.additionGenreFocalAdvanceDecoderStroke style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)tapButForbid {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *spaGray = [self.stableScrollDingbatsCoalescePlane floatingNormal];

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

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

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

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

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

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

@end
