//
//  IMSiLopOAXibLanguageManage.m
//  IMSOpenAccountCustom
//
//  Created by chuntao.wang1 on 2019/4/15.
//

#import "IMSiLopOAXibLanguageManage.h"
#import <ALBBOpenAccountCloud/ALBBOpenAccountSDK.h>
#import "IMSiLopOALocalizeManage.h"

@interface IMSiLopOAXibLanguageManage ()<
ALBBOpenAccountLoginViewDelegate,
ALBBOpenAccountRegisterViewDelegate,
ALBBOpenAccountSetPwdViewDelegate,
ALBBOpenAccountResetPwdViewDelegate,
ALBBOpenAccountFindPwdViewDelegate,
ALBBOpenAccountEmailFindPwdViewDelegate,
ALBBOpenAccountEmailRegisterViewDelegate>

@property (nonatomic, copy) NSString *bundleName;

@end

@implementation IMSiLopOAXibLanguageManage

+ (instancetype)shareInstance {
    static IMSiLopOAXibLanguageManage *instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[[self class] alloc] init];
    });

    return instance;
}

- (instancetype)init {
    if (self = [super init]) {
        id<ALBBOpenAccountUIService> uiService = ALBBService(ALBBOpenAccountUIService);
        [uiService setLoginViewDelegate:self];
        [uiService setRegisterViewDelegate:self];
        [uiService setSetPwdViewDelegate:self];
        [uiService setFindPwdViewDelegate:self];
        [uiService setResetPwdViewDelegate:self];
        // 注册流程
        [uiService setEmailRegisterViewDelegate:self];
        [uiService setEmailFindPwdViewDelegate:self];
    }
    
    return self;
}

- (void)setUpTheXibResourceBundleName:(NSString *)bundleName {
    _bundleName = bundleName;
}

- (NSString *)IMSOpenAccountCustomLocalize:(NSString *)key {
   return [IMSiLopOALocalizeManage localizedString:key inBundle:_bundleName];
}

#pragma mark - ALBBOpenAccountLoginViewDelegate

- (void)loginViewDidLoad:(ALBBOpenAccountLoginViewController *)viewController {
    if (viewController.navigationController) {
        viewController.title = [self IMSOpenAccountCustomLocalize:@"account_login"];
    }
    viewController.usernameField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_name_hint"];
    viewController.passwordField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_password_hint"];
    [viewController.registerLinkBtn setTitle:[self IMSOpenAccountCustomLocalize:@"account_register"] forState:UIControlStateNormal];
    [viewController.findPwdLinkBtn setTitle:[self IMSOpenAccountCustomLocalize:@"account_forget_password"] forState:UIControlStateNormal];
    [viewController.submitButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_login"] forState:UIControlStateNormal];

    for (UIView *view in [viewController.wrapperView subviews]) {
        if ([view.accessibilityLabel isEqual: @"email_account_register"]) {
            UIButton *button = (UIButton *)view;
            [button setTitle:[self IMSOpenAccountCustomLocalize:@"account_register"] forState:UIControlStateNormal];
        }
        
        if ([view.accessibilityLabel isEqual: @"email_account_forget_password"]) {
            UIButton *button = (UIButton *)view;
            [button setTitle:[self IMSOpenAccountCustomLocalize:@"account_forget_password"] forState:UIControlStateNormal];
        }
    }
}

#pragma mark - ALBBOpenAccountRegisterViewDelegate

- (void)registerViewDidLoad:(ALBBOpenAccountRegisterViewController *)viewController {
    if (viewController.navigationController) {
        viewController.title = [self IMSOpenAccountCustomLocalize:@"account_register_free"];
    }
    viewController.usernameField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_phone_number"];
    viewController.smscodeField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_sms_verify_code"];
    [viewController.sendButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_send_verify_code"] forState:UIControlStateNormal];
    [viewController.submitButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_next"] forState:UIControlStateNormal];
}

#pragma mark - ALBBOpenAccountSetPwdViewDelegate

- (void)setPwdViewDidLoad:(ALBBOpenAccountSetPwdViewController *)viewController {
    if (viewController.navigationController) {
        viewController.title = [self IMSOpenAccountCustomLocalize:@"account_find_password"];
    }
    viewController.passwordField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_password_hint"];
    [viewController.submitButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_complete"] forState:UIControlStateNormal];
}

#pragma mark - ALBBOpenAccountFindPwdViewDelegate

- (void)findPwdViewDidLoad:(ALBBOpenAccountFindPwdViewController *)viewController {
    if (viewController.navigationController) {
        viewController.title = [self IMSOpenAccountCustomLocalize:@"account_find_password"];
    }
    viewController.usernameField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_phone_number"];
    viewController.smscodeField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_sms_verify_code"];
    [viewController.nextButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_next"] forState:UIControlStateNormal];
    [viewController.sendButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_send_verify_code"] forState:UIControlStateNormal];
}

#pragma mark - ALBBOpenAccountResetPwdViewDelegate

- (void)resetPwdViewDidLoad:(ALBBOpenAccountResetPwdViewController *)viewController {
    if (viewController.navigationController) {
        viewController.title = [self IMSOpenAccountCustomLocalize:@"account_reset_pwd"];
    }
    viewController.passwordField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_password_hint"];
    [viewController.submitButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_complete"] forState:UIControlStateNormal];
}

#pragma mark - ALBBOpenAccountEmailRegisterViewDelegate

- (void)emailRegisterViewDidLoad:(ALBBOpenAccountEmailRegisterViewController *)viewController {
    if (viewController.navigationController) {
        viewController.title = [self IMSOpenAccountCustomLocalize:@"account_choose_register_style_email"];
    }
    viewController.emailField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_email"];
    viewController.checkcodeField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_email_verify_code"];
    viewController.passwordField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_password_hint"];
    [viewController.sendButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_send_email_code"] forState:UIControlStateNormal];
    [viewController.submitButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_complete"] forState:UIControlStateNormal];
}

#pragma mark - ALBBOpenAccountEmailFindPwdViewDelegate

- (void)emailFindPwdViewDidLoad:(ALBBOpenAccountEmailFindPwdViewController *)viewController {
    if (viewController.navigationController) {
        viewController.title = [self IMSOpenAccountCustomLocalize:@"account_change_pwd"];
    }
    viewController.emailCodeField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_sms_verify_code"];
    viewController.usernameField.placeholder = [self IMSOpenAccountCustomLocalize:@"account_email"];
    [viewController.sendButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_send_email_code"] forState:UIControlStateNormal];
    [viewController.nextButton setTitle:[self IMSOpenAccountCustomLocalize:@"account_next"] forState:UIControlStateNormal];
}

@end
