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

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.Organizations.List,
          )
        }
        toolBarRender={(action) => [
          <OrganizationsCreate
            key="Create"
            reload={action?.reload}
            item={props?.item}
            title="组织"
          />,
        ]}
        options={false}
        columns={[
          MyColumns.EnumTag({
            title: '组织类型',
            dataIndex: 'type',
            valueEnum: OrganizationsTypeEnum,
            search: false,
          }),
          {
            title: '组织名称',
            dataIndex: 'name',
          },
          {
            title: '组织ID',
            dataIndex: 'id',
            search: false,
          },
          {
            title: '上级组织',
            dataIndex: ['organization_parent', 'name'],
            search: false,
          },
          {
            title: '上级组织ID',
            dataIndex: ['organization_parent', 'id'],
            search: false,
          },

          // {
          //   title: '负责人',
          //   dataIndex: ['manager', 'name'],
          // },
          // {
          //   title: '联系电话',
          //   dataIndex: 'manager_phone',
          // },

          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <OrganizationsUpdate
                  item={{ ...item, companies_id: props?.item?.id }}
                  reload={action?.reload}
                  title="组织"
                />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Company.Organizations.Delete({ id: item.id }).then(
                      () => action?.reload(),
                    )
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
