<script setup lang="ts">
import { computed } from 'vue'

const props = defineProps<{
  id: string
  originalText: any
  revisionText: string
  basisText: string
  isHighRisk?: boolean
  revised: boolean
}>()

const emit = defineEmits<{
  (e: 'locate'): void
  (e: 'accept'): void
  (e: 'reject'): void
}>()

const showActionButton = computed<boolean>(() => {
  return (props.originalText || []).length !== 0
})
</script>

<template>
  <el-card class="audit-item">
    <div class="text-section original-text">
      <p class="title">合同原文</p>
      <p style="display: flex;gap: 6px; flex-wrap: wrap">
        <span v-for="item in props.originalText" :key="item.uuid"> {{ item.original_char }}</span>
      </p>
    </div>

    <div class="text-section revision">
      <p class="title">修订建议</p>
      <p>{{ props.revisionText }}</p>
    </div>

    <div class="text-section basis">
      <p class="title">审查依据</p>
      <p>{{ props.basisText }}</p>
    </div>

    <div class="action-area" v-if="showActionButton">
      <div style="display: flex">
        <el-tag
          v-if="props.isHighRisk"
          type="danger"
          size="small"
          class="pointer"
          style="font-size: 10px; height: 20px"
          >高风险
        </el-tag>
        <div class="action-btn locate-btn pointer" @click="emit('locate')">
          <img src="@/assets/webapp/15.svg" alt="" /> 定位到原文
        </div>
      </div>
      <template v-if="(props.originalText || []).length === 1">
        <div
          v-if="+props.revised === 1"
          class="action-btn reject-btn pointer"
          @click="emit('reject')"
        >
          <img src="@/assets/webapp/17.svg" alt="" /> 撤销修订
        </div>
        <div v-else class="action-btn accept-btn pointer" @click="emit('accept')">
          <img src="@/assets/webapp/16.svg" alt="" /> 接受修订
        </div>
      </template>
    </div>
  </el-card>
</template>

<style scoped lang="scss">
.audit-item {
  margin-bottom: 10px;
  border-radius: 8px;

  :deep(.el-card__body) {
    padding: 12px !important;
  }

  .text-section {
    margin-bottom: 10px;
    font-weight: 500;
    font-size: 12px;
    line-height: 22px;

    .title {
      font-weight: bold;
      color: #191919 !important;
    }

    &.original-text,
    &.basis {
      color: #797979;
    }

    &.revision p {
      color: #e24141;
    }
  }

  .action-area {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .action-btn {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 0 4px;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;

      img {
        margin-right: 2px;
      }
    }

    .locate-btn {
      color: #666666;
    }

    .accept-btn {
      color: #3067ef;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid rgba(48, 103, 239, 0.5);
    }

    .reject-btn {
      color: #999999;
      border-radius: 4px 4px 4px 4px;
      border: 1px solid #d9d9d9;
    }
  }
}
</style>
