import { MyButtons, MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
// import { AssetItemMaintenanceRuleStatusEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import RulesCreate from './modals/RulesCreate';
import RulesUpdate from './modals/RulesUpdate';

export default function Index({ title = '维保规则' }) {
  return (
    <ProTable
      {...MyProTableProps.props}
      request={async (params, sort) =>
        MyProTableProps.request(
          params,
          sort,
          Apis.Asset.AssetItemMaintenanceRules.List,
        )
      }
      headerTitle={title}
      toolBarRender={(action) => [
        <RulesCreate
          key="create"
          reload={action?.reload}
          title="添加维保规则"
        />,
      ]}
      columns={[
        MyColumns.ID({
          search: false,
        }),
        {
          title: '名称',
          dataIndex: 'name',
        },
        // MyColumns.EnumTag({
        //   title: '状态',
        //   dataIndex: 'status',
        //   valueEnum: AssetItemMaintenanceRuleStatusEnum,
        // }),
        {
          title: '维保项目',
          dataIndex: ['asset_project', 'name'],
          search: false,
        },
        {
          title: '维保资产数量',
          dataIndex: 'asset_item_maintenance_rule_items_count',
          search: false,
        },
        {
          title: '维保时间间隔（天）',
          dataIndex: 'cycle_days',
          search: false,
        },
        {
          title: '提前生成天数',
          dataIndex: 'advance_days',
          search: false,
        },
        {
          title: '完成期限天数',
          dataIndex: 'deadline_days',
          search: false,
        },
        // MyColumns.ToggleEnabled({
        //   onToggleEnabled: Apis.Asset.AssetItemMaintenanceRules.Toggle,
        //   search: false,
        // }),
        MyColumns.CreatedAt(),
        MyColumns.Option({
          render: (_, item: any, index, action) => (
            <Space key={`item_${index}`}>
              <RulesUpdate item={item} reload={action?.reload} title="编辑" />
              <MyButtons.Delete
                onConfirm={() =>
                  Apis.Asset.AssetItemMaintenanceRules.SoftDelete({
                    id: item.id,
                  }).then(() => action?.reload())
                }
              />
            </Space>
          ),
        }),
      ]}
    />
  );
}
