<template>
  <div class="home-banner">
    <el-carousel arrow="never" class="banner-swiper">
      <el-carousel-item v-for="item in bannerList" :key="item.src"><img :src="item.src"/></el-carousel-item>
    </el-carousel>
    <router-link to="profession">
      <div class="cover">
        <img src="https://webapp-pub.ezijing.com/project/cuw/banner_top.jpg" />
        <div class="cover-inner">
          <h1>威斯康星协和大学</h1>
          <h2>家庭教育硕士</h2>
          <p>
            围绕“广义家庭教育”进行教学，从家庭系统的视角深度剖析全部家庭元素以及家庭与社会的关系，从根本上理解并解决家庭的问题。
          </p>
        </div>
      </div>
    </router-link>
    <div class="video-box" v-show="isPlaying">
      <video ref="video" src="https://webapp-pub.ezijing.com/project/cuw/video.mp4" preload="auto" playsinline></video>
    </div>
    <div class="button-group">
      <!-- <div class="button-item"><router-link to="profession">了解更多</router-link></div> -->
      <div class="button-item button-play" :class="{ 'is-playing': isPlaying }" @click="togglePlay">学校视频</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HomeBanner',
  data() {
    return {
      isPlaying: false,

      bannerList: [
        {
          src: 'https://webapp-pub.ezijing.com/project/cuw/banner_1.jpg'
        },
        {
          src: 'https://webapp-pub.ezijing.com/project/cuw/banner_2.jpg'
        },
        {
          src: 'https://webapp-pub.ezijing.com/project/cuw/banner_3.jpg'
        },
        {
          src: 'https://webapp-pub.ezijing.com/project/cuw/banner_4.jpg'
        }
      ]
    }
  },
  methods: {
    togglePlay() {
      this.isPlaying = !this.isPlaying
      this.$nextTick(() => {
        this.isPlaying ? this.$refs.video.play() : this.$refs.video.pause()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.home-banner {
  position: relative;
  height: calc(100vh - 10px);
  min-height: 600px;
}
.banner-swiper {
  height: 100%;
  ::v-deep .el-carousel__container {
    height: 100%;
  }
  img {
    height: 100%;
    width: 100%;
    object-fit: cover;
  }
}
.video-box {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 11;
  background-color: #000;
  video {
    width: 100%;
    height: 100%;
    object-fit: fill;
  }
}
.button-group {
  z-index: 21;
  position: absolute;
  left: 100px;
  bottom: 30%;
  display: flex;
  .button-item {
    width: 132px;
    border: 1px solid;
    border-radius: 5px;
    font-size: 18px;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #fff;
    line-height: 54px;
    text-align: center;
    cursor: pointer;
  }
  .button-item + .button-item {
    margin-left: 20px;
  }
  .button-play {
    width: 138px;
    padding-right: 20px;
    background: #faa634 url('@/assets/images/play.png') no-repeat right 20px center;
    border-color: #faa634;
    &.is-playing {
      background: url('@/assets/images/stop.png') no-repeat right 20px center;
      border-color: #fff;
    }
  }
}
.cover {
  position: absolute;
  top: 0;
  right: 100px;
  width: 434px;
  height: 100%;
  z-index: 10;
  box-sizing: border-box;
  overflow: hidden;
  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: all 0.25s ease-in-out;
  }
  &:hover {
    .cover-inner {
      background-color: rgba(0, 0, 0, 0.4);
    }
    img {
      transform: scale(1.1);
    }
  }

  .cover-inner {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 11;
    padding: 0 30px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding-bottom: 25%;
  }
  h1 {
    font-size: 36px;
    color: #fff;
    font-weight: 500;
    text-align: right;
  }
  h2 {
    margin-top: 16px;
    font-size: 26px;
    color: #faa634;
    font-weight: 400;
    text-align: right;
  }
  p {
    margin-top: 16px;
    font-size: 18px;
    color: #fff;
    line-height: 2;
    text-align: justify;
  }
}
</style>
