






#import "NapSafeUseViewController.h"
#import "BlobCopticConfig.h"
#import "NSObject+MayModel.h"
#import "UIColor+BitColor.h"
#import "KinToast.h"

@interface NapSafeUseViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation NapSafeUseViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _kilogramsExhaustedMobileMenDesigner = [NSMutableArray array];
    _frameAnyHexHue = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self sinWasGolfView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets distantPut = [[NextBeganManager shared] bedHasEnableWindow].safeAreaInsets;
    
    distantPut.top    += 10;
    distantPut.left   += 10;
    distantPut.bottom += 10;
    distantPut.right  += 10;

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


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


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

- (void)digitVitalityInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_kilogramsExhaustedMobileMenDesigner addObject:[info copy]];
            NSArray *hitToolSin = [self helpItemFriendDictionary:info];
            self->_frameAnyHexHue = [self->_frameAnyHexHue arrayByAddingObject:hitToolSin];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *plan = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger thinDueIndex = indexPath.section;
    key = _frameAnyHexHue[thinDueIndex][indexPath.row];
    value = _kilogramsExhaustedMobileMenDesigner[thinDueIndex][key];
    BOOL addBrown = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    plan.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *special in plan.contentView.subviews) {
        [special removeFromSuperview];
    }
    
    
    UILabel *addLabel = [[UILabel alloc] init];
    addLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    addLabel.textColor = [UIColor darkGrayColor];
    addLabel.text = key;
    addLabel.numberOfLines = 0;
    [plan.contentView addSubview:addLabel];
    
    
    UILabel *photoLabel = [[UILabel alloc] init];
    photoLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    photoLabel.textColor = [UIColor blackColor];
    photoLabel.numberOfLines = 0;
    photoLabel.textAlignment = NSTextAlignmentRight;
    [plan.contentView addSubview:photoLabel];
    
    
    [addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(plan.contentView).offset(FixMaterial.capsLoopsAge.twoFunStream);
        make.top.equalTo(plan.contentView).offset(FixMaterial.capsLoopsAge.expiredBuilt);
        make.bottom.equalTo(plan.contentView).offset(-FixMaterial.capsLoopsAge.expiredBuilt);
        make.width.equalTo(plan.contentView.mas_width).multipliedBy(addBrown?FixMaterial.capsLoopsAge.ourSquashHas:FixMaterial.capsLoopsAge.wetHoursSmall);
    }];
    
    [photoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(plan.contentView).offset(-FixMaterial.capsLoopsAge.twoFunStream);
        make.top.equalTo(plan.contentView).offset(FixMaterial.capsLoopsAge.expiredBuilt);
        make.bottom.equalTo(plan.contentView).offset(-FixMaterial.capsLoopsAge.expiredBuilt);
        make.left.equalTo(addLabel.mas_right).offset(FixMaterial.capsLoopsAge.expiredBuilt);
    }];
    
    
    if (addBrown) {
        plan.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        photoLabel.text = [value description];
        plan.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return plan;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger thinDueIndex = indexPath.section;
    key = _frameAnyHexHue[thinDueIndex][indexPath.row];
    value = _kilogramsExhaustedMobileMenDesigner[thinDueIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self generalPubDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self specifyTopArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [KinToast eyeNear:FixMaterial.capsLoopsAge.oddBezelPenTriggerTeamKilogram];
    }
}


- (void)generalPubDictionary:(NSDictionary *)cube withTitle:(NSString *)title {
    NapSafeUseViewController *sawPhone = [[NapSafeUseViewController alloc] init];
    [self.navigationController pushViewController:sawPhone animated:NO];
    [sawPhone digitVitalityInfo:cube withTitle:title];
}

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

@end
