<template>
  <aside class="project-analysis-sidebar">
    <div class="sidebar-profile-card">
      <section class="sidebar-profile">
        <div class="sidebar-profile__identity">
          <div class="sidebar-profile__identity-label">人物档案</div>
          <div class="sidebar-profile__name-row">
            <div class="sidebar-profile__name">{{ sidebarData.basicInfo.name || "-" }}</div>
            <div class="sidebar-risk-badge">{{ sidebarData.basicInfo.riskLevel || "-" }}</div>
          </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-summary__title">命中模型摘要</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>
    </div>
  </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-card {
  border: 1px solid #dde3ec;
  border-radius: 3px;
  background: #ffffff;
}

.sidebar-profile {
  padding: 34px 42px 28px;
  border-bottom: 1px solid #edf1f5;
}

.sidebar-summary {
  padding: 30px 42px 34px;
  border-top: 1px solid #dde3ec;
  background: #fcfdfe;
}

.sidebar-profile__identity-label {
  color: #637187;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 28px;
}

.sidebar-profile__name-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.sidebar-profile__name {
  color: #111827;
  font-size: 34px;
  font-weight: 700;
  line-height: 1.2;
}

.sidebar-risk-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 102px;
  height: 44px;
  padding: 0 16px;
  border: 1px solid #f0c6c1;
  border-radius: 2px;
  background: #fff3f2;
  color: #c43d33;
  font-size: 17px;
  font-weight: 600;
  line-height: 42px;
  text-align: center;
}

.sidebar-profile__meta {
  display: grid;
  gap: 0;
  margin-top: 30px;
}

.sidebar-profile__item {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 16px;
  padding: 18px 0;
  border-bottom: 1px solid #edf1f5;
}

.sidebar-profile__item:last-child {
  border-bottom: 0;
}

.sidebar-profile__label,
.sidebar-summary__count-label {
  color: #637187;
  font-size: 16px;
}

.sidebar-profile__value,
.sidebar-summary__count-value {
  color: #172033;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.4;
  word-break: break-all;
}

.sidebar-summary__title {
  margin: 0 0 24px;
  color: #223047;
  font-size: 18px;
  font-weight: 700;
}

.sidebar-summary__count {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-top: 0;
  margin-bottom: 28px;
}

.sidebar-summary__tags {
  display: grid;
  gap: 16px;
  margin-top: 0;
}

.sidebar-summary__count-label {
  font-size: 17px;
}

.sidebar-summary__count-value {
  color: #172033;
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
}

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

.sidebar-tag-list ::v-deep(.el-tag) {
  height: 38px;
  padding: 0 16px;
  border: 1px solid #cad8eb;
  border-radius: 2px;
  background: #ffffff;
  color: #245b8f;
  font-size: 15px;
  font-weight: 600;
  line-height: 36px;
}
</style>
