






#import "MixDidHandViewController.h"
#import "WorkoutCapConfig.h"
#import "NSObject+BoxModel.h"
#import "UIColor+FaxColor.h"
#import "UseToast.h"

@interface MixDidHandViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation MixDidHandViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _weightedAsleepForbidCapButtons = [NSMutableArray array];
    _dayAddSubPager = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self peopleInfoView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets rareIndent = [[SoloSlantManager shared] foggyTiedDueWindow].safeAreaInsets;
    
    rareIndent.top    += 10;
    rareIndent.left   += 10;
    rareIndent.bottom += 10;
    rareIndent.right  += 10;

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


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


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

- (void)flipRebusHaveInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_weightedAsleepForbidCapButtons addObject:[info copy]];
            NSArray *datumPiece = [self barBigOptPulseDictionary:info];
            self->_dayAddSubPager = [self->_dayAddSubPager arrayByAddingObject:datumPiece];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger extractIndex = indexPath.section;
    key = _dayAddSubPager[extractIndex][indexPath.row];
    value = _weightedAsleepForbidCapButtons[extractIndex][key];
    BOOL indexing = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    cell.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *teamMan in cell.contentView.subviews) {
        [teamMan removeFromSuperview];
    }
    
    
    UILabel *binLabel = [[UILabel alloc] init];
    binLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    binLabel.textColor = [UIColor darkGrayColor];
    binLabel.text = key;
    binLabel.numberOfLines = 0;
    [cell.contentView addSubview:binLabel];
    
    
    UILabel *appleLabel = [[UILabel alloc] init];
    appleLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    appleLabel.textColor = [UIColor blackColor];
    appleLabel.numberOfLines = 0;
    appleLabel.textAlignment = NSTextAlignmentRight;
    [cell.contentView addSubview:appleLabel];
    
    
    [binLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cell.contentView).offset(HexDiscrete.shelfTenSide.yetAlongSort);
        make.top.equalTo(cell.contentView).offset(HexDiscrete.shelfTenSide.ruleOffVital);
        make.bottom.equalTo(cell.contentView).offset(-HexDiscrete.shelfTenSide.ruleOffVital);
        make.width.equalTo(cell.contentView.mas_width).multipliedBy(indexing?HexDiscrete.shelfTenSide.bigFreestyle:HexDiscrete.shelfTenSide.walkingRemote);
    }];
    
    [appleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(cell.contentView).offset(-HexDiscrete.shelfTenSide.yetAlongSort);
        make.top.equalTo(cell.contentView).offset(HexDiscrete.shelfTenSide.ruleOffVital);
        make.bottom.equalTo(cell.contentView).offset(-HexDiscrete.shelfTenSide.ruleOffVital);
        make.left.equalTo(binLabel.mas_right).offset(HexDiscrete.shelfTenSide.ruleOffVital);
    }];
    
    
    if (indexing) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        appleLabel.text = [value description];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger extractIndex = indexPath.section;
    key = _dayAddSubPager[extractIndex][indexPath.row];
    value = _weightedAsleepForbidCapButtons[extractIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self sinTwoArtsDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self gopherReadArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [UseToast dashMen:HexDiscrete.shelfTenSide.tapYearsAirMultipleVariableTool];
    }
}


- (void)sinTwoArtsDictionary:(NSDictionary *)shot withTitle:(NSString *)title {
    MixDidHandViewController *shearKin = [[MixDidHandViewController alloc] init];
    [self.navigationController pushViewController:shearKin animated:NO];
    [shearKin flipRebusHaveInfo:shot withTitle:title];
}

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

@end
