/********* jinkeh-customerservice.m Cordova Plugin Implementation *******/

#import <Cordova/CDV.h>
//#import "JKCCEntranceVC.h"
#import "UIViewController+JKCC.h"
#import "JKCCCallCenter.h"
#import "JKCCAssistantsVC.h"

@interface CustomerServicePlugin : CDVPlugin {
  // Member variables go here.
}

- (void)startCustomerService:(CDVInvokedUrlCommand*)command;
@end

@implementation CustomerServicePlugin

- (void)startCustomerService:(CDVInvokedUrlCommand*)command
{
//    CDVPluginResult* pluginResult = nil;
//    NSString* echo = [command.arguments objectAtIndex:0];
//
//    if (echo != nil && [echo length] > 0) {
//        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:echo];
//    } else {
//        pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
//    }
//
//    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
    
    
    //弹出alertbox
//    NSString *msg = [NSString stringWithFormat:@"VC=%@",self.viewController];
//    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"测试" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//    [av show];
    
    [SVProgressHUD show];
    
    [[JKCCCallCenter shareInstance] loginWithCompletion:^(BOOL b) {
        [SVProgressHUD dismiss];
        if (b == NO) {
            [SVProgressHUD showErrorWithStatus:JKCC_STRING_BAD_NETWOK];
        }else{
            //[SVProgressHUD showSuccessWithStatus:@"登录成功"];
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"JKCC" bundle:nil];
            JKCCAssistantsVC *vc = [sb instantiateViewControllerWithIdentifier:@"JKCCAssistantsVC"];
            UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
            [self.viewController presentViewController:nc animated:YES completion:nil];
        }
    }];
    
}

@end
