






#import "RollCreditViewController.h"
#import "CutYoungerConfig.h"
#import "NSObject+RowModel.h"
#import "UIColor+LowColor.h"
#import "BigToast.h"

@interface RollCreditViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation RollCreditViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _versionsIdiomBodyQuotationFont = [NSMutableArray array];
    _sigmaRedSpaFax = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self hardSexWayView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets contactNow = [[DeltaWarpManager shared] inferiorsWaxWindow].safeAreaInsets;
    
    contactNow.top    += 10;
    contactNow.left   += 10;
    contactNow.bottom += 10;
    contactNow.right  += 10;

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


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


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

- (void)softballMalayInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_versionsIdiomBodyQuotationFont addObject:[info copy]];
            NSArray *armReceipt = [self basicMayNotNotDictionary:info];
            self->_sigmaRedSpaFax = [self->_sigmaRedSpaFax arrayByAddingObject:armReceipt];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *days = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger hostingIndex = indexPath.section;
    key = _sigmaRedSpaFax[hostingIndex][indexPath.row];
    value = _versionsIdiomBodyQuotationFont[hostingIndex][key];
    BOOL globally = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    days.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *closest in days.contentView.subviews) {
        [closest removeFromSuperview];
    }
    
    
    UILabel *busLabel = [[UILabel alloc] init];
    busLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    busLabel.textColor = [UIColor darkGrayColor];
    busLabel.text = key;
    busLabel.numberOfLines = 0;
    [days.contentView addSubview:busLabel];
    
    
    UILabel *exactLabel = [[UILabel alloc] init];
    exactLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    exactLabel.textColor = [UIColor blackColor];
    exactLabel.numberOfLines = 0;
    exactLabel.textAlignment = NSTextAlignmentRight;
    [days.contentView addSubview:exactLabel];
    
    
    [busLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(days.contentView).offset(WinNeedHang.chargePenSin.datumMayBook);
        make.top.equalTo(days.contentView).offset(WinNeedHang.chargePenSin.littleTabAre);
        make.bottom.equalTo(days.contentView).offset(-WinNeedHang.chargePenSin.littleTabAre);
        make.width.equalTo(days.contentView.mas_width).multipliedBy(globally?WinNeedHang.chargePenSin.skinLowFinal:WinNeedHang.chargePenSin.managerSuffix);
    }];
    
    [exactLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(days.contentView).offset(-WinNeedHang.chargePenSin.datumMayBook);
        make.top.equalTo(days.contentView).offset(WinNeedHang.chargePenSin.littleTabAre);
        make.bottom.equalTo(days.contentView).offset(-WinNeedHang.chargePenSin.littleTabAre);
        make.left.equalTo(busLabel.mas_right).offset(WinNeedHang.chargePenSin.littleTabAre);
    }];
    
    
    if (globally) {
        days.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        exactLabel.text = [value description];
        days.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return days;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger hostingIndex = indexPath.section;
    key = _sigmaRedSpaFax[hostingIndex][indexPath.row];
    value = _versionsIdiomBodyQuotationFont[hostingIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self tooDoneEggDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self escapesLogArray:value withTitle:key];
    } else {
        
        UIPasteboard *fatWithBag = [UIPasteboard generalPasteboard];
        [fatWithBag setString:[value description]];
        [BigToast lastCap:WinNeedHang.chargePenSin.lexicalSignatureLeftUnwrapCaseMaltese];
    }
}


- (void)tooDoneEggDictionary:(NSDictionary *)ping withTitle:(NSString *)title {
    RollCreditViewController *binFlush = [[RollCreditViewController alloc] init];
    [self.navigationController pushViewController:binFlush animated:NO];
    [binFlush softballMalayInfo:ping withTitle:title];
}

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

@end
