






#import "VowelSurgeViewController.h"
#import "ArmpitMathConfig.h"
#import "NSObject+DayModel.h"
#import "UIColor+SeeColor.h"
#import "HowToast.h"

@interface VowelSurgeViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation VowelSurgeViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _illegalChannelsApplyingSecondLoop = [NSMutableArray array];
    _effortFeedback = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self longWayFixView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets wayHerGray = [[FrequencyManager shared] putAboutStopWindow].safeAreaInsets;
    
    wayHerGray.top    += 10;
    wayHerGray.left   += 10;
    wayHerGray.bottom += 10;
    wayHerGray.right  += 10;

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


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


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

- (void)videoDeletingInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_illegalChannelsApplyingSecondLoop addObject:[info copy]];
            NSArray *busyTabKin = [self oddLevelTooEraDictionary:info];
            self->_effortFeedback = [self->_effortFeedback arrayByAddingObject:busyTabKin];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _effortFeedback[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 blobSheIndex = indexPath.section;
    key = _effortFeedback[blobSheIndex][indexPath.row];
    value = _illegalChannelsApplyingSecondLoop[blobSheIndex][key];
    BOOL feedUnit = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    rare.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *downHex in rare.contentView.subviews) {
        [downHex removeFromSuperview];
    }
    
    
    UILabel *youLabel = [[UILabel alloc] init];
    youLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    youLabel.textColor = [UIColor darkGrayColor];
    youLabel.text = key;
    youLabel.numberOfLines = 0;
    [rare.contentView addSubview:youLabel];
    
    
    UILabel *totalLabel = [[UILabel alloc] init];
    totalLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    totalLabel.textColor = [UIColor blackColor];
    totalLabel.numberOfLines = 0;
    totalLabel.textAlignment = NSTextAlignmentRight;
    [rare.contentView addSubview:totalLabel];
    
    
    [youLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(rare.contentView).offset(ExtentEuler.maleSubtitle.prepCoverTap);
        make.top.equalTo(rare.contentView).offset(ExtentEuler.maleSubtitle.sixColumnRed);
        make.bottom.equalTo(rare.contentView).offset(-ExtentEuler.maleSubtitle.sixColumnRed);
        make.width.equalTo(rare.contentView.mas_width).multipliedBy(feedUnit?ExtentEuler.maleSubtitle.patchHexText:ExtentEuler.maleSubtitle.tenWireZipAsk);
    }];
    
    [totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(rare.contentView).offset(-ExtentEuler.maleSubtitle.prepCoverTap);
        make.top.equalTo(rare.contentView).offset(ExtentEuler.maleSubtitle.sixColumnRed);
        make.bottom.equalTo(rare.contentView).offset(-ExtentEuler.maleSubtitle.sixColumnRed);
        make.left.equalTo(youLabel.mas_right).offset(ExtentEuler.maleSubtitle.sixColumnRed);
    }];
    
    
    if (feedUnit) {
        rare.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        totalLabel.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 blobSheIndex = indexPath.section;
    key = _effortFeedback[blobSheIndex][indexPath.row];
    value = _illegalChannelsApplyingSecondLoop[blobSheIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self learnCrossDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self teethBlackArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [HowToast weekHis:ExtentEuler.maleSubtitle.tenSlavicAllocatorLeadPutPinch];
    }
}


- (void)learnCrossDictionary:(NSDictionary *)lift withTitle:(NSString *)title {
    VowelSurgeViewController *atomArea = [[VowelSurgeViewController alloc] init];
    [self.navigationController pushViewController:atomArea animated:NO];
    [atomArea videoDeletingInfo:lift withTitle:title];
}

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

@end
