//
//  AccountAndSecurityViewController.m
//  ChinaTheoryNetwork
//
//  Created by 张毅成 on 2019/1/28.
//  Copyright © 2019 张毅成. All rights reserved.
//

#import "AccountAndSecurityViewController.h"
#import "AccountAndSecurityModel.h"
#import "AccountAndSecurityTableViewCell.h"
#import "ReplacePhoneNumberViewController.h"

@interface AccountAndSecurityViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

/**
 
 */
@property (strong, nonatomic) AccountAndSecurityModel *model;
@end

@implementation AccountAndSecurityViewController

- (AccountAndSecurityModel *)model {
    if (!_model) {
        _model = [AccountAndSecurityModel new];
    }
    return _model;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"账号与安全";
    self.view.backgroundColor = kBackgroundColor;
    [self createTableView];
}

- (void)createTableView {
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [UIView new];
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 60;
//    self.tableView.separatorStyle = 0;
    self.tableView.backgroundColor = kBackgroundColor;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [UIView new];
    [view setBackgroundColor:kBackgroundColor];
    return view;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [UIView new];
    [view setBackgroundColor:kBackgroundColor];
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return AccountAndSecurityModel.arrayData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    AccountAndSecurityTableViewCell *cell = [AccountAndSecurityTableViewCell cellWithTableView:tableView];
    cell.labelTItle.text = AccountAndSecurityModel.arrayData[indexPath.row];
    if (indexPath.row == 0) {
        cell.labelDetail.text = self.modelMy.nickname;
    }else
        cell.labelDetail.text = self.modelMy.mobile;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ReplacePhoneNumberViewController *controller = [ReplacePhoneNumberViewController new];
    controller.modelMy = self.modelMy;
    [self.navigationController pushViewController:controller animated:true];
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [cell setPreservesSuperviewLayoutMargins:NO];
    }
}

@end