import { MyButtons, MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import Create from '../modals/LevelCreate';
import Update from '../modals/LevelUpdate';

export default function Index({ title = '等级' }) {
  return (
    <ProTable
      {...MyProTableProps.props}
      request={async (params, sort) =>
        MyProTableProps.request(
          params,
          sort,
          Apis.Emergency.EmergencyEventLevels.List,
        )
      }
      headerTitle="突发事件等级"
      toolBarRender={(action) => [
        <Create key="Create" reload={action?.reload} title={title} />,
      ]}
      columns={[
        MyColumns.ID({
          search: false,
        }),
        {
          title: '名称',
          dataIndex: 'name',
        },
        MyColumns.Boolean({
          title: '是否启用',
          dataIndex: 'is_enabled',
          search: false,
        }),
        MyColumns.UpdatedAt(),
        MyColumns.CreatedAt(),
        MyColumns.Option({
          render: (_, item: any, index, action) => (
            <Space key={index}>
              <Update item={item} reload={action?.reload} title={title} />
              <MyButtons.Delete
                key="delete"
                onConfirm={() =>
                  Apis.Emergency.EmergencyEventLevels.Delete({
                    id: item.id,
                  }).then(() => action?.reload())
                }
              />
            </Space>
          ),
        }),
      ]}
    />
  );
}
