import {
  MyBetaModalFormProps,
  MyButtons,
  MyColumns,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import PositionAdd from '../../positions/modals/PositionAdd';
import PositionCreate from '../../positions/modals/PositionCreate';
import PositionUpdate from '../../positions/modals/PositionUpdate';

export default function Organizations(props: MyBetaModalFormProps) {
  return (
    <>
      <ProTable
        {...MyProTableProps.props}
        search={false}
        request={async (params, sort) =>
          MyProTableProps.request(
            { ...params, companies_id: props?.item?.id },
            sort,
            Apis.Company.CompanyPositions.List,
          )
        }
        toolBarRender={(action) => [
          <PositionAdd
            key="Create"
            reload={action?.reload}
            item={props?.item}
            title="岗位111"
          />,
          <PositionCreate
            key="Create"
            reload={action?.reload}
            item={props?.item}
            title="组织"
          />,
        ]}
        // options={false}
        columns={[
          MyColumns.ID(),

          {
            title: '岗位名称',
            dataIndex: 'name',
            width: 200,
          },
          {
            title: '岗位编号',
            dataIndex: 'code',
            search: false,
            width: 200,
          },
          {
            title: '岗位说明',
            dataIndex: 'remark',
            search: false,
          },
          MyColumns.UpdatedAt(),
          // MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <PositionUpdate
                  item={item}
                  reload={action?.reload}
                  title="岗位"
                />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Company.CompanyPositions.Delete({ id: item.id }).then(
                      () => action?.reload(),
                    )
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
