////
////  FeedbackViewController.swift
////  kt
////
////  Created by Assylkhan Rakhatov on 01.02.16.
////  Copyright © 2016 Alexandr Zalutskiy. All rights reserved.
////
//
//import Foundation
////
////  FeedbackViewController.m
////  kt
////
////  Created by Alexandr Zalutskiy on 31.01.15.
////  Copyright (c) 2015 Alexandr Zalutskiy. All rights reserved.
////
////import "iOSNgnStack.h"
////import "KTAudioCallViewController.h"
////import "Reachability.h"
//
////import "iOSNgnStack.h"
////import "KTAudioCallViewController.h"
////import "Reachability.h"
//import UIKit
//
////import "telecom-Swift.h"
////import "ViewControllerWithCustomTitle.swift"
//
//let kNetworkAlertMsgThreedGNotEnabled  =    "Only 3G network is available. Please enable 3G and try again."
//let kNetworkAlertMsgNotReachable      = "No network connection"
//let kAlertMsgButtonOkText           = "OK"
//
//let kTAG = "Kazaktelecom///: "
//let TAG = kTAG
//
//
//class FeedbackViewController : UIViewController {
//  @IBOutlet var supportButton: UIButton!
//  @IBOutlet var repairButton: UIButton!
//  @IBOutlet var subtitleLabel: UILabel!
//  @IBOutlet var button1DescriptionLabel: UILabel!
//  @IBOutlet var button2DescriptionLabel: UILabel!
//  @IBOutlet var menuButton: UIButton!
//  
//  var multitaskingSupported: Bool?
//  func networkAlert(message: String) {
//    let alert = UIAlertView(title: "Ошибка", message: message, delegate: nil, cancelButtonTitle: kAlertMsgButtonOkText)
//    alert.show()
//  }
//  
//  //  pragma mark -
//  //  pragma mark - Network events
//  
//  func onNetworkEvent(notification: NSNotification) {
//    let eargs = notification.object
//    
//    //  switch (eargs?.type) {
//    //  case NETWORK_EVENT_STATE_CHANGED:
//    //  default:
//    //  {
//    NSLog(TAG,"NetworkEvent reachable=% networkType=%i",
//             NgnEngine.sharedInstance().networkService.reachable ? "YES" : "NO", NgnEngine.sharedInstance().networkService.networkType)
//    
//    if (NgnEngine.sharedInstance().networkService.reachable){
//      let onMobileNework = (NgnEngine.sharedInstance().networkService.networkType & NetworkType_WWAN)
//      
//      // unregister the application and schedule another registration
//      let on3G = onMobileNework; // Downgraded to 3G even if it could be 4G or EDGE
//      
//      let use3G = NgnEngine.sharedInstance().configurationService().getBoolWithKey(NETWORK_USE_3G)
//      if (on3G && !use3G){
//        self.networkAlert(kNetworkAlertMsgThreedGNotEnabled)
//        kNetworkAlertMsgThreedGNotEnabled.sipService.stopStackSynchronously()
//      }
//      else {
//        if (!NgnEngine.sharedInstance().sipService.isRegistered) {
//          NgnEngine.sharedInstance().sipService.registerIdentity()
//        }
//      }
//    }
//    else if (NgnEngine.sharedInstance().sipService.registered){
//      NgnEngine.sharedInstance().sipService.stopStackSynchronously();
//    }
//    //  break;
//    //  }
//  }
//  
//  //pragma mark -
//  //pragma mark - REGISTER events
//  
//  func onRegistrationEvent(notification: NSNotification) {
//    let eargs = notification.object
//    //    NSLog("onRegistrationEvent - NgnRegistrationEventArgs:/// \n sessionId - %ld \n eventType - %u \n sipPhrase - % \n sipCode - %hd", eargs.sessionId, eargs.eventType, eargs.sipPhrase, eargs.sipCode)
//    
//    // gets the new registration state
//    let registrationState = NgnEngine.sharedInstance().sipService.getRegistrationState()
//    switch (registrationState) {
//    case CONN_STATE_NONE: break
//    case CONN_STATE_TERMINATED:
//      
//      break
//    case CONN_STATE_CONNECTING: break
//    case CONN_STATE_TERMINATING:
//      break
//    case CONN_STATE_CONNECTED:
//      break
//    default:
//      break
//    }
//  }
//  
//  //  pragma mark -
//  //  pragma mark - INVITE (audio/video, file transfer, chat, ...) events
//  
//  func onInviteEvent(notification: NSNotification) {
//    
//    let eargs = notification.object
//    switch (eargs.eventType) {
//    case INVITE_EVENT_INCOMING:
//      break
//    case INVITE_EVENT_MEDIA_UPDATED:
//      break
//    case INVITE_EVENT_TERMINATED:
//      break
//    case INVITE_EVENT_TERMWAIT:
//      
//      let audioCallViewController = self.presentedViewController as! KTAudioCallViewController
//      if (audioCallViewController) {
//        audioCallViewController.endCall(nil)
//      }
//      break
//    default:
//      break
//    }
//  }
//  
//  
//  func queryConfigurationAndRegister() -> Bool {
//    
//    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("onNetworkEvent:"), name: kNgnNetworkEventArgs_Name, object: nil)
//    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("onRegistrationEvent:"), name: kNgnNetworkEventArgs_Name, object: nil)
//    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("onInviteEvent:"), name: kNgnInviteEventArgs_Name, object: nil)
//    
//    if (NgnEngine.sharedInstance().sipService.isRegistered()) {
//      return true
//    } else {
//      let realm = "sip.telecom.kz"
//      let impi = "1774380923"
//      
//      let impu = NSString(format: "sip:%%", impi, realm)
//      
//      NgnEngine.sharedInstance().configurationService.setStringWithKey(IDENTITY_IMPI, value:impi)
//      NgnEngine.sharedInstance().configurationService.setStringWithKey(IDENTITY_IMPU, value:impu)
//      NgnEngine.sharedInstance().configurationService.setStringWithKey(IDENTITY_PASSWORD, value: "XajFfd63")
//      NgnEngine.sharedInstance().configurationService.setStringWithKey(NETWORK_REALM, value: realm)
//      
//      NgnEngine.sharedInstance().configurationService.setStringWithKey(NETWORK_PCSCF_HOST, value: realm)
//      NgnEngine.sharedInstance().configurationService.setIntWithKey(NETWORK_PCSCF_PORT, value: 5060)
//      NgnEngine.sharedInstance().configurationService.setBoolWithKey(NETWORK_USE_EARLY_IMS, value: true)
//      NgnEngine.sharedInstance().configurationService.setBoolWithKey(NETWORK_USE_KEEPAWAKE, value: false)
//      NgnEngine.sharedInstance().configurationService.setBoolWithKey(NATT_USE_STUN, value: false)
//      
//      NgnEngine.sharedInstance().configurationService.setStringWithKey(NATT_USE_STUN, value: false)
//      NgnEngine.sharedInstance().configurationService.setBoolWithKey(MEDIA_CODEC_USE_OPUS, value, true)
//      //        [NgnEngine.sharedInstance().configurationService setBoolWithKey:MEDIA_CODEC_USE_OPUS andValue:NO];
//      
//      NgnEngine.sharedInstance().configurationService.setBoolWithKey(MEDIA_CODEC_USE_PCMA, value: true)
//      NgnEngine.sharedInstance().configurationService.setBoolWithKey(MEDIA_CODEC_USE_PCMU, value: true)
//      NgnEngine.sharedInstance().configurationService.setBoolWithKey(MEDIA_CODEC_USE_GSM, value: true)
//      NgnEngine.sharedInstance().configurationService.setBoolWithKey(MEDIA_CODEC_USE_G729AB, value: true)
//      NgnEngine.sharedInstance().configurationService.setBoolWithKey(MEDIA_CODEC_USE_SPEEX_NB, value: true) //сносно воркает
//      
//      NgnEngine.sharedInstance().configurationService.setIntWithKey(MEDIA_AUDIO_RESAMPLER_QUALITY, value: 1)
//      NgnEngine.sharedInstance().configurationService.setIntWithKey(MEDIA_AUDIO_PRODUCER_ATTENUATION, value: 0)
//      
//      NgnEngine.sharedInstance().configurationService.setIntWithKey(MEDIA_AUDIO_OPUS_MAXCAPTURERATE, value: 0)
//      NgnEngine.sharedInstance().configurationService.setIntWithKey(MEDIA_AUDIO_OPUS_MAXPLAYBACKRATE, value: 0)
//      
//      
//      let on3G = (NgnEngine.sharedInstance().networkService.networkType & NetworkType_WWAN)
//      let use3G = NgnEngine.sharedInstance().configurationService.getBoolWithKey(NETWORK_USE_3G)
//      if(on3G && !use3G){
//        self.networkAlert.kNetworkAlertMsgThreedGNotEnabled()
//        return false
//      }
//      else if(!NgnEngine.sharedInstance().networkService.isReachable()){
//        self.networkAlert.kNetworkAlertMsgNotReachable()
//        return false
//      }
//      else {
//        NgnEngine.sharedInstance().sipService.registerIdentity()
//      }
//      
//    }
//    
//    return NgnEngine.sharedInstance().sipService.isRegistered()
//  }
//  
//  
//  func dealloc() {
//    NSNotificationCenter.defaultCenter().removeObserver(self)
//    NgnEngine.sharedInstance().sipService.unRegisterIdentity()
//    NgnEngine.sharedInstance().stop()
//  }
//  
//  
//  override func viewDidLoad() {
//    super.viewDidLoad()
//    var NavigationBarFont: UIFont = UIFont(name: "PTSans-Bold", size: 17.0)!
//    var defaultLanguage: String = NSUserDefaults.standardUserDefaults().stringForKey("UserDefaultsLanguage")!
//    var langPath: String = NSBundle.mainBundle().pathForResource(defaultLanguage, ofType: "lproj")!
//    var appLanguageBundle: NSBundle = NSBundle(path: langPath)!
//    var titleLabel: UILabel = UILabel(frame: CGRectMake(0, 0, 150, 36))
//    titleLabel.text = appLanguageBundle.localizedStringForKey("menu.feedback", value: "???", table: "Localizable")
//    titleLabel.textAlignment = .Center
//    titleLabel.font = NavigationBarFont
//    self.navigationItem.titleView = titleLabel
//    var menuIcon: UIImage = UIImage(named: "menu_icon")!
//    self.menuButton = UIButton(frame: CGRectMake(0, 0, menuIcon.size.width, menuIcon.size.height))
//    menuButton.setImage(menuIcon, forState: .Normal)
//    
//    
//    
//    menuButton.setImage(UIImage(named: "menu_icon_highlighted"), forState: UIControlState.Highlighted)
//    
//    menuButton.addTarget(self, action: Selector("menuButton_TouchUpInside:"), forControlEvents: UIControlEvents.TouchUpInside)
//    
//    self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: menuButton)
//    
//    if UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad {
//      
//      menuButton.enabled = !UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation)
//      menuButton.hidden = UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation)
//    }
//    
//    let reachability = Reachability.reachabilityForInternetConnection()
//    reachability.startNotifier()
//    
//    let status = reachability.currentReachabilityStatus()
//    
//    if (status != ReachableViaWiFi) {
//      _supportButton.enabled = false;
//      _repairButton.enabled = false;
//      UIAlertView(title: "Ошибка", message: "Вызов доступен только по сети Wi-Fi", delegate: nil, cancelButtonTitle: "Ok").show()
//    } else {
//      
//      dispatch_async(dispatch_get_global_queue(0, 0), {
//        
//        NgnEngine.sharedInstance().configurationService.start()
//        NgnEngine.sharedInstance().networkService.start()
//        ////  [NgnEngine.sharedInstance().storageService start];
//        ////  [NgnEngine.sharedInstance().contactService start];
//        NgnEngine.sharedInstance().sipService.start()
//        NgnEngine.sharedInstance().httpClientService.start()
//        ////  [NgnEngine.sharedInstance().historyService start];
//        NgnEngine.sharedInstance().soundService.start()
//        
//        self.queryConfigurationAndRegister()
//        
//        NgnEngine.sharedInstance().soundService.setSpeakerEnabled(true)
//        
//      });
//      
//      //    [NgnEngine.sharedInstance() start];
//      
//    }
//    
//  }
//  
//  override func viewWillAppear(animated: Bool) {
//    super.viewWillAppear(animated)
//    
//    self.localizable()
//    
//    if (UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation)) {
//      menuButton.enabled = false
//      menuButton.hidden = true
//    } else {
//      menuButton.enabled = true
//      menuButton.hidden = false
//    }
//  }
//  
//  
//  
//  //  self.title = [KTAppLanguage string:STRING_KEY_FEEDBACK];
//  //
//  //  [_supportButton setTitle:[KTAppLanguage string:STRING_KEY_SUPPORT_CENTER] forState:UIControlStateNormal];
//  //  [_repairButton setTitle:[KTAppLanguage string:STRING_KEY_REPAIR] forState:UIControlStateNormal];
//  //
//  //  if ([KTAppLanguage isRussian]) {
//  //    [_supportButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 10.0f)];
//  //    [_repairButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f)];
//  //  } else if ([KTAppLanguage isEnglish]) {
//  //    [_supportButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 34.0f)];
//  //    [_repairButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0f, 8.0f, 0.0f, 0.0f)];
//  //  } else {
//  //    [_supportButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0f, 34.0f, 0.0f, 0.0f)];
//  //    [_repairButton setTitleEdgeInsets:UIEdgeInsetsMake(0.0f, 26.0f, 0.0f, 0.0f)];
//  //  }
//  
//  
//  override func willAnimateRotationToInterfaceOrientation(toInterfaceOrientation: UIInterfaceOrientation, duration: NSTimeInterval) {
//    super.willAnimateRotationToInterfaceOrientation(toInterfaceOrientation, duration: duration)
//    super.willAnimateRotationToInterfaceOrientation(toInterfaceOrientation, duration: duration)
//    
//    menuButton.enabled = !UIInterfaceOrientationIsLandscape(toInterfaceOrientation)
//    menuButton.hidden = UIInterfaceOrientationIsLandscape(toInterfaceOrientation)
//    
//    
//    let rvc = self.navigationController!.parentViewController!
//    rvc.performSelector(Selector("closeSideViewControllerAnimated"), withObject: false, withObject: nil)
//  }
//  
//  func localizable() {
//    let defaultLanguage: String = NSUserDefaults.standardUserDefaults().stringForKey("UserDefaultsLanguage")!
//    let langPath: String = NSBundle.mainBundle().pathForResource(defaultLanguage, ofType: "lproj")!
//    let appLanguageBundle: NSBundle = NSBundle(path: langPath)!
//    self.subtitleLabel.text = appLanguageBundle.localizedStringForKey("feedback.support_call", value: "???", table: "Localizable")
//    self.button1DescriptionLabel.text = appLanguageBundle.localizedStringForKey("feedback.customer_support_center", value: "???", table: "Localizable")
//    self.button2DescriptionLabel.text = appLanguageBundle.localizedStringForKey("feedback.central_repair_bureau", value: "???", table: "Localizable")
//  }
//  
//  
//  //pragma mark - segue
//  
//  @IBAction func buttonPressed(sender: AnyObject)
//  {
//    if (NgnEngine.sharedInstance().networkService.isReachable()) {
//      let audioCallViewController = self.storyboard!.instantiateViewControllerWithIdentifier("KTAudioCallViewController") as! KTAudioCallViewController
//      if _supportButton.isEqual(sender) {
//        audioCallViewController.remoteNumber = "160"
//        audioCallViewController.dtmfUrlString = "https://www.dropbox.com/s/ik7fvm4aya901tm/160.json?dl=1"
//      } else {
//        audioCallViewController.remoteNumber = "165"
//        audioCallViewController.dtmfUrlString = "https://www.dropbox.com/s/8hd703ep2fvbvui/165.json?dl=1"
//      }
//      
//      self.presentViewController(audioCallViewController, animated: true, completion:nil)
//      
//    } else {
//      let alertView = UIAlertView(title: "Ошибка", message: "Проверьте интернет соединение", delegate: nil, cancelButtonTitle: "OK")
//      alertView.show()
//    }
//  }
//  
//  @IBAction func menuButton_TouchUpInside(sender: UIButton) {
//    let rvc = self.navigationController?.parentViewController
//    rvc?.performSelector(Selector("openLeftSideViewControllerAnimated"), withObject: true, withObject: nil)
//    //    (Selector())performSelector:@selector(openLeftSideViewControllerAnimated:completion:) withObject:@YES withObject:nil];
//    
//  }
//  //  rvc.openLeftSideViewControllerAnimated(true, completion: { _ in })
//  
//}
