

#import "UnifyViewController.h"
#import "Title.h"
#import "ProtocolsHerMonitoredWhoNowGujarati.h"
#import "DetachingCostRenderLandmarkBusy.h"
#import "WasDaysOptConfig.h"

@interface UnifyViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) ProtocolsHerMonitoredWhoNowGujarati *localesStopStartupIntensityThreads;
@property (nonatomic, strong) DetachingCostRenderLandmarkBusy *peakPushThreadsCommentDate;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static DetachingCostRenderLandmarkBusy *colorGetEightLawSevenTake = nil;
static ProtocolsHerMonitoredWhoNowGujarati *eraFocalTeaspoonsDriveTriggerBefore = nil;

@implementation UnifyViewController

+ (void)bookOverdue {
    
    [Title faxClearedFamilyLightenBlockFootball];

    eraFocalTeaspoonsDriveTriggerBefore = [[ProtocolsHerMonitoredWhoNowGujarati alloc] init];
    eraFocalTeaspoonsDriveTriggerBefore.squashLevel = BleedExtentsOptPerfusionHold;

    [Title shipmentStripFitOuncesPrecise:eraFocalTeaspoonsDriveTriggerBefore];

    colorGetEightLawSevenTake = [[DetachingCostRenderLandmarkBusy alloc] init];
    colorGetEightLawSevenTake.squashLevel = TemplatePhone;
    colorGetEightLawSevenTake.spaTool = 7;
    colorGetEightLawSevenTake.actualReviewSonSpokenTatar = YES;
    [Title shipmentStripFitOuncesPrecise:colorGetEightLawSevenTake];

    [colorGetEightLawSevenTake execPintOddIts];
}

+ (DetachingCostRenderLandmarkBusy *)reachedFireGenericAndExchangeFirst {
    return colorGetEightLawSevenTake;
}
+ (ProtocolsHerMonitoredWhoNowGujarati *)enumerateManagersPrimeEligibleResetTop {
    return eraFocalTeaspoonsDriveTriggerBefore;
}

- (ProtocolsHerMonitoredWhoNowGujarati *)localesStopStartupIntensityThreads {
    return eraFocalTeaspoonsDriveTriggerBefore;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = knowDidExec.workWarningHitBlueChamberScaling;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(sameMayAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(stillAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(sobTheLiftAction)]
    ];
    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.peakPushThreadsCommentDate = [UnifyViewController reachedFireGenericAndExchangeFirst];

    [self voiceDay];
}

- (void)voiceDay {
    if (!self.peakPushThreadsCommentDate) {
        _textView.text = knowDidExec.clinicalBuilderUniversalIntegersOuncesChat;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.peakPushThreadsCommentDate laterEraFitDate:self.selectedDate];
        } else {
            logs = [self.peakPushThreadsCommentDate mailBadLook];
        }

        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 = knowDidExec.sindhiWatchedIgnoringAskFifteenStrip;
            }

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

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

- (void)sameMayAction {
    [self voiceDay];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *bloodVery = [[NSDateFormatter alloc] init];
        bloodVery.dateFormat = knowDidExec.alongSindhiHitDisablingPrepareEndpointsWorkout;
        NSString *letterPort = [bloodVery stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = knowDidExec.baseNauticalEjectFilenamesAllocatedDegrees;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = knowDidExec.officialHandlerInvalidMomentFiveGuestToo;
        } else {
            self.title = letterPort;
        }
    } else {
        self.title = knowDidExec.fixConsumerDidMoreSheCondition;
    }
}

- (void)sobTheLiftAction {
    if (!self.peakPushThreadsCommentDate) {
        return;
    }

    NSArray<NSDate *> *modifyExisting = [self.peakPushThreadsCommentDate bankMapPrep];
    if (modifyExisting.count == 0) {
        UIAlertController *yahoo = [UIAlertController alertControllerWithTitle:knowDidExec.speakersTeacherLogoStylusExtendingFour
                                                                       message:knowDidExec.sindhiWatchedIgnoringAskFifteenStrip
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [yahoo addAction:[UIAlertAction actionWithTitle:knowDidExec.assertionStoneMasterAmbienceSucceedBiometry style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:yahoo animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:knowDidExec.extrinsicUseDailyItsMagentaReleasePolicy
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:knowDidExec.fixConsumerDidMoreSheCondition
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self voiceDay];
    }]];

    NSDateFormatter *bloodVery = [[NSDateFormatter alloc] init];
    bloodVery.dateFormat = knowDidExec.alongSindhiHitDisablingPrepareEndpointsWorkout;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in modifyExisting) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = knowDidExec.baseNauticalEjectFilenamesAllocatedDegrees;
        } else if ([calendar isDateInYesterday:date]) {
            title = knowDidExec.officialHandlerInvalidMomentFiveGuestToo;
        } else {
            title = [bloodVery stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:knowDidExec.planeCatalogReservedAddHybridHer style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)stillAction {
    if (!self.peakPushThreadsCommentDate) {
        return;
    }

    NSArray *setupMax = [self.peakPushThreadsCommentDate dueGlyphOld];
    if (setupMax.count == 0) {
        UIAlertController *yahoo = [UIAlertController alertControllerWithTitle:knowDidExec.speakersTeacherLogoStylusExtendingFour
                                                                       message:knowDidExec.stampOffsetsArbitraryNetSmallEquality
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [yahoo addAction:[UIAlertAction actionWithTitle:knowDidExec.assertionStoneMasterAmbienceSucceedBiometry style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:yahoo animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:knowDidExec.napCatEntitledOptimizedFeaturesEscapeCenter
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:knowDidExec.brownSeparateHelloStorylineFreeGroupedInferiors
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self execCapRaise];
    }]];

    for (NSURL *fileURL in setupMax) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:knowDidExec.tagsGetProviderTornadoDecodingDryStair, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self notifiesFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:knowDidExec.planeCatalogReservedAddHybridHer style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)execCapRaise {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *forkKit = [self.peakPushThreadsCommentDate herStepDogSock];

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

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

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

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

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

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

@end
