<template>
  <div class="card" :style="styles">
    <div class="card-header">
      <slot name="header">
        <h5 class="card-title" v-if="title">
          <slot name="title">{{ title }}</slot>
        </h5>
        <div class="card-option">
          <slot name="option">
            <a
              :href="item.url || 'javascript:;'"
              v-for="(item, index) in option"
              :key="index"
              @click="optionClick(index)"
            >
              {{ item }}
            </a>
          </slot>
        </div>
      </slot>
    </div>
    <div class="card-body">
      <slot><div v-html="content"></div></slot>
    </div>
    <div class="card-footer" v-if="footer">
      <slot name="footer">{{ footer }}</slot>
    </div>
  </div>
</template>

<script>
/**
 * @description: 面板组件
 * @param {type}
 * @return:
 */
const OPTION_CLICK_EVENT = "option-click";
export default {
  name: "Card",
  props: {
    title: {
      type: String,
      default: ""
    },
    content: {
      type: String,
      default: ""
    },
    option: {
      type: Array,
      default() {
        return [];
      }
    },
    footer: {
      type: String,
      default: ""
    },
    styles: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  methods: {
    optionClick(index, item) {
      this.$emit(OPTION_CLICK_EVENT, { index, item });
    }
  }
};
</script>

<style lang="less" scoped>
@import "../style/var.less";
.card {
  padding: 20px;
  background-color: @white;
  // margin-bottom: 10px;
  &-header {
    padding: 4px 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  &-title {
    font-size: @font-size-18;
    font-weight: @font-weight-bold;
    color: @black;
    line-height: @line-height-sm + 2;
  }
  &-option {
    display: flex;
    align-items: center;
  }
  &-body {
    margin-bottom: 20px;
  }
}
</style>
