<template>
  <div class="_head">
    <h1 class="i-logo" @click="$router.push('/entry')">
      {{ name }} <span>V{{ version }}</span>
    </h1>

    <div
      v-if="!$store.isOpenWin"
      class="action_icon i-x-ktbj-text-align-justify"
    >
      <ul class="actions_layout">
        <li
          v-for="(v, i) in actions"
          :key="i"
          @click="v.handle"
          :class="v.icon"
        >
          {{ v.label }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { name, version } from '~/package.json'

export default {
  data: () => ({ name, version }),

  created () {
    this.actions = [
      {
        label: '修改密码',
        icon: 'i-mima',
        handle: this.$store.showUpdatePasswordDialog
      },
      {
        label: '在线答疑',
        icon: 'i-j-fbks-pingyu',
        handle: () => {
          this.openWin('#/online-course/online-FAQ?win=1', '在线答疑')
        }
      },
      // { label: '上传资源', icon: 'i-tianjia', handle: this.$store.showUploadDialog },
      {
        label: '退出登录',
        icon: 'i-tb-tuichudenglu',
        handle: this.$store.logout
      }
    ]

    if (this.$store.user.baseRole === 3) {
      this.actions.splice(1, 0, {
        label: '课堂笔记',
        icon: 'i-j-fbks-pingyu',
        handle: () => {
          this.openWin('#/online-course/class-notes?win=1', '课堂笔记')
        }
      })
    }
  },

  methods: {
    openWin (link, target = '') {
      window.open(
        link,
        target,
        'scrollbars=no,resizable=yes,statebar=no,location=no,width=1000,height=700,left=100,top=100'
      )
    },

    toHome () {
      this.$router.push('/')
    }
  }
}
</script>

<style lang="scss" scoped>
._head {
  padding: 0 30px;
  display: flex;
  align-items: center;
  color: #fff;
  font-size: 12px;
  background-color: #208ac6;
  user-select: none;
  .i-logo {
    cursor: pointer;
  }
  h1 {
    flex: 1;
    margin: 0 10px;
    font-size: 22px;
    color: #fff;

    &::before {
      font-weight: initial;
      font-size: 40px;
      vertical-align: middle;
    }

    span {
      font-size: 16px;
    }
  }

  .action_icon {
    padding: 16px 0 16px 16px;
    position: relative;
    font-size: 22px;
    cursor: pointer;
  }

  .actions_layout {
    padding: 6px 0;
    position: absolute;
    top: 50px;
    right: 0;
    z-index: 31;
    transform: scaleY(0);
    transform-origin: top;
    transition: transform 0.2s;
    color: $--color-text-primary;
    background-color: #fff;
    border-radius: 4px;
    box-shadow: 0px 2px 5px 0px rgba(16, 166, 180, 0.4);

    > li {
      padding: 6px 12px;
      display: block;
      font-size: 12px;
      white-space: nowrap;
      cursor: pointer;

      &::before {
        margin-right: 6px;
        display: inline-block;
        width: 22px;
        line-height: 22px;
        text-align: center;
        font-size: 12px;
        color: #fff;
        background-color: $--color-primary;
        border-radius: 50%;
      }

      &:hover {
        background-color: #e7f7f7;
      }
    }
  }

  .action_icon:hover .actions_layout {
    transform: scaleY(1);
  }
}
</style>
