/*
 * @Author: donghao donghao@supervision.ltd
 * @Date: 2024-04-22 15:23:36
 * @LastEditors: donghao donghao@supervision.ltd
 * @LastEditTime: 2024-05-10 17:07:15
 * @FilePath: \general-ai-platform-web\src\pages\Business\BusinessState\components\detailDeviceStateLog.tsx
 * @Description: 设备日志
 * @交互说明
 * 1、设备日志列表的分页展示
 */

import { getDeviceStateLogList } from '@/services/testApi/businessState';
import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProCard, ProTable } from '@ant-design/pro-components';
import { FormattedMessage } from '@umijs/max';
import { useRef, useState } from 'react';
import { proTablePaginationOptions } from '../../../../../config/defaultTable';

const DetailDeviceStateLog: React.FC = () => {
  const actionRef = useRef<ActionType>();
  //  动态设置每页数量
  const [currentPageSize, setCurrentPageSize] = useState<number>(10);
  // 业务模型列表信息
  const columns: ProColumns<Record<string, any>>[] = [
    {
      title: <FormattedMessage id="device_state.table.stateLog.list.ip" defaultMessage="名称" />,
      dataIndex: 'IP',
      hideInSearch: true,
      key: 'fixedName',
      fixed: 'left',
      width: '40%',
    },
    {
      title: (
        <FormattedMessage id="device_state.table.stateLog.list.runTime" defaultMessage="运行时长" />
      ),
      dataIndex: 'runTime',
      hideInSearch: true,
      width: '20%',
    },
    {
      title: (
        <FormattedMessage
          id="device_state.table.stateLog.list.updateTime"
          defaultMessage="更新时间"
        />
      ),
      dataIndex: 'updateTime',
      hideInSearch: true,
      valueType: 'dateTime',
    },
  ];
  return (
    <div className="detailDeviceStateLog_wrap">
      <ProCard className="gn_card_wrap" bodyStyle={{ padding: 0 }}>
        <ProTable
          className="gn_pro_table"
          cardProps={{
            bodyStyle: { padding: 0 },
          }}
          // 标题栏
          search={false}
          options={{ fullScreen: false, setting: false, density: false, reload: false }}
          actionRef={actionRef}
          rowKey="id"
          pagination={{
            ...proTablePaginationOptions,
            pageSize: currentPageSize,
            onChange: (page, pageSize) => setCurrentPageSize(pageSize),
          }}
          columnsState={{
            persistenceKey: 'bs_server_log_list',
            persistenceType: 'localStorage',
          }}
          request={async (params = {}) => {
            const { current, ...rest } = params;
            const reqParams = {
              page: current,
              ...rest,
            };
            let resp = await getDeviceStateLogList({ ...reqParams });
            console.log(resp, 'getDeviceStateLogList_resp');
            return {
              data: resp.data?.results,
              success: resp.success,
              total: resp.data.count,
              current: current,
              pageSize: currentPageSize,
            };
          }}
          columns={columns}
        />
      </ProCard>
    </div>
  );
};

export default DetailDeviceStateLog;
