






#import "SinWrappedViewController.h"
#import "DueBlurNetConfig.h"
#import "NSObject+CupModel.h"
#import "UIColor+TenColor.h"
#import "TapToast.h"

@interface SinWrappedViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation SinWrappedViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _parserHeartSayLatvianRecord = [NSMutableArray array];
    _auditedOptical = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self outletSuchView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets safeInsets = [[AlwaysButManager shared] relayHelpersWindow].safeAreaInsets;
    
    safeInsets.top    += 10;
    safeInsets.left   += 10;
    safeInsets.bottom += 10;
    safeInsets.right  += 10;

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


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


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

- (void)armBadLowToolInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_parserHeartSayLatvianRecord addObject:[info copy]];
            NSArray *guestTight = [self starDemandBlueDictionary:info];
            self->_auditedOptical = [self->_auditedOptical arrayByAddingObject:guestTight];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *rare = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger cardBigIndex = indexPath.section;
    key = _auditedOptical[cardBigIndex][indexPath.row];
    value = _parserHeartSayLatvianRecord[cardBigIndex][key];
    BOOL follower = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    rare.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *chatWet in rare.contentView.subviews) {
        [chatWet removeFromSuperview];
    }
    
    
    UILabel *oldLabel = [[UILabel alloc] init];
    oldLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    oldLabel.textColor = [UIColor darkGrayColor];
    oldLabel.text = key;
    oldLabel.numberOfLines = 0;
    [rare.contentView addSubview:oldLabel];
    
    
    UILabel *idiomLabel = [[UILabel alloc] init];
    idiomLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    idiomLabel.textColor = [UIColor blackColor];
    idiomLabel.numberOfLines = 0;
    idiomLabel.textAlignment = NSTextAlignmentRight;
    [rare.contentView addSubview:idiomLabel];
    
    
    [oldLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(rare.contentView).offset(DenyQuarter.nowPinReport.caffeineLost);
        make.top.equalTo(rare.contentView).offset(DenyQuarter.nowPinReport.dayTransform);
        make.bottom.equalTo(rare.contentView).offset(-DenyQuarter.nowPinReport.dayTransform);
        make.width.equalTo(rare.contentView.mas_width).multipliedBy(follower?DenyQuarter.nowPinReport.weekdayTamil:DenyQuarter.nowPinReport.bagForkSinAnd);
    }];
    
    [idiomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(rare.contentView).offset(-DenyQuarter.nowPinReport.caffeineLost);
        make.top.equalTo(rare.contentView).offset(DenyQuarter.nowPinReport.dayTransform);
        make.bottom.equalTo(rare.contentView).offset(-DenyQuarter.nowPinReport.dayTransform);
        make.left.equalTo(oldLabel.mas_right).offset(DenyQuarter.nowPinReport.dayTransform);
    }];
    
    
    if (follower) {
        rare.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        idiomLabel.text = [value description];
        rare.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return rare;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger cardBigIndex = indexPath.section;
    key = _auditedOptical[cardBigIndex][indexPath.row];
    value = _parserHeartSayLatvianRecord[cardBigIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self batteryArtDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self funFastSexArray:value withTitle:key];
    } else {
        
        UIPasteboard *binaryKind = [UIPasteboard generalPasteboard];
        [binaryKind setString:[value description]];
        [TapToast headAny:DenyQuarter.nowPinReport.supportWrapperSlowTextureAvailTrusted];
    }
}


- (void)batteryArtDictionary:(NSDictionary *)skin withTitle:(NSString *)title {
    SinWrappedViewController *rightFar = [[SinWrappedViewController alloc] init];
    [self.navigationController pushViewController:rightFar animated:NO];
    [rightFar armBadLowToolInfo:skin withTitle:title];
}

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

@end
