<template>
  <div class="split-preview">
    <el-dialog title="拆分结果预览" :visible.sync="visible" width="60%" :before-close="handleClose">
      <div v-loading="loading" class="preview-content">
        <template v-if="!loading && previewData">
          <el-tree class="tree" :data="previewData" :props="defaultProps" default-expand-all @node-click="handleNodeClick"></el-tree>
        </template>
        <el-empty v-else-if="!loading && !previewData" description="暂无预览数据"></el-empty>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="medium" @click="handleReUpload">重新上传</el-button>
        <el-button size="medium" type="primary" @click="handleConfirm">完成</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'SplitPreview',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    previewData: {
      type: Array
    },
    isAutoSplit: {
      type: Boolean,
      default: true
    },
    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      defaultProps: {
        children: 'children',
        label: 'paragraphTitle'
      }
    }
  },
  methods: {
    handleNodeClick() {},
    handleClose() {
      this.$emit('update:visible', false)
    },
    handleReUpload() {
      this.$emit('handleReUpload')
    },
    handleConfirm() {
      this.$emit('confirm')
    }
  }
}
</script>

<style lang="scss" scoped>
.split-preview {
  .preview-content {
    min-height: 200px;
    overflow-y: auto;
  }

  .preview-list {
    .preview-item {
      margin-bottom: 16px;
      border: 1px solid #ebeef5;
      border-radius: 4px;

      .item-header {
        padding: 8px 16px;
        background-color: #f5f7fa;
        border-bottom: 1px solid #ebeef5;
        display: flex;
        justify-content: space-between;

        .item-title {
          font-weight: bold;
        }

        .item-info {
          color: #909399;
        }
      }

      .item-content {
        padding: 16px;
        white-space: pre-wrap;
        max-height: 200px;
        overflow-y: auto;
      }
    }
  }

  .stat-info {
    padding: 16px;
  }
}
</style>
