import React, { useMemo, Fragment } from 'react';
const validatePassword = (password, lengthRestriction = 0, upperCaseRestriction = false, specialCharacterRestriction = false, numberRestriction = false, lowerCaseRestriction = false) => {
    let issues = [];
    if (!password)
        return [];
    if (lengthRestriction && password.length < lengthRestriction) {
        issues.push(`Password must be at least ${lengthRestriction} characters long.`);
    }
    if (upperCaseRestriction && !/[A-Z]/.test(password)) {
        issues.push('Password must contain at least one uppercase letter.');
    }
    if (specialCharacterRestriction && !/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
        issues.push('Password must contain at least one special character.');
    }
    if (numberRestriction && !/\d/.test(password)) {
        issues.push('Password must contain at least one number.');
    }
    if (lowerCaseRestriction && !/[a-z]/.test(password)) {
        issues.push('Password must contain at least one lowercase letter.');
    }
    return issues;
};
export const isPasswordValid = (password, lengthRestriction = 0, upperCaseRestriction = false, specialCharacterRestriction = false, numberRestriction = false, lowerCaseRestriction = false) => {
    return (validatePassword(password, lengthRestriction, upperCaseRestriction, specialCharacterRestriction, numberRestriction, lowerCaseRestriction).length === 0);
};
const PasswordValidator = ({ password, lengthRestriction, upperCaseRestriction, specialCharacterRestriction, numberRestriction, lowerCaseRestriction, }) => {
    const issues = useMemo(() => {
        return validatePassword(password, lengthRestriction, upperCaseRestriction, specialCharacterRestriction, numberRestriction, lowerCaseRestriction);
    }, [
        password,
        lengthRestriction,
        upperCaseRestriction,
        specialCharacterRestriction,
        numberRestriction,
        lowerCaseRestriction
    ]);
    // Check for length on both to avoid unnecessary empty divs
    if (!password || issues.length === 0)
        return null;
    return (React.createElement("div", null, React.createElement("p", { style: { color: 'red' } }, issues.map((issue, index) => (React.createElement(Fragment, { key: `${issue}-${index}` }, issue, React.createElement("br", null)))))));
};
export default PasswordValidator;
//# sourceMappingURL=PasswordValidator.js.map