
import Emiter from 'tiny-emitter'

export default class Tags extends Emiter {
  constructor(app) {
    super()
    this.app = app;
  }

  /**
 * 打开热点链接
 */

  linkopen(sceneCode, id, hid) {
    this.emit('clickHotspot', { sceneCode, id, hid })
  }

  /**
   * 添加热点
   */

  addhotspot(param, type) {
    let ath = this.app.krpanoDom.get("curscreen_ath");
    let atv = this.app.krpanoDom.get("curscreen_atv");
    this.app.krpanoDom.call(`addImgTextHotSpot(
        ${param.img.replace('static/','showviewer/').replace('.svg','.png')},
        ${param.name},
        ${param.hotspotTitle},
        ${param.ath != '' ? param.ath : ath},
        ${param.atv != '' ? param.atv : atv},
        ${param.secne ? param.secne.sceneCode : 'notjump'},
        ${type},
        ${param.link},
        ${true},
        ${param.visible},
        ${(param.size * 50) || 1},
        ${Number(param.fontSize)})`);


    // 设置热点图片默认的偏移值
    let offset = '-130%'
    if (param.size < 1) {
      offset = '-200%'
    }
    if (param.size > 1) {
      offset = '-100%'
    }
    this.app.krpanoDom.set('layer[tooltip_' + param.name + '].y', `${offset}`)

  }


  /**
  * 初始化
  */

  initHotspot(hotspots, type) {
    hotspots.forEach(item => {
      this.addhotspot(item, type)
    });
  }


  /**
   * 显示隐藏热点
   */

  toggleHotspot(toggle) {
    try {
      this.app.krpanoDom.call(`set_hotspot_visible(${toggle})`);
    } catch (e) {
      e
    }
  }

}
