"use client"
import { useAuth } from "@/lib/provider/auth.provider";
import { FC, PropsWithChildren } from "react";
import { i18n } from "@/i18n/i18n";
import AccessDenied from "@/components/common/access-denied.component";

interface AuthAccessProps {
    isAuth: boolean;
    defaultMessage?: boolean;
}

export const AuthAccess: FC<PropsWithChildren & AuthAccessProps> = ({ isAuth = true, defaultMessage = false, children }) => {
    const { state } = useAuth();
    return (
        state == isAuth ? children : (defaultMessage ? <AccessDenied message={i18n('errors:auth-access-error')} /> : null)
    );
}

export default AuthAccess