






#import "StripAlarmViewController.h"
#import "FitAzimuthConfig.h"
#import "NSObject+OneModel.h"
#import "UIColor+GetColor.h"
#import "AnyToast.h"

@interface StripAlarmViewController ()<UITableViewDataSource, UITableViewDelegate>

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

@end

@implementation StripAlarmViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    _stoneFaxWindowsMonthExporting = [NSMutableArray array];
    _millAirWasPast = @[];
    _sectionTitles = [NSMutableArray array];
    
    [self cousinSkipView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    UIEdgeInsets addTagType = [[DigitSongManager shared] irregularHerWindow].safeAreaInsets;
    
    addTagType.top    += 10;
    addTagType.left   += 10;
    addTagType.bottom += 10;
    addTagType.right  += 10;

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


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


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

- (void)entryModalTooInfo:(NSDictionary *)info withTitle:(NSString *)title {
    if (!info || ![info isKindOfClass:[NSDictionary class]]) {
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        @synchronized (self) {
            
            [self->_stoneFaxWindowsMonthExporting addObject:[info copy]];
            NSArray *mixOldTake = [self icySobSixWidthDictionary:info];
            self->_millAirWasPast = [self->_millAirWasPast arrayByAddingObject:mixOldTake];
            [self->_sectionTitles addObject:title];
            
            
            [self.tableView reloadData];
        }
    });
}


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

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

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *best = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self.class) forIndexPath:indexPath];
    
    NSString *key;
    id value;
    NSInteger airTurnIndex = indexPath.section;
    key = _millAirWasPast[airTurnIndex][indexPath.row];
    value = _stoneFaxWindowsMonthExporting[airTurnIndex][key];
    BOOL splitDog = [value isKindOfClass:[NSDictionary class]] || [value isKindOfClass:[NSArray class]];
    best.backgroundColor = [UIColor clearColor];
    
    
    for (UIView *segment in best.contentView.subviews) {
        [segment removeFromSuperview];
    }
    
    
    UILabel *tryLabel = [[UILabel alloc] init];
    tryLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightMedium];
    tryLabel.textColor = [UIColor darkGrayColor];
    tryLabel.text = key;
    tryLabel.numberOfLines = 0;
    [best.contentView addSubview:tryLabel];
    
    
    UILabel *evictLabel = [[UILabel alloc] init];
    evictLabel.font = [UIFont monospacedSystemFontOfSize:14 weight:UIFontWeightRegular];
    evictLabel.textColor = [UIColor blackColor];
    evictLabel.numberOfLines = 0;
    evictLabel.textAlignment = NSTextAlignmentRight;
    [best.contentView addSubview:evictLabel];
    
    
    [tryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(best.contentView).offset(ZipRestThat.heartHowLead.queueZeroOld);
        make.top.equalTo(best.contentView).offset(ZipRestThat.heartHowLead.brandMasters);
        make.bottom.equalTo(best.contentView).offset(-ZipRestThat.heartHowLead.brandMasters);
        make.width.equalTo(best.contentView.mas_width).multipliedBy(splitDog?ZipRestThat.heartHowLead.cropBagBegan:ZipRestThat.heartHowLead.levelDenyTags);
    }];
    
    [evictLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(best.contentView).offset(-ZipRestThat.heartHowLead.queueZeroOld);
        make.top.equalTo(best.contentView).offset(ZipRestThat.heartHowLead.brandMasters);
        make.bottom.equalTo(best.contentView).offset(-ZipRestThat.heartHowLead.brandMasters);
        make.left.equalTo(tryLabel.mas_right).offset(ZipRestThat.heartHowLead.brandMasters);
    }];
    
    
    if (splitDog) {
        best.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        evictLabel.text = [value description];
        best.accessoryType = UITableViewCellAccessoryNone;
    }
    
    return best;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    id value;
    NSString *key;
    
    NSInteger airTurnIndex = indexPath.section;
    key = _millAirWasPast[airTurnIndex][indexPath.row];
    value = _stoneFaxWindowsMonthExporting[airTurnIndex][key];
    
    
    if ([value isKindOfClass:[NSDictionary class]]) {
        [self columnSnapDictionary:value withTitle:key];
    } else if ([value isKindOfClass:[NSArray class]]) {
        [self sumRunFiveArray:value withTitle:key];
    } else {
        
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        [pasteboard setString:[value description]];
        [AnyToast fifteen:ZipRestThat.heartHowLead.sparseBeenWayEsperantoStylizeOne];
    }
}


- (void)columnSnapDictionary:(NSDictionary *)hail withTitle:(NSString *)title {
    StripAlarmViewController *tipToday = [[StripAlarmViewController alloc] init];
    [self.navigationController pushViewController:tipToday animated:NO];
    [tipToday entryModalTooInfo:hail withTitle:title];
}

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

@end
