//
//  RDSAddHomeVC.m
//  Temperature
//
//  Created by RD on 2023/2/1.
//

#import "RDSAddHomeVC.h"
#import "RDSMapHelper.h"

@interface RDSAddHomeVC ()
@property (weak, nonatomic) IBOutlet UITextField *nameTF;
@property (weak, nonatomic) IBOutlet UIButton *defaultHomeBtn;


@end

@implementation RDSAddHomeVC

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

- (IBAction)onDefaultHomeClick:(UIButton *)sender {
    
    sender.selected = !sender.isSelected;
    
}

- (IBAction)onSureClick:(id)sender {
    
    if(kNULLString(_nameTF.text)){
        [RDSHudShower showBottomToast:@"请为家庭设置一个名称"];
        return;
    }
    
    [RDSDemoApiHelper rds_addHomeWithName:_nameTF.text isDefault:_defaultHomeBtn.isSelected city:nil success:^(id responseObject) {
            
        if ([responseObject[@"code"] intValue] == 0) {
            [RDSHudShower showCenterToast:responseObject[@"添加成功"]];
            [self popViewControllerAnimated:YES];
        } else{
            [RDSHudShower showErrorWithStatus:responseObject[@"message"]];
        }
        } failure:^(NSError *error) {
            [RDSHudShower showBottomToast:@"连接服务器失败"];
        }];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [self.view endEditing:YES];
}

@end
