
export default {
  namespaced: true,
  state() {
    return {
      // 导览列表
      toursList: [],
      toursStatus: false,
      v3toursStatus: false,
      isShowToursList: false,
      isPlayTours: false,
      isFlying: false,
      v3IsVr: false,

      // v3场景是否有音乐
      v3IsBgm: '',

      // v3场景是否在播放
      v3BGMStatus: '',
      
      mode: 'panorama',
      //当时场景的背景音乐
      fdkkBGM: '',
      //当时场景的info
      metadata: ''
    };
  },
  getters: {
    toursList: (state) => state.toursList,
    isShowToursList: (state) => state.isShowToursList,
    v3IsVr: (state) => state.v3IsVr,
    v3toursStatus: (state) => state.v3toursStatus,
    toursStatus: (state) => state.toursStatus,
    isPlayTours: (state) => state.isPlayTours,
    isFlying: (state) => state.isFlying,
    mode: (state) => state.mode,
    fdkkBGM: (state) => state.fdkkBGM,
    v3IsBgm: (state) => state.v3IsBgm,
    v3BGMStatus: (state) => state.v3BGMStatus,
    metadata: (state) => state.metadata,
  },
  mutations: {
    setShowToursList(state, payload) {
      state.isShowToursList = payload;
      document.querySelector('#fdkkifr') && document.querySelector('#fdkkifr').contentWindow.postMessage(
        {
          source: "qjkankan",
          event: "openTours",
          params: {
            showTours: state.isShowToursList
          }
        },
        "*"
      );
    },

    setV3IsInVR(state, payload) {
      state.v3IsVr = payload;

    },
    setToursStatus(state, payload) {
      state.toursStatus = payload;
      document.querySelector('#fdkkifr') && document.querySelector('#fdkkifr').contentWindow.postMessage(
        {
          source: "qjkankan",
          event: "playTour"
        },
        "*"
      );
    },

    setV3ToursStatus(state, payload) {
      state.v3toursStatus = payload;
    },
    setIsPlayTours(state, payload) {
      state.isPlayTours = payload;
    },
    setIsFlying(state, payload) {
      state.isFlying = payload;
    },

    setMode(state, payload) {
      state.mode = payload
      if (state.mode != 'panorama') {
        this.commit("functions/setShowScenesList", false)
      }
    },

    setMetadata(state, payload) {
      state.metadata = payload
    },

    setToursList(state, payload) {
      console.log(payload, 'payload');
      state.toursList = payload;
    },

    setReset(state, payload) {
      state.toursList = [],
        state.toursStatus = false,
        state.isShowToursList = false,
        state.isPlayTours = false,
        state.isFlying = false,
        state.mode = 'panorama'
    },

    setFdkkBGM(state, payload) {
      if (payload) {
        let bgm = ''
        if (payload.indexOf('http') > -1) {
          bgm = payload
        } else {
          bgm = `https://${window.location.hostname}/panorama/${payload}`
        }

        state.fdkkBGM = bgm
      } else {
        state.fdkkBGM = null
      }
    },
    setV3FdkkBGM(state, payload) {
        state.v3IsBgm = payload
    },
    setV3BGMStatus(state, payload) {
        state.v3BGMStatus = payload
    }
  },
};
