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

const { Title, Text } = Typography;

interface TechnicalEvaluationProps {
  supplierName?: string;
}

const TechnicalEvaluation: React.FC<TechnicalEvaluationProps> = ({ supplierName }) => {
  // 评价数据
  const evaluationData = [
    {
      key: '1',
      firstIndex: '技术实力',
      firstDescription: '技术团队规模与研发能力',
      firstScore: 20,
      secondIndex: '研发团队规模',
      secondScore: 10,
      averageScore: 9,
      rowSpan: 2,
    },
    {
      key: '2',
      firstIndex: '技术实力',
      firstDescription: '技术团队规模与研发能力',
      firstScore: 20,
      secondIndex: '技术创新能力',
      secondScore: 10,
      averageScore: 8,
      rowSpan: 0, // 设为0表示不显示
    },
    {
      key: '3',
      firstIndex: '产品性能',
      firstDescription: '产品的技术指标与性能表现',
      firstScore: 25,
      secondIndex: '核心性能指标',
      secondScore: 15,
      averageScore: 14,
      rowSpan: 2,
    },
    {
      key: '4',
      firstIndex: '产品性能',
      firstDescription: '产品的技术指标与性能表现',
      firstScore: 25,
      secondIndex: '稳定性与可靠性',
      secondScore: 10,
      averageScore: 9.5,
      rowSpan: 0,
    },
    {
      key: '5',
      firstIndex: '技术支持',
      firstDescription: '提供的技术服务与支持能力',
      firstScore: 15,
      secondIndex: '响应速度',
      secondScore: 8,
      averageScore: 7.5,
      rowSpan: 2,
    },
    {
      key: '6',
      firstIndex: '技术支持',
      firstDescription: '提供的技术服务与支持能力',
      firstScore: 15,
      secondIndex: '问题解决能力',
      secondScore: 7,
      averageScore: 6.5,
      rowSpan: 0,
    },
    {
      key: '7',
      firstIndex: '技术文档',
      firstDescription: '技术文档的完整性与准确性',
      firstScore: 10,
      secondIndex: '文档完整性',
      secondScore: 5,
      averageScore: 4.5,
      rowSpan: 2,
    },
    {
      key: '8',
      firstIndex: '技术文档',
      firstDescription: '技术文档的完整性与准确性',
      firstScore: 10,
      secondIndex: '文档准确性',
      secondScore: 5,
      averageScore: 4,
      rowSpan: 0,
    },
    {
      key: '9',
      firstIndex: '技术培训',
      firstDescription: '提供的技术培训与知识转移',
      firstScore: 15,
      secondIndex: '培训质量',
      secondScore: 8,
      averageScore: 7,
      rowSpan: 2,
    },
    {
      key: '10',
      firstIndex: '技术培训',
      firstDescription: '提供的技术培训与知识转移',
      firstScore: 15,
      secondIndex: '培训频率',
      secondScore: 7,
      averageScore: 6,
      rowSpan: 0,
    },
    {
      key: '11',
      firstIndex: '兼容性',
      firstDescription: '与现有系统的兼容性',
      firstScore: 15,
      secondIndex: '系统兼容性评估',
      secondScore: 15,
      averageScore: 13.5,
      rowSpan: 1,
    },
    {
      key: '12',
      firstIndex: '合计',
      firstDescription: '',
      firstScore: 100,
      secondIndex: '',
      secondScore: 100,
      averageScore: 89.5,
      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,
          className: styles.requiredColumn,
          render: (text: string, record: any, index: number) => {
            return {
              children: text,
              props: {
                rowSpan: record.rowSpan,
              },
            };
          },
        },
        {
          title: '*指标说明',
          dataIndex: 'firstDescription',
          key: 'firstDescription',
          width: 220,
          className: styles.requiredColumn,
          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,
          className: styles.requiredColumn,
        },
        {
          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}>
      <Card className={styles.summaryCard}>
        <div className={styles.scoreSummary}>
          <div className={styles.scoreCircle}>
            <Progress
              type="circle"
              percent={scorePercentage}
              format={() => `${totalScore}`}
              width={80}
              strokeColor={{
                '0%': '#108ee9',
                '100%': '#87d068',
              }}
            />
          </div>
          <div className={styles.scoreInfo}>
            <Title level={4}>技术评价总分</Title>
            <Text type="secondary">满分: {totalPossibleScore}分</Text>
            {supplierName && <Text type="secondary">供应商: {supplierName}</Text>}
          </div>
        </div>
      </Card>

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

export default TechnicalEvaluation;
