//
//  MySetViewController.m
//  双子星云手机
//
//  Created by APPLE on 2023/8/17.
//

#import "MySetViewController.h"
#import <SDWebImage.h>
#import <Masonry.h>
#import "HelpDownScrollView.h"
#import "MineViewCell.h"
#import "ChangeLogoViewController.h"
#import "HidenMaskSetViewController.h"
#import "CustomerWebViewController.h"
#import "AboutViewController.h"
#import "iPhone.h"
#import "CloudPhoneAPI.h"
#import "ComontAlretViewController.h"
#import "ModifyPWDFirstViewController.h"
#import "TipsQRCodeForChangeDeviceViewController.h"

@interface MySetViewController ()<HelpDownScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,ComontAlretViewControllerDelegate>
{
    UILabel *phoneLabel;
    UILabel *vipTypeTipsLabel;
}
@property (nonatomic, strong, nullable) UITableView *tableView;

@end

@implementation MySetViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self drawAnyView];
}

- (void)drawAnyView{
    [self.view setBackgroundColor:HWF5F7FAColor];
    
    [self.toolBar setHidden:YES];
    [self.navigationBar setHidden:YES];
    [self.navBarBGView setHidden:NO];
    [self.titleLabel setText:NSLocalizedString(@"more_set",nil)];
    
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.top.equalTo(self.navBarBGView.mas_bottom).offset(5.f);
    }];
}


- (UIView *)tableFoorView{
    UIView *bgView = [[UIView alloc] initWithFrame:(CGRectMake(0, 0, SCREEN_W, 68.f))];
    [bgView setBackgroundColor:[UIColor clearColor]];
    
    UIButton *tvP2PBtn = [[UIButton alloc] initWithFrame:(CGRectMake(15, 20, SCREEN_W - 2*15.f, 48.f))];
    [tvP2PBtn setBackgroundColor:HWFFFFFFColor];
    [tvP2PBtn setTitle:NSLocalizedString(@"my_set_no_TV_p2p",nil) forState:(UIControlStateNormal)];
    [tvP2PBtn setTitleColor:HW0A132BColor forState:(UIControlStateNormal)];
    [tvP2PBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:14.f]];
    [tvP2PBtn addTarget:self
                 action:@selector(tvP2PBtnPressed)
       forControlEvents:(UIControlEventTouchUpInside)];
    [tvP2PBtn.layer setCornerRadius:8.f];
    [bgView addSubview:tvP2PBtn];
    return bgView;
}

- (void)tvP2PBtnPressed{
    ;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)helpDownScrollViewBePressed:(nonnull id)sender withIndex:(NSInteger)index {
    HLog(@"\n----点击了第个%ld按钮----",index);
    if (index == 0){
        ChangeLogoViewController *nextVC = [[ChangeLogoViewController alloc] init];
        [self.navigationController pushViewController:nextVC animated:YES];
    }else if (index == 1){/**/
        HidenMaskSetViewController *nextVC = [[HidenMaskSetViewController alloc] init];
        [self.navigationController pushViewController:nextVC animated:YES];
    }
}

#pragma mark - 懒加载
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, SCREEN_H - TABBARHEIGHT) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
//        _tableView.contentInset = UIEdgeInsetsMake(-H_STATE_BAR, 0, 0, 0);
        [_tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
        [_tableView setSeparatorColor:[UIColor clearColor]];
        [_tableView setBackgroundColor:[UIColor clearColor]];
        [_tableView setTableFooterView:[UIView new]];
        [_tableView setBounces:YES];
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
        
        //TV投屏 阿胡说暂不做
        //[_tableView setTableFooterView:[self tableFoorView]];
    }
    
    return _tableView;
}

#pragma mark - 列表委托
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //return 7;
    return 6;//去掉隐藏进程
}

