<script setup lang="ts">
import type { ReportModel }                        from '@/model';
import { indicatorByReportIdMethod, reportMethod } from '@/request/api/report.api';
import { ArrowDownOutlined, ArrowUpOutlined }      from '@ant-design/icons-vue';
import { useWatcher }                              from 'alova/client';


const props = defineProps<{ report?: ReportModel }>();
const emits = defineEmits<{ loaded: [] }>();
const reportId = inject('report-id', toRef(() => props.report?.id));

const { data: report, loading: reportLoading } = useWatcher(
  () => reportMethod(reportId.value!),
  [ reportId ],
  { initialData: props.report, immediate: true },
).onComplete(() => { emits('loaded'); });
const { data: indicator, loading: indicatorLoading } = useWatcher(
  () => indicatorByReportIdMethod(reportId.value!),
  [ reportId ],
  { initialData: [], immediate: true },
);
</script>
<template>
  <div class="widget-wrapper">
    <a-card class="card no-bordered" size="small">
      <a-descriptions :column="3">
        <a-descriptions-item v-if="report.willillStateName" label="健康状态">
          {{ report.willillStateName }}
        </a-descriptions-item>
        <a-descriptions-item v-if="report.willillDegreeName" label="程度" :span="2">
          {{ report.willillDegreeName }}
        </a-descriptions-item>
        <a-descriptions-item v-if="report.willillFunctionName" label="表现">
          {{ report.willillFunctionName }}
        </a-descriptions-item>
        <a-descriptions-item v-if="report.constitutionGroupName" label="体质" :span="2">
          {{ report.constitutionGroupName }}
        </a-descriptions-item>
      </a-descriptions>
    </a-card>
    <a-card class="card" size="small">
      <p v-if="report.constitutionGroupDefinition">体质： {{ report.constitutionGroupDefinition }}</p>
      <a-descriptions :column="1" bordered>
        <a-descriptions-item v-if="report.constitutionGroupGeneralCharacteristics" label="总体特征">
          {{ report.constitutionGroupGeneralCharacteristics }}
        </a-descriptions-item>
        <a-descriptions-item v-if="report.constitutionGroupPhysicalCharacteristics" label="形体特征">
          {{ report.constitutionGroupPhysicalCharacteristics }}
        </a-descriptions-item>
        <a-descriptions-item v-if="report.constitutionGroupPsychicCharacteristics" label="精神特征">
          {{ report.constitutionGroupPsychicCharacteristics }}
        </a-descriptions-item>
        <a-descriptions-item v-if="report.constitutionGroupCommonManifestations" label="常见表现">
          {{ report.constitutionGroupCommonManifestations }}
        </a-descriptions-item>
        <a-descriptions-item v-if="report.constitutionGroupDiseaseTendency" label="发病倾向">
          {{ report.constitutionGroupDiseaseTendency }}
        </a-descriptions-item>
        <a-descriptions-item v-if="report.constitutionGroupAdaptability" label="环境适应能力">
          {{ report.constitutionGroupAdaptability }}
        </a-descriptions-item>
      </a-descriptions>
    </a-card>
    <a-card class="card" size="small" title="舌象分析">
      <a-descriptions :column="3">
        <a-descriptions-item>
          <a-image :width="200" :src="report.upImg" :preview="true" v-if="report.upImg" />
        </a-descriptions-item>
        <a-descriptions-item>
          <a-image :width="200" :src="report.downImg" :preview="true" v-if="report.downImg" />
        </a-descriptions-item>
        <a-descriptions-item></a-descriptions-item>
      </a-descriptions>
      <a-descriptions :column="3" bordered>
        <a-descriptions-item style="font-size: 16px;font-weight: 600;">舌象维度</a-descriptions-item>
        <a-descriptions-item style="font-size: 16px;font-weight: 600;">检测结果</a-descriptions-item>
        <a-descriptions-item style="font-size: 16px;font-weight: 600;">标准值</a-descriptions-item>
        <template v-if="report.tongueColor?.actualList">
          <a-descriptions-item>舌色</a-descriptions-item>
          <a-descriptions-item>
            <span class="tongue-value" v-for="item in report.tongueColor.actualList" :key="item?.actualValue">
              <span>{{ item.actualValue }}</span>
              <span v-if="item.contrast !== 's'">({{ item.contrast }})</span>
            </span>
          </a-descriptions-item>
          <a-descriptions-item>{{ report.tongueColor.standardValue }}</a-descriptions-item>
        </template>
        <template v-if="report.tongueCoatingColor?.actualList">
          <a-descriptions-item>苔色</a-descriptions-item>
          <a-descriptions-item>
            <span class="tongue-value" v-for="item in report.tongueCoatingColor.actualList" :key="item?.actualValue">
              <span>{{ item.actualValue }}</span>
              <span v-if="item.contrast !== 's'">({{ item.contrast }})</span>
            </span>
          </a-descriptions-item>
          <a-descriptions-item>{{ report.tongueCoatingColor.standardValue }}</a-descriptions-item>
        </template>
        <template v-if="report.tongueShape?.actualList">
          <a-descriptions-item>舌形</a-descriptions-item>
          <a-descriptions-item>
            <span class="tongue-value" v-for="item in report.tongueShape.actualList" :key="item?.actualValue">
              <span>{{ item.actualValue }}</span>
              <span v-if="item.contrast !== 's'">({{ item.contrast }})</span>
            </span>
          </a-descriptions-item>
          <a-descriptions-item>{{ report.tongueShape.standardValue }}</a-descriptions-item>
        </template>
        <template v-if="report.tongueCoating?.actualList">
          <a-descriptions-item>苔质</a-descriptions-item>
          <a-descriptions-item>
            <span class="tongue-value" v-for="item in report.tongueCoating.actualList" :key="item?.actualValue">
              <span>{{ item.actualValue }}</span>
              <span v-if="item.contrast !== 's'">({{ item.contrast }})</span>
            </span>
          </a-descriptions-item>
          <a-descriptions-item>{{ report.tongueCoating.standardValue }}</a-descriptions-item>
        </template>
        <template v-if="report.bodyFluid?.actualList">
          <a-descriptions-item>津液</a-descriptions-item>
          <a-descriptions-item>
            <span class="tongue-value" v-for="item in report.bodyFluid.actualList" :key="item?.actualValue">
              <span>{{ item.actualValue }}</span>
              <span v-if="item.contrast !== 's'">({{ item.contrast }})</span>
            </span>
          </a-descriptions-item>
          <a-descriptions-item>{{ report.bodyFluid.standardValue }}</a-descriptions-item>
        </template>
        <template v-if="report.sublingualVein?.actualList">
          <a-descriptions-item>舌下</a-descriptions-item>
          <a-descriptions-item>
            <span class="" v-for="item in report.sublingualVein.actualList" :key="item?.actualValue">
              <span>{{ item.actualValue }}</span>
              <span v-if="item.contrast !== 's'">({{ item.contrast }})</span>
            </span>
          </a-descriptions-item>
          <a-descriptions-item>{{ report.sublingualVein.standardValue }}</a-descriptions-item>
        </template>
      </a-descriptions>
    </a-card>
    <a-card class="card no-bordered" size="small" title="面象分析" v-if="report.faceAnalysisResult">
      <a-descriptions :column="3">
        <a-descriptions-item>
          <a-image :width="200" :src="report.faceImg" :preview="true" v-if="report.faceImg" />
        </a-descriptions-item>
        <a-descriptions-item :span="2">{{ report.faceAnalysisResult }}</a-descriptions-item>
      </a-descriptions>
    </a-card>
    <a-card class="card symptom-card" size="small" title="中医证素" v-if="report.factorItems?.length">
      <a-descriptions :column="1" bordered>
        <a-descriptions-item v-for="item in report.factorItems" :key="item.factorItemName"
                             :label="item.factorItemName"
        >
          {{ item.factorItemDescription }}
        </a-descriptions-item>
      </a-descriptions>
    </a-card>
    <a-card class="card symptom-card" size="small" title="中医证型" v-if="report.diagnoseSyndromes?.length">
      <a-descriptions :column="1" bordered>
        <a-descriptions-item v-for="item in report.diagnoseSyndromes" :key="item.diagnoseSyndromeName"
                             :label="item.diagnoseSyndromeName"
        >
          {{ item.diagnoseSyndromeAnalysis }}
        </a-descriptions-item>
      </a-descriptions>
    </a-card>
    <a-card class="card no-bordered" size="small" :loading="indicatorLoading" title="指标信息" v-if="indicator?.length">
      <a-descriptions :column="3">
        <a-descriptions-item v-for="item in indicator" :label="item?.name" :key="item?.quotaId">
          {{ item?.quotaVal }}
          {{ item.unit }}
          <ArrowUpOutlined class="icon" v-if="item?.abnormal === 1" />
          <ArrowDownOutlined class="icon" v-else-if="item?.abnormal === -1" />
        </a-descriptions-item>
      </a-descriptions>
    </a-card>
  </div>
</template>
<style scoped lang="scss">
.card {
  margin-bottom: 12px;

  &.no-bordered {
    :deep(.ant-card-body) {
      padding-top: 16px;
      padding-bottom: 0;
    }
  }

  .tongue-value {
    margin: 0 4px;

    &:first-of-type {
      margin-left: 0;
    }

    &:last-of-type {
      margin-right: 0;
    }
  }
}

.symptom-card {
  :deep(.ant-descriptions-item-label) {
    padding: 8px 12px;
    width: 120px;
    text-align: center;
  }
}

.icon {
  margin-left: 4px;
  font-size: 18px;
  color: #b22222ff;
  transform: translateY(2px);
}
</style>
