

#import "RelayViewController.h"
#import "Power.h"
#import "SpecificIdlePersistGradePreventedReject.h"
#import "MenTrySwitchLeftoverMark.h"
#import "WorkAreWasConfig.h"

@interface RelayViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) SpecificIdlePersistGradePreventedReject *andMoreScaleDistanceAdvanced;
@property (nonatomic, strong) MenTrySwitchLeftoverMark *indexesSinkStepsonFeaturesIncrease;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static MenTrySwitchLeftoverMark *easyRotateSwitchRoleThumbnailSequencer = nil;
static SpecificIdlePersistGradePreventedReject *flippedAscendedTransferTapBlueElastic = nil;

@implementation RelayViewController

+ (void)polarSobFat {
    
    [Power reversingWonAnchoringGuideIllAudit];

    flippedAscendedTransferTapBlueElastic = [[SpecificIdlePersistGradePreventedReject alloc] init];
    flippedAscendedTransferTapBlueElastic.polishLevel = OldPacketTwoAlpineAge;

    [Power whileHyphensStrictPlainOwnership:flippedAscendedTransferTapBlueElastic];

    easyRotateSwitchRoleThumbnailSequencer = [[MenTrySwitchLeftoverMark alloc] init];
    easyRotateSwitchRoleThumbnailSequencer.polishLevel = SixDroppedDid;
    easyRotateSwitchRoleThumbnailSequencer.tryKeep = 7;
    easyRotateSwitchRoleThumbnailSequencer.looperQuoteVolumesNoticeAdd = YES;
    [Power whileHyphensStrictPlainOwnership:easyRotateSwitchRoleThumbnailSequencer];

    [easyRotateSwitchRoleThumbnailSequencer mustGainKeyHex];
}

+ (MenTrySwitchLeftoverMark *)barAxesSexPaletteRuleAspect {
    return easyRotateSwitchRoleThumbnailSequencer;
}
+ (SpecificIdlePersistGradePreventedReject *)sparseBirthFileCentralsPermanentCentral {
    return flippedAscendedTransferTapBlueElastic;
}

- (SpecificIdlePersistGradePreventedReject *)andMoreScaleDistanceAdvanced {
    return flippedAscendedTransferTapBlueElastic;
}

+ (void)decayCapViewController:(UIViewController *)parentVC {
    RelayViewController *tatar = [[RelayViewController alloc] init];
    UINavigationController *ask = [[UINavigationController alloc] initWithRootViewController:tatar];
    ask.modalPresentationStyle = UIModalPresentationFullScreen;
    [parentVC presentViewController:ask animated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = goalSubDrop.ourSingleDividingFaeroeseCanResizing;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(nowDenyAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(shareAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(eggFocusesAction)]
    ];
    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.indexesSinkStepsonFeaturesIncrease = [RelayViewController barAxesSexPaletteRuleAspect];

    [self inferYet];
}

- (void)inferYet {
    if (!self.indexesSinkStepsonFeaturesIncrease) {
        _textView.text = goalSubDrop.exemplarIdiomPortRadiansBiotinPolo;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.indexesSinkStepsonFeaturesIncrease yetBoldHalfDate:self.selectedDate];
        } else {
            logs = [self.indexesSinkStepsonFeaturesIncrease withPackets];
        }

        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 = goalSubDrop.closeTryScoreMattingIntroLoss;
            }

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

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

- (void)nowDenyAction {
    [self inferYet];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *penIodine = [[NSDateFormatter alloc] init];
        penIodine.dateFormat = goalSubDrop.snapMenThinCanMasterGrantedFix;
        NSString *dateString = [penIodine stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = goalSubDrop.senderShrinkEncodedSubmitSlavicStale;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = goalSubDrop.permutePostalPointerProcedureBalticAgeMicro;
        } else {
            self.title = dateString;
        }
    } else {
        self.title = goalSubDrop.useHeadphoneDeviationRemotelyAlbanianAtom;
    }
}

- (void)eggFocusesAction {
    if (!self.indexesSinkStepsonFeaturesIncrease) {
        return;
    }

    NSArray<NSDate *> *dogHallFindSin = [self.indexesSinkStepsonFeaturesIncrease chineseSock];
    if (dogHallFindSin.count == 0) {
        UIAlertController *entry = [UIAlertController alertControllerWithTitle:goalSubDrop.thousandsTruncatesDitherBeginBasquePink
                                                                       message:goalSubDrop.closeTryScoreMattingIntroLoss
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [entry addAction:[UIAlertAction actionWithTitle:goalSubDrop.containedFocusingYellowEnterAdoptPen style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:entry animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:goalSubDrop.perfusionOfferWhiteMeasuredBedArmSex
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:goalSubDrop.useHeadphoneDeviationRemotelyAlbanianAtom
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self inferYet];
    }]];

    NSDateFormatter *penIodine = [[NSDateFormatter alloc] init];
    penIodine.dateFormat = goalSubDrop.snapMenThinCanMasterGrantedFix;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in dogHallFindSin) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = goalSubDrop.senderShrinkEncodedSubmitSlavicStale;
        } else if ([calendar isDateInYesterday:date]) {
            title = goalSubDrop.permutePostalPointerProcedureBalticAgeMicro;
        } else {
            title = [penIodine stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:goalSubDrop.nearbyPanFourPreserveBagReusable style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)shareAction {
    if (!self.indexesSinkStepsonFeaturesIncrease) {
        return;
    }

    NSArray *bitSolve = [self.indexesSinkStepsonFeaturesIncrease lockContent];
    if (bitSolve.count == 0) {
        UIAlertController *entry = [UIAlertController alertControllerWithTitle:goalSubDrop.thousandsTruncatesDitherBeginBasquePink
                                                                       message:goalSubDrop.eachEncryptVariationExtrasRequestEffective
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [entry addAction:[UIAlertAction actionWithTitle:goalSubDrop.containedFocusingYellowEnterAdoptPen style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:entry animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:goalSubDrop.explicitUnchangedMemoryFriendItalianEstablishToo
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:goalSubDrop.permuteNumeralDryThatBiometryFaeroeseCircular
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self selectingWay];
    }]];

    for (NSURL *fileURL in bitSolve) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:goalSubDrop.winRareTriplePresentedSuccessMildSlash, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self addBlockFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:goalSubDrop.nearbyPanFourPreserveBagReusable style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)selectingWay {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *cutTaps = [self.indexesSinkStepsonFeaturesIncrease animationGreek];

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

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

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

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

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

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

@end
