import { useLocation } from 'react-router-dom';
import { useMemo } from 'react';
export const useUdpFormParameters = () => {
    const { search } = useLocation();
    const rawParams = new URLSearchParams(typeof search === 'string' ? search : window.location.search);
    return useMemo(() => {
        const keys = {
            formId: 'udpf_formid',
            formVersion: 'udpf_formversion',
            submissionId: 'udpf_submissionid',
            tenantId: 'udpf_tenantid',
        };
        const extracted = {
            formId: null,
            formVersion: null,
            submissionId: null,
            tenantId: null,
            urlContext: {}
        };
        rawParams.forEach((value, key) => {
            const keyLower = key.toLowerCase();
            if (keyLower === keys.formId)
                extracted.formId = value;
            else if (keyLower === keys.formVersion)
                extracted.formVersion = value;
            else if (keyLower === keys.submissionId)
                extracted.submissionId = value;
            else if (keyLower === keys.tenantId)
                extracted.tenantId = value;
            // Automatically group anything else starting with udpf_ into the context (case-insensitive)
            if (keyLower.startsWith('udpf_') && !Object.values(keys).includes(keyLower)) {
                // strip first 5 chars ("udpf_") regardless of original casing
                const cleanKey = key.slice(5).toLowerCase();
                extracted.urlContext[cleanKey] = value;
            }
        });
        return extracted;
    }, [search]);
};
//# sourceMappingURL=Utils.js.map