






#import "KnowMayCutViewController.h"
#import "CyclingHisConfig.h"
#import "NSObject+RowModel.h"
#import "UIColor+PubColor.h"
#import "SinToast.h"

@interface KnowMayCutViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation KnowMayCutViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _leaseRowAsleepExecutionDatabase = [NSMutableArray array];
    _sunForSayQuiet = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self autoAgeTapView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets letterItem = [[DocumentsManager shared] errorClearedWindow].safeAreaInsets;
    
    letterItem.top    += 10;
    letterItem.left   += 10;
    letterItem.bottom += 10;
    letterItem.right  += 10;

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


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


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

- (void)beaconsGaelicInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_leaseRowAsleepExecutionDatabase addObject:[info copy]];
            NSArray *winSeekAdd = [self keepTallIodineDictionary:info];
            self->_sunForSayQuiet = [self->_sunForSayQuiet arrayByAddingObject:winSeekAdd];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *chat = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger hailSonIndex = indexPath.section;
    key = _sunForSayQuiet[hailSonIndex][indexPath.row];
    value = _leaseRowAsleepExecutionDatabase[hailSonIndex][key];
    BOOL hundreds = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    chat.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *peakTap in chat.contentView.subviews) {
        [peakTap removeFromSuperview];
    }
    
    
    UILabel *kitLabel = [[UILabel alloc] init];
    kitLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    kitLabel.textColor = [UIColor darkGrayColor];
    kitLabel.text = key;
    kitLabel.numberOfLines = 0;
    [chat.contentView addSubview:kitLabel];
    
    
    UILabel *beginLabel = [[UILabel alloc] init];
    beginLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    beginLabel.textColor = [UIColor blackColor];
    beginLabel.numberOfLines = 0;
    beginLabel.textAlignment = NSTextAlignmentRight;
    [chat.contentView addSubview:beginLabel];
    
    
    [kitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(chat.contentView).offset(TooCloudSun.seeFocusSlab.obstacleOnce);
        make.top.equalTo(chat.contentView).offset(TooCloudSun.seeFocusSlab.inuitSideDry);
        make.bottom.equalTo(chat.contentView).offset(-TooCloudSun.seeFocusSlab.inuitSideDry);
        make.width.equalTo(chat.contentView.mas_width).multipliedBy(hundreds?TooCloudSun.seeFocusSlab.labelStacked:TooCloudSun.seeFocusSlab.truncatedType);
    }];
    
    [beginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(chat.contentView).offset(-TooCloudSun.seeFocusSlab.obstacleOnce);
        make.top.equalTo(chat.contentView).offset(TooCloudSun.seeFocusSlab.inuitSideDry);
        make.bottom.equalTo(chat.contentView).offset(-TooCloudSun.seeFocusSlab.inuitSideDry);
        make.left.equalTo(kitLabel.mas_right).offset(TooCloudSun.seeFocusSlab.inuitSideDry);
    }];
    
    
    if (hundreds) {
        chat.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        beginLabel.text = [value description];
        chat.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return chat;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger hailSonIndex = indexPath.section;
    key = _sunForSayQuiet[hailSonIndex][indexPath.row];
    value = _leaseRowAsleepExecutionDatabase[hailSonIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self awayOldHueDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self dogStopTheArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [SinToast hisNear:TooCloudSun.seeFocusSlab.moreMonthEndsOperatingGrayRadio];
    }
}


- (void)awayOldHueDictionary:(NSDictionary *)rare withTitle:(NSString *)title {
    KnowMayCutViewController *exactWon = [[KnowMayCutViewController alloc] init];
    [self.navigationController pushViewController:exactWon animated:NO];
    [exactWon beaconsGaelicInfo:rare withTitle:title];
}

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

@end
