<template>
  <div class="sidebar-logo-container" :class="{ collapse: collapse }">
    <router-link class="sidebar-logo-link" to="/">
      <img v-if="logImg" :src="logImg" class="sidebar-logo" alt="" />
      <span v-if="!collapse" class="sidebar-title">{{ title }}</span>
    </router-link>
  </div>
</template>

<script>
export default {
  name: 'SidebarLogo',
  props: {
    collapse: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      title: process.env.VUE_APP_TITLE_INDEX || '云联融智SAAS'
    }
  },
  computed: {
    logImg() {
      try {
        return require(process.env.VUE_APP_LOG_URL)
      } catch (e) {
        return ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/styles/variables.scss';

/* 与右侧顶栏同高，垂直居中；右侧竖线与 adminUI 一致 */
.sidebar-logo-container {
  display: flex;
  align-items: center;
  width: 100%;
  height: 56px;
  flex-shrink: 0;
  background: $nav-top-bg;
  border-bottom: 1px solid $sidebar-border;
  border-right: 1px solid $sidebar-border;
  box-sizing: border-box;

  .sidebar-logo-link {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    height: 100%;
    padding: 0 16px;
    text-decoration: none;
    box-sizing: border-box;
  }

  .sidebar-logo {
    display: block;
    width: 30px;
    height: 30px;
    flex-shrink: 0;
    object-fit: contain;
  }

  .sidebar-title {
    margin: 0 0 0 10px;
    padding: 0;
    color: #303133;
    font-weight: 600;
    font-size: 15px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  &.collapse {
    .sidebar-logo-link {
      justify-content: center;
      padding: 0;
    }
  }
}
</style>
