

#import "StampViewController.h"
#import "Thumb.h"
#import "ProvisionPashtoDenseParallelMidSliding.h"
#import "GrandauntDropPasteUpperConcert.h"
#import "ArtLogWrapConfig.h"

@interface StampViewController ()
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) ProvisionPashtoDenseParallelMidSliding *aboutFairShowersIgnoringKind;
@property (nonatomic, strong) GrandauntDropPasteUpperConcert *matchSignCurveStampRegular;
@property (nonatomic, strong) NSDate *selectedDate; 
@end

static GrandauntDropPasteUpperConcert *fitAdoptRatioUnsavedFeetMinor = nil;
static ProvisionPashtoDenseParallelMidSliding *foodRebusOptBookmarkChooseSay = nil;

@implementation StampViewController

+ (void)butSenseThe {
    
    [Thumb counterUnlearnPlaybackWaxInitiallyOpt];

    foodRebusOptBookmarkChooseSay = [[ProvisionPashtoDenseParallelMidSliding alloc] init];
    foodRebusOptBookmarkChooseSay.normalLevel = StepExistOwnUseManagers;

    [Thumb wrapUnloadPinkThumbnailEsperanto:foodRebusOptBookmarkChooseSay];

    fitAdoptRatioUnsavedFeetMinor = [[GrandauntDropPasteUpperConcert alloc] init];
    fitAdoptRatioUnsavedFeetMinor.normalLevel = RetrieveTable;
    fitAdoptRatioUnsavedFeetMinor.roleDue = 7;
    fitAdoptRatioUnsavedFeetMinor.creditsBinCleanBandSystem = YES;
    [Thumb wrapUnloadPinkThumbnailEsperanto:fitAdoptRatioUnsavedFeetMinor];

    [fitAdoptRatioUnsavedFeetMinor dueFairWarpRed];
}

+ (GrandauntDropPasteUpperConcert *)prefersRetryMixConnectNaturalExtras {
    return fitAdoptRatioUnsavedFeetMinor;
}
+ (ProvisionPashtoDenseParallelMidSliding *)stepFaxAngleRoomButStore {
    return foodRebusOptBookmarkChooseSay;
}

- (ProvisionPashtoDenseParallelMidSliding *)aboutFairShowersIgnoringKind {
    return foodRebusOptBookmarkChooseSay;
}

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

- (void)viewDidLoad {
    [super viewDidLoad];

    self.title = napBondGolf.streetAddPressSedentaryCircularCascade;
    self.view.backgroundColor = [UIColor systemBackgroundColor];

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

    self.navigationItem.rightBarButtonItems = @[
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
                                                      target:self
                                                      action:@selector(renewalAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
                                                      target:self
                                                      action:@selector(groupAction)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks
                                                      target:self
                                                      action:@selector(sobFailSonAction)]
    ];
    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.matchSignCurveStampRegular = [StampViewController prefersRetryMixConnectNaturalExtras];

    [self aliveOut];
}

- (void)aliveOut {
    if (!self.matchSignCurveStampRegular) {
        _textView.text = napBondGolf.mapAssumeTempUtteranceDirectorEngraved;
        return;
    }

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *logs;
        if (self.selectedDate) {
            logs = [self.matchSignCurveStampRegular squareRaiseDate:self.selectedDate];
        } else {
            logs = [self.matchSignCurveStampRegular itsHalftone];
        }

        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 = napBondGolf.rowFinishingTowerWetPubClockwise;
            }

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

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

- (void)renewalAction {
    [self aliveOut];
}

- (void)updateTitle {
    if (self.selectedDate) {
        NSDateFormatter *photosBed = [[NSDateFormatter alloc] init];
        photosBed.dateFormat = napBondGolf.silenceLowercaseGetBringIntroDayRendered;
        NSString *mouseLower = [photosBed stringFromDate:self.selectedDate];

        NSCalendar *calendar = [NSCalendar currentCalendar];
        if ([calendar isDateInToday:self.selectedDate]) {
            self.title = napBondGolf.ordinalGallonsSymptomGregorianMapAudited;
        } else if ([calendar isDateInYesterday:self.selectedDate]) {
            self.title = napBondGolf.nineSentFourteenNorwegianDismissDetailLookup;
        } else {
            self.title = mouseLower;
        }
    } else {
        self.title = napBondGolf.outcomeWrestlingAnchoredGeneralDarwinLookup;
    }
}

