"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useNativeValidity = void 0;
const react_1 = require("react");
const useNativeValidity = (error) => {
    const [nativeInvalid, setNativeInvalid] = (0, react_1.useState)(false);
    const onBlur = (0, react_1.useCallback)((e) => {
        setNativeInvalid(!e.currentTarget.checkValidity());
    }, []);
    const onChange = (0, react_1.useCallback)((e) => {
        if (e.currentTarget.checkValidity()) {
            setNativeInvalid(false);
        }
    }, []);
    const onInvalid = (0, react_1.useCallback)(() => {
        setNativeInvalid(true);
    }, []);
    const revalidate = (0, react_1.useCallback)((input) => {
        if (input === null || input === void 0 ? void 0 : input.checkValidity()) {
            setNativeInvalid(false);
        }
    }, []);
    return {
        finalError: Boolean(error) || nativeInvalid,
        onBlur,
        onChange,
        onInvalid,
        revalidate,
    };
};
exports.useNativeValidity = useNativeValidity;
//# sourceMappingURL=useNativeValidity.js.map