//
//  SLFriensInfoVc.m
//  SLAiELTS
//
//  Created by Gusont on 2023/4/10.
//

#import "SLFriensInfoVc.h"
#import "SDTimeLineTableHeaderView.h"
#import "SLMessageViewController.h"
#import "SLMomentsVc.h"
#import "SLBaseCellView.h"
#import "SLFriendPowerVc.h"

@interface SLFriensInfoVc ()
@property (weak, nonatomic) IBOutlet UIImageView *fHeardImageView;
@property (weak, nonatomic) IBOutlet UIButton *userNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *locLabel;
@property (weak, nonatomic) IBOutlet UIView *fpyqBgView;

@property (weak, nonatomic) IBOutlet SLBaseCellView *pyqxView;
@property (weak, nonatomic) IBOutlet UIButton *addFriendBtn;

@end

@implementation SLFriensInfoVc

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[SLHttpCenter SharedInstance] getWithUrl:@"/api/User/GetUserInfo" parameter:@{@"userId":self.friendModel.userId} success:^(id responseObject) {
        SLFriendsModel *model = [SLFriendsModel mj_objectWithKeyValues:[responseObject objectForKey:@"data"]];
        model.distance = self.friendModel.distance;
        self.friendModel = model;
        [self confignUI];
        self.addFriendBtn.hidden = self.friendModel.isFriend;
    } failure:^(SPRequestError *error) {
        
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    WS(weakSelf);
    [self.fpyqBgView addTapWithBlock:^{
        SLMomentsVc *vc = [SLMomentsVc loadViewControllewWithNib];
        SLUserModel *userModel = [[SLUserModel alloc] init];
        userModel.userId = weakSelf.friendModel.userId;
        userModel.userName = weakSelf.friendModel.userName;
        userModel.userHead = weakSelf.friendModel.userHead;
        vc.userModel = userModel;
        vc.isFriendList = YES;
        [weakSelf navPushViewController:vc animated:YES];
    }];
    [self confignPyqxView];
    [self confignUI];
}

- (void)confignUI {
    NSString *userImg = [self.friendModel getUserHeadUrl];
    [self.fHeardImageView sd_setImageWithURL:[NSURL URLWithString:userImg] placeholderImage:ImageName(@"icon_ellipse")];
    [self.userNameLabel setTitle:self.friendModel.userName forState:UIControlStateNormal];
    self.navigationBar.separatorHeight = 0.0f;
    NSString *locStr;
//    地区：江西 南昌      2公里以内
    if (self.friendModel.province.length || self.friendModel.city.length) {
        locStr = [NSString stringWithFormat:@"地区：%@  %@",self.friendModel.province, self.friendModel.city];
    }
    if (self.friendModel.distance.length) {
        locStr = [locStr stringByAppendingFormat:@"  %@",self.friendModel.distance];;
    }
    self.locLabel.text = locStr;

}

- (void)confignPyqxView {
    [self.pyqxView updateConstraintsWith:SLBaseCellView1];
    self.pyqxView.titleLabel.text = @"朋友权限";
    self.pyqxView.subTitleLabel.text = @"";
    self.pyqxView.rightImageViw.image = ImageName(@"icon_chevron_right");
    WS(weakSelf);
    [self.pyqxView addTapWithBlock:^{
        SLFriendPowerVc *vc = [SLFriendPowerVc loadViewControllewWithNib];
        vc.friendModel = weakSelf.friendModel;
        [weakSelf navPushViewController:vc animated:YES];
    }];
}

- (IBAction)toMsgBtnClick:(id)sender {
    SLMessageViewController *vc = [SLMessageViewController loadViewControllewWithNib];
    vc.friendModel = self.friendModel;
    [self navPushViewController:vc animated:YES];
}
- (IBAction)addFriendBtnClick:(id)sender {
    NSString *msg = [NSString stringWithFormat:@"是否添加用户：%@ 为好友", self.friendModel.userName];
    WS(weakSelf);
    [SLCustomizeAlert showAletrWithTitle:@"提示" message:msg sureBtnTitle:@"确定" cancelBtnTitle:@"取消" sureBtnAction:^{
        [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Contacts/AddContacts" parameter:@{@"userId" : self.friendModel.userId} success:^(id responseObject) {
            [ZFToast ShowWithMessage:@"添加成功"];
            self.addFriendBtn.hidden = YES;
        } failure:^(SPRequestError *error) {

        }];
    } cancelBtnAction:nil];
}

@end
