//
//  ForwardViewController.m
//  AIIM
//
//  Created by qitewei on 2025/5/10.
//

#import "ReportViewController.h"

#import "FriendListCell.h"
#import "FriendNetApi.h"
#import "GroupNetApi.h"
#import "ChatListStore.h"
#import "GWebSocket.h"
#import "UDManager.h"

@interface ReportViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UIImageView * bgImageView;
@property (nonatomic, strong) UIButton * leftBtn;
@property (nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) NSMutableArray * textSrray;
@property (nonatomic, strong) NSMutableArray * selSrray;


@end

@implementation ReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _selSrray = [NSMutableArray new];
    _textSrray = [NSMutableArray new];
    [self configUI];
    
}

- (void)configUI{
    [self setNavigationTitle:NSLocalizedString(@"FriendCtr-toushujb", @"")];
    [self setNavigationBarTransparent:YES];
    [self setNavigationBarBackgroundColor:UIColor.clearColor];
    [self setNavigationTitleColor:UIColor.whiteColor font:SYSBFONT(18)];
    [self addBarButtonWithImage:kImageMake(@"fanhui") position:BarButtonItemPositionLeft action:@selector(backToChat)];
    
    [self.view addSubview:self.bgImageView];
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];
    
    [_textSrray addObject:NSLocalizedString(@"Report-fabubudangnr", @"")];
    [_selSrray addObject:@"0"];
    
    [_textSrray addObject:NSLocalizedString(@"Report-cunzaiqzxw", @"")];
    [_selSrray addObject:@"0"];
    
    [_textSrray addObject:NSLocalizedString(@"Report-zhanghaobd", @"")];
    [_selSrray addObject:@"0"];
    
    [_textSrray addObject:NSLocalizedString(@"Report-fangmaopin", @"")];
    [_selSrray addObject:@"0"];
    
    [_textSrray addObject:NSLocalizedString(@"Report-maocongtr", @"")];
    [_selSrray addObject:@"0"];
    
    [_textSrray addObject:NSLocalizedString(@"Report-qinquan", @"")];
    [_selSrray addObject:@"0"];
    
    [_textSrray addObject:NSLocalizedString(@"Report-qinfanwcnr", @"")];
    [_selSrray addObject:@"0"];
    
    [_textSrray addObject:NSLocalizedString(@"Report-qitayuanyin", @"")];
    [_selSrray addObject:@"0"];
    
    
    
    
    [self layoutselectitem];
}
#pragma mark lazy
- (UIImageView *)bgImageView{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] initWithImage:kImageMake(@"loginBG")];
    }
    return _bgImageView;
}
- (void)backToChat{
    NSLog(@"backToChat");
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark statusBar
- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}


-(void)layoutselectitem{
    // 标题
    UILabel *notelb1 = [[UILabel alloc] init];
    notelb1.font = SYSBFONT(18);
    notelb1.textColor = UIColor.whiteColor;
    notelb1.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:notelb1];
    notelb1.text =NSLocalizedString(@"Report-duixiang", @"");
    
    UIButton *tijiaoBT = [UIButton buttonWithType:UIButtonTypeSystem];
    [tijiaoBT setTitle:NSLocalizedString(@"app-tijiao", @"") forState:UIControlStateNormal];
    [tijiaoBT setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
    [tijiaoBT setBackgroundColor:globalColor(GCTypeGreen)];
    tijiaoBT.layer.cornerRadius = 5.f;
    tijiaoBT.layer.masksToBounds = YES;
    [self.view addSubview:tijiaoBT];
    [tijiaoBT addTarget:self action:@selector(tijiaojubao) forControlEvents:UIControlEventTouchUpInside];
    
    UIImageView *avatar = [[UIImageView alloc] initWithImage:nil];
    [avatar sd_setImageWithURL:[NSURL URLWithString:self.friendAvatar] placeholderImage:[UIImage imageNamed:@"Avatar"]];
    [self.view addSubview:avatar];
    
    UILabel *notelb2 = [[UILabel alloc] init];
    notelb2.font = SYSBFONT(18);
    notelb2.textColor = UIColor.whiteColor;
    notelb2.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:notelb2];
    notelb2.text = self.friendName?:@"";
    
    
    UILabel *notelb3 = [[UILabel alloc] init];
    notelb3.font = SYSBFONT(18);
    notelb3.textColor = globalColor(GCTypeYellow);
    notelb3.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:notelb3];
    notelb3.text =NSLocalizedString(@"Report-yuanyin", @"");
    
    _tableview = [[UITableView alloc] init];
    [self.view addSubview:_tableview];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.backgroundColor = [UIColor clearColor];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    [_tableview registerClass:UITableViewCell.class forCellReuseIdentifier:@"cell"];
    
    // 标题标签布局
    [notelb1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(SCREEN_TOP+48);
        make.left.equalTo(self.view.mas_left).offset(40);
        make.right.equalTo(self.view.mas_right).offset(-80);
        make.height.equalTo(@30);
    }];
