<script>
export default {
  name: 'PictometryLayer',
  computed: {
    ipa() {
      return this.$store.state.pictometry.ipa;
    },
    activeTopic() {
      return this.$store.state.activeTopic;
    },
  },
  watch: {
    activeTopic(nextTopic, prevTopic) {
      this.didDeactivateTopic(prevTopic);
      this.didActivateTopic(nextTopic);
    },
  },
  mounted() {
    this.didActivateTopic(this.activeTopic);
  },
  beforeDestroy() {
    this.didDeactivateTopic(this.activeTopic);
  },
  methods: {
    didActivateTopic(topic) {
      // console.log('didActivateTopic is firing with topic: ', topic);
      switch (topic) {
      case 'deeds':
        // turn on DOR Parcels
        this.ipa.showLayer({
          id: 114828,
          visible: true,
        });
        break;
      case 'zoning':
        // turn on zoning
        this.ipa.showLayer({
          id: 112230,
          visible: true,
        });
        break;
      case 'water':
        // turn on water Parcels
        this.ipa.showLayer({
          id: 108982,
          visible: true,
        });
        break;

      default:
        // turn off DOR parcels
        this.ipa.showLayer({
          id: 113478,
          visible: false,
        });
        // turn off zoning
        this.ipa.showLayer({
          id: 112230,
          visible: false,
        });
      }
    },

    didDeactivateTopic(topic) {
      switch (topic) {
      case 'deeds':
        // turn off DOR parcels
        this.ipa.showLayer({
          id: 114828,
          visible: false,
        });
        break;

      case 'zoning':
        // turn on zoning
        this.ipa.showLayer({
          id: 112230,
          visible: false,
        });
        break;

      case 'water':
        // turn off water
        this.ipa.showLayer({
          id: 108982,
          visible: false,
        });
        break;

      default:
        // turn off DOR parcels
        this.ipa.showLayer({
          id: 113478,
          visible: false,
        });
        // turn off zoning
        this.ipa.showLayer({
          id: 112230,
          visible: false,
        });
      }
    },


  },
  render(h) {
    return;
  },
};
</script>
