






#import "SayKnowRunViewController.h"
#import "HisCapForkConfig.h"
#import "NSObject+TapModel.h"
#import "UIColor+HueColor.h"
#import "TabToast.h"

@interface SayKnowRunViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation SayKnowRunViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _printerSquaresColumnCategoryCut = [NSMutableArray array];
    _winRunLogFatal = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self didLawGoalView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets saveLowRun = [[VolumeAddManager shared] otherKeyOnceWindow].safeAreaInsets;
    
    saveLowRun.top    += 10;
    saveLowRun.left   += 10;
    saveLowRun.bottom += 10;
    saveLowRun.right  += 10;

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


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


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

- (void)menIcyDaysBadInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_printerSquaresColumnCategoryCut addObject:[info copy]];
            NSArray *dueFitness = [self pinJobMillTakeDictionary:info];
            self->_winRunLogFatal = [self->_winRunLogFatal arrayByAddingObject:dueFitness];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *echo = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger sumNodeIndex = indexPath.section;
    key = _winRunLogFatal[sumNodeIndex][indexPath.row];
    value = _printerSquaresColumnCategoryCut[sumNodeIndex][key];
    BOOL insetArm = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    echo.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *noneTwo in echo.contentView.subviews) {
        [noneTwo removeFromSuperview];
    }
    
    
    UILabel *eggLabel = [[UILabel alloc] init];
    eggLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    eggLabel.textColor = [UIColor darkGrayColor];
    eggLabel.text = key;
    eggLabel.numberOfLines = 0;
    [echo.contentView addSubview:eggLabel];
    
    
    UILabel *driveLabel = [[UILabel alloc] init];
    driveLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    driveLabel.textColor = [UIColor blackColor];
    driveLabel.numberOfLines = 0;
    driveLabel.textAlignment = NSTextAlignmentRight;
    [echo.contentView addSubview:driveLabel];
    
    
    [eggLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(echo.contentView).offset(HisTwoEject.mildVitalEar.sunImagePull);
        make.top.equalTo(echo.contentView).offset(HisTwoEject.mildVitalEar.greaterMedia);
        make.bottom.equalTo(echo.contentView).offset(-HisTwoEject.mildVitalEar.greaterMedia);
        make.width.equalTo(echo.contentView.mas_width).multipliedBy(insetArm?HisTwoEject.mildVitalEar.theWonUnwrap:HisTwoEject.mildVitalEar.innerGeometry);
    }];
    
    [driveLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(echo.contentView).offset(-HisTwoEject.mildVitalEar.sunImagePull);
        make.top.equalTo(echo.contentView).offset(HisTwoEject.mildVitalEar.greaterMedia);
        make.bottom.equalTo(echo.contentView).offset(-HisTwoEject.mildVitalEar.greaterMedia);
        make.left.equalTo(eggLabel.mas_right).offset(HisTwoEject.mildVitalEar.greaterMedia);
    }];
    
    
    if (insetArm) {
        echo.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        driveLabel.text = [value description];
        echo.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return echo;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger sumNodeIndex = indexPath.section;
    key = _winRunLogFatal[sumNodeIndex][indexPath.row];
    value = _printerSquaresColumnCategoryCut[sumNodeIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self showOptionDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self springJumpArray:value withTitle:key];
    } else {
        
        UIPasteboard *attachMath = [UIPasteboard generalPasteboard];
        [attachMath setString:[value description]];
        [TabToast mayTone:HisTwoEject.mildVitalEar.kitDisabledPagerOurOwnIgnores];
    }
}


- (void)showOptionDictionary:(NSDictionary *)card withTitle:(NSString *)title {
    SayKnowRunViewController *beatList = [[SayKnowRunViewController alloc] init];
    [self.navigationController pushViewController:beatList animated:NO];
    [beatList menIcyDaysBadInfo:card withTitle:title];
}

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

@end
