<?php

/*
 * SaasSwitcher global helpers. Loaded by SaasSwitcherServiceProvider::register()
 * (require_once), so these are available app-wide without any core-script edit.
 */

if (! function_exists('module_entitled')) {
    /**
     * Is the given module visible/reachable for the active business?
     *
     * Per-business, DATA-driven entitlement gate (not a permission check), so it
     * is immune to the Admin#<business> Gate::before bypass. Fail-open: modules
     * not in config('saasswitcher.gateable_modules') and unconfigured businesses
     * are always allowed. See Modules\SaasSwitcher\Support\ModuleEntitlementService.
     *
     * @param  string  $module  Module name, e.g. 'VetClinic', 'ClinicSite'
     * @return bool
     */
    function module_entitled($module)
    {
        return app(\Modules\SaasSwitcher\Support\ModuleEntitlementService::class)->isModuleEntitled($module);
    }
}
