import {
  MyBetaModalFormProps,
  MyButtons,
  MyColumns,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import EmployeeCreate from '../../employees/modals/EmployeeCreate';
import EmployeeUpdate from '../../employees/modals/EmployeeUpdate';

export default function Index(props: MyBetaModalFormProps) {
  return (
    <ProTable
      {...MyProTableProps.props}
      // search={false}
      request={async (params, sort) =>
        MyProTableProps.request(
          { ...params, companies_id: props?.item?.id },
          sort,
          Apis.Company.CompanyEmployees.List,
        )
      }
      toolBarRender={(action) => [
        <EmployeeCreate
          key="Create"
          item={props?.item}
          reload={action?.reload}
          title="员工"
        />,
      ]}
      // options={false}
      columns={[
        MyColumns.ID(),
        //to-do 按层级选择
        {
          title: '所在组织',
          dataIndex: 'organization_path',
          search: {
            transform: (value) => {
              return { organization_name: value };
            },
          },
        },
        {
          title: '姓名',
          dataIndex: 'name',
        },
        {
          title: '手机号',
          dataIndex: 'phone',
        },
        {
          title: '岗位',
          dataIndex: ['position', 'name'],
          search: false,
        },
        MyColumns.UpdatedAt(),
        // MyColumns.CreatedAt(),
        MyColumns.Option({
          render: (_, item: any, index, action) => (
            <Space key={index}>
              <EmployeeUpdate
                item={item}
                reload={action?.reload}
                title="员工"
              />
              <MyButtons.Delete
                onConfirm={() =>
                  Apis.Common.Admins.Delete({ id: item.id }).then(() =>
                    action?.reload(),
                  )
                }
              />
            </Space>
          ),
        }),
      ]}
    />
  );
}
