//
//  MemberAddPopupView.m
//  kneet
//
//  Created by Jason Lee on 6/15/15.
//  Copyright (c) 2015 ntels. All rights reserved.
//
#import "JDObject.h"
#import "LoginModel.h"

#import "CustomLabel.h"
#import "CustomRadioGroup.h"
#import "MemberAddPopupView.h"
#import "ValidateUtil.h"
#import "CustomTextField.h"


@interface MemberAddPopupView () {
    CustomRadioGroup *_rgroup;
}

@end

@implementation MemberAddPopupView

- (id)initFromNib {

    for (UIView *view in [CommonUtil nibViews:@"MemberAddPopupView"]) {
        if ([view isKindOfClass:[MemberAddPopupView class]]) {
            self = (MemberAddPopupView *)view;

            //XIB의 경우, 현재 화면 사이즈로 맞춰줘야 함.
            self.frame = [UIScreen mainScreen].bounds;

            self.lblTitle.text = NSLocalizedString(@"초대할 멤버 이메일 입력", @"초대할 멤버 이메일 입력");

            _rdoPower.value = KNEET_MEMBER_POWER;
            _rdoSimple.value= KNEET_MEMBER_SIMPLE;
            
            [_rdoPower setTitle:NSLocalizedString(@"멤버등급 : 파워", @"멤버등급 : 파워") forState:UIControlStateNormal];
            [_rdoSimple setTitle:NSLocalizedString(@"멤버등급 : 심플", @"멤버등급 : 심플") forState:UIControlStateNormal];

            _rgroup = [[CustomRadioGroup alloc] initWithRadioButtons:_rdoPower, _rdoSimple, nil];
            
            _txtEmail.placeholder = NSLocalizedString(@"이메일 주소 입력", @"이메일 주소 입력");
            
            _lblPowerDesc.text = NSLocalizedString(@"홈 셋팅을 제외한 모든 것을 할 수 있습니다", @"홈 셋팅을 제외한 모든 것을 할 수 있습니다");
            _lblSimpleDesc.text = NSLocalizedString(@"단순 사용만 가능합니다", @"단순 사용만 가능합니다");
            
            [self.btnConfirm setTitle:NSLocalizedString(@"확인", @"확인") forState:UIControlStateNormal];
            [self.btnCancel setTitle:NSLocalizedString(@"취소", @"취소") forState:UIControlStateNormal];
        }
    }

    return self;
}

- (void)didMoveToSuperview {

}

- (HomeMemberModel *)newMember {
    HomeMemberModel *member = [[HomeMemberModel alloc] init];
    member.targetEmail = _txtEmail.text;
    member.gradeCode = _rgroup.valueForChecked;

    return member;
}

- (void)btnConfirmTouched:(id)sender {

    //validate
    if (![ValidateUtil validateTextfiled:_txtEmail type:ValidateTypeEmail title:NSLocalizedString(@"이메일", @"이메일")]) {
        return;
    }

    for (HomeMemberModel *member in _inviteList) {
        if ([member.targetEmail isEqualToString:_txtEmail.text]) {
            [[JDFacade facade] alert:NSLocalizedString(@"이미 초대할 멤버에 추가된 이메일입니다", @"이미 초대할 멤버에 추가된 이메일입니다")];
            return;
        }
    }

    [super btnConfirmTouched:sender];
}

@end
