<template>
  <aside class="project-analysis-sidebar">
    <section class="sidebar-profile">
      <div class="sidebar-section__title">人物档案</div>
      <div class="sidebar-profile__name-row">
        <div>
          <div class="sidebar-profile__name">{{ sidebarData.basicInfo.name || "-" }}</div>
          <div class="sidebar-profile__meta">
            <span>工号 {{ sidebarData.basicInfo.staffCode || "-" }}</span>
            <span>部门 {{ sidebarData.basicInfo.department || "-" }}</span>
          </div>
        </div>
        <span class="sidebar-risk-badge">{{ sidebarData.basicInfo.riskLevel || "-" }}</span>
      </div>
      <div class="sidebar-profile__grid">
        <div class="sidebar-profile__item">
          <span class="sidebar-profile__label">所属项目</span>
          <span class="sidebar-profile__value">{{ sidebarData.basicInfo.projectName || "-" }}</span>
        </div>
        <div class="sidebar-profile__item">
          <span class="sidebar-profile__label">风险等级</span>
          <span class="sidebar-profile__value">{{ sidebarData.basicInfo.riskLevel || "-" }}</span>
        </div>
      </div>
    </section>

    <section class="sidebar-summary">
      <div class="sidebar-section__title">模型摘要</div>
      <div class="sidebar-summary__metric">
        <span class="sidebar-summary__label">命中模型数</span>
        <strong class="sidebar-summary__value">{{ sidebarData.modelSummary.modelCount || "-" }}</strong>
      </div>
      <div class="sidebar-summary__block">
        <span class="sidebar-summary__label">核心异常标签</span>
        <div v-if="sidebarData.modelSummary.riskTags.length" class="tag-list">
          <el-tag
            v-for="(tag, index) in sidebarData.modelSummary.riskTags"
            :key="`${formatRiskTag(tag)}-${index}`"
            size="mini"
            effect="plain"
          >
            {{ formatRiskTag(tag) }}
          </el-tag>
        </div>
        <span v-else class="sidebar-summary__empty">暂无异常标签</span>
      </div>
    </section>

    <section class="sidebar-hint">
      <div class="sidebar-section__title">辅助提示</div>
      <p class="sidebar-hint__text">
        侧栏仅保留人物身份与模型摘要，详细异常请在主区页签中继续查看。
      </p>
    </section>
  </aside>
</template>

<script>
export default {
  name: "ProjectAnalysisSidebar",
  props: {
    sidebarData: {
      type: Object,
      default: () => ({
        basicInfo: {},
        modelSummary: {
          riskTags: [],
        },
      }),
    },
  },
  methods: {
    formatRiskTag(tag) {
      if (typeof tag === "string") {
        return tag;
      }
      if (tag && typeof tag === "object") {
        return tag.ruleName || tag.label || tag.name || "";
      }
      return "";
    },
  },
};
</script>

<style lang="scss" scoped>
.project-analysis-sidebar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-profile,
.sidebar-summary,
.sidebar-hint {
  padding: 20px;
  border-radius: 20px;
  background: #ffffff;
}

.sidebar-section__title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #92400e;
}

.sidebar-profile__name-row {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 12px;
  margin-top: 14px;
}

.sidebar-profile__name {
  font-size: 24px;
  font-weight: 600;
  color: #0f172a;
}

.sidebar-profile__meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: #64748b;
}

.sidebar-risk-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fee2e2;
  font-size: 12px;
  font-weight: 600;
  color: #b91c1c;
}

.sidebar-profile__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  margin-top: 18px;
}

.sidebar-profile__item,
.sidebar-summary__metric,
.sidebar-summary__block {
  padding: 14px 16px;
  border-radius: 16px;
  background: #f8fafc;
}

.sidebar-profile__label,
.sidebar-summary__label {
  display: block;
  font-size: 12px;
  color: #64748b;
}

.sidebar-profile__value,
.sidebar-summary__value,
.sidebar-summary__empty {
  display: block;
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.6;
  color: #0f172a;
  word-break: break-all;
}

.sidebar-summary {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-hint__text {
  margin: 14px 0 0;
  font-size: 13px;
  line-height: 1.7;
  color: #64748b;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 8px;
}
</style>
