

#import "StoneViewController.h"
#import "Maker.h"
#import "OldDiastolicExponentsRemembersProgramExcluded.h"
#import "FolderRuleContainDirectionPop.h"
#import "SoloCutterConfig.h"

@interface StoneViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) OldDiastolicExponentsRemembersProgramExcluded *belowDiscreteIterationAnswerSpherical;
@property (nonatomic, strong) FolderRuleContainDirectionPop *fileMidQuechuaDetermineStale;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static FolderRuleContainDirectionPop *kernelDirectionOffHeightHeadphoneYou = nil;
static OldDiastolicExponentsRemembersProgramExcluded *putExistingRopeBackRaceMute = nil;

@implementation StoneViewController

+ (void)nowDryLoose {
    
    [Maker malteseExponentManagersUndoSenderTool];

    putExistingRopeBackRaceMute = [[OldDiastolicExponentsRemembersProgramExcluded alloc] init];
    putExistingRopeBackRaceMute.clientLevel = ChangeConstantsSubmittedChestInternet;

    [Maker alongCutterThinEvaluatedObject:putExistingRopeBackRaceMute];

    kernelDirectionOffHeightHeadphoneYou = [[FolderRuleContainDirectionPop alloc] init];
    kernelDirectionOffHeightHeadphoneYou.clientLevel = HexWetLogLazy;
    kernelDirectionOffHeightHeadphoneYou.cubeWas = 7;
    kernelDirectionOffHeightHeadphoneYou.persistInventoryEraPluralPointers = YES;
    [Maker alongCutterThinEvaluatedObject:kernelDirectionOffHeightHeadphoneYou];

    [kernelDirectionOffHeightHeadphoneYou sideFourBottom];
}

+ (FolderRuleContainDirectionPop *)mantissaAscentDustFinalizeHistoryDestroy {
    return kernelDirectionOffHeightHeadphoneYou;
}
+ (OldDiastolicExponentsRemembersProgramExcluded *)trapUnableStereoEventPoloUnload {
    return putExistingRopeBackRaceMute;
}

- (OldDiastolicExponentsRemembersProgramExcluded *)belowDiscreteIterationAnswerSpherical {
    return putExistingRopeBackRaceMute;
}

+ (void)alertOffViewController:(UIViewController *)parentVC {
    StoneViewController *brief = [[StoneViewController alloc] init];
    UINavigationController *are = [[UINavigationController alloc] initWithRootViewController:brief];
    are.modalPresentationStyle = UIModalPresentationFullScreen;
    [parentVC presentViewController:are animated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = ownDaysWork.deliveredParserRaceSixCupEncodings;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(costBinAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(shareAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(marginYearAction)]
    ];
    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.fileMidQuechuaDetermineStale = [StoneViewController mantissaAscentDustFinalizeHistoryDestroy];

    [self stayFind];
}

- (void)stayFind {
    if (!self.fileMidQuechuaDetermineStale) {
        _textView.text = ownDaysWork.outFlightInvitedJouleOffModal;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.fileMidQuechuaDetermineStale lawObsoleteDate:self.selectedDate];
        } else {
            logs = [self.fileMidQuechuaDetermineStale buddyDegree];
        }

        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 = ownDaysWork.localeTamilCommittedStepsonAddressesZip;
            }

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

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

- (void)costBinAction {
    [self stayFind];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *sixReview = [[NSDateFormatter alloc] init];
        sixReview.dateFormat = ownDaysWork.askWaitExtrinsicPluralBaseTokenScattered;
        NSString *dateString = [sixReview stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = ownDaysWork.policyNewsstandMixerWinAndKit;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = ownDaysWork.azimuthLatvianMeanBarsStretchNibblesAge;
        } else {
            self.title = dateString;
        }
    } else {
        self.title = ownDaysWork.databasesWeekSeedOccurBendSchemes;
    }
}

- (void)marginYearAction {
    if (!self.fileMidQuechuaDetermineStale) {
        return;
    }

    NSArray<NSDate *> *boundAndKitTab = [self.fileMidQuechuaDetermineStale bigYahooIts];
    if (boundAndKitTab.count == 0) {
        UIAlertController *thick = [UIAlertController alertControllerWithTitle:ownDaysWork.penAfterEncryptAboutFloatingReference
                                                                       message:ownDaysWork.localeTamilCommittedStepsonAddressesZip
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [thick addAction:[UIAlertAction actionWithTitle:ownDaysWork.encodingCopperAdjectiveElementsSceneEllipse style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:thick animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:ownDaysWork.tryVideoArtworkBlackSolveDeepResponses
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:ownDaysWork.databasesWeekSeedOccurBendSchemes
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self stayFind];
    }]];

    NSDateFormatter *sixReview = [[NSDateFormatter alloc] init];
    sixReview.dateFormat = ownDaysWork.askWaitExtrinsicPluralBaseTokenScattered;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in boundAndKitTab) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = ownDaysWork.policyNewsstandMixerWinAndKit;
        } else if ([calendar isDateInYesterday:date]) {
            title = ownDaysWork.azimuthLatvianMeanBarsStretchNibblesAge;
        } else {
            title = [sixReview stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:ownDaysWork.windowInfinityLossyKilogramsDrainNote 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.fileMidQuechuaDetermineStale) {
        return;
    }

    NSArray *addAlpha = [self.fileMidQuechuaDetermineStale waxPinOther];
    if (addAlpha.count == 0) {
        UIAlertController *thick = [UIAlertController alertControllerWithTitle:ownDaysWork.penAfterEncryptAboutFloatingReference
                                                                       message:ownDaysWork.dueProgramSigningMeanPinAssertion
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [thick addAction:[UIAlertAction actionWithTitle:ownDaysWork.encodingCopperAdjectiveElementsSceneEllipse style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:thick animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:ownDaysWork.toolPostalSlavicBufferAdditivePaddleZip
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:ownDaysWork.uniformGainAssumeDownBrotherAlbumSub
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self causeMailWin];
    }]];

    for (NSURL *fileURL in addAlpha) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:ownDaysWork.returnDetachCostCollapsedDecodeWarnAudio, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self singularFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:ownDaysWork.windowInfinityLossyKilogramsDrainNote style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)causeMailWin {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *usePrep = [self.fileMidQuechuaDetermineStale tipHerStackAir];

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

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

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

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

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

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

@end
