import { useCallback } from 'react';
import { usePersSDK } from '../providers/PersSDKProvider';
/**
 * React hook for donation operations in the PERS SDK
 *
 * Provides methods for managing donations and donation types within the platform.
 * Supports retrieving available donation categories and types.
 *
 * @returns Donation hook with methods for donation management
 *
 * @example
 * ```typescript
 * function DonationsComponent() {
 *   const { getDonationTypes } = useDonations();
 *
 *   const loadDonationTypes = async () => {
 *     try {
 *       const types = await getDonationTypes();
 *       console.log('Available donation types:', types);
 *     } catch (error) {
 *       console.error('Failed to load donation types:', error);
 *     }
 *   };
 *
 *   return <button onClick={loadDonationTypes}>Load Donation Types</button>;
 * }
 * ```
 */
export const useDonations = () => {
    const { sdk, isInitialized } = usePersSDK();
    /**
     * Retrieves all available donation types in the system
     *
     * @returns Promise resolving to array of donation types
     * @throws Error if SDK is not initialized
     *
     * @example
     * ```typescript
     * const { getDonationTypes } = useDonations();
     * const types = await getDonationTypes();
     * console.log('Donation types:', types.map(t => t.name));
     * ```
     */
    const getDonationTypes = useCallback(async () => {
        if (!isInitialized || !sdk) {
            throw new Error('SDK not initialized. Call initialize() first.');
        }
        try {
            const result = await sdk.donations.getDonationTypes();
            return result;
        }
        catch (error) {
            console.error('Failed to fetch donation types:', error);
            throw error;
        }
    }, [sdk, isInitialized]);
    return {
        getDonationTypes,
        isAvailable: isInitialized && !!sdk?.donations,
    };
};
