import React from 'react'
import { useNavigate } from "react-router-dom";
import List from "@/components/Page/List";
import { Button, message, Popconfirm } from "antd";
import { getTaIncompatible, deleteTaIncompatible } from "@/service/taIncompatible";
import { queryDict } from "@/utils/request";
import { getSysPosition } from "@/service/sysposition";

const queryPosition = queryDict(getSysPosition, { labelKey: "name", valueKey: "positionId" });

export default (props) => {
  const actionRef = React.useRef();
  const navigate = useNavigate();

  const columns = [
    {
      title: "原岗位",
      dataIndex: "primaryPost",
      valueType: "select",
      request: queryPosition,
      key: "primaryPost",
    },
    {
      title: "目标岗位",
      dataIndex: "targetPost",
      valueType: "select",
      request: queryPosition,
      key: "targetPost",
    },
    {
      title: "规则",
      dataIndex: "rule",
      key: "rule",
      valueEnum: {
        "regularRules": "普通规则",
        "monthRules": "三个月规则",
      },
    },
    {
      title: "状态",
      dataIndex: "status",
      key: "status",
      search: false,
      valueEnum: {
        1: {
          text: "正常",
          status: "Processing",
        },
        0: {
          text: "禁用",
          status: "Error",
        },
      },
    }
  ]

  const onEdit = (it) => {
    navigate(`/system/incompatible/edit?id=${it.incompatibleId}`);
  };
  const onAdd = () => {
    navigate("/system/incompatible/edit");
  };
  const onDelete = (it) => {
    deleteTaIncompatible(it.incompatibleId).then((res) => {
      actionRef.current?.reload()
    })
  };

  return (
    <List
      actionRef={actionRef}
      rowKey="incompatibleId"
      columns={columns}
      onEdit={onEdit}
      onAdd={onAdd}
      onDelete={onDelete}
      request={getTaIncompatible}
    />
  )
}