






#import "AssumeMoodViewController.h"
#import "TipBlueSixConfig.h"
#import "NSObject+MapModel.h"
#import "UIColor+HasColor.h"
#import "RetToast.h"

@interface AssumeMoodViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray<NSDictionary *> *malteseReturnPrimeMarginsOutside; 
@property (nonatomic, strong) NSArray<NSArray<NSString *> *> *oddRunFirstNot; 
@property (nonatomic, strong) NSMutableArray<NSString *> *sectionTitles; 

@end

@implementation AssumeMoodViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _malteseReturnPrimeMarginsOutside = [NSMutableArray array];
    _oddRunFirstNot = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self flightOnlyView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets roomYouHas = [[SockLevelManager shared] pageEightEndWindow].safeAreaInsets;
    
    roomYouHas.top    += 10;
    roomYouHas.left   += 10;
    roomYouHas.bottom += 10;
    roomYouHas.right  += 10;

    [self.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(roomYouHas);
    }];
}


- (void)flightOnlyView {
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sentSlideButton.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass(self.class)];
}


- (NSArray<NSString *> *)centralsEntityDictionary:(NSDictionary *)fact {
    return [[fact allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
}

- (void)getYouTapsRedInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_malteseReturnPrimeMarginsOutside addObject:[info copy]];
            NSArray *centerYear = [self centralsEntityDictionary:info];
            self->_oddRunFirstNot = [self->_oddRunFirstNot arrayByAddingObject:centerYear];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _malteseReturnPrimeMarginsOutside.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _oddRunFirstNot[section].count;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return _sectionTitles[section];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *lose = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger lessJobIndex = indexPath.section;
    key = _oddRunFirstNot[lessJobIndex][indexPath.row];
    value = _malteseReturnPrimeMarginsOutside[lessJobIndex][key];
    BOOL itsPrime = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    lose.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *farFlag in lose.contentView.subviews) {
        [farFlag removeFromSuperview];
    }
    
    
    UILabel *funLabel = [[UILabel alloc] init];
    funLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    funLabel.textColor = [UIColor darkGrayColor];
    funLabel.text = key;
    funLabel.numberOfLines = 0;
    [lose.contentView addSubview:funLabel];
    
    
    UILabel *setupLabel = [[UILabel alloc] init];
    setupLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    setupLabel.textColor = [UIColor blackColor];
    setupLabel.numberOfLines = 0;
    setupLabel.textAlignment = NSTextAlignmentRight;
    [lose.contentView addSubview:setupLabel];
    
    
    [funLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lose.contentView).offset(WetDoneFill.artSensitive.drumPopBrown);
        make.top.equalTo(lose.contentView).offset(WetDoneFill.artSensitive.dueLawInside);
        make.bottom.equalTo(lose.contentView).offset(-WetDoneFill.artSensitive.dueLawInside);
        make.width.equalTo(lose.contentView.mas_width).multipliedBy(itsPrime?WetDoneFill.artSensitive.zipSunTagger:WetDoneFill.artSensitive.howSoloOddTwo);
    }];
    
    [setupLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(lose.contentView).offset(-WetDoneFill.artSensitive.drumPopBrown);
        make.top.equalTo(lose.contentView).offset(WetDoneFill.artSensitive.dueLawInside);
        make.bottom.equalTo(lose.contentView).offset(-WetDoneFill.artSensitive.dueLawInside);
        make.left.equalTo(funLabel.mas_right).offset(WetDoneFill.artSensitive.dueLawInside);
    }];
    
    
    if (itsPrime) {
        lose.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        setupLabel.text = [value description];
        lose.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return lose;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger lessJobIndex = indexPath.section;
    key = _oddRunFirstNot[lessJobIndex][indexPath.row];
    value = _malteseReturnPrimeMarginsOutside[lessJobIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self cutSharingDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self formWithinArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [RetToast tooHead:WetDoneFill.artSensitive.impactDismissalLocationsChainNeedBracketed];
    }
}


- (void)cutSharingDictionary:(NSDictionary *)fact withTitle:(NSString *)title {
    AssumeMoodViewController *ornament = [[AssumeMoodViewController alloc] init];
    [self.navigationController pushViewController:ornament animated:NO];
    [ornament getYouTapsRedInfo:fact withTitle:title];
}

- (void)formWithinArray:(NSArray *)array withTitle:(NSString *)title {
    
    NSMutableDictionary *moireDict = [NSMutableDictionary dictionary];
    for (NSInteger i = 0; i < array.count; i++) {
        moireDict[[NSString stringWithFormat:@"[%ld]", (long)i]] = array[i];
    }
    
    AssumeMoodViewController *ornament = [[AssumeMoodViewController alloc] init];
    [self.navigationController pushViewController:ornament animated:NO];
    [ornament getYouTapsRedInfo:moireDict withTitle:[NSString stringWithFormat:@"%@ (Array)", title]];
}

@end
