<template>
  <el-dialog
    title="项目分析"
    :visible.sync="visibleProxy"
    width="1280px"
    append-to-body
    custom-class="project-analysis-dialog"
    @close="handleDialogClosed"
  >
    <div class="project-analysis-layout">
      <project-analysis-sidebar
        class="project-analysis-layout__sidebar"
        :sidebar-data="dialogData.sidebar"
      />
      <div class="project-analysis-layout__main">
        <div
          v-if='dialogData.sourceSummary.showCurrentModel && source === "riskModelPeople"'
          class="source-summary"
        >
          <span class="source-summary__label">当前命中模型</span>
          <span class="source-summary__value">{{ dialogData.sourceSummary.currentModelValue }}</span>
        </div>
        <el-tabs v-model="activeTab" stretch>
          <el-tab-pane label="异常明细" name="abnormalDetail">
            <project-analysis-abnormal-tab :detail-data="dialogData.abnormalDetail" />
          </el-tab-pane>
          <el-tab-pane label="资产分析" name="assetAnalysis">
            <project-analysis-placeholder-tab :tab-data="getTabData('assetAnalysis')" />
          </el-tab-pane>
          <el-tab-pane label="征信摘要" name="creditSummary">
            <project-analysis-placeholder-tab :tab-data="getTabData('creditSummary')" />
          </el-tab-pane>
          <el-tab-pane label="关系图谱" name="relationshipGraph">
            <project-analysis-placeholder-tab :tab-data="getTabData('relationshipGraph')" />
          </el-tab-pane>
          <el-tab-pane label="资金流向" name="fundFlow">
            <project-analysis-placeholder-tab :tab-data="getTabData('fundFlow')" />
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import ProjectAnalysisAbnormalTab from "./ProjectAnalysisAbnormalTab";
import ProjectAnalysisPlaceholderTab from "./ProjectAnalysisPlaceholderTab";
import ProjectAnalysisSidebar from "./ProjectAnalysisSidebar";
import { buildProjectAnalysisDialogData } from "./preliminaryCheck.mock";

export default {
  name: "ProjectAnalysisDialog",
  components: {
    ProjectAnalysisAbnormalTab,
    ProjectAnalysisPlaceholderTab,
    ProjectAnalysisSidebar,
  },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    person: {
      type: Object,
      default: () => null,
    },
    source: {
      type: String,
      default: "riskPeople",
    },
    projectName: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      activeTab: "abnormalDetail",
    };
  },
  computed: {
    dialogData() {
      return buildProjectAnalysisDialogData({
        person: this.person,
        source: this.source,
        projectName: this.projectName,
      });
    },
    visibleProxy: {
      get() {
        return this.visible;
      },
      set(value) {
        this.$emit("update:visible", value);
      },
    },
  },
  watch: {
    visible(value) {
      if (value) {
        this.resetDialogState();
      }
    },
  },
  methods: {
    resetDialogState() {
      this.activeTab = "abnormalDetail";
    },
    getTabData(tabKey) {
      return (
        this.dialogData.tabs.find((item) => item.key === tabKey) || {
          label: "",
          description: "",
        }
      );
    },
    handleDialogClosed() {
      this.resetDialogState();
      this.$emit("close");
    },
  },
};
</script>

<style lang="scss" scoped>
.project-analysis-layout {
  display: flex;
  gap: 20px;
  min-height: 640px;
}

.project-analysis-layout__sidebar {
  flex: 0 0 320px;
}

.project-analysis-layout__main {
  flex: 1;
  min-width: 0;
}

.source-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid #fde68a;
  background: #fffbeb;
}

.source-summary__label {
  font-size: 12px;
  color: #92400e;
}

.source-summary__value {
  font-size: 13px;
  font-weight: 600;
  color: #b45309;
}
</style>
