<template>
  <div class="com-panel" :class="{ 'no-title': !hasTitle }">
    <div v-if="hasTitle" class="panel-header">
      <div class="panel-title">
        <i v-if="hasIcon" class="panel-icon" :class="icon"></i>
        {{ title }}
      </div>
      <div class="panel-tools">{{ subTitle }}</div>
    </div>
    <div class="panel-body">
      <slot></slot>
    </div>
  </div>
</template>

<script>
export default {
  name: "com-panel",
  componentName: "com-panel",
  props: {
    title: String,
    icon: String,
    subTitle: String,
  },
  computed: {
    hasTitle() {
      if (this.title) return true;
      return false;
    },
    hasIcon() {
      if (this.icon) return true;
      return false;
    },
  },
};
</script>
<style lang="less" scoped>
.com-panel {
  border-left: 0.185vh solid rgba(255, 255, 255, 50%);

  &:before {
    content: " ";
    width: 0.37vh;
    height: 0.37vh;
    float: left;
    background: #fff;
    margin: 0.185vh 0.556vh 0vh 0.185vh;
  }

  &.no-title {
    border-left: 0vh;
  }

  &.no-title::before {
    display: none;
  }

  .panel-header {
    display: flex;
    font-size: @fontsize;
    padding-left: 1.4815vh;
    background: rgba(255, 255, 255, 10%);
    line-height: 2.963vh;
    margin-bottom: 1.481vh;

    .panel-title {
      color: rgba(255, 255, 255, 0.8);
      flex: 1 1 auto;
      .panel-icon {
        margin-right: 0.741vh;
      }
    }

    .panel-tools {
      flex: 0 0 auto;
      color: #fff;
      opacity: 0.3;
      padding: 0 0.741vh;
      font-size: @fontsize-s;
      letter-spacing: 0.093vh;
    }
  }

  .panel-body {
    padding-left: 1.111vh;
    color: rgba(255, 255, 255, 0.8);
  }

  &.no-title .panel-body {
    padding-left: 0vh;
  }
}
</style>