//    notelb1.backgroundColor=[UIColor linkColor];
    
    
    // 提交按钮布局
    [tijiaoBT mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(SCREEN_TOP+48);
        make.right.mas_equalTo(-20);
        make.height.equalTo(@34);
        make.width.equalTo(@70);
    }];
    
    // 头像布局
    [avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(notelb1.mas_bottom).offset(10);
        make.left.equalTo(self.view.mas_left).offset(40);
        make.width.equalTo(@50);
        make.height.equalTo(@50);
    }];
    
    // 用户名布局
    [notelb2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(notelb1.mas_bottom).offset(10);
        make.left.equalTo(avatar.mas_right).offset(20);
        make.height.equalTo(@50);
    }];
    
    // 选择提示
    [notelb3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(avatar.mas_bottom).offset(20);
        make.left.equalTo(self.view.mas_left).offset(10);
        make.right.equalTo(self.view.mas_right).offset(-80);
        make.height.equalTo(@30);
    }];
    
    [_tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(notelb3.mas_bottom).offset(5);
        make.left.equalTo(self.view.mas_left).offset(0);
        make.right.mas_equalTo(0);
        make.bottom.equalTo(self.view.mas_bottom).offset(-20);
    }];
    
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    // 设置勾选框
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.selectionStyle = UITableViewCellSelectionStyleDefault;
    cell.tintColor = [UIColor whiteColor];
    cell.textLabel.textColor = globalColor(GCTypeOrangeR);
    cell.textLabel.font = SYSBFONT(16);
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.text = _textSrray[indexPath.row];
    if([_selSrray[indexPath.row] isEqualToString:@"1"]){
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else{
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _textSrray.count;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *mark = _selSrray[indexPath.row];
    if([mark isEqualToString:@"0"]){
        [_selSrray setObject:@"1" atIndexedSubscript:indexPath.row];
    }
    else{
        [_selSrray setObject:@"0" atIndexedSubscript:indexPath.row];
    }
    [_tableview reloadData];
    
}

-(void)tijiaojubao{
    
    NSString *spec=@"";
    
    for (NSString *item in _selSrray) {
        if([item isEqualToString:@"1"]){
            NSInteger index =[_selSrray indexOfObject:item];
            if(spec.length==0){
                spec=_textSrray[index];
            }
            else{
                spec= [NSString stringWithFormat:@"%@;%@",spec,_textSrray[index]];
            }
            
        }
    }
    
    if(spec.length==0){
        [MBProgressHUD showWithText:NSLocalizedString(@"Report-yuanyin", @"")];
        return;
    }
    
    NSDictionary *data=@{
        @"jsonStr":[NSString stringWithFormat:@"%@",self.friendMsg],
        @"spec":spec,
        @"type":@"0"

    };
    
    [FriendNetApi reportUser:data succ:^(int code, NSDictionary * res) {
        NSLog(@"reportUser res:%@",res);
        NSString *coder=res[@"code"];
        if (coder.intValue==200) {
            [MBProgressHUD showWithText:NSLocalizedString(@"friendCtr-caozuocg", @"")];
        }
        
    } fail:^(NSError * _Nonnull error) {
        NSLog(@"reportUser:%@",error);
    }];
    
}



@end
