import { useEditContext } from "../client/editContext";
/**
 * Hook to access general Parhelia settings like Sitecore name validation
 * @returns ParheliaSettings containing validation patterns and character restrictions
 */
export function useParheliaSettings() {
    const editContext = useEditContext();
    return editContext?.parheliaSettings;
}
/**
 * Hook to validate item names against Sitecore settings
 * @returns Validation functions for item names
 */
export function useItemNameValidation() {
    const parheliaSettings = useParheliaSettings();
    const validateItemName = (name) => {
        if (!parheliaSettings) {
            return { isValid: true }; // No settings loaded, assume valid
        }
        // Check invalid characters
        if (parheliaSettings.invalidItemNameChars) {
            const invalidChars = parheliaSettings.invalidItemNameChars.replace(/\\/g, "");
            for (const char of invalidChars) {
                if (name.includes(char)) {
                    return {
                        isValid: false,
                        message: `Item name cannot contain the character: ${char}`,
                    };
                }
            }
        }
        // Check name validation regex
        if (parheliaSettings.itemNameValidation) {
            try {
                const regex = new RegExp(parheliaSettings.itemNameValidation);
                if (!regex.test(name)) {
                    return {
                        isValid: false,
                        message: `Item name must satisfy the pattern: ${parheliaSettings.itemNameValidation}`,
                    };
                }
            }
            catch (error) {
                console.warn("Invalid regex pattern for item name validation:", error);
            }
        }
        // Check maximum length
        if (parheliaSettings.maxItemNameLength &&
            name.length > parheliaSettings.maxItemNameLength) {
            return {
                isValid: false,
                message: `Item name cannot exceed ${parheliaSettings.maxItemNameLength} characters`,
            };
        }
        return { isValid: true };
    };
    return {
        validateItemName,
        settings: parheliaSettings,
    };
}
//# sourceMappingURL=useParheliaSettings.js.map