

#import "ElderViewController.h"
#import "Slash.h"
#import "StylizeSafeElementsExpertAbovePicture.h"
#import "UplinkLandmarkHelpersBracketedUniversal.h"
#import "PersonFillConfig.h"

@interface ElderViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) StylizeSafeElementsExpertAbovePicture *execButRemovesGenreAuxiliary;
@property (nonatomic, strong) UplinkLandmarkHelpersBracketedUniversal *recorderFoodAddressesFrontDisallow;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static UplinkLandmarkHelpersBracketedUniversal *mayBehavePatientLoadingAlongThickness = nil;
static StylizeSafeElementsExpertAbovePicture *actionsWarpKitButterflySentCompleted = nil;

@implementation ElderViewController

+ (void)idleSentLaw {
    
    [Slash memberDiscardedStrokeBufferingSnowNetwork];

    actionsWarpKitButterflySentCompleted = [[StylizeSafeElementsExpertAbovePicture alloc] init];
    actionsWarpKitButterflySentCompleted.defineLevel = CosmicAlignIndicatorRetainedFinger;

    [Slash busPeriodFunnelCustomLibrary:actionsWarpKitButterflySentCompleted];

    mayBehavePatientLoadingAlongThickness = [[UplinkLandmarkHelpersBracketedUniversal alloc] init];
    mayBehavePatientLoadingAlongThickness.defineLevel = EngineerBlack;
    mayBehavePatientLoadingAlongThickness.pubFree = 7;
    mayBehavePatientLoadingAlongThickness.boxElementsNothingOurLocalizes = YES;
    [Slash busPeriodFunnelCustomLibrary:mayBehavePatientLoadingAlongThickness];

    [mayBehavePatientLoadingAlongThickness tagPanFourYard];
}

+ (UplinkLandmarkHelpersBracketedUniversal *)blueThresholdBinaryStateCascadeProduced {
    return mayBehavePatientLoadingAlongThickness;
}
+ (StylizeSafeElementsExpertAbovePicture *)flipAdjustUseImageCategoryAirborne {
    return actionsWarpKitButterflySentCompleted;
}

- (StylizeSafeElementsExpertAbovePicture *)execButRemovesGenreAuxiliary {
    return actionsWarpKitButterflySentCompleted;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = chinaInsert.vortexAirborneWaxLaterHandlesWas;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(sunSeekAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(clickAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(airShutterAction)]
    ];
    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.recorderFoodAddressesFrontDisallow = [ElderViewController blueThresholdBinaryStateCascadeProduced];

    [self dryRound];
}

- (void)dryRound {
    if (!self.recorderFoodAddressesFrontDisallow) {
        _textView.text = chinaInsert.columnCadenceCupCursorsSwitchAway;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.recorderFoodAddressesFrontDisallow edgaBridgedDate:self.selectedDate];
        } else {
            logs = [self.recorderFoodAddressesFrontDisallow mindTextCut];
        }

        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 = chinaInsert.handlingTipHandGenericHectaresLove;
            }

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

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

- (void)sunSeekAction {
    [self dryRound];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *leaveHang = [[NSDateFormatter alloc] init];
        leaveHang.dateFormat = chinaInsert.tipSuchShoulderVersionLibraryGrowRank;
        NSString *beatAskMin = [leaveHang stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = chinaInsert.blackScanImplicitLoveBagEffect;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = chinaInsert.claimRedEitherCivilProjectsCallbackFoot;
        } else {
            self.title = beatAskMin;
        }
    } else {
        self.title = chinaInsert.productsFetchedRightWireModerateRefreshed;
    }
}

- (void)airShutterAction {
    if (!self.recorderFoodAddressesFrontDisallow) {
        return;
    }

    NSArray<NSDate *> *teluguSnapshot = [self.recorderFoodAddressesFrontDisallow mathKeyJust];
    if (teluguSnapshot.count == 0) {
        UIAlertController *setup = [UIAlertController alertControllerWithTitle:chinaInsert.targetedParticleHandlesBondBecomePick
                                                                       message:chinaInsert.handlingTipHandGenericHectaresLove
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [setup addAction:[UIAlertAction actionWithTitle:chinaInsert.patientDocumentsExposePenLongitudeAccepted style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:setup animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:chinaInsert.masteringEncodedLibrariesEdgaDecodeResolvedUpside
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:chinaInsert.productsFetchedRightWireModerateRefreshed
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self dryRound];
    }]];

    NSDateFormatter *leaveHang = [[NSDateFormatter alloc] init];
    leaveHang.dateFormat = chinaInsert.tipSuchShoulderVersionLibraryGrowRank;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in teluguSnapshot) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = chinaInsert.blackScanImplicitLoveBagEffect;
        } else if ([calendar isDateInYesterday:date]) {
            title = chinaInsert.claimRedEitherCivilProjectsCallbackFoot;
        } else {
            title = [leaveHang stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:chinaInsert.bottomSelectedModifiedCollisionLineMegabits style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)clickAction {
    if (!self.recorderFoodAddressesFrontDisallow) {
        return;
    }

    NSArray *skipFeed = [self.recorderFoodAddressesFrontDisallow ageTryRetry];
    if (skipFeed.count == 0) {
        UIAlertController *setup = [UIAlertController alertControllerWithTitle:chinaInsert.targetedParticleHandlesBondBecomePick
                                                                       message:chinaInsert.digitizedInventoryQualifiedBehaviorsWorkspaceCancelled
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [setup addAction:[UIAlertAction actionWithTitle:chinaInsert.patientDocumentsExposePenLongitudeAccepted style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:setup animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:chinaInsert.offerRequiringShowersPicturesPeerFairPrime
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:chinaInsert.countReusableStillSubjectPublishExpandedUnit
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self pulseRematch];
    }]];

    for (NSURL *fileURL in skipFeed) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:chinaInsert.distanceAllowRightRoomAbsentVisitorSkin, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self fixAngleFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:chinaInsert.bottomSelectedModifiedCollisionLineMegabits style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)pulseRematch {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *scanBit = [self.recorderFoodAddressesFrontDisallow chooseLoadPast];

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

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

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

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

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

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

@end
