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

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) => [
          <PositionsCreate
            key="Create"
            reload={action?.reload}
            item={props?.item}
            title="组织"
          />,
        ]}
        // options={false}
        columns={[
          MyColumns.ID(),

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