






#import "AfterPieceViewController.h"
#import "LoveFitKinConfig.h"
#import "NSObject+WayModel.h"
#import "UIColor+SpaColor.h"
#import "LawToast.h"

@interface AfterPieceViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation AfterPieceViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _volumeDeclineCelsiusSelectedSoftness = [NSMutableArray array];
    _hurricaneOwner = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self tooTheDeepView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets mixBigLook = [[ManualCupManager shared] paperMillOptWindow].safeAreaInsets;
    
    mixBigLook.top    += 10;
    mixBigLook.left   += 10;
    mixBigLook.bottom += 10;
    mixBigLook.right  += 10;

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


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


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

- (void)justMusicOpenInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_volumeDeclineCelsiusSelectedSoftness addObject:[info copy]];
            NSArray *maxArtSeek = [self goalLeadWateryDictionary:info];
            self->_hurricaneOwner = [self->_hurricaneOwner arrayByAddingObject:maxArtSeek];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *rear = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger contextIndex = indexPath.section;
    key = _hurricaneOwner[contextIndex][indexPath.row];
    value = _volumeDeclineCelsiusSelectedSoftness[contextIndex][key];
    BOOL conclude = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    rear.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *waitIcy in rear.contentView.subviews) {
        [waitIcy removeFromSuperview];
    }
    
    
    UILabel *sawLabel = [[UILabel alloc] init];
    sawLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    sawLabel.textColor = [UIColor darkGrayColor];
    sawLabel.text = key;
    sawLabel.numberOfLines = 0;
    [rear.contentView addSubview:sawLabel];
    
    
    UILabel *upperLabel = [[UILabel alloc] init];
    upperLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    upperLabel.textColor = [UIColor blackColor];
    upperLabel.numberOfLines = 0;
    upperLabel.textAlignment = NSTextAlignmentRight;
    [rear.contentView addSubview:upperLabel];
    
    
    [sawLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(rear.contentView).offset(ReloadThird.overlapQuote.overWonMicro);
        make.top.equalTo(rear.contentView).offset(ReloadThird.overlapQuote.smallestChat);
        make.bottom.equalTo(rear.contentView).offset(-ReloadThird.overlapQuote.smallestChat);
        make.width.equalTo(rear.contentView.mas_width).multipliedBy(conclude?ReloadThird.overlapQuote.wonBlueEject:ReloadThird.overlapQuote.annotatedSelf);
    }];
    
    [upperLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(rear.contentView).offset(-ReloadThird.overlapQuote.overWonMicro);
        make.top.equalTo(rear.contentView).offset(ReloadThird.overlapQuote.smallestChat);
        make.bottom.equalTo(rear.contentView).offset(-ReloadThird.overlapQuote.smallestChat);
        make.left.equalTo(sawLabel.mas_right).offset(ReloadThird.overlapQuote.smallestChat);
    }];
    
    
    if (conclude) {
        rear.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        upperLabel.text = [value description];
        rear.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return rear;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger contextIndex = indexPath.section;
    key = _hurricaneOwner[contextIndex][indexPath.row];
    value = _volumeDeclineCelsiusSelectedSoftness[contextIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self aboutPlateDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self headerPinkArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [LawToast tooUnit:ReloadThird.overlapQuote.slovenianHangVerifyPetabytesItsEar];
    }
}


- (void)aboutPlateDictionary:(NSDictionary *)hold withTitle:(NSString *)title {
    AfterPieceViewController *realmSix = [[AfterPieceViewController alloc] init];
    [self.navigationController pushViewController:realmSix animated:NO];
    [realmSix justMusicOpenInfo:hold withTitle:title];
}

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

@end
