//
//  AppDelegate+suspensionBtn.swift
//  Huangshan
//
//  Created by xiejiangbo on 2018/10/12.
//  Copyright © 2018 yin chen. All rights reserved.
//

import UIKit

extension AppDelegate {
    
    @objc func setVoiceWindow(){
        
//        BDVoiceWakeUp.share().initwakeupEventManager()
//        IFlySpeech.share().initIFlyAIUIAgent()
//        IFlySpeech.share().getActionValueBlock {[weak self](value:AnyObject!)->() in
//            self!.actionValue(str: value as! String)
//        }
        SuspensionView.share().getsuspensionBtn().frame = CGRect(x:50, y: SCREEN_HEIGHT()/1.5, width:50*WHIDTH_RATIO() , height:50*WHIDTH_RATIO() )
        SuspensionView.share().getsuspensionBtn().addTarget(self, action: #selector(suspensionBtnAction), for: .touchUpInside)
//        SuspensionView.share().getsuspensionLabel().frame = CGRect(x:SuspensionView.share().getsuspensionBtn().originX+SuspensionView.share().getsuspensionBtn().width+15, y: 0, width:SCREEN_WHIDTH() , height:20 )
//        SuspensionView.share().getsuspensionLabel().centerY = SuspensionView.share().getsuspensionBtn().centerY
        //SuspensionView.share().getsuspensionLabel()
        windows.addSubview(SuspensionView.share().getsuspensionBtn())
//        window?.addSubview(SuspensionView.share().getsuspensionLabel())
        let pan:UIPanGestureRecognizer = UIPanGestureRecognizer.init(target: self, action: #selector(locationChange(p:)))
        pan.delaysTouchesBegan = true
        SuspensionView.share().getsuspensionBtn().addGestureRecognizer(pan)
//        VoiceWaveView.share().initView()
//        VoiceWaveView.share().getBagView().frame = CGRect(x:0, y: SCREEN_HEIGHT()-HEIGHT_TAB_BAR()-HEIGHT_BOTTOM_MARGIN()-50, width:SCREEN_WHIDTH() , height:50 )
//        window?.addSubview(VoiceWaveView.share().getBagView())
    }
    @objc func suspensionBtnAction(){
//        BDVoiceWakeUp.share().startWakeup()
//        IFlySpeech.share().startParsing()
//        SuspensionView.share().setSuspensionLabel("123456789")
//        AudioPlayerPrompt.share().wakeUpPlay {
//
//        }
        NotificationCenter.default.post(name: Notification.Name(rawValue: "gotoVoiceDialogueVC"), object: "0")
       
    }
    @objc func locationChange(p:UIPanGestureRecognizer){
        let HEIGHT:CGFloat = SuspensionView.share().getsuspensionBtn().height
        let WIDTH:CGFloat = SuspensionView.share().getsuspensionBtn().width
        let panPoint:CGPoint = p.location(in: UIApplication.shared.windows[0])
        if panPoint.x < WIDTH/2 {
            UIView.animate(withDuration: 0.2, animations: {
                SuspensionView.share().setBenCent(CGPoint(x: WIDTH/2, y: panPoint.y))
            })
        }else if panPoint.y < HEIGHT/2{
            UIView.animate(withDuration: 0.2, animations: {
                SuspensionView.share().setBenCent(CGPoint(x: panPoint.x, y: HEIGHT/2))
                
            })
        }else if panPoint.x > SCREEN_WHIDTH()-WIDTH/2{
            UIView.animate(withDuration: 0.2, animations: {
              SuspensionView.share().setBenCent(CGPoint(x: SCREEN_WHIDTH()-WIDTH/2, y: panPoint.y))
            })
        }else if panPoint.y > SCREEN_HEIGHT()-HEIGHT/2{
            UIView.animate(withDuration: 0.2, animations: {
                SuspensionView.share().setBenCent(CGPoint(x: panPoint.x, y: SCREEN_HEIGHT()-HEIGHT/2))
            })
        }
        else{
            UIView.animate(withDuration: 0.1, animations: {
                SuspensionView.share().setBenCent(CGPoint(x: panPoint.x, y: panPoint.y))
            })
        }

    }
    func actionValue(str:String){
        if str == "new_flowsheet" {
//           BaseTabBarView.share().oneBtnAction(UIButton())
        }
        //getVoiceHttpPostCmd(value: str)
    }
}
