






#import "IllWinPickViewController.h"
#import "RangeThirdConfig.h"
#import "NSObject+SawModel.h"
#import "UIColor+IcyColor.h"
#import "SinToast.h"

@interface IllWinPickViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation IllWinPickViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _sharpnessWonUnionArtistInner = [NSMutableArray array];
    _netHangFlatSub = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self dashCanHowView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets pairKitCan = [[RecordingManager shared] abnormalCropWindow].safeAreaInsets;
    
    pairKitCan.top    += 10;
    pairKitCan.left   += 10;
    pairKitCan.bottom += 10;
    pairKitCan.right  += 10;

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


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


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

- (void)cellTorchViewInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_sharpnessWonUnionArtistInner addObject:[info copy]];
            NSArray *panLeftPut = [self goldenJustEasyDictionary:info];
            self->_netHangFlatSub = [self->_netHangFlatSub arrayByAddingObject:panLeftPut];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *deny = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger falloffIndex = indexPath.section;
    key = _netHangFlatSub[falloffIndex][indexPath.row];
    value = _sharpnessWonUnionArtistInner[falloffIndex][key];
    BOOL clearOur = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    deny.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *treeLow in deny.contentView.subviews) {
        [treeLow removeFromSuperview];
    }
    
    
    UILabel *outLabel = [[UILabel alloc] init];
    outLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    outLabel.textColor = [UIColor darkGrayColor];
    outLabel.text = key;
    outLabel.numberOfLines = 0;
    [deny.contentView addSubview:outLabel];
    
    
    UILabel *focusLabel = [[UILabel alloc] init];
    focusLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    focusLabel.textColor = [UIColor blackColor];
    focusLabel.numberOfLines = 0;
    focusLabel.textAlignment = NSTextAlignmentRight;
    [deny.contentView addSubview:focusLabel];
    
    
    [outLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(deny.contentView).offset(BounceBrief.cropSobCanon.errorFaceNap);
        make.top.equalTo(deny.contentView).offset(BounceBrief.cropSobCanon.unableOpaque);
        make.bottom.equalTo(deny.contentView).offset(-BounceBrief.cropSobCanon.unableOpaque);
        make.width.equalTo(deny.contentView.mas_width).multipliedBy(clearOur?BounceBrief.cropSobCanon.panYetVisual:BounceBrief.cropSobCanon.passMajorSort);
    }];
    
    [focusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(deny.contentView).offset(-BounceBrief.cropSobCanon.errorFaceNap);
        make.top.equalTo(deny.contentView).offset(BounceBrief.cropSobCanon.unableOpaque);
        make.bottom.equalTo(deny.contentView).offset(-BounceBrief.cropSobCanon.unableOpaque);
        make.left.equalTo(outLabel.mas_right).offset(BounceBrief.cropSobCanon.unableOpaque);
    }];
    
    
    if (clearOur) {
        deny.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        focusLabel.text = [value description];
        deny.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return deny;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger falloffIndex = indexPath.section;
    key = _netHangFlatSub[falloffIndex][indexPath.row];
    value = _sharpnessWonUnionArtistInner[falloffIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self turnRenderDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self cricketHitArray:value withTitle:key];
    } else {
        
        UIPasteboard *tapBinRoom = [UIPasteboard generalPasteboard];
        [tapBinRoom setString:[value description]];
        [SinToast kernels:BounceBrief.cropSobCanon.trackExactnessDenyLessPromotionGreek];
    }
}


- (void)turnRenderDictionary:(NSDictionary *)drum withTitle:(NSString *)title {
    IllWinPickViewController *phaseBar = [[IllWinPickViewController alloc] init];
    [self.navigationController pushViewController:phaseBar animated:NO];
    [phaseBar cellTorchViewInfo:drum withTitle:title];
}

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

@end