- (MineViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSInteger row = indexPath.row;
    static NSString *identifier = @"MineViewCell";
    
    MineViewCell * cell =  [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (!cell){
        cell = [[MineViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        [cell setBackgroundColor:[UIColor clearColor]];
        [cell setAccessoryType:(UITableViewCellAccessoryNone)];
    }
    [cell.bgViewLayer removeFromSuperlayer];
    [cell.titleLabel2 setHidden:YES];
    [cell.rightImage setHidden:NO];
    [cell.lineView setHidden:NO];
    [cell.maskSwitch setHidden:YES];
    if (row == 0){
        [cell.titleLabel setText:NSLocalizedString(@"my_set_no_modify_pwd",nil)];
        [cell.mImageView setImage:[UIImage imageNamed:@"mdoify_pwd"]];
        /*上圆角*/
        //设置部分圆角  贝塞尔曲线
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
                                                       byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                             cornerRadii:CGSizeMake(8, 8)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = cell.cellBgView.bounds;
        maskLayer.path = maskPath.CGPath;
        cell.bgViewLayer = maskLayer;
        cell.cellBgView.layer.mask = cell.bgViewLayer;
    }else if (row == 1){
        [cell.titleLabel setText:NSLocalizedString(@"my_set_no_change_logo",nil)];
        [cell.mImageView setImage:[UIImage imageNamed:@"icon_change_logo"]];
        //    }else if (row == 2){
        //        [cell.titleLabel setText:NSLocalizedString(@"mask_view_hiden_set_hiden",nil)];
        //        [cell.mImageView setImage:[UIImage imageNamed:@"icon-jincheng"]];
        //    }else if (row == 3){
    }else if (row == 2){
        [cell.titleLabel setText:NSLocalizedString(@"my_set_no_fanzhuan_exit",nil)];
        [cell.mImageView setImage:[UIImage imageNamed:@"fanzhuan"]];
        [cell.rightImage setHidden:YES];
        [cell.maskSwitch setHidden:NO];
    //}else if (row == 4){/*版本信息*/
    }else if (row == 3){/*版本信息*/
        [cell.titleLabel setText:NSLocalizedString(@"my_set_no_check_update",nil)];
        [cell.mImageView setImage:[UIImage imageNamed:@"app_update"]];
        [cell.titleLabel2 setText:[iPhone appVersion]];
        [cell.titleLabel2 setHidden:NO];
    //}else if (row == 5){/*更换设备*/
    }else if (row == 4){/*更换设备*/
        [cell.titleLabel setText:NSLocalizedString(@"my_set_no_change_phone",nil)];
        [cell.mImageView setImage:[UIImage imageNamed:@"icon_change_ohone"]];
    //}else if (row == 6){
    }else if (row == 5){
        [cell.titleLabel setText:NSLocalizedString(@"my_set_no_restart_phone",nil)];
        [cell.mImageView setImage:[UIImage imageNamed:@"icon-gengxin"]];
        /*下圆角*/
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, SCREEN_W-30 , 60)
                                                       byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
                                                             cornerRadii:CGSizeMake(8, 8)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = cell.cellBgView.bounds;
        maskLayer.path = maskPath.CGPath;
        cell.bgViewLayer = maskLayer;
        cell.cellBgView.layer.mask = cell.bgViewLayer;
        
        [cell.lineView setHidden:YES];
    }

    return cell;
}

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

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSInteger row = indexPath.row;
    if (0 == row){
        /*修改密码*/
        ModifyPWDFirstViewController *nextVC = [[ModifyPWDFirstViewController alloc] init];
        [self.navigationController pushViewController:nextVC animated:YES];
    }else if (1 == row){
        /*更换图标*/
        ChangeLogoViewController *nextVC = [[ChangeLogoViewController alloc] init];
        [self.navigationController pushViewController:nextVC animated:YES];
    }else if (2 == row){/*进城隐藏*/
//        HidenMaskSetViewController *nextVC = [[HidenMaskSetViewController alloc] init];
//        [self.navigationController pushViewController:nextVC animated:YES];
//    }else if (3 == row){/*设备翻转*/
//        ;
    }
    //else if (4 == row){/*版本信息*/
    else if (3 == row){/*版本信息*/
        AboutViewController *vc = [[AboutViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    //}else if (5 == row){/*更换设备*/
    }else if (4 == row){/*更换设备*/
        TipsQRCodeForChangeDeviceViewController *vc = [[TipsQRCodeForChangeDeviceViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
//    }else if (6 == row){/*重启空间*/
    }else if (5 == row){/*重启空间*/
        /*弹窗提示重启*/
        ComontAlretViewController *nextVC = [[ComontAlretViewController alloc] initWithTiTle:NSLocalizedString(@"my_set_no_restart_phone_tips",nil)
                                                                                         msg:nil
                                                                                 cancelTitle:NSLocalizedString(@"other_cancel",nil)
                                                                                     okTitle:NSLocalizedString(@"my_set_no_restart_phone_btn_ok",nil) isOkBtnHighlight:NO];
        nextVC.modalPresentationStyle = UIModalPresentationCustom;
        nextVC.delegate = self;
        [self presentViewController:nextVC animated:YES completion:^{
            nextVC.view.superview.backgroundColor = [UIColor clearColor];
        }];
    }
}

- (void)okBtnClickPressed{
//    /*重启云手机*/
//  通过指令通道发送 {"type":"reboot"}
    if(_needToReboot){
        _needToReboot();
    }
    
    //提示语
    [[iToast makeText:NSLocalizedString(@"my_set_no_restart_phone_ok_tips",nil)] show];
}

@end
