<template>
  <div class="control-left" :class="{ collapse: listCollapse }">
    <div class="left-bar-item item" @click="onClickTask">
      <img class="left-bar-item__icon" src="./assets/images/task.svg" />
      <div class="left-bar-item__text">任务</div>
    </div>
    <AirwayList class="task-list" v-if="openTask"></AirwayList>
    <!-- 展示视频 -->
    <div class="left-video" :class="{collapse: playerCollapse}" v-if="hangar && showPanel && listCollapse">
      <div class="collapse-btn" @click="playerCollapse = !playerCollapse">
        <img src="./assets/images/collapse.svg" />
      </div>

      <div class="left-video-header">
        <div class="left-video-header__title" @click="openList">机库列表</div>
        <div class="nest-name">
          <span class="nest-name__text">{{ hangar.name }}</span>
          <span class="nest-name__text">{{ hangar.name }}</span>
        </div>
      </div>
      <div class="left-video-nest">
        <div id="playInnerParent" class="player1">
          <PlayerInner id="playInner" />
        </div>
        <div id="playOutParent" class="player2">
          <PlayerOuter id="playerOuter" />
        </div>
        <div id="playerUavParent" class="player3">
          <PlayerUav id="playerUav" />
        </div>
      </div>
    </div>
    <VideoMapSwitch ref="videoMapSwitch"></VideoMapSwitch>
  </div>
</template>

<script>
import { mapState } from "vuex";
import AirwayList from "./components/airwayList";
import PlayerInner from "./components/player/inner";
import PlayerOuter from "./components/player/outer";
import PlayerUav from "./components/player/uav";
import VideoMapSwitch from './components/videoMapSwitch';

export default {
  name: "ControlLeft",
  components: {
    AirwayList,
    PlayerInner,
    PlayerOuter,
    PlayerUav,
    VideoMapSwitch
  },
  data() {
    return {
      openTask: true, //打开任务
      playerCollapse: false, //收起播放器
    };
  },
  computed: {
    ...mapState("MMCFlightControlCenter/hangar", ["hangar", "showPanel"]),
    ...mapState("MMCFlightControlCenter", ["showAirwayEdit"]),
    // 收起列表按钮
    listCollapse: {
      get() {
        return this.$store.state.MMCFlightControlCenter.listCollapse;
      },
      set(val) {
        this.$store.commit("MMCFlightControlCenter/setState", {
          key: "listCollapse",
          value: val,
        });
      },
    },
  },
  watch: {
    hangar(){
      this.openTask = false;
      this.$nextTick(() => {
        this.openTask = true;
      })
    },
    showAirwayEdit(newVal){
      this.playerCollapse = true;
    }
  },
  methods: {
    onClickTask() {
      this.openTask = !this.openTask;
    },
    openList(){
      this.listCollapse = false; 
      this.$refs.videoMapSwitch.reset();
    }
  },
};
</script>

<style scoped lang="scss">
.task-list {
  position: absolute;
  left: 60px;
  top: 0px;
  cursor: initial;
}
.control-left {
  position: absolute;
  z-index: 2;
  left: 430px;
  top: 68px;
  transition: 0.3s;

  &.collapse {
    left: 10px;
  }

  .left-bar-item {
    cursor: pointer;
    position: relative;
    width: 48px;
    height: 48px;
    background: #ffffff;
    border-radius: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-bottom: 2px;

    .left-bar-item__icon {
      width: 20px;
      height: 20px;
      margin-bottom: 2px;
    }

    .left-bar-item__text {
      font-size: 16px;
      transform: scale(0.6);
      white-space: nowrap;
      color: #000;
    }
  }

  .ai-list {
    width: 0;
    position: absolute;
    left: 65px;
    top: 62px;
    display: none;
    gap: 4px;

    &.active {
      display: flex;
    }

    .left-bar-item {
      padding-top: 3px;
    }
  }
}

.ai-dialog {
  position: absolute;
  top: 56px;
  left: 0;
}

.left-video {
  width: 382px;
  position: absolute;
  left: -10px;
  top: 308px;
  z-index: 10;
  background: #222222;
  border-radius: 10px;
  z-index: 1;
  transition: 0.3s;

  &.collapse {
    transform: translateX(-100%);

    .collapse-btn {
      &::before {
        transform: translate(-63%, -50%) rotate(90deg) !important;
      }
    }
  }

  .collapse-btn {
    position: absolute;
    cursor: pointer;
    right: -35px;
    top: 50%;
    transform: translate(0, -50%);
    z-index: 99;

    &::before {
      content: "";
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-63%, -50%) rotate(-90deg);
      width: 0px;
      height: 0px;
      border-left: 7px solid transparent;
      border-right: 7px solid transparent;
      border-bottom: 9px solid #fff;
    }
  }

  .left-video-header {
    width: 100%;
    height: 32px;
    border-radius: 10px 10px 0 0;
    border-bottom: 1px solid rgba(207, 234, 255, 0.33);
    background: url("./assets/images/line.png") no-repeat;
    background-position: 60%;
    font-size: 16px;
    font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
    font-weight: bold;
    color: #70daf9;
    display: flex;
    // justify-content: center;
    align-items: center;

    .left-video-header__title {
      cursor: pointer;
      flex-shrink: 0;
      margin-left: 16px;
      width: 86px;
      height: 22px;
      line-height: 22px;
      text-align: center;
      font-size: 12px;
      font-weight: 500;
      font-family: SourceHanSansCN-Medium, SourceHanSansCN;
      background: url("./assets/images/nestlist.png");
      color: #fff;
    }

    .nest-name {
      margin-left: 30px;
      margin-right: 20px;
      width: 250px;
      overflow: hidden;
      white-space: nowrap;

      .nest-name__text {
        display: inline-block;
        white-space: nowrap;
        animation: scrollTitle 15s linear infinite;
        min-width: 100%;
        padding-right: 50px;
        box-sizing: border-box;
        font-family: YouSheBiaoTiHei;
        background-image: -webkit-linear-gradient(
          right,
          #e3aa77,
          #f5cda9,
          #f9ecd3,
          #fcdbb1,
          #edb07a
        );
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        font-size: 20px;
        font-weight: 100;
      }
    }
  }

  @keyframes scrollTitle {
    0% {
      transform: translateX(0);
    }
    100% {
      transform: translateX(-100%);
    }
  }

  .left-video-nest::v-deep {
    display: flex;
    flex-wrap: wrap;
    box-sizing: border-box;
    gap: 10px;
    padding: 16px 14px;
    position: relative;

    .player1,
    .player2 {
      flex: 1;
      height: 96px;
    }
    .player3 {
      width: 100%;
      height: 235px;
    }
  }
}
</style>