<template>
  <div class="location-map">
    <ods-sub-header data-id="map-subheader" cssClass="overrideSubHeader">
      <div class="flex">
        <h6>
          {{translate('header')}}
          <span v-if="isShowActiveBredcrumb">> {{$route.params.id}}</span>
        </h6>
      </div>
    </ods-sub-header>
    <div class="flex mainSection">
      <div :class="['mapContainer', { 'hideMap': isShowMap }]">
        {{featureCollection}}
        <CesiumMap data-id="cesium-map" :collection="collection"></CesiumMap>
      </div>
      <section :class="isShowMap === true ? 'fakeBackground' : ''"></section>
      <button
        data-id="toggle-map"
        class="btnHideMap"
        :class="isShowMap ? 'btnHiding' : 'btnFirstPosition'"
        @click="toogleMap"
      >
        <span :class="isShowMap ? 'ods-icon-double-right' : 'ods-icon-double-left'"></span>
      </button>
      <div :class="['inventory-map', { 'extended': isShowMap }]">
        <router-view></router-view>
      </div>
    </div>
  </div>
</template>

<script>
import {mapGetters, mapActions, mapMutations, mapState} from 'vuex';

import CesiumMap from '@/components/map/CesiumMap';

export default {
  name: 'location-map',
  data() {
    return {
      dataAssets: null,
      dataPlants: null,
      isShowMap: false,
      isShowActiveBredcrumb: false,
    };
  },
  components: {CesiumMap},
  computed: {
    ...mapState(['featureCollection']),
    ...mapGetters(['mapIsLoaded', 'currentAsset', 'collection']),
  },
  mounted() {
    this.fetchFeatureCollection();
  },
  methods: {
    ...mapActions(['fetchFeatureCollection']),
    ...mapMutations([
      'setCurrentAsset',
      'clearCurrentAsset',
      'toogleMapIsVisible',
    ]),
    translate(data) {
      return this.$t(`map.${data}`);
    },
    toogleMap() {
      this.isShowMap = !this.isShowMap;
      this.toogleMapIsVisible({mapIsVisible: !this.isShowMap});
    },
    sendStationEventCallback(e) {
      const asset = e.detail;

      this.clearCurrentAsset();
      this.setCurrentAsset({currentAsset: asset});

      this.$router.push({path: `/map/assets/${asset.id}`});
    },
  },
};
</script>

<style lang="scss" scoped>
.location-map {
  width: 100%;
}

.mainSection {
  margin-top: 66px;
}

.mapContainer {
  position: relative;
  margin-right: -16px;
  overflow: hidden;
  width: 100%;
  &.hideMap {
    width: 0;
    visibility: hidden;
  }
}

.ods-sub-header {
  padding: 25px 30px;
  h6 {
    font-size: 14px;
  }
}

.btnHideMap {
  cursor: pointer;
  z-index: 10;
  border: none;
  border-radius: 50%;
  background-color: #ffffff;
  height: 32px;
  width: 32px;
  -ms-flex-item-align: center;
  align-self: center;
  box-shadow: 2px 0px 10px 0px rgba(0, 0, 0, 0.1);
  span {
    vertical-align: middle;
    font-size: 16px;
  }
}

.fakeBackground {
  background-color: #cbe4f5;
  width: 155px;
  margin-right: -16px;
}

.inventory-map {
  display: flex;
  background-color: #f9f9fb;
  margin-left: -16px;
  margin-top: 50px;
  padding: 0 25px;
  width: 932px;
  overflow-y: scroll;
  border-left: 1px solid #eee;
  &.extended {
    width: 1100px;
    margin: 0 auto;
    margin-top: 50px;
    border-left: 0;
  }
  > * {
    width: 100%;
  }
}
</style>
