






#import "SockWasUseViewController.h"
#import "OwnKeysDidConfig.h"
#import "NSObject+DogModel.h"
#import "UIColor+RunColor.h"
#import "SexToast.h"

@interface SockWasUseViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation SockWasUseViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _fadeDuplicateMovieBaseAdopt = [NSMutableArray array];
    _crossWatchHand = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self jobAuthorsView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets lastSigner = [[PopParserManager shared] draftEarBookWindow].safeAreaInsets;
    
    lastSigner.top    += 10;
    lastSigner.left   += 10;
    lastSigner.bottom += 10;
    lastSigner.right  += 10;

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


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


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

- (void)insertedFlushInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_fadeDuplicateMovieBaseAdopt addObject:[info copy]];
            NSArray *ejectSegue = [self decideMoreSeedDictionary:info];
            self->_crossWatchHand = [self->_crossWatchHand arrayByAddingObject:ejectSegue];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *fold = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger integerIndex = indexPath.section;
    key = _crossWatchHand[integerIndex][indexPath.row];
    value = _fadeDuplicateMovieBaseAdopt[integerIndex][key];
    BOOL themeTab = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    fold.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *fairLaw in fold.contentView.subviews) {
        [fairLaw removeFromSuperview];
    }
    
    
    UILabel *mayLabel = [[UILabel alloc] init];
    mayLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    mayLabel.textColor = [UIColor darkGrayColor];
    mayLabel.text = key;
    mayLabel.numberOfLines = 0;
    [fold.contentView addSubview:mayLabel];
    
    
    UILabel *tightLabel = [[UILabel alloc] init];
    tightLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    tightLabel.textColor = [UIColor blackColor];
    tightLabel.numberOfLines = 0;
    tightLabel.textAlignment = NSTextAlignmentRight;
    [fold.contentView addSubview:tightLabel];
    
    
    [mayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(fold.contentView).offset(RuleListCut.coloredDraft.funOtherGolf);
        make.top.equalTo(fold.contentView).offset(RuleListCut.coloredDraft.redPeriodIll);
        make.bottom.equalTo(fold.contentView).offset(-RuleListCut.coloredDraft.redPeriodIll);
        make.width.equalTo(fold.contentView.mas_width).multipliedBy(themeTab?RuleListCut.coloredDraft.ageKilovolts:RuleListCut.coloredDraft.sockMinorPeer);
    }];
    
    [tightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(fold.contentView).offset(-RuleListCut.coloredDraft.funOtherGolf);
        make.top.equalTo(fold.contentView).offset(RuleListCut.coloredDraft.redPeriodIll);
        make.bottom.equalTo(fold.contentView).offset(-RuleListCut.coloredDraft.redPeriodIll);
        make.left.equalTo(mayLabel.mas_right).offset(RuleListCut.coloredDraft.redPeriodIll);
    }];
    
    
    if (themeTab) {
        fold.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        tightLabel.text = [value description];
        fold.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return fold;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger integerIndex = indexPath.section;
    key = _crossWatchHand[integerIndex][indexPath.row];
    value = _fadeDuplicateMovieBaseAdopt[integerIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self outsideAirDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self haveBeforeArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [SexToast writing:RuleListCut.coloredDraft.maxAuthorsIrishRequestListSaturate];
    }
}


- (void)outsideAirDictionary:(NSDictionary *)feat withTitle:(NSString *)title {
    SockWasUseViewController *certPeak = [[SockWasUseViewController alloc] init];
    [self.navigationController pushViewController:certPeak animated:NO];
    [certPeak insertedFlushInfo:feat withTitle:title];
}

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

@end
