






#import "MetricsFaxViewController.h"
#import "OptTextSeeConfig.h"
#import "NSObject+WayModel.h"
#import "UIColor+WinColor.h"
#import "ZipToast.h"

@interface MetricsFaxViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation MetricsFaxViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _croppingTraverseAccurateEditorialPortion = [NSMutableArray array];
    _formDogCupWeek = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self serviceFitView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets serviceWin = [[TalkArrayManager shared] oceanIntegerWindow].safeAreaInsets;
    
    serviceWin.top    += 10;
    serviceWin.left   += 10;
    serviceWin.bottom += 10;
    serviceWin.right  += 10;

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


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


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

- (void)finalGenerateInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_croppingTraverseAccurateEditorialPortion addObject:[info copy]];
            NSArray *pubDropBit = [self kitEraLikeTypeDictionary:info];
            self->_formDogCupWeek = [self->_formDogCupWeek arrayByAddingObject:pubDropBit];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *bike = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger jobCropIndex = indexPath.section;
    key = _formDogCupWeek[jobCropIndex][indexPath.row];
    value = _croppingTraverseAccurateEditorialPortion[jobCropIndex][key];
    BOOL timeBurn = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    bike.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *pipeHit in bike.contentView.subviews) {
        [pipeHit removeFromSuperview];
    }
    
    
    UILabel *twoLabel = [[UILabel alloc] init];
    twoLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    twoLabel.textColor = [UIColor darkGrayColor];
    twoLabel.text = key;
    twoLabel.numberOfLines = 0;
    [bike.contentView addSubview:twoLabel];
    
    
    UILabel *quickLabel = [[UILabel alloc] init];
    quickLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    quickLabel.textColor = [UIColor blackColor];
    quickLabel.numberOfLines = 0;
    quickLabel.textAlignment = NSTextAlignmentRight;
    [bike.contentView addSubview:quickLabel];
    
    
    [twoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bike.contentView).offset(DueIcyFetch.itsPosterIcy.designSpaCar);
        make.top.equalTo(bike.contentView).offset(DueIcyFetch.itsPosterIcy.netIndianFat);
        make.bottom.equalTo(bike.contentView).offset(-DueIcyFetch.itsPosterIcy.netIndianFat);
        make.width.equalTo(bike.contentView.mas_width).multipliedBy(timeBurn?DueIcyFetch.itsPosterIcy.blobPinEmail:DueIcyFetch.itsPosterIcy.microStandard);
    }];
    
    [quickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(bike.contentView).offset(-DueIcyFetch.itsPosterIcy.designSpaCar);
        make.top.equalTo(bike.contentView).offset(DueIcyFetch.itsPosterIcy.netIndianFat);
        make.bottom.equalTo(bike.contentView).offset(-DueIcyFetch.itsPosterIcy.netIndianFat);
        make.left.equalTo(twoLabel.mas_right).offset(DueIcyFetch.itsPosterIcy.netIndianFat);
    }];
    
    
    if (timeBurn) {
        bike.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        quickLabel.text = [value description];
        bike.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return bike;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger jobCropIndex = indexPath.section;
    key = _formDogCupWeek[jobCropIndex][indexPath.row];
    value = _croppingTraverseAccurateEditorialPortion[jobCropIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self withinSameDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self darkPubFarArray:value withTitle:key];
    } else {
        
        UIPasteboard *twoSinkPub = [UIPasteboard generalPasteboard];
        [twoSinkPub setString:[value description]];
        [ZipToast zipFlat:DueIcyFetch.itsPosterIcy.dryMirroringOppositeCookiesClinicalTall];
    }
}


- (void)withinSameDictionary:(NSDictionary *)star withTitle:(NSString *)title {
    MetricsFaxViewController *overflow = [[MetricsFaxViewController alloc] init];
    [self.navigationController pushViewController:overflow animated:NO];
    [overflow finalGenerateInfo:star withTitle:title];
}

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

@end
