
import { createFromIconfontCN } from "@ant-design/icons";
import { ProColumns } from "@ant-design/pro-components";

/*
 * @Author: code4eat awesomedema@gmail.com
 * @Date: 2025-02-14 17:50:16
 * @LastEditors: code4eat awesomedema@gmail.com
 * @LastEditTime: 2025-02-17 17:59:04
 * @FilePath: /MediResourceManaSys/src/pages/dataFilling/fillingMana/generateTableData.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import { Drawer, Input, message, Popconfirm, Popover, Switch, Tooltip } from 'antd';
import AuthHisContent from "./authHisttory";


type HistoryItem = {
  value: number;
  createTime: string;
};

type ItemDic = {
  code: string;
  name: string;
  type: number;
  unit: string;
  status: number;
  periodType: number;
  description: string;
  dimensionType: number;
};

type ItemData = {
  code: string;
  value: any;
  history?: HistoryItem[];
  itemDic?: ItemDic;
};

type ItemTitle = {
  code: string;
  name: string;
};

const IconFont = createFromIconfontCN({
  scriptUrl: '',
});

export default function generateTableData(itemTitles: ItemTitle[], itemDatas: ItemData[]) {
  const columns: ProColumns[] = itemTitles.map((title, index) => ({
    title: title.name,
    dataIndex: title.code,
    key: title.code,
    width: 120,
    render: (text: any, record: any) => {
      const { history=[] } = record;
      const content = <AuthHisContent hisList={[...history]} />
      return <>{text}{true && (
        <Popover className='qualificationAuth-popover' overlayInnerStyle={{ borderRadius: 4 }} content={content} title={false} >
          <IconFont type={'icon-qingliangtishi'} style={{ marginLeft: 10 }} />
        </Popover>
      )}</>; // 返回 text 对应的数据
    },
  }));
  
  const dataSource = itemDatas.map((data, index) => {
    const rowData: any = {
      id: `${data.code}_mockid`,
      [data.code]: data.value,
    };

    // 如果存在 itemDic，添加到行数据中
    if (data.itemDic) {
      rowData[data.code + '_itemDic'] = data.itemDic;
    }

    return rowData;
  });

  return { columns, dataSource };
}
