import { useUserProfileStore } from "../context/zustand-store/userStore";

type CheckAccessParams = {
  page: string;
  access: string;
};

export const checkAccess = ({ page, access }: CheckAccessParams): boolean => {
  const profile = useUserProfileStore.getState()?.profile;

  if (!access || !page) {
    return true;
  }

  const finded = profile?.permissions?.find(
    (item: any) => item.page_name === page
  );

  if (finded && finded.page_access.includes(access)) {
    return true;
  }

  return false;
};
