

#import "WriteViewController.h"
#import "Mouth.h"
#import "EarMusicResetNumeralReverseExpert.h"
#import "OddGramPubTabSettling.h"
#import "ZoomingPinConfig.h"

@interface WriteViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) EarMusicResetNumeralReverseExpert *rateLocationManTrailingLimit;
@property (nonatomic, strong) OddGramPubTabSettling *publicSubmittedSymptomQueueSafari;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static OddGramPubTabSettling *scanSerbianBagSubscriptBasicPerfusion = nil;
static EarMusicResetNumeralReverseExpert *magicEyeDialogMaximumUnwindOdd = nil;

@implementation WriteViewController

+ (void)offMagicPop {
    
    [Mouth gaspAltitudeFocusesPrefixedHiddenGopher];

    magicEyeDialogMaximumUnwindOdd = [[EarMusicResetNumeralReverseExpert alloc] init];
    magicEyeDialogMaximumUnwindOdd.wetTabLevel = AdvisedSheResumeAbortedRate;

    [Mouth ruleIgnoresFeetPatternsBag:magicEyeDialogMaximumUnwindOdd];

    scanSerbianBagSubscriptBasicPerfusion = [[OddGramPubTabSettling alloc] init];
    scanSerbianBagSubscriptBasicPerfusion.wetTabLevel = RedAdobeInuit;
    scanSerbianBagSubscriptBasicPerfusion.artsMap = 7;
    scanSerbianBagSubscriptBasicPerfusion.newsstandPullConflictGurationInuit = YES;
    [Mouth ruleIgnoresFeetPatternsBag:scanSerbianBagSubscriptBasicPerfusion];

    [scanSerbianBagSubscriptBasicPerfusion mayLoveWordDry];
}

+ (OddGramPubTabSettling *)abortBondApplyTibetanDecoderTemporal {
    return scanSerbianBagSubscriptBasicPerfusion;
}
+ (EarMusicResetNumeralReverseExpert *)createdCricketRowShowStakeLoad {
    return magicEyeDialogMaximumUnwindOdd;
}

- (EarMusicResetNumeralReverseExpert *)rateLocationManTrailingLimit {
    return magicEyeDialogMaximumUnwindOdd;
}

+ (void)homepageViewController:(UIViewController *)parentVC {
    WriteViewController *farsi = [[WriteViewController alloc] init];
    UINavigationController *net = [[UINavigationController alloc] initWithRootViewController:farsi];
    net.modalPresentationStyle = UIModalPresentationFullScreen;
    [parentVC presentViewController:net animated:YES completion:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = rankedMerge.barOvulationRawIndianOutputFeat;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(visitorAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(shareAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(lettersSobAction)]
    ];
    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.publicSubmittedSymptomQueueSafari = [WriteViewController abortBondApplyTibetanDecoderTemporal];

    [self wakeFair];
}

- (void)wakeFair {
    if (!self.publicSubmittedSymptomQueueSafari) {
        _textView.text = rankedMerge.retVisitSinPoolInviteLoops;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.publicSubmittedSymptomQueueSafari bagDryInsetDate:self.selectedDate];
        } else {
            logs = [self.publicSubmittedSymptomQueueSafari sixMoireDue];
        }

        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 = rankedMerge.semanticPredictedNeutralMightChineseRows;
            }

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

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

- (void)visitorAction {
    [self wakeFair];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *runNordic = [[NSDateFormatter alloc] init];
        runNordic.dateFormat = rankedMerge.maskHitRedirectWhileSayRollSee;
        NSString *dateString = [runNordic stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = rankedMerge.listenersReportsLeftCandidateTipPattern;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = rankedMerge.funSinhaleseReorderFailReadableMasterDecide;
        } else {
            self.title = dateString;
        }
    } else {
        self.title = rankedMerge.farJapaneseInfoMixStrictShe;
    }
}

- (void)lettersSobAction {
    if (!self.publicSubmittedSymptomQueueSafari) {
        return;
    }

    NSArray<NSDate *> *rootMaxWhoMale = [self.publicSubmittedSymptomQueueSafari barOffMagic];
    if (rootMaxWhoMale.count == 0) {
        UIAlertController *malay = [UIAlertController alertControllerWithTitle:rankedMerge.fractionsFlippedRawOccurYahooRaw
                                                                       message:rankedMerge.semanticPredictedNeutralMightChineseRows
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [malay addAction:[UIAlertAction actionWithTitle:rankedMerge.beganSeventeenLoudTakeSingleNear style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:malay animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:rankedMerge.buddhistTraveledLawDecryptedImmutableIndicatedStarted
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:rankedMerge.farJapaneseInfoMixStrictShe
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self wakeFair];
    }]];

    NSDateFormatter *runNordic = [[NSDateFormatter alloc] init];
    runNordic.dateFormat = rankedMerge.maskHitRedirectWhileSayRollSee;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in rootMaxWhoMale) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = rankedMerge.listenersReportsLeftCandidateTipPattern;
        } else if ([calendar isDateInYesterday:date]) {
            title = rankedMerge.funSinhaleseReorderFailReadableMasterDecide;
        } else {
            title = [runNordic stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:rankedMerge.monthObscuresTerahertzMakerMandatoryAffiliate 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.publicSubmittedSymptomQueueSafari) {
        return;
    }

    NSArray *halftone = [self.publicSubmittedSymptomQueueSafari fillSongIll];
    if (halftone.count == 0) {
        UIAlertController *malay = [UIAlertController alertControllerWithTitle:rankedMerge.fractionsFlippedRawOccurYahooRaw
                                                                       message:rankedMerge.batchLetterNotifiesTopPulseCroatian
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [malay addAction:[UIAlertAction actionWithTitle:rankedMerge.beganSeventeenLoudTakeSingleNear style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:malay animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:rankedMerge.badLifetimeShapeEchoAcquireChooseWon
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:rankedMerge.kindPacketsBaseballManagersSignatureModelRouter
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self tabSelectors];
    }]];

    for (NSURL *fileURL in halftone) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:rankedMerge.recoveredBusUbiquityMasteringCutBlobUkrainian, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self bedDeltaFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:rankedMerge.monthObscuresTerahertzMakerMandatoryAffiliate style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)tabSelectors {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *chatAll = [self.publicSubmittedSymptomQueueSafari indexingNepali];

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

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

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

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

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

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

@end
