import React, { useState } from 'react';
import { Popconfirm, Button } from 'antd';
import { useModel } from 'umi';

function PremButton(props) {
  const { initialState, setInitialState } = useModel('@@initialState');
  let buttonPerm = initialState?.newMenu?.buttonPerm;
  const { children, btn, pop, access } = props;
  let res =
    buttonPerm && buttonPerm.length > 0
      ? buttonPerm?.filter((it) => it.typeName == access && it.show == 1)
      : [];
  let accesses = access ? res.map((it) => it.typeName).includes(access) : true;
  //配置按钮权限接口

  return pop ? (
    <Popconfirm {...pop} disabled={pop?.disabled || !accesses}>
      <Button {...btn} disabled={btn?.disabled || !accesses}>
        {children}
      </Button>
    </Popconfirm>
  ) : (
    <Button {...btn} disabled={btn?.disabled || !accesses}>
      {children}
    </Button>
  );
}

export default PremButton;
