






#import "DeclineTwoViewController.h"
#import "BagSpecifyConfig.h"
#import "NSObject+DryModel.h"
#import "UIColor+YouColor.h"
#import "KeyToast.h"

@interface DeclineTwoViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation DeclineTwoViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _pubStoppedEnglishHourlyFamily = [NSMutableArray array];
    _whoTakeCharHer = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self caseIcyKeyView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets herTakeAnd = [[ProducingManager shared] normalOldPutWindow].safeAreaInsets;
    
    herTakeAnd.top    += 10;
    herTakeAnd.left   += 10;
    herTakeAnd.bottom += 10;
    herTakeAnd.right  += 10;

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


- (void)caseIcyKeyView {
    _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.execAlarmButton.mas_bottom);
        make.left.right.bottom.equalTo(self.view);
    }];
    
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass(self.class)];
}


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

- (void)focalFeetKeysInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_pubStoppedEnglishHourlyFamily addObject:[info copy]];
            NSArray *forOperate = [self needFormatBackDictionary:info];
            self->_whoTakeCharHer = [self->_whoTakeCharHer arrayByAddingObject:forOperate];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cube = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger notMildIndex = indexPath.section;
    key = _whoTakeCharHer[notMildIndex][indexPath.row];
    value = _pubStoppedEnglishHourlyFamily[notMildIndex][key];
    BOOL mostFree = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    cube.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *skipKit in cube.contentView.subviews) {
        [skipKit removeFromSuperview];
    }
    
    
    UILabel *menLabel = [[UILabel alloc] init];
    menLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    menLabel.textColor = [UIColor darkGrayColor];
    menLabel.text = key;
    menLabel.numberOfLines = 0;
    [cube.contentView addSubview:menLabel];
    
    
    UILabel *spellLabel = [[UILabel alloc] init];
    spellLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    spellLabel.textColor = [UIColor blackColor];
    spellLabel.numberOfLines = 0;
    spellLabel.textAlignment = NSTextAlignmentRight;
    [cube.contentView addSubview:spellLabel];
    
    
    [menLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cube.contentView).offset(MouthOunces.logTwelveEnd.greenHangAsk);
        make.top.equalTo(cube.contentView).offset(MouthOunces.logTwelveEnd.oldBandUnify);
        make.bottom.equalTo(cube.contentView).offset(-MouthOunces.logTwelveEnd.oldBandUnify);
        make.width.equalTo(cube.contentView.mas_width).multipliedBy(mostFree?MouthOunces.logTwelveEnd.blueEggSwipe:MouthOunces.logTwelveEnd.airlineHealth);
    }];
    
    [spellLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(cube.contentView).offset(-MouthOunces.logTwelveEnd.greenHangAsk);
        make.top.equalTo(cube.contentView).offset(MouthOunces.logTwelveEnd.oldBandUnify);
        make.bottom.equalTo(cube.contentView).offset(-MouthOunces.logTwelveEnd.oldBandUnify);
        make.left.equalTo(menLabel.mas_right).offset(MouthOunces.logTwelveEnd.oldBandUnify);
    }];
    
    
    if (mostFree) {
        cube.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        spellLabel.text = [value description];
        cube.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return cube;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger notMildIndex = indexPath.section;
    key = _whoTakeCharHer[notMildIndex][indexPath.row];
    value = _pubStoppedEnglishHourlyFamily[notMildIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self faxAgeNoneDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self sobOffLeftArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [KeyToast canSeek:MouthOunces.logTwelveEnd.allowMixLogGenericEpsilonFail];
    }
}


- (void)faxAgeNoneDictionary:(NSDictionary *)rest withTitle:(NSString *)title {
    DeclineTwoViewController *mapOffer = [[DeclineTwoViewController alloc] init];
    [self.navigationController pushViewController:mapOffer animated:NO];
    [mapOffer focalFeetKeysInfo:rest withTitle:title];
}

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

@end
