<template>
  <div>
    <transition
      enter-active-class="animate__animated animate__fadeInLeft"
      leave-active-class="animate__animated animate__fadeOutLeft"
    >
      <div
        v-if="leftAnimationKey !== 0"
        :key="leftAnimationKey"
        class="left_content"
      >
        <template v-if="!leftCollapse">
          <left-content />
        </template>
        <div
          :class="[
            'collapse_menu collapse_menu_left',
            { active: leftCollapse },
          ]"
          @click="fnChangeLeftCollapse"
        >
          <img src="/src/assets/images/map/collapse_menu.png" alt="" />
        </div>
      </div>
    </transition>
    <transition
      enter-active-class="animate__animated animate__fadeInRight"
      leave-active-class="animate__animated animate__fadeOutRight"
    >
      <div
        v-if="rightAnimationKey !== 0"
        :key="rightAnimationKey"
        class="right_content"
      >
        <template v-if="!rightCollapse">
          <right-content />
        </template>
        <div
          :class="[
            'collapse_menu collapse_menu_right',
            { active: rightCollapse },
          ]"
          @click="fnChangeRightCollapse"
        >
          <img src="/src/assets/images/map/collapse_menu.png" alt="" />
        </div>
      </div>
    </transition>
  </div>
</template>

<script setup>
import { onMounted, ref } from "vue";
import LeftContent from "./left_content.vue";
import RightContent from "./right_content.vue";

const leftAnimationKey = ref(0);
const rightAnimationKey = ref(0);
const leftCollapse = ref(false);
const rightCollapse = ref(false);
onMounted(() => {
  leftAnimationKey.value = Math.random();
  rightAnimationKey.value = Math.random();
});
const fnChangeLeftCollapse = () => {
  leftAnimationKey.value = Math.random();
  leftCollapse.value = !leftCollapse.value;
};
const fnChangeRightCollapse = () => {
  rightAnimationKey.value = Math.random();
  rightCollapse.value = !rightCollapse.value;
};
</script>

<style scoped lang="scss">
.left_content {
  width: 480px;
  position: absolute;
  left: 0;
  top: 64px;
  background-image: url("/src/assets/images/map/leftbg.png");
  background-size: 450px 100%;
  background-repeat: no-repeat;
  padding-top: 15px;
  padding-left: 15px;
  padding-bottom: 15px;
}

.right_content {
  width: 480px;
  position: absolute;
  right: 0;
  top: 64px;
  background-image: url("/src/assets/images/map/rightbg.png");
  background-size: 450px 100%;
  background-repeat: no-repeat;
  background-position: right center;
  padding-top: 15px;
  padding-right: 15px;
  padding-bottom: 15px;
}

.collapse_menu {
  width: 30px;
  height: 89px;
  position: absolute;
  top: 50%;
  background-image: url("/src/assets/images/map/collapse_menu_bg.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  cursor: pointer;

  &.collapse_menu_left {
    left: 480px;
    transform: translateY(-50%);

    &.active {
      left: 0;
    }
  }

  &.collapse_menu_right {
    right: 480px;
    transform: translateY(-50%) rotate(180deg);

    &.active {
      right: 0;
    }
  }

  &.active {
    top: 50vh;

    img {
      transform: translate(-50%, -50%) rotate(180deg);
    }
  }

  img {
    width: 10px;
    height: 17px;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%) rotate(0);
  }
}
</style>
