import React from 'react';

let allBtns = [];
let current = [];

const AuthButton = ({ children, name, noRight = null }) => {
  const btn = allBtns.filter(x => x.code === name)[0]
  if (!btn || !name) {
    return children
  }

  const hasRight = current.filter(x => x.code === name)[0]  
  return hasRight ? <>{children}</> : <>{noRight}</>
}

const setAllBtnAuth = x => allBtns = x;
const setUserBtnAuth = x => current = x;

export default AuthButton;
export {
  setAllBtnAuth,
  setUserBtnAuth,
};
