import { TUICallKitServer } from "../../../TUICallService/index";
import {throttle} from "../../../utils/util"
const PATH = '../../../static';
Component({
  properties: {
    callRole: {
      type: String,
    },
    callStatus: {
      type: String,
      observer(callStatus) {
        console.log("改编状态："+callStatus);
      }
    },
    callMediaType: {
      type: Number,
    },
    callDuration: {
      type: String,
    },
    pusher: {
      type: Object,
    },
    playerList: {
      type: Array,
    },
    localUserInfo: {
      type:Object
    },
    doctorInfo:{
        type:Object,
        observer(doctorInfo) {
          this.setData({
            doctorInfo:doctorInfo
          })
          }
    },
    remoteUserInfoList: {
      type: Array,
    },
    isEarPhone: {
      type: Boolean,
    },
    bigScreenUserId: {
      type: Boolean
    }
  },
  lifetimes: {
    moved(){
        //console.log('moved')
    },
    async detached(){
        //await TUICallKitServer.enableFloatWindow(true);
        //console.log('detached')
        // this.reject();
        // this.hangup()
    }
  },
  pageLifetimes: {
    show() {
       //TUICallKitServer.enableFloatWindow(true);
    },
    hide() {
        // this.reject();
        // this.hangup()
    
    },
  },
  data:{
    IMG_DEFAULT_AVATAR:`${PATH}/default_avatar.png`,
    IMG_HANGUP:`${PATH}/hangup.png`,
    IMG_ACCEPT: `${PATH}/dialing.png`,
    IMG_SPEAKER_FALSE:`${PATH}/speaker-false.png`,
    IMG_SPEAKER_TRUE:`${PATH}/speaker-true.png`,
    IMG_AUDIO_TRUE:`${PATH}/patient_audio_true.png`,
    IMG_AUDIO_FALSE:`${PATH}/patient_audio_false.png`,
    IMG_CAMERA_TRUE:`${PATH}/camera-true.png`,
    IMG_CAMERA_FALSE:`${PATH}/camera-false.png`,
    IMG_TRANS:`${PATH}/trans.png`,
    IMG_SWITCH_CAMERA:`${PATH}/patient_switch_camera.png`,
    doctorInfo:{}
  },
  methods: {
    accept:throttle(async()=> {
        //延迟接听；
        await TUICallKitServer.enableMuteMode(false);
        await TUICallKitServer.accept();
    }),
    async hangup() {
        console.log("hangup")
      await TUICallKitServer.hangup();
    },
    async reject() {
        console.log("reject")
      await TUICallKitServer.reject();
    },
    async switchCamera() {
      await TUICallKitServer.switchCamera();
    },
    async switchCallMediaType() {
      await TUICallKitServer.switchCallMediaType();
    },
    async microPhoneHandler() {
      if (this.data.localUserInfo.isAudioAvailable) {
        await TUICallKitServer.closeMicrophone();
      } else {
        await TUICallKitServer.openMicrophone();
      }
    },
    async cameraHandler() {
      if (this.data.localUserInfo.isVideoAvailable) {
        await TUICallKitServer.closeCamera();
      } else {
        await TUICallKitServer.openCamera();
      }
    },
    async toggleSoundMode() {
      await TUICallKitServer.setSoundMode();
    },
    toggleViewSize() {
      TUICallKitServer.switchScreen(this.data.bigScreenUserId ? 'player':'localVideo') 
    },
    pusherStateChangeHandler(e) {
      TUICallKitServer._tuiCallEngine._pusherStateChangeHandler(e);
    },
    pusherNetStatus(e) {
      TUICallKitServer._tuiCallEngine._pusherNetStatus(e);
    },
    pusherErrorHandler(e) {
      TUICallKitServer._tuiCallEngine._pusherNetStatus(e);
    },
    pusherAudioVolumeNotify(e) {
      TUICallKitServer._tuiCallEngine._pusherAudioVolumeNotify(e);
    },
    playerStateChange(e) {
      TUICallKitServer._tuiCallEngine._playerStateChange(e);
    },
    playNetStatus(e) {
      TUICallKitServer._tuiCallEngine._playNetStatus(e);
    },
    playerAudioVolumeNotify(e) {
      TUICallKitServer._tuiCallEngine._playerAudioVolumeNotify(e);
    },
  },
});
