import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  MyTableActions,
  renderTextHelper,
} from '@/common';
import { Selects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
import { CompanyEmployeesTypeEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Space } from 'antd';

export default function Index({ title = '员工轨迹' }) {
  const navigate = useNavigate();
  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="attendance_employees"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        // search={false}
        headerTitle="员工轨迹列表"
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              type: 'External',
              ...params,
            },
            sort,
            Apis.Company.CompanyEmployees.List,
          )
        }
        columns={[
          MyColumns.ID({ search: false }),
          Selects?.OrganizationSearch({
            title: '所属组织',
            key: 'organizations_id',
            colProps: { span: 24 },
            fieldProps: {
              showSearch: true,
            },
            search: {
              transform: (value) => {
                return {
                  organization_name:
                    value.length > 0 ? value[value.length - 1] : '',
                };
              },
            },
          }),
          {
            title: '所在组织',
            dataIndex: 'organization_path',
            // search: {
            //   transform: (value) => {
            //     return { organization_name: value };
            //   },
            // },
            search: false,
          },
          {
            title: '姓名',
            dataIndex: 'name',
          },
          {
            title: '手机号',
            dataIndex: 'phone',
          },
          {
            title: '角色',
            dataIndex: 'roles',
            renderText: renderTextHelper.TagList,
            hideInSearch: true,
          },
          {
            title: '岗位',
            dataIndex: ['position', 'name'],
            search: false,
          },
          MyColumns.EnumTag({
            title: '来源',
            dataIndex: 'type',
            valueEnum: CompanyEmployeesTypeEnum,
            search: false,
          }),
          MyColumns.UpdatedAt(),
          MyColumns.Option({
            render: (_, item: any, index) => (
              <Space key={index}>
                <MyTableActions
                  actions={{
                    view: (
                      <MyButtons.Default
                        title="查看轨迹"
                        type="primary"
                        onClick={() =>
                          navigate(`/attendance/employee_tracks/${item.id}`)
                        }
                      />
                    ),
                  }}
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
