<template>
  <aside class="project-analysis-sidebar">
    <section class="sidebar-profile">
      <div class="sidebar-profile__name-row">
        <div>
          <div class="sidebar-section__eyebrow">人物档案</div>
          <div class="sidebar-profile__name">{{ sidebarData.basicInfo.name || "-" }}</div>
        </div>
        <div class="sidebar-risk-badge">{{ sidebarData.basicInfo.riskLevel || "-" }}</div>
      </div>

      <div class="sidebar-profile__meta">
        <div class="sidebar-profile__item">
          <span class="sidebar-profile__label">工号</span>
          <span class="sidebar-profile__value">{{ sidebarData.basicInfo.staffCode || "-" }}</span>
        </div>
        <div class="sidebar-profile__item">
          <span class="sidebar-profile__label">部门</span>
          <span class="sidebar-profile__value">{{ sidebarData.basicInfo.department || "-" }}</span>
        </div>
        <div class="sidebar-profile__item">
          <span class="sidebar-profile__label">所属项目</span>
          <span class="sidebar-profile__value">{{ sidebarData.basicInfo.projectName || "-" }}</span>
        </div>
      </div>
    </section>

    <section class="sidebar-summary">
      <div class="sidebar-section__eyebrow">命中模型摘要</div>
      <div class="sidebar-summary__count">
        <span class="sidebar-summary__count-label">命中模型数</span>
        <span class="sidebar-summary__count-value">{{ sidebarData.modelSummary.modelCount || "-" }}</span>
      </div>
      <div class="sidebar-summary__tags">
        <span class="sidebar-profile__label">核心异常标签</span>
        <div v-if="sidebarData.modelSummary.riskTags.length" class="sidebar-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-profile__value">暂无异常标签</span>
      </div>
    </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%;
  align-self: flex-start;
}

.sidebar-profile,
.sidebar-summary {
  padding: 20px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.18);
}

.sidebar-summary {
  margin-top: 16px;
}

.sidebar-section__eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: #64748b;
}

.sidebar-profile__name-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.sidebar-profile__name {
  margin-top: 8px;
  font-size: 24px;
  font-weight: 600;
  line-height: 1.2;
  color: #0f172a;
}

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

.sidebar-profile__meta {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.sidebar-profile__item {
  display: grid;
  gap: 6px;
}

.sidebar-profile__label,
.sidebar-summary__count-label {
  font-size: 12px;
  color: #64748b;
}

.sidebar-profile__value,
.sidebar-summary__count-value {
  font-size: 13px;
  line-height: 1.6;
  color: #0f172a;
  word-break: break-all;
}

.sidebar-summary__count {
  display: grid;
  gap: 6px;
  margin-top: 16px;
}

.sidebar-summary__tags {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.sidebar-tag-list {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  gap: 8px;
}
</style>
