import { usePage } from "@inertiajs/react";

interface TenantAccess {
    apps: string[];
    modules: string[];
    features: string[];
}

interface PageProps {
    tenant_access?: TenantAccess;
}

export default function useTenantAccess() {
    const { tenant_access } = usePage<PageProps>().props;

    const tenantAccess = (searchFrom: 'apps' | 'modules' | 'features', slug: string) => {
        // Safe access with optional chaining and nullish coalescing
        return tenant_access?.[searchFrom]?.includes(slug) ?? false;
    };

    return { tenantAccess };
}
