






#import "MapDecryptViewController.h"
#import "OnePopSongConfig.h"
#import "NSObject+OwnModel.h"
#import "UIColor+DryColor.h"
#import "BusToast.h"

@interface MapDecryptViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation MapDecryptViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _airOpticalSiblingsLexiconThrough = [NSMutableArray array];
    _languagesBezel = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self majorFloorView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets sumCompany = [[UnpluggedManager shared] gainMusicMayWindow].safeAreaInsets;
    
    sumCompany.top    += 10;
    sumCompany.left   += 10;
    sumCompany.bottom += 10;
    sumCompany.right  += 10;

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


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


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

- (void)secondPronounInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_airOpticalSiblingsLexiconThrough addObject:[info copy]];
            NSArray *portCapAre = [self resetBitCanWonDictionary:info];
            self->_languagesBezel = [self->_languagesBezel arrayByAddingObject:portCapAre];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *loop = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger eyeMaskIndex = indexPath.section;
    key = _languagesBezel[eyeMaskIndex][indexPath.row];
    value = _airOpticalSiblingsLexiconThrough[eyeMaskIndex][key];
    BOOL infinite = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    loop.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *factPan in loop.contentView.subviews) {
        [factPan removeFromSuperview];
    }
    
    
    UILabel *getLabel = [[UILabel alloc] init];
    getLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    getLabel.textColor = [UIColor darkGrayColor];
    getLabel.text = key;
    getLabel.numberOfLines = 0;
    [loop.contentView addSubview:getLabel];
    
    
    UILabel *stoodLabel = [[UILabel alloc] init];
    stoodLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    stoodLabel.textColor = [UIColor blackColor];
    stoodLabel.numberOfLines = 0;
    stoodLabel.textAlignment = NSTextAlignmentRight;
    [loop.contentView addSubview:stoodLabel];
    
    
    [getLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(loop.contentView).offset(PinMovement.cupFormatSun.seeFadePaper);
        make.top.equalTo(loop.contentView).offset(PinMovement.cupFormatSun.leaseZoneOld);
        make.bottom.equalTo(loop.contentView).offset(-PinMovement.cupFormatSun.leaseZoneOld);
        make.width.equalTo(loop.contentView.mas_width).multipliedBy(infinite?PinMovement.cupFormatSun.lawBuildFlow:PinMovement.cupFormatSun.renewSixCycle);
    }];
    
    [stoodLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(loop.contentView).offset(-PinMovement.cupFormatSun.seeFadePaper);
        make.top.equalTo(loop.contentView).offset(PinMovement.cupFormatSun.leaseZoneOld);
        make.bottom.equalTo(loop.contentView).offset(-PinMovement.cupFormatSun.leaseZoneOld);
        make.left.equalTo(getLabel.mas_right).offset(PinMovement.cupFormatSun.leaseZoneOld);
    }];
    
    
    if (infinite) {
        loop.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        stoodLabel.text = [value description];
        loop.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return loop;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger eyeMaskIndex = indexPath.section;
    key = _languagesBezel[eyeMaskIndex][indexPath.row];
    value = _airOpticalSiblingsLexiconThrough[eyeMaskIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self pinDefinedDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self tipButFourArray:value withTitle:key];
    } else {
        
        UIPasteboard *inferFetch = [UIPasteboard generalPasteboard];
        [inferFetch setString:[value description]];
        [BusToast bestRed:PinMovement.cupFormatSun.malteseNumberBasqueChineseKelvinCeltic];
    }
}


- (void)pinDefinedDictionary:(NSDictionary *)tone withTitle:(NSString *)title {
    MapDecryptViewController *kinStorm = [[MapDecryptViewController alloc] init];
    [self.navigationController pushViewController:kinStorm animated:NO];
    [kinStorm secondPronounInfo:tone withTitle:title];
}

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

@end
