import { MyBetaModalFormProps, MyColumns, MyProTableProps } from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { Space, Tooltip } from 'antd';

import {
  HouseWorkOrdersAssignStatusEnum,
  HouseWorkOrdersStatusEnum,
  HouseWorkOrdersTypeEnum,
} from '@/gen/Enums';
import WorkOrderShow from '@/pages/work_order/list/modals/WorkOrderShow';

export default function Index(props: MyBetaModalFormProps) {
  // const navigate = useNavigate();
  const { item } = props;
  if (!item) {
    return null;
  }

  return (
    <ProTable
      {...MyProTableProps.props}
      headerTitle="工单记录"
      request={async (params, sort) =>
        MyProTableProps.request(
          {
            ...params,
            asset_houses_id: item.id,
            type: [HouseWorkOrdersTypeEnum.Repair.value],
          },
          sort,
          Apis.WorkOrder.HouseWorkOrders.List,
        )
      }
      // options={false}
      search={false}
      columns={[
        MyColumns.ID({ search: false }),
        MyColumns.EnumTag({
          title: '处理状态',
          dataIndex: 'status',
          valueEnum: HouseWorkOrdersStatusEnum,
        }),
        {
          title: '项目名称',
          dataIndex: 'project_name',
          hidden: true,
        },
        MyColumns.EnumTag({
          title: '分配状态',
          dataIndex: 'assign_status',
          valueEnum: HouseWorkOrdersAssignStatusEnum,
        }),
        // MyColumns.EnumTag({
        //   title: '工单类型',
        //   dataIndex: 'type',
        //   valueEnum: HouseWorkOrdersTypeEnum,
        //   search: false,
        // }),
        // MyColumns.EnumTag({
        //   title: '报修位置',
        //   dataIndex: 'location',
        //   valueEnum: HouseWorkOrdersLocationEnum,
        // }),
        {
          title: '位置信息',
          dataIndex: ['asset_house', 'full_name'],
          render: (_, record) => {
            return (
              <Space>
                {record?.asset_house?.full_name
                  ? record?.asset_house?.full_name
                  : record?.asset_project?.name}
              </Space>
            );
          },
          search: {
            transform: (value) => {
              return { house_name: value };
            },
          },
        },
        {
          title: '工单描述',
          dataIndex: 'content',
          search: false,
          width: 200, // 关键：固定列宽（若父容器过窄，可设 minWidth: 200 优先保证列宽）
          render: (text) => (
            <Tooltip title={text} placement="topLeft">
              <div
                style={{
                  width: '100%', // 继承列宽
                  overflow: 'hidden', // 超出隐藏
                  textOverflow: 'ellipsis', // 省略号
                  display: '-webkit-box',
                  WebkitBoxOrient: 'vertical',
                  WebkitLineClamp: 1, // 显示1行
                  cursor: 'help', // 鼠标指针变化提示可查看更多
                }}
              >
                {text}
              </div>
            </Tooltip>
          ),
        },

        // MyColumns.EnumTag({
        //   title: '优先级',
        //   dataIndex: 'level',
        //   valueEnum: HouseWorkOrdersLevelEnum,
        // }),
        // {
        //   title: '时间要求',
        //   dataIndex: 'predict_complete_at',
        //   render: (_, record) => {
        //     return record?.predict_complete_at?.substring(0, 10) || '-';
        //   },
        //   search: false,
        // },
        // MyColumns.Boolean({
        //   title: '是否回访',
        //   dataIndex: 'is_visited',
        // }),
        // MyColumns.Boolean({
        //   title: '是否评价',
        //   dataIndex: 'is_evaluated',
        // }),
        {
          title: '处理人',
          dataIndex: ['assign_employee', 'name'],
          search: false,
          render: (_, record) => {
            return `${record?.assign_employee?.name || ''}-${
              record?.assign_employee?.phone || ''
            }`;
          },
        },
        // MyColumns.UpdatedAt(),
        MyColumns.Option({
          render: (_, item: any, index, action) => (
            <Space key={index}>
              <WorkOrderShow item={item} title="查看" reload={action?.reload} />
            </Space>
          ),
        }),
      ]}
    />
  );
}
