<?php

/**
 * SSO login page display helpers.
 * Determines whether to show the "Login with [PROVIDER]" button on the login page.
 */

require_once(dirname(__FILE__) . '/sso-storage.php');
require_once(dirname(__FILE__) . '/sso-tenant-manager.php');

if (!function_exists('should_show_msft_sso_login_button')) {
    function should_show_msft_sso_login_button()
    {
        if (!has_configured_sso_users()) {
            return false;
        }

        try {
            $tenants = get_tenants_credentials_helper();
        } catch (Exception $e) {
            return false;
        }

        if (empty($tenants) || !is_array($tenants)) {
            return false;
        }

        foreach ($tenants as $tenant) {
            if (isset($tenant['enabled']) && (int)$tenant['enabled'] === 1) {
                return true;
            }
        }

        return false;
    }
}
