import { useCallback } from 'react';
import { usePersSDK } from '../providers/PersSDKProvider';
export const useTenants = () => {
    const { sdk, isInitialized } = usePersSDK();
    const getTenantInfo = useCallback(async () => {
        if (!isInitialized || !sdk) {
            throw new Error('SDK not initialized. Call initialize() first.');
        }
        try {
            const result = await sdk.tenants.getTenantInfo();
            return result;
        }
        catch (error) {
            console.error('Failed to fetch tenant info:', error);
            throw error;
        }
    }, [sdk, isInitialized]);
    const getClientConfig = useCallback(async () => {
        if (!isInitialized || !sdk) {
            throw new Error('SDK not initialized. Call initialize() first.');
        }
        try {
            const result = await sdk.tenants.getClientConfig();
            return result;
        }
        catch (error) {
            console.error('Failed to fetch client config:', error);
            throw error;
        }
    }, [sdk, isInitialized]);
    const getLoginToken = useCallback(async () => {
        if (!isInitialized || !sdk) {
            throw new Error('SDK not initialized. Call initialize() first.');
        }
        try {
            const result = await sdk.tenants.getLoginToken();
            return result;
        }
        catch (error) {
            console.error('Failed to fetch login token:', error);
            throw error;
        }
    }, [sdk, isInitialized]);
    const getAdmins = useCallback(async () => {
        if (!isInitialized || !sdk) {
            throw new Error('SDK not initialized. Call initialize() first.');
        }
        try {
            const result = await sdk.tenants.getAdmins();
            return result;
        }
        catch (error) {
            console.error('Failed to fetch admins:', error);
            throw error;
        }
    }, [sdk, isInitialized]);
    return {
        getTenantInfo,
        getClientConfig,
        getLoginToken,
        getAdmins,
        isAvailable: isInitialized && !!sdk?.tenants,
    };
};
