<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;
  border: 1px solid #dbe4ef;
  border-radius: 6px;
  background: #ffffff;
  overflow: hidden;
}

.sidebar-profile,
.sidebar-summary {
  padding: 22px 24px;
  background: #ffffff;
}

.sidebar-profile {
  border-bottom: 1px solid #edf1f5;
}

.sidebar-summary {
  margin-top: 0;
  background: #fbfcfe;
}

.sidebar-section__eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  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;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid #edcaca;
  border-radius: 6px;
  background: #fbefef;
  font-size: 12px;
  font-weight: 600;
  line-height: 24px;
  color: #ad2f2f;
}

.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;
}

.sidebar-tag-list ::v-deep(.el-tag) {
  height: 26px;
  padding: 0 9px;
  border: 1px solid #bfd0e2;
  border-radius: 6px;
  background: #ffffff;
  color: #245b8f;
  font-size: 12px;
  font-weight: 600;
  line-height: 24px;
}
</style>
