






#import "RussianOneViewController.h"
#import "PersonFillConfig.h"
#import "NSObject+LowModel.h"
#import "UIColor+BusColor.h"
#import "CatToast.h"

@interface RussianOneViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation RussianOneViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _meterTorqueIllegalWayHighlight = [NSMutableArray array];
    _mixerGigahertz = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self mediaCacheView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets flowUnwind = [[OutDemandManager shared] headlineSentWindow].safeAreaInsets;
    
    flowUnwind.top    += 10;
    flowUnwind.left   += 10;
    flowUnwind.bottom += 10;
    flowUnwind.right  += 10;

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


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


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

- (void)sawTooSnapHerInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_meterTorqueIllegalWayHighlight addObject:[info copy]];
            NSArray *oddOddDown = [self kitEarSugarOptDictionary:info];
            self->_mixerGigahertz = [self->_mixerGigahertz arrayByAddingObject:oddOddDown];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *sink = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger areDoneIndex = indexPath.section;
    key = _mixerGigahertz[areDoneIndex][indexPath.row];
    value = _meterTorqueIllegalWayHighlight[areDoneIndex][key];
    BOOL stampWax = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    sink.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *appears in sink.contentView.subviews) {
        [appears removeFromSuperview];
    }
    
    
    UILabel *subLabel = [[UILabel alloc] init];
    subLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    subLabel.textColor = [UIColor darkGrayColor];
    subLabel.text = key;
    subLabel.numberOfLines = 0;
    [sink.contentView addSubview:subLabel];
    
    
    UILabel *sevenLabel = [[UILabel alloc] init];
    sevenLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    sevenLabel.textColor = [UIColor blackColor];
    sevenLabel.numberOfLines = 0;
    sevenLabel.textAlignment = NSTextAlignmentRight;
    [sink.contentView addSubview:sevenLabel];
    
    
    [subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(sink.contentView).offset(SkinEchoMen.pauseKirghiz.rareInserted);
        make.top.equalTo(sink.contentView).offset(SkinEchoMen.pauseKirghiz.slovakFunDog);
        make.bottom.equalTo(sink.contentView).offset(-SkinEchoMen.pauseKirghiz.slovakFunDog);
        make.width.equalTo(sink.contentView.mas_width).multipliedBy(stampWax?SkinEchoMen.pauseKirghiz.jouleOverdue:SkinEchoMen.pauseKirghiz.eastPenAnyRet);
    }];
    
    [sevenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(sink.contentView).offset(-SkinEchoMen.pauseKirghiz.rareInserted);
        make.top.equalTo(sink.contentView).offset(SkinEchoMen.pauseKirghiz.slovakFunDog);
        make.bottom.equalTo(sink.contentView).offset(-SkinEchoMen.pauseKirghiz.slovakFunDog);
        make.left.equalTo(subLabel.mas_right).offset(SkinEchoMen.pauseKirghiz.slovakFunDog);
    }];
    
    
    if (stampWax) {
        sink.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        sevenLabel.text = [value description];
        sink.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return sink;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger areDoneIndex = indexPath.section;
    key = _mixerGigahertz[areDoneIndex][indexPath.row];
    value = _meterTorqueIllegalWayHighlight[areDoneIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self userSourceDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self germanWeekArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [CatToast theSoft:SkinEchoMen.pauseKirghiz.beaconManyItsThreadsMountTriangle];
    }
}


- (void)userSourceDictionary:(NSDictionary *)trap withTitle:(NSString *)title {
    RussianOneViewController *tomorrow = [[RussianOneViewController alloc] init];
    [self.navigationController pushViewController:tomorrow animated:NO];
    [tomorrow sawTooSnapHerInfo:trap withTitle:title];
}

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

@end
