






#import "OwnPassWayViewController.h"
#import "OurDragFitConfig.h"
#import "NSObject+AirModel.h"
#import "UIColor+SubColor.h"
#import "FunToast.h"

@interface OwnPassWayViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation OwnPassWayViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _exceptionBitHighEsperantoWill = [NSMutableArray array];
    _moleNoneOurNot = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self tipOutNearView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets sobTapPort = [[StandCapsManager shared] kilobytesBagWindow].safeAreaInsets;
    
    sobTapPort.top    += 10;
    sobTapPort.left   += 10;
    sobTapPort.bottom += 10;
    sobTapPort.right  += 10;

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


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


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

- (void)butSaltOutKeyInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_exceptionBitHighEsperantoWill addObject:[info copy]];
            NSArray *askCharWon = [self discountResumeDictionary:info];
            self->_moleNoneOurNot = [self->_moleNoneOurNot arrayByAddingObject:askCharWon];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cube = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger herPrepIndex = indexPath.section;
    key = _moleNoneOurNot[herPrepIndex][indexPath.row];
    value = _exceptionBitHighEsperantoWill[herPrepIndex][key];
    BOOL faceTake = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    cube.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *justKit in cube.contentView.subviews) {
        [justKit removeFromSuperview];
    }
    
    
    UILabel *wayLabel = [[UILabel alloc] init];
    wayLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    wayLabel.textColor = [UIColor darkGrayColor];
    wayLabel.text = key;
    wayLabel.numberOfLines = 0;
    [cube.contentView addSubview:wayLabel];
    
    
    UILabel *todayLabel = [[UILabel alloc] init];
    todayLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    todayLabel.textColor = [UIColor blackColor];
    todayLabel.numberOfLines = 0;
    todayLabel.textAlignment = NSTextAlignmentRight;
    [cube.contentView addSubview:todayLabel];
    
    
    [wayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cube.contentView).offset(ReadWaxDash.strideFooter.toolFunClear);
        make.top.equalTo(cube.contentView).offset(ReadWaxDash.strideFooter.slovenianCan);
        make.bottom.equalTo(cube.contentView).offset(-ReadWaxDash.strideFooter.slovenianCan);
        make.width.equalTo(cube.contentView.mas_width).multipliedBy(faceTake?ReadWaxDash.strideFooter.offSlovenian:ReadWaxDash.strideFooter.subValueSlice);
    }];
    
    [todayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(cube.contentView).offset(-ReadWaxDash.strideFooter.toolFunClear);
        make.top.equalTo(cube.contentView).offset(ReadWaxDash.strideFooter.slovenianCan);
        make.bottom.equalTo(cube.contentView).offset(-ReadWaxDash.strideFooter.slovenianCan);
        make.left.equalTo(wayLabel.mas_right).offset(ReadWaxDash.strideFooter.slovenianCan);
    }];
    
    
    if (faceTake) {
        cube.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        todayLabel.text = [value description];
        cube.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return cube;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger herPrepIndex = indexPath.section;
    key = _moleNoneOurNot[herPrepIndex][indexPath.row];
    value = _exceptionBitHighEsperantoWill[herPrepIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self sleepLiterDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self pushLocaleArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [FunToast pubRule:ReadWaxDash.strideFooter.producePitchSupportedDocumentLeaseRemovable];
    }
}


- (void)sleepLiterDictionary:(NSDictionary *)burn withTitle:(NSString *)title {
    OwnPassWayViewController *lookSame = [[OwnPassWayViewController alloc] init];
    [self.navigationController pushViewController:lookSame animated:NO];
    [lookSame butSaltOutKeyInfo:burn withTitle:title];
}

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

@end
