<template>
  <div :class="`custom-table-tree ${shadow ? 'custom-table-tree__shadow' : ''}`">
    <div v-if="title" class="title">{{ title }}</div>
    <el-tree
      node-key="id"
      :data="data"
      :show-checkbox="option.showCheckbox"
      :default-expanded-keys="option.defaultExpandedKeys"
      :default-checked-keys="option.defaultCheckedKeys"
      :props="option.defaultProps"
      @node-click="handleNodeClick"
    />
  </div>
</template>
<script setup name="custom-table-tree">
const props = defineProps({
  title: { type: String, default: '' },
  shadow: { type: Boolean, default: true },
  data: { type: Array, default: () => [] },
  option: {
    type: Object,
    default: () => {
      return {
        showCheckbox: false,
        defaultProps: {
          children: 'children',
          label: 'label',
        },
        defaultExpandedKeys: [],
        defaultCheckedKeys: [],
      };
    },
  },
});
const emit = defineEmits(['node-click']);

const handleNodeClick = (data) => {
  emit('node-click', data);
};
</script>
<style lang="scss" scoped>
.custom-table-tree {
  width: 100%;
  height: 100%;
  min-width: 200px;
  @include flex-column();

  &__shadow {
    box-shadow: 2px 0px 5px rgba(0, 0, 0, 0.1);
  }

  .title {
    height: 36px;
    padding: 0 20px;
    line-height: 36px;
    border-radius: 4px;
    font-size: 16px;
    color: #fff;
    background: var(--el-color-primary);
  }

  .el-tree {
    padding: 16px 10px 10px;
    box-sizing: border-box;
  }
}
</style>
