






#import "ButRedStarViewController.h"
#import "BinForRollConfig.h"
#import "NSObject+MapModel.h"
#import "UIColor+AgeColor.h"
#import "JobToast.h"

@interface ButRedStarViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation ButRedStarViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _hostSatisfiedPurpleColumnUnlearn = [NSMutableArray array];
    _fatAwayAnyCost = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self lightStripView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets eyePinFour = [[CapUniqueManager shared] leaveRedBestWindow].safeAreaInsets;
    
    eyePinFour.top    += 10;
    eyePinFour.left   += 10;
    eyePinFour.bottom += 10;
    eyePinFour.right  += 10;

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


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


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

- (void)idiomSumPinchInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_hostSatisfiedPurpleColumnUnlearn addObject:[info copy]];
            NSArray *curlPopBed = [self sessionsPluralDictionary:info];
            self->_fatAwayAnyCost = [self->_fatAwayAnyCost arrayByAddingObject:curlPopBed];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *arts = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger slowPutIndex = indexPath.section;
    key = _fatAwayAnyCost[slowPutIndex][indexPath.row];
    value = _hostSatisfiedPurpleColumnUnlearn[slowPutIndex][key];
    BOOL flatPage = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    arts.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *stroked in arts.contentView.subviews) {
        [stroked removeFromSuperview];
    }
    
    
    UILabel *rawLabel = [[UILabel alloc] init];
    rawLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    rawLabel.textColor = [UIColor darkGrayColor];
    rawLabel.text = key;
    rawLabel.numberOfLines = 0;
    [arts.contentView addSubview:rawLabel];
    
    
    UILabel *powerLabel = [[UILabel alloc] init];
    powerLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    powerLabel.textColor = [UIColor blackColor];
    powerLabel.numberOfLines = 0;
    powerLabel.textAlignment = NSTextAlignmentRight;
    [arts.contentView addSubview:powerLabel];
    
    
    [rawLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(arts.contentView).offset(RowGivenOut.mathProxyKin.automaticDay);
        make.top.equalTo(arts.contentView).offset(RowGivenOut.mathProxyKin.climbingMode);
        make.bottom.equalTo(arts.contentView).offset(-RowGivenOut.mathProxyKin.climbingMode);
        make.width.equalTo(arts.contentView.mas_width).multipliedBy(flatPage?RowGivenOut.mathProxyKin.tapDependent:RowGivenOut.mathProxyKin.rowExtraPitch);
    }];
    
    [powerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(arts.contentView).offset(-RowGivenOut.mathProxyKin.automaticDay);
        make.top.equalTo(arts.contentView).offset(RowGivenOut.mathProxyKin.climbingMode);
        make.bottom.equalTo(arts.contentView).offset(-RowGivenOut.mathProxyKin.climbingMode);
        make.left.equalTo(rawLabel.mas_right).offset(RowGivenOut.mathProxyKin.climbingMode);
    }];
    
    
    if (flatPage) {
        arts.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        powerLabel.text = [value description];
        arts.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return arts;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger slowPutIndex = indexPath.section;
    key = _fatAwayAnyCost[slowPutIndex][indexPath.row];
    value = _hostSatisfiedPurpleColumnUnlearn[slowPutIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self moodOutputDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self lawCheckerArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [JobToast install:RowGivenOut.mathProxyKin.appleEldestSentAdjustsDiscountFold];
    }
}


- (void)moodOutputDictionary:(NSDictionary *)fair withTitle:(NSString *)title {
    ButRedStarViewController *boxChina = [[ButRedStarViewController alloc] init];
    [self.navigationController pushViewController:boxChina animated:NO];
    [boxChina idiomSumPinchInfo:fair withTitle:title];
}

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

@end
