<template>
  <el-card class="m-b card-layout" :class="{ 'cmdb-card-hidden': !isShow }">
    <template #header>
      <span class="icon">
        <i class="el-icon-arrow-right" v-if="!isShow" @click="handleClick"></i>
        <i class="el-icon-arrow-down" v-else @click="handleClick"></i>
      </span>
      <span class="title">{{ title }}</span>
    </template>
    <el-collapse-transition>
      <div class="slot-container" v-show="isShow">
        <slot></slot>
      </div>
    </el-collapse-transition>
  </el-card>
</template>

<script>
import { ref } from 'vue'
export default {
  props: {
    title: {
      type: String,
    },
  },
  setup() {
    const isShow = ref(true)

    function handleClick() {
      isShow.value = !isShow.value
    }
    return {
      isShow,
      handleClick,
    }
  },
}
</script>
<style lang="scss" scoped>
.card-layout {
  border: none;
  border-bottom: 1px solid #f0f0f0;
}

.el-card.el-card.is-always-shadow {
  box-shadow: none;
}
::v-deep .el-card__header {
  border: none;
}
.card-layout {
  .icon {
    margin-right: 10px;
    cursor: pointer;
    padding: 2px;
    i {
      font-size: 20px;
    }
  }
  .title {
    font-weight: 600;
    display: flex;
    align-items: center;
  }
  .operate {
    margin-top: 3px;
  }
  .slot-container {
    padding: 10px 20px;
  }
  ::v-deep > .el-card__header {
    display: flex;
    .operate {
      flex: 1;
      display: flex;
      justify-content: flex-end;
    }
  }
  ::v-deep > .el-card__body {
    padding: 0;
  }
  &.cmdb-card-hidden {
    ::v-deep {
      & > .el-card__header {
        border-bottom: none;
      }
    }
  }
}
</style>
