import { 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="attendance_configs"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        // search={false}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Attendance.AttendanceConfigs.List,
          )
        }
        headerTitle="打卡参数配置"
        toolBarRender={(action) => [
          <Create key="Create" reload={action?.reload} title={title} />,
        ]}
        search={false}
        columns={[
          MyColumns.ID({
            search: false,
          }),
          {
            title: '可打卡范围(米内)',
            dataIndex: 'check_in_range',
            search: false,
          },
          MyColumns.Boolean({
            dataIndex: 'require_photo',
            title: '是否要求拍照打卡',
            search: false,
          }),
          // MyColumns.Boolean({
          //   dataIndex: 'allow_out_range_checkin',
          //   title: '是否允许范围外打卡',
          //   search: false,
          // }),
          // MyColumns.IsEnabled({
          //   onRestore: Apis.Attendance.AttendanceConfigs.Enable,
          //   onSoftDelete: Apis.Attendance.AttendanceConfigs.Enable,
          //   search: false,
          // }),
          // MyColumns.CreatedAt(),
          MyColumns.UpdatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <Update item={item} reload={action?.reload} title={title} />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
