<template>
  <div class="comp-content comp-tree-edit-item">
    <div v-if="data" class="text-data" :title="hideTitle ? '' : data">
      <el-icon v-if="icon" :size="16" class="icon">
        <component :is="icon" />
      </el-icon>
      <slot name="default">
        {{ data }}
      </slot>
    </div>
    <div v-else-if="editMode" class="tip">
      <el-icon :size="14">
        <Edit />
      </el-icon>
      <span class="text">双击编辑</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Edit } from '@element-plus/icons-vue';

interface Props {
  data: any;
  editMode?: boolean;
  icon?: any;
  hideTitle?: boolean;
}

const props = withDefaults(defineProps<Props>(), {
  data: null,
  editMode: false,
  icon: null,
  hideTitle: false,
});
</script>

<style lang="scss" scoped>
.comp-tree-edit-item {
  .text-data {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    .icon {
      margin-right: 2px;
      transform: translateY(2px);
    }
  }
  .tip {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    font-size: 12px;
    color: var(--el-text-color-secondary);
    .text {
      padding-left: 2px;
    }
  }
}
</style>