- (void)sobFailSonAction {
    if (!self.matchSignCurveStampRegular) {
        return;
    }

    NSArray<NSDate *> *grayJumpAscent = [self.matchSignCurveStampRegular disposeJoin];
    if (grayJumpAscent.count == 0) {
        UIAlertController *mouse = [UIAlertController alertControllerWithTitle:napBondGolf.serverProgressWatchedForbidFocalBlue
                                                                       message:napBondGolf.rowFinishingTowerWetPubClockwise
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [mouse addAction:[UIAlertAction actionWithTitle:napBondGolf.completedBagStylisticInsulinSoundViability style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:mouse animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:napBondGolf.leftLogProminentAnimateEndDecayDirectory
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:napBondGolf.outcomeWrestlingAnchoredGeneralDarwinLookup
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        self.selectedDate = nil;
        [self aliveOut];
    }]];

    NSDateFormatter *photosBed = [[NSDateFormatter alloc] init];
    photosBed.dateFormat = napBondGolf.silenceLowercaseGetBringIntroDayRendered;

    NSCalendar *calendar = [NSCalendar currentCalendar];

    for (NSDate *date in grayJumpAscent) {
        NSString *title;
        if ([calendar isDateInToday:date]) {
            title = napBondGolf.ordinalGallonsSymptomGregorianMapAudited;
        } else if ([calendar isDateInYesterday:date]) {
            title = napBondGolf.nineSentFourteenNorwegianDismissDetailLookup;
        } else {
            title = [photosBed stringFromDate:date];
        }

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

    [actionSheet addAction:[UIAlertAction actionWithTitle:napBondGolf.seventeenDetailsBitsPriceFoldDisorder style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)groupAction {
    if (!self.matchSignCurveStampRegular) {
        return;
    }

    NSArray *topGuest = [self.matchSignCurveStampRegular unitLeftBut];
    if (topGuest.count == 0) {
        UIAlertController *mouse = [UIAlertController alertControllerWithTitle:napBondGolf.serverProgressWatchedForbidFocalBlue
                                                                       message:napBondGolf.sinhaleseCreditsParameterSubmitHexMember
                                                                preferredStyle:UIAlertControllerStyleAlert];
        [mouse addAction:[UIAlertAction actionWithTitle:napBondGolf.completedBagStylisticInsulinSoundViability style:UIAlertActionStyleDefault handler:nil]];
        [self presentViewController:mouse animated:YES completion:nil];
        return;
    }

    UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:napBondGolf.bleedFootnoteDispatchPanoramaHindiFrenchSum
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleActionSheet];

    [actionSheet addAction:[UIAlertAction actionWithTitle:napBondGolf.unionTriggerIterateSequencerSelectArrayPart
                                                    style:UIAlertActionStyleDefault
                                                  handler:^(UIAlertAction *action) {
        [self logoTwoCycle];
    }]];

    for (NSURL *fileURL in topGuest) {
        NSString *fileName = fileURL.lastPathComponent;
        [actionSheet addAction:[UIAlertAction actionWithTitle:[NSString stringWithFormat:napBondGolf.roomRetCasePosterLightInsertSleep, fileName]
                                                        style:UIAlertActionStyleDefault
                                                      handler:^(UIAlertAction *action) {
            [self styleMapFile:fileURL];
        }]];
    }

    [actionSheet addAction:[UIAlertAction actionWithTitle:napBondGolf.seventeenDetailsBitsPriceFoldDisorder style:UIAlertActionStyleCancel handler:nil]];

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

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

- (void)logoTwoCycle {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSString *drizzle = [self.matchSignCurveStampRegular putSonLiveHome];

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

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

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

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

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

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

@end
