import { Button, Popconfirm } from "antd";

export default function getPrem(name, type, text, clickfn, pop) {
  let { buttonPerm } = { buttonPerm: [] }; //单独运行

  // let res = buttonPerm && buttonPerm.length > 0 ? buttonPerm.filter((it) => { return it.typeName == name }) : [];
  let res = [];
  if (res.length == 1) {
    res = res[0];
  } else {
    res = {};
  }

  let ifs = name === false ? false : true;

  if (type == "ifs") {
    return ifs;
  }

  if (pop) {
    return (
      <Popconfirm
        disabled={!ifs}
        okText="确认"
        cancelText="取消"
        placement="bottomRight"
        title={pop.title}
        onConfirm={() => {
          if (!ifs) {
            return;
          }
          pop.onConfirm();
        }}
      >
        <Button
          size="small"
          type={type?.type || "default"}
          disabled={!ifs}
          danger
          style={{ userSelect: "none" }}
          onClick={() => {
            clickfn ? clickfn() : null;
          }}
        >
          {text}
        </Button>
      </Popconfirm>
    );
  } else {
    return (
      <Button
        size="small"
        type={type?.type || "primary"}
        disabled={!ifs}
        style={{ userSelect: "none" }}
        onClick={() => {
          clickfn ? clickfn() : null;
        }}
      >
        {text}
      </Button>
    );
  }
}
