<route lang="json5" type="page">
{
  style: {
    navigationStyle: 'custom',
  },
}
</route>

<template>
  <view :scroll-y="true" class="flex flex-col h-screen relative custom-bg">
    <Navbar
      safeAreaInsetTop
      :bordered="false"
      leftArrow
      @clickLeft="handleBack"
      bg-color="transparent"
    >
      <template #title>
        <text class="text-[#1F2329] text-[36rpx] font-medium text-[#fff]">SDS抑郁测评报告</text>
      </template>
    </Navbar>

    <view class="flex-1 overflow-auto relative flex flex-col">
      <view class="flex flex-col flex-1 overflow-auto pb-[20rpx]">
        <!-- 顶部卡片 -->
        <view class="mt-[30rpx] mx-[24rpx]">
          <StatusCard
            :score="score"
            :rules="depressionRules"
            tip="结果只做参考，不能准确判断是否有抑郁症。"
            :level="level"
            :description="studyRecord.description"
            :tagName="studyRecord.tagName"
          />
        </view>
        <view class="mt-[30rpx] mx-[24rpx]">
          <SuggestionCard />
        </view>
      </view>

      <!-- 底部AI智能顾问 -->
      <AiFooter :pageId="pageId" :pageType="pageType" />
    </view>
  </view>
</template>
<script setup lang="ts">
import Navbar from '@/pages-evaluation-sub/components/navbar/Navbar.vue'
import StatusCard from '../components/StatusCard.vue'
import SuggestionCard from '../components/SuggestionCard.vue'
import { getCustomScaleExplains } from '@/service/index/api'
import AiFooter from '../components/AiFooter.vue'
import { handleBack } from '../hooks/useEvaluateBack'

const pageType = ref(0)
const pageId = ref(0)

// 示例规则2：抑郁评估
const depressionRules = [
  {
    label: '正常范围',
    range: '<52分',
    color: '#00B281',
  },
  {
    label: '轻度抑郁',
    range: '53-61分',
    color: '#F8B801',
  },
  {
    label: '中度抑郁',
    range: '62-71分',
    color: '#F79C33',
  },
  {
    label: '重度抑郁',
    range: '≥72分',
    color: '#F5663E',
  },
]

const studyRecord = ref({
  description: '',
  title: '',
  result: '',
  tagName: '',
  total: '',
})

const calcLevel = (val: string) => {
  let _s = +val
  if (_s >= 72) {
    return 3
  } else if (_s >= 62) {
    return 2
  } else if (_s >= 53) {
    return 1
  } else {
    return 0
  }
}

const score = ref(0)
const level = ref(0)

onLoad((options) => {
  pageType.value = +options.type
  pageId.value = options.id

  getCustomScaleExplains({ CustomScaleId: pageId.value }).then((resp) => {
    if (resp.code === 200) {
      studyRecord.value = resp.result as {
        description: string
        title: string
        result: string
        tagName: string
        total: string
      }
      level.value = calcLevel(studyRecord.value.total)
      score.value = JSON.parse(studyRecord.value.total)
    }
  })
})
</script>

<style scoped lang="scss">
.custom-bg {
  background: linear-gradient(184deg, #0d79fc 0%, #2186fc 100%);
}
:deep(.icon-class) {
  color: #fff !important;
}

.custom-border {
  width: 162rpx;
  height: 162rpx;
  border-radius: 50%;
  border: 6rpx dashed;
  border-color: #05d69c transparent transparent transparent;
}
</style>
