// 대상이 없을 경우 숨기는 기능
var hideNoTarget = true;

// 역할
var JobRole = {
 PLD: 'PLD',
 WAR: 'WAR',
 GLD: 'GLD',
 MRD: 'MRD',
 DRK: 'DRK',

 CNJ: 'CNJ',
 WHM: 'WHM',
 SCH: 'SCH',
 AST: 'AST',

 PGL: 'PGL',
 LNC: 'LNC',
 ARC: 'ARC',
 THM: 'THM',
 MNK: 'MNK',
 DRG: 'DRG',
 BRD: 'BRD',
 BLM: 'BLM',
 ACN: 'ACN',
 SMN: 'SMN',
 ROG: 'ROG',
 NIN: 'NIN',
 MCH: 'MCH',
 SAM: 'SAM',
 RDM: 'RDM'
};

// ターゲットしてないときのダミーデータ
var noTarget = {
  Name: '대상없음',
  MaxHP: '--',
  CurrentHP: '--',
  HPPercent: '--',
  Distance: '- ',
  EffectiveDistance: ' - ',
  HorizontalDistance: ' - ',
}

// 필터
Vue.filter('jobclass', function (v) {
 var role = JobRole[v.JobName];
 if (v.isPet) return "Pet";
 if (role != null) return role;
 return "UNKNOWN";
});

Vue.filter('hpcolor', function (t) {
  if (t.HPPercent > 75) return "green";
  if (t.HPPercent > 50) return "yellow";
  if (t.HPPercent > 25) return "orange";
  return "red";
});

Vue.filter('you', function (v) {
  return v.isMe ? "YOU" : v.Name;
});

// 데이터 처리
var enmity = new Vue({
  el: '#enmity',
  data: {
    updated: false,
    locked: false,
    collapsed: false,
    target: null,
    entries: null,
    hide: false
  },
  attached: function() {
    document.addEventListener('onOverlayDataUpdate', this.update);
    document.addEventListener('onOverlayStateUpdate', this.updateState);
  },
  detached: function() {
    document.removeEventListener('onOverlayStateUpdate', this.updateState);
    document.removeEventListener('onOverlayDataUpdate', this.update);
  },
  methods: {
    update: function(e) {
      this.updated = true;
      this.entries = e.detail.Enmity.Entries;
      this.target  = e.detail.Enmity.Target ? e.detail.Enmity.Target : noTarget;
      this.hide = (hideNoTarget && e.detail.Enmity.Target == null);
    },
    updateState: function(e) {
      this.locked = e.detail.isLocked;
    },
    toggleCollapse: function() {
      this.collapsed = !this.collapsed;
    }
  }
});

