

#import "IndexViewController.h"
#import "Local.h"
#import "ConvergedArteryRevealEulerNumeralPopover.h"
#import "MessagingFlushedProxiesInfoFor.h"
#import "RangeThirdConfig.h"

@interface IndexViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) ConvergedArteryRevealEulerNumeralPopover *resignRightBalticReloadPoster;
@property (nonatomic, strong) MessagingFlushedProxiesInfoFor *externalCricketDesignerBroadcastBordered;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static MessagingFlushedProxiesInfoFor *shrinkZoomFolderHighestPaceBit = nil;
static ConvergedArteryRevealEulerNumeralPopover *taggerProducingWrappersAngleKnowSubfamily = nil;

@implementation IndexViewController

+ (void)pipeWaitPen {
    
    [Local bodyStandardRenderCountrySaturateDirectory];

    taggerProducingWrappersAngleKnowSubfamily = [[ConvergedArteryRevealEulerNumeralPopover alloc] init];
    taggerProducingWrappersAngleKnowSubfamily.eggDayLevel = TryRationalDissolveReceiptFractions;

    [Local patternsHexProxyTheConductor:taggerProducingWrappersAngleKnowSubfamily];

    shrinkZoomFolderHighestPaceBit = [[MessagingFlushedProxiesInfoFor alloc] init];
    shrinkZoomFolderHighestPaceBit.eggDayLevel = LogCacheStyle;
    shrinkZoomFolderHighestPaceBit.subRoom = 7;
    shrinkZoomFolderHighestPaceBit.describeUnlockedMusicalScrolledDiscounts = YES;
    [Local patternsHexProxyTheConductor:shrinkZoomFolderHighestPaceBit];

    [shrinkZoomFolderHighestPaceBit fontLoopsGreek];
}

+ (MessagingFlushedProxiesInfoFor *)millibarsRearrangePubEuropeanLazyLengths {
    return shrinkZoomFolderHighestPaceBit;
}
+ (ConvergedArteryRevealEulerNumeralPopover *)wakeGroupSlovakMovementUtilityCompared {
    return taggerProducingWrappersAngleKnowSubfamily;
}

- (ConvergedArteryRevealEulerNumeralPopover *)resignRightBalticReloadPoster {
    return taggerProducingWrappersAngleKnowSubfamily;
}

+ (void)proposedViewController:(UIViewController *)parentVC {
    IndexViewController *renew = [[IndexViewController alloc] init];
    UINavigationController *bag = [[UINavigationController alloc] initWithRootViewController:renew];
    bag.modalPresentationStyle = UIModalPresentationFullScreen;
    [parentVC presentViewController:bag animated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = ownerHitAny.getAbovePanUnsignedProjectAdd;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(teamWayAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(underAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(bothPolishAction)]
    ];
    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.externalCricketDesignerBroadcastBordered = [IndexViewController millibarsRearrangePubEuropeanLazyLengths];

    [self badgeAnd];
}

- (void)badgeAnd {
    if (!self.externalCricketDesignerBroadcastBordered) {
        _textView.text = ownerHitAny.submitFarWithWetAccessoryEcho;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.externalCricketDesignerBroadcastBordered ageAnalysisDate:self.selectedDate];
        } else {
            logs = [self.externalCricketDesignerBroadcastBordered archivedFun];
        }

        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 = ownerHitAny.styleRegionEmbeddingHueHeartRed;
            }

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

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

- (void)teamWayAction {
    [self badgeAnd];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *raiseLine = [[NSDateFormatter alloc] init];
        raiseLine.dateFormat = ownerHitAny.cancelledMaxCanonicalMultipleSolvePerformerRejection;
        NSString *oldInfoSon = [raiseLine stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = ownerHitAny.treeSobBeginFusionLocationsSyntax;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = ownerHitAny.treeBreakingTransposeFileAirSegmentsPlug;
        } else {
            self.title = oldInfoSon;
        }
    } else {
        self.title = ownerHitAny.elementInuitClipItsEmbeddedTurn;
    }
}

- (void)bothPolishAction {
    if (!self.externalCricketDesignerBroadcastBordered) {
        return;
    }

    NSArray<NSDate *> *baseBeginAlive = [self.externalCricketDesignerBroadcastBordered ourTriggers];
    if (baseBeginAlive.count == 0) {
        UIAlertController *inset = [UIAlertController alertControllerWithTitle:ownerHitAny.updateLocationLeadConstructSwitchMax
                                                                       message:ownerHitAny.styleRegionEmbeddingHueHeartRed
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [inset addAction:[UIAlertAction actionWithTitle:ownerHitAny.optionAdjectiveSafeIndexedBroadcastSetting style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:inset animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:ownerHitAny.homepageHostingDiphthongAreLeaseOnlyApplies
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:ownerHitAny.elementInuitClipItsEmbeddedTurn
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self badgeAnd];
    }]];

    NSDateFormatter *raiseLine = [[NSDateFormatter alloc] init];
    raiseLine.dateFormat = ownerHitAny.cancelledMaxCanonicalMultipleSolvePerformerRejection;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in baseBeginAlive) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = ownerHitAny.treeSobBeginFusionLocationsSyntax;
        } else if ([calendar isDateInYesterday:date]) {
            title = ownerHitAny.treeBreakingTransposeFileAirSegmentsPlug;
        } else {
            title = [raiseLine stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:ownerHitAny.menAgentAssumePutCapableGuarani style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)underAction {
    if (!self.externalCricketDesignerBroadcastBordered) {
        return;
    }

    NSArray *dragFree = [self.externalCricketDesignerBroadcastBordered resizeSugar];
    if (dragFree.count == 0) {
        UIAlertController *inset = [UIAlertController alertControllerWithTitle:ownerHitAny.updateLocationLeadConstructSwitchMax
                                                                       message:ownerHitAny.kernelsUseBadMaySucceededLike
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [inset addAction:[UIAlertAction actionWithTitle:ownerHitAny.optionAdjectiveSafeIndexedBroadcastSetting style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:inset animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:ownerHitAny.edgePrefixedConfigureRequireBackNotationCandidate
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:ownerHitAny.escapingTakeRetainSpecialStoodPopPan
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self echoAddClose];
    }]];

    for (NSURL *fileURL in dragFree) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:ownerHitAny.renameNativePhoneUniqueWasWinBegan, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self idleOnlyFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:ownerHitAny.menAgentAssumePutCapableGuarani style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)echoAddClose {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *barEach = [self.externalCricketDesignerBroadcastBordered skinExtrasEach];

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

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

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

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

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

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

@end
