<script lang="ts">
import type { PropType } from 'vue';
import { defineComponent } from 'vue';

interface CompareResult {
  baseBoxArea: string;
  baseDiffContent: string;
  baseDiffType: 'modify' | 'insert' | 'delete';
  basePageNum: number;
  compareBoxArea: string;
  compareDiffContent: string;
  compareDiffType: 'modify' | 'insert' | 'delete';
  comparePageNum: number;
  id: number;
}

interface DiffTypeMap {
  [key: string]: string;
}

export default defineComponent({
  name: 'DiffItem',
  props: {
    item: {
      type: Object as PropType<CompareResult>,
      required: true
    },
    isSelected: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    diffTypeLabel(): string {
      const typeMap: DiffTypeMap = {
        insert: '新增',
        delete: '删除',
        modify: '修改'
      };
      return typeMap[this.item.compareDiffType] || this.item.compareDiffType;
    }
  }
});
</script>

<template>
  <div
    class="result-item"
    :class="[`diff-${item.compareDiffType}`, { selected: isSelected }]"
    :data-id="item.id"
    @click="$emit('click', item)"
  >
    <div class="result-item-header">
      <span class="diff-type">{{ diffTypeLabel }}</span>
      <span class="page-info">第{{ item.basePageNum }}页</span>
    </div>
    <div class="result-content">
      <div class="original-content">
        <strong>原合同：</strong>
        <span>{{ item.baseDiffContent || '无内容' }}</span>
      </div>
      <div class="compare-content">
        <strong>对比合同：</strong>
        <span>{{ item.compareDiffContent || '无内容' }}</span>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.result-item {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid #e8e8e8;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  position: relative;

  &.diff-insert {
    border-left: 4px solid #52c41a;
  }
  &.diff-delete {
    border-left: 4px solid #ff4d4f;
  }
  &.diff-modify {
    border-left: 4px solid #faad14;
  }

  &:hover {
    border-color: #1890ff;
    box-shadow: 0 4px 16px rgba(24, 144, 255, 0.15);
    transform: translateY(-2px);
  }

  &.selected {
    background: #e6f7ff;
    border: 2px solid #1890ff;
    box-shadow: 0 4px 16px rgba(24, 144, 255, 0.2);
  }



  /* 添加选中状态标记 */
  &.selected::after {
    content: '';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #1890ff;
    animation: pulse 1.5s infinite;
  }
}

.result-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;

  .diff-type {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 16px;
    color: white;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  .diff-insert & .diff-type {
    background: linear-gradient(135deg, #52c41a 0%, #73d13d 100%);
  }
  .diff-delete & .diff-type {
    background: linear-gradient(135deg, #ff4d4f 0%, #ff7875 100%);
  }
  .diff-modify & .diff-type {
    background: linear-gradient(135deg, #faad14 0%, #ffc53d 100%);
  }

  .page-info {
    font-size: 12px;
    color: #8c8c8c;
    font-weight: 500;
    background: #f5f5f5;
    padding: 4px 8px;
    border-radius: 4px;
  }
}

.result-content {
  font-size: 14px;
  line-height: 1.6;

  .original-content,
  .compare-content {
    margin-bottom: 8px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 3px solid #e8e8e8;

    strong {
      color: #262626;
      margin-right: 8px;
      font-weight: 600;
    }
  }
}

@keyframes pulse {
  0% {
    transform: scale(0.95);
    opacity: 0.7;
  }
  70% {
    transform: scale(1.1);
    opacity: 1;
  }
  100% {
    transform: scale(0.95);
    opacity: 0.7;
  }
}


</style>
