import React from 'react';
import { Table, Progress, Typography, Card, Tag } from 'antd';
import styles from './components.less';

const { Title, Text } = Typography;

interface GeneralEvaluationProps {
  supplierName?: string;
}

const GeneralEvaluation: React.FC<GeneralEvaluationProps> = ({ supplierName }) => {
  // 评价数据
  const evaluationData = [
    {
      key: '1',
      firstIndex: '基本情况(base case)',
      firstDescription: '企业基本资质与存续状态证明',
      firstScore: 4,
      secondIndex: '资质文件',
      secondScore: 1,
      averageScore: 3,
      rowSpan: 2,
    },
    {
      key: '2',
      firstIndex: '基本情况(base case)',
      firstDescription: '企业基本资质与存续状态证明',
      firstScore: 4,
      secondIndex: 'XXX',
      secondScore: 3,
      averageScore: 1,
      rowSpan: 0, // 设为0表示不显示
    },
    {
      key: '3',
      firstIndex: '成本(cost)',
      firstDescription: '商品与服务的总拥有成本',
      firstScore: 7,
      secondIndex: 'XXX',
      secondScore: 7,
      averageScore: 6.5,
      rowSpan: 1,
    },
    {
      key: '4',
      firstIndex: '创新(innovate)',
      firstDescription: '为公司提供竞争优势，提高商业价值而持续提供创新性建议及解决方案',
      firstScore: 20,
      secondIndex: 'XXX',
      secondScore: 20,
      averageScore: 18.5,
      rowSpan: 1,
    },
    {
      key: '5',
      firstIndex: '服务 (service)',
      firstDescription: '为满足公司商业需求而提供的服务与支持',
      firstScore: 10,
      secondIndex: 'XXX',
      secondScore: 10,
      averageScore: 10,
      rowSpan: 1,
    },
    {
      key: '6',
      firstIndex: '质量(quality)',
      firstDescription: '提供满足需求（规格）的产品与服务',
      firstScore: 25,
      secondIndex: 'XXX',
      secondScore: 25,
      averageScore: 24,
      rowSpan: 1,
    },
    {
      key: '7',
      firstIndex: '绿色(environment protection)',
      firstDescription: '优秀的交付能力及与之相关的灵活性',
      firstScore: 25,
      secondIndex: 'XXX',
      secondScore: 25,
      averageScore: 24,
      rowSpan: 1,
    },
    {
      key: '8',
      firstIndex: '安全(safety)',
      firstDescription: '产品质量安全、环境保护、风险防控及商业道德约束',
      firstScore: 6,
      secondIndex: 'XXX',
      secondScore: 6,
      averageScore: 5,
      rowSpan: 1,
    },
    {
      key: '9',
      firstIndex: '廉洁(integrity)',
      firstDescription: '商业道德约束',
      firstScore: 3,
      secondIndex: '商业贿赂与道德风险',
      secondScore: 3,
      averageScore: 3,
      rowSpan: 1,
    },
    {
      key: '10',
      firstIndex: '合计',
      firstDescription: '',
      firstScore: 100,
      secondIndex: '',
      secondScore: 100,
      averageScore: 95,
      rowSpan: 1,
    },
  ];

  const columns = [
    {
      title: '',
      dataIndex: 'index',
      key: 'index',
      width: 50,
      render: (text: string, record: any, index: number) => index + 1,
    },
    {
      title: '一级指标',
      children: [
        {
          title: '*基本指标',
          dataIndex: 'firstIndex',
          key: 'firstIndex',
          width: 150,
          render: (text: string, record: any, index: number) => {
            return {
              children: text,
              props: {
                rowSpan: record.rowSpan,
              },
            };
          },
        },
        {
          title: '*指标说明',
          dataIndex: 'firstDescription',
          key: 'firstDescription',
          width: 220,
          render: (text: string, record: any) => {
            return {
              children: text,
              props: {
                rowSpan: record.rowSpan,
              },
            };
          },
        },
        {
          title: '分值',
          dataIndex: 'firstScore',
          key: 'firstScore',
          width: 80,
          render: (text: number, record: any) => {
            return {
              children: text,
              props: {
                rowSpan: record.rowSpan,
              },
            };
          },
        },
      ],
    },
    {
      title: '二级指标',
      children: [
        {
          title: '*细分指标',
          dataIndex: 'secondIndex',
          key: 'secondIndex',
          width: 180,
        },
        {
          title: '分值',
          dataIndex: 'secondScore',
          key: 'secondScore',
          width: 80,
        },
      ],
    },
    {
      title: '平均分',
      dataIndex: 'averageScore',
      key: 'averageScore',
      width: 80,
      render: (score: number) => (
        <span className={score < 60 ? styles.lowScore : ''}>
          {score}
        </span>
      ),
    },
  ];

  // 计算总分
  const totalScore = evaluationData[evaluationData.length - 1].averageScore;
  const totalPossibleScore = evaluationData[evaluationData.length - 1].firstScore;
  const scorePercentage = (totalScore / totalPossibleScore) * 100;

  return (
    <div className={styles.evaluationContainer}>

      <Table
        columns={columns}
        dataSource={evaluationData}
        pagination={false}
        className={styles.scoreTable}
        bordered
        size="middle"
      />
    </div>
  );
};

export default GeneralEvaluation;
