<template>
  <div class="sidebar-logo-container" :class="{ 'collapse': collapse }">
    <transition name="sidebarLogoFade">
      <div v-if="collapse" key="collapse" class="sidebar-logo-link">
        <img v-if="logo" :src="logo || Avatar" class="sidebar-logo">
        <h1 v-else class="sidebar-title">{{ shopName }} </h1>
        <i class="el-icon-arrow-down icon"></i>
      </div>
      <div v-else key="expand" class="sidebar-logo-link">
        <img v-if="logo" :src="logo || Avatar" class="sidebar-logo">
        <h1 class="sidebar-title">{{ shopName }} </h1>
        <i class="el-icon-arrow-down icon"></i>
      </div>
    </transition>
  </div>
</template>

<script>
import Avatar from '@/assets/images/avatar.png'
export default {
  name: 'SidebarLogo',
  props: {
    collapse: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      shopName: localStorage.getItem('shopName'),
      Avatar,
      logo: localStorage.getItem('logo'),
    }
  }
}
</script>

<style lang="scss" scoped>
.sidebarLogoFade-enter-active {
  transition: opacity 1.5s;
}

.sidebarLogoFade-enter,
.sidebarLogoFade-leave-to {
  opacity: 0;
}

h1 {
  width: 100px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.sidebar-logo-container {
  position: relative;
  width: 100%;
  height: 50px;
  line-height: 50px;
  text-align: center;
  overflow: hidden;

  & .sidebar-logo-link {
    height: 100%;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;

    .icon {
      font-size: 14px;
      margin-left: 6px;
    }

    & .sidebar-logo {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      margin-right: 6px;
    }

    & .sidebar-title {
      color: #333;
      font-size: 14px;
    }
  }

  &.collapse {
    .sidebar-logo {
      margin-right: 0px;
    }

    .sidebar-logo {
      width: 24px;
      height: 24px;
    }
  }
}
</style>
