<template>
  <div
    class="ui-layout"
    :class="['ui-layout--' + type]"
  >
    <div class="ui-layout__sidebar" v-if="showSidebar">
      <div class="ui-layout__sidebar-head" v-if="title || backUrl">
        <router-link
          v-if="backUrl"
          replace
          class="ui-layout__back"
          :to="backUrl"
        ></router-link>
        <div class="ui-layout__sidebar-title">{{ title }}</div>
      </div>
      <div class="ui-layout__sidebar-main">
        <slot name="sidebar" />
      </div>
    </div>
    <div class="ui-layout__main">
      <slot />
    </div>
  </div>
</template>
<script>
export default {
  name: 'UiLayout',
  props: {
    title: {
      type: String,
      default: ''
    },
    type: {
      type: String,
      default: 'simple',
      validator(value) {
        return ['simple', 'weight'].includes(value)
      }
    },
    backUrl: {
      type: String
    },
    showSidebar: {
      type: Boolean,
      default: true
    }
  }
}
</script>
<style lang="less">
.ui-layout{
  height: 100%;
  display: flex;
  flex-direction: row;
}
.ui-layout__sidebar{
  width: 220px;
  height: 100%;
  border-right: 1px solid #E6E7EA;
  box-sizing: border-box;
  overflow: auto;
}
.ui-layout__sidebar-title{
  height: 32px;
  line-height: 32px;
  padding: 2px 0;
  font-size: 18px;
  font-weight: bold;
  color: #202D40;
}
.ui-layout__main{
  flex: 1;
  min-width: 0;
  overflow: auto;
}
.ui-layout--weight{
  > .ui-layout__sidebar{
    background-color: #f7f8fa;
    .ui-layout__sidebar-main{
      padding-top: 8px;
      padding-bottom: 8px;
    }
  }
}
.ui-layout--simple {
  > .ui-layout__sidebar {
    padding: 10px;
  }
}
.ui-layout__sidebar-head{
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-bottom: 15px;
  padding-left: 15px;
}
.ui-layout__back{
  display: inline-block;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0px 0px 4px 0px rgba(169,169,169,0.5000);
  margin-right: 12px;
  position: relative;
  background: url('./icons/back-line.svg') no-repeat 50% 50% #fff;
  background-size: 85%;
  transition: all .25s;
  cursor: pointer;
  &:hover {
    background-color: #f3f3f3;
  }
}
</style>
