

#import "BatchViewController.h"
#import "Farsi.h"
#import "MediaDenseRejectLongerOutDid.h"
#import "SolidTildeTruncatesFrontSudden.h"
#import "IllNumbersConfig.h"

@interface BatchViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) MediaDenseRejectLongerOutDid *entityOptExhaustedHebrewFor;
@property (nonatomic, strong) SolidTildeTruncatesFrontSudden *preparingDisplaysPopoverAggregateSpring;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static SolidTildeTruncatesFrontSudden *producesSayRectumHexQualifiedDust = nil;
static MediaDenseRejectLongerOutDid *farPendingPreparingMagneticFadeBag = nil;

@implementation BatchViewController

+ (void)withRowWrap {
    
    [Farsi decrementSiteWeeklyRepairFalloffDestroy];

    farPendingPreparingMagneticFadeBag = [[MediaDenseRejectLongerOutDid alloc] init];
    farPendingPreparingMagneticFadeBag.tabGetLevel = ResponseKinCorruptPinkProposed;

    [Farsi achievedStrengthEsperantoHourlyLiteral:farPendingPreparingMagneticFadeBag];

    producesSayRectumHexQualifiedDust = [[SolidTildeTruncatesFrontSudden alloc] init];
    producesSayRectumHexQualifiedDust.tabGetLevel = KinCertRunLog;
    producesSayRectumHexQualifiedDust.artsLaw = 7;
    producesSayRectumHexQualifiedDust.middleRangeRecentPresetExecution = YES;
    [Farsi achievedStrengthEsperantoHourlyLiteral:producesSayRectumHexQualifiedDust];

    [producesSayRectumHexQualifiedDust arbiterChecked];
}

+ (SolidTildeTruncatesFrontSudden *)apertureObserverMaximumIllegalBandwidthHomepage {
    return producesSayRectumHexQualifiedDust;
}
+ (MediaDenseRejectLongerOutDid *)farthestHourProvidingGenderRetBatch {
    return farPendingPreparingMagneticFadeBag;
}

- (MediaDenseRejectLongerOutDid *)entityOptExhaustedHebrewFor {
    return farPendingPreparingMagneticFadeBag;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = notWireSign.fatSlovakFoldUnlockPopRequire;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(chapterAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(mergeAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(allowTrackAction)]
    ];
    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.preparingDisplaysPopoverAggregateSpring = [BatchViewController apertureObserverMaximumIllegalBandwidthHomepage];

    [self wristAnd];
}

- (void)wristAnd {
    if (!self.preparingDisplaysPopoverAggregateSpring) {
        _textView.text = notWireSign.icyDingbatsNetTransposeAppearsHold;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.preparingDisplaysPopoverAggregateSpring finalCloudyDate:self.selectedDate];
        } else {
            logs = [self.preparingDisplaysPopoverAggregateSpring carNapOccur];
        }

        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 = notWireSign.directoryLikeYiddishDidFootballInfinite;
            }

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

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

- (void)chapterAction {
    [self wristAnd];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *minRhythm = [[NSDateFormatter alloc] init];
        minRhythm.dateFormat = notWireSign.indexesAdjustsCancelingPubRetChinaRoute;
        NSString *sinPaceDry = [minRhythm stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = notWireSign.minSubscriptDirtyPacketMetricLexical;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = notWireSign.shiftIndexedRowResignCollisionAcuteCloud;
        } else {
            self.title = sinPaceDry;
        }
    } else {
        self.title = notWireSign.verticalProgramMaterialVerticalHailExecutor;
    }
}

- (void)allowTrackAction {
    if (!self.preparingDisplaysPopoverAggregateSpring) {
        return;
    }

    NSArray<NSDate *> *foldMathRetain = [self.preparingDisplaysPopoverAggregateSpring justHueWalk];
    if (foldMathRetain.count == 0) {
        UIAlertController *claim = [UIAlertController alertControllerWithTitle:notWireSign.unsafeOneSeparatedObserversStretchRemotely
                                                                       message:notWireSign.directoryLikeYiddishDidFootballInfinite
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [claim addAction:[UIAlertAction actionWithTitle:notWireSign.foodSerializeDatabasesAnchorsFinishingInterval style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:claim animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:notWireSign.biotinIndianAngleWasBevelHowStarted
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:notWireSign.verticalProgramMaterialVerticalHailExecutor
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self wristAnd];
    }]];

    NSDateFormatter *minRhythm = [[NSDateFormatter alloc] init];
    minRhythm.dateFormat = notWireSign.indexesAdjustsCancelingPubRetChinaRoute;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in foldMathRetain) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = notWireSign.minSubscriptDirtyPacketMetricLexical;
        } else if ([calendar isDateInYesterday:date]) {
            title = notWireSign.shiftIndexedRowResignCollisionAcuteCloud;
        } else {
            title = [minRhythm stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:notWireSign.mismatchSelectedSexualWatchedFormattedTitle style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)mergeAction {
    if (!self.preparingDisplaysPopoverAggregateSpring) {
        return;
    }

    NSArray *meterWay = [self.preparingDisplaysPopoverAggregateSpring totalTipDay];
    if (meterWay.count == 0) {
        UIAlertController *claim = [UIAlertController alertControllerWithTitle:notWireSign.unsafeOneSeparatedObserversStretchRemotely
                                                                       message:notWireSign.hexEpsilonArtsDuctilityGuaraniPen
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [claim addAction:[UIAlertAction actionWithTitle:notWireSign.foodSerializeDatabasesAnchorsFinishingInterval style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:claim animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:notWireSign.escapePrintableTapMillNineResignTone
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:notWireSign.earlierImagePlugAlphabetMoleReleasedMagnesium
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self withRealmHas];
    }]];

    for (NSURL *fileURL in meterWay) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:notWireSign.partiallyNearestGermanPromptRenewKannadaSlovenian, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self linerSonFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:notWireSign.mismatchSelectedSexualWatchedFormattedTitle style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)withRealmHas {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *homeBig = [self.preparingDisplaysPopoverAggregateSpring absentDispense];

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

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

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

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

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

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

@end
