






#import "RingEarSunViewController.h"
#import "PricePointConfig.h"
#import "NSObject+BusModel.h"
#import "UIColor+RedColor.h"
#import "IcyToast.h"

@interface RingEarSunViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation RingEarSunViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _marginClickedLowVideoExecution = [NSMutableArray array];
    _bitsTradModule = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self towerBriefView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets pickResume = [[JobDegreeManager shared] wasDraftSockWindow].safeAreaInsets;
    
    pickResume.top    += 10;
    pickResume.left   += 10;
    pickResume.bottom += 10;
    pickResume.right  += 10;

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


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


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

- (void)outStepsonNotInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_marginClickedLowVideoExecution addObject:[info copy]];
            NSArray *airIronNet = [self draftSentWorldDictionary:info];
            self->_bitsTradModule = [self->_bitsTradModule arrayByAddingObject:airIronNet];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *loss = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger minimumIndex = indexPath.section;
    key = _bitsTradModule[minimumIndex][indexPath.row];
    value = _marginClickedLowVideoExecution[minimumIndex][key];
    BOOL spanUndo = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    loss.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *sameBag in loss.contentView.subviews) {
        [sameBag removeFromSuperview];
    }
    
    
    UILabel *allLabel = [[UILabel alloc] init];
    allLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    allLabel.textColor = [UIColor darkGrayColor];
    allLabel.text = key;
    allLabel.numberOfLines = 0;
    [loss.contentView addSubview:allLabel];
    
    
    UILabel *flushLabel = [[UILabel alloc] init];
    flushLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    flushLabel.textColor = [UIColor blackColor];
    flushLabel.numberOfLines = 0;
    flushLabel.textAlignment = NSTextAlignmentRight;
    [loss.contentView addSubview:flushLabel];
    
    
    [allLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(loss.contentView).offset(SchemesSong.targetRemote.musicDynamic);
        make.top.equalTo(loss.contentView).offset(SchemesSong.targetRemote.subDecrypted);
        make.bottom.equalTo(loss.contentView).offset(-SchemesSong.targetRemote.subDecrypted);
        make.width.equalTo(loss.contentView.mas_width).multipliedBy(spanUndo?SchemesSong.targetRemote.leadCloudKit:SchemesSong.targetRemote.tildeWasMusic);
    }];
    
    [flushLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(loss.contentView).offset(-SchemesSong.targetRemote.musicDynamic);
        make.top.equalTo(loss.contentView).offset(SchemesSong.targetRemote.subDecrypted);
        make.bottom.equalTo(loss.contentView).offset(-SchemesSong.targetRemote.subDecrypted);
        make.left.equalTo(allLabel.mas_right).offset(SchemesSong.targetRemote.subDecrypted);
    }];
    
    
    if (spanUndo) {
        loss.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        flushLabel.text = [value description];
        loss.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return loss;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger minimumIndex = indexPath.section;
    key = _bitsTradModule[minimumIndex][indexPath.row];
    value = _marginClickedLowVideoExecution[minimumIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self anyTwoSeedDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self otherSpineArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [IcyToast garbage:SchemesSong.targetRemote.hectaresCompletedPosterPlayHexWalk];
    }
}


- (void)anyTwoSeedDictionary:(NSDictionary *)take withTitle:(NSString *)title {
    RingEarSunViewController *putBegan = [[RingEarSunViewController alloc] init];
    [self.navigationController pushViewController:putBegan animated:NO];
    [putBegan outStepsonNotInfo:take withTitle:title];
}

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

@end
