const app = getApp();
var url = app.globalData.url;
Component({
  behaviors: [require('../../../common/share-behavior').default],
  properties: {
    markerImg: {
      type: String
    },recordState: {
      type: Number,
      value: 0,
      observer: function (newVal, oldVal) { 
        if (newVal !== oldVal) {
        if (newVal === 1) {
          this.recordStart();
        } else if (newVal === 2)  {
          this.recordEnd();
        }
      }
      }
    },captureState: {
      type: Number,
      value: 0,
      observer: function (newVal, oldVal) {
        console.log("observer===>"+newVal);
        this.capture();
      }
    },
  },
  data: {
    loaded: false,
    arReady: false,
    loadedSaoMiao:false,
    ar_1img:url+"targets/ar_1.png",
    baseurl:url,
  },
  
  lifetimes: {
    attached() {
      console.log('data', this.data)
    }
  },
  methods: {
    handleReady({
      detail
    }) {
      const xrScene = this.scene = detail.value;
      console.log('xr-scene', xrScene);
    },
    handleAssetsProgress: function ({
      detail
    }) {
      console.log('assets progress', detail.value);
    },handleTrackerSwitch: function ({detail}) {
      const active = detail.value;
      if(active)
      {       
        this.triggerEvent('assetsstr',true);
        
        this.setData({loadedSaoMiao: true});
       // this.scene.share.captureToFriends();
      }
    },handleARTrackerState({detail}) {
    },
    handleAnimationStop: function() {
      console.log('animation Stop');
    },
    handleAssetsLoaded: function ({
      detail
    }) {
      console.log('assets loaded', detail.value);
      this.setData({
        loaded: true
      });

    },
    handleARReady: function ({
      detail
    }) {
      console.log('arReady');
      this.setData({
        arReady: true
      })
    },
    capture: function () {
      this.scene.share.captureToFriends({
        fileType: this.data.captureType,
        quality: this.data.captureQuality
      });
    },
    recordStart() {
      console.log('recordStart') 
      wx.updateShareMenu({
        withShareTicket: true,
        success () { }
      })
      this.scene.share.recordStart({
        fps: 15,
        videoBitsPerSecond: 10000,
      });
    },
    recordEnd() {
      console.log('recordEnd')
     
      
      //
      const tempFilePath =  this.scene.share.recordFinishToAlbum({
        fps: 15,
        videoBitsPerSecond: 10000,
      });
      wx.shareVideoMessage({
        videoPath: tempFilePath,
      });
      wx.showToast({
        title: '视频已经保存至相册',
      });
    }
  }
})