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

export default function Index({ title = '审批模板' }) {
  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="contract_types"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Approval.ApprovalTemplates.List,
          )
        }
        headerTitle={title}
        toolBarRender={(action) => [
          <Create key="Create" reload={action?.reload} title={title} />,
        ]}
        columns={[
          MyColumns.ID({
            search: false,
          }),
          MyColumns.EnumTag({
            title: '业务类型',
            dataIndex: 'type',
            // valueEnum: ApprovalTemplatesTypeEnum,
          }),
          {
            title: '模版名称',
            dataIndex: 'name',
          },
          {
            title: '模版编码',
            dataIndex: 'code',
            search: false,
          },

          MyColumns.ToggleEnabled({
            onToggleEnabled: Apis.Approval.ApprovalTemplates.ToggleEnabled,
            search: false,
          }),
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <Update item={item} reload={action?.reload} title={title} />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Approval.ApprovalTemplates.SoftDelete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
