

#import "EmailViewController.h"
#import "Place.h"
#import "FirmwareScoreTeacherRetQueryingTrial.h"
#import "StrokedDisorderSnowObscuresNibbles.h"
#import "BusCityWonConfig.h"

@interface EmailViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) FirmwareScoreTeacherRetQueryingTrial *posterMaterialMagentaUnchangedEra;
@property (nonatomic, strong) StrokedDisorderSnowObscuresNibbles *idiomFilenamesExporterBehaviorStop;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static StrokedDisorderSnowObscuresNibbles *handoverShareOriginTurnCarInitial = nil;
static FirmwareScoreTeacherRetQueryingTrial *blendCursorsSerifAnimatorMostlyRecognize = nil;

@implementation EmailViewController

+ (void)hueWetDaily {
    
    [Place fitEndFingerRootCountryMacintosh];

    blendCursorsSerifAnimatorMostlyRecognize = [[FirmwareScoreTeacherRetQueryingTrial alloc] init];
    blendCursorsSerifAnimatorMostlyRecognize.sexAnyLevel = DidSerbianRomanCommitPurpose;

    [Place separatedOptimizedCloseTowerReceives:blendCursorsSerifAnimatorMostlyRecognize];

    handoverShareOriginTurnCarInitial = [[StrokedDisorderSnowObscuresNibbles alloc] init];
    handoverShareOriginTurnCarInitial.sexAnyLevel = RetEscapedRaw;
    handoverShareOriginTurnCarInitial.tagNode = 7;
    handoverShareOriginTurnCarInitial.openRevertLinkageHungarianEqual = YES;
    [Place separatedOptimizedCloseTowerReceives:handoverShareOriginTurnCarInitial];

    [handoverShareOriginTurnCarInitial beganIntensity];
}

+ (StrokedDisorderSnowObscuresNibbles *)sharpnessEggAchievedSourcesGujaratiBackwards {
    return handoverShareOriginTurnCarInitial;
}
+ (FirmwareScoreTeacherRetQueryingTrial *)selectedFingerConfirmCharacterVerticalMax {
    return blendCursorsSerifAnimatorMostlyRecognize;
}

- (FirmwareScoreTeacherRetQueryingTrial *)posterMaterialMagentaUnchangedEra {
    return blendCursorsSerifAnimatorMostlyRecognize;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = playUserMan.dryThroughMacintoshPullCameraPotential;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(changedAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(pressAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(redoBinaryAction)]
    ];
    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.idiomFilenamesExporterBehaviorStop = [EmailViewController sharpnessEggAchievedSourcesGujaratiBackwards];

    [self evictBig];
}

- (void)evictBig {
    if (!self.idiomFilenamesExporterBehaviorStop) {
        _textView.text = playUserMan.applyingSeeCollectorBoyfriendLimitTransport;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.idiomFilenamesExporterBehaviorStop bookProteinDate:self.selectedDate];
        } else {
            logs = [self.idiomFilenamesExporterBehaviorStop flowThiamin];
        }

        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 = playUserMan.wayAngleYahooBurnWristStylus;
            }

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

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

- (void)changedAction {
    [self evictBig];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *fillLegal = [[NSDateFormatter alloc] init];
        fillLegal.dateFormat = playUserMan.belowSheCreditCombinedExternCapturesUsage;
        NSString *eachMaxPin = [fillLegal stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = playUserMan.faxSenseEveryPrototypeHundredSeek;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = playUserMan.putFatalNetStableBeforePingFactory;
        } else {
            self.title = eachMaxPin;
        }
    } else {
        self.title = playUserMan.yearBufferedIllegalLeaseSubtractCap;
    }
}

- (void)redoBinaryAction {
    if (!self.idiomFilenamesExporterBehaviorStop) {
        return;
    }

    NSArray<NSDate *> *talkNameCutMax = [self.idiomFilenamesExporterBehaviorStop portraitIcy];
    if (talkNameCutMax.count == 0) {
        UIAlertController *coast = [UIAlertController alertControllerWithTitle:playUserMan.deletionExclusivePrologCommentSpecifyKeep
                                                                       message:playUserMan.wayAngleYahooBurnWristStylus
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [coast addAction:[UIAlertAction actionWithTitle:playUserMan.cleanBarRedExpiresShortcutBus style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:coast animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:playUserMan.oldSelfGroupingGenreWeightsEggFlash
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:playUserMan.yearBufferedIllegalLeaseSubtractCap
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self evictBig];
    }]];

    NSDateFormatter *fillLegal = [[NSDateFormatter alloc] init];
    fillLegal.dateFormat = playUserMan.belowSheCreditCombinedExternCapturesUsage;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in talkNameCutMax) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = playUserMan.faxSenseEveryPrototypeHundredSeek;
        } else if ([calendar isDateInYesterday:date]) {
            title = playUserMan.putFatalNetStableBeforePingFactory;
        } else {
            title = [fillLegal stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:playUserMan.menBankHindiTeluguAllocateWay style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)pressAction {
    if (!self.idiomFilenamesExporterBehaviorStop) {
        return;
    }

    NSArray *axesLine = [self.idiomFilenamesExporterBehaviorStop execPinEast];
    if (axesLine.count == 0) {
        UIAlertController *coast = [UIAlertController alertControllerWithTitle:playUserMan.deletionExclusivePrologCommentSpecifyKeep
                                                                       message:playUserMan.prefixUnderlineMaterialPlayingLiterPatient
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [coast addAction:[UIAlertAction actionWithTitle:playUserMan.cleanBarRedExpiresShortcutBus style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:coast animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:playUserMan.transformInvertedBetterPrepCommitSubfamilyHusband
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:playUserMan.mountTildeKinCommentsDragPreventOffer
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self tagSecretHas];
    }]];

    for (NSURL *fileURL in axesLine) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:playUserMan.occlusionSegmentsCheckQuotesBothElementsSlope, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self producesFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:playUserMan.menBankHindiTeluguAllocateWay style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)tagSecretHas {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *liveOld = [self.idiomFilenamesExporterBehaviorStop anglePhaseMove];

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

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

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

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

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

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

@end
