var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import React, { forwardRef, useCallback, useEffect, } from 'react';
import { FormSpy, useForm } from 'react-final-form';
import { FluentButton } from '../../UI/inputs/buttons/FluentButton';
/**
 * Submit button
 */
const AltSubmitButton = forwardRef((props, ref) => {
    const { disabled, disablePristine = true, ButtonComponent = FluentButton, name, value } = props, otherProps = __rest(props, ["disabled", "disablePristine", "ButtonComponent", "name", "value"]);
    const form = useForm();
    useEffect(() => {
        if (!name)
            return;
        return form.registerField(name, () => { }, {}, {
            defaultValue: null,
        });
    }, [form, name]);
    const onClick = useCallback(() => {
        if (name)
            form.change(name, value);
        form.submit();
        if (name)
            form.change(name, null);
    }, [form, name, value]);
    return (React.createElement(FormSpy, { subscription: { submitting: true, pristine: true } }, ({ submitting, pristine }) => (React.createElement(ButtonComponent, Object.assign({ ref: ref, type: "button", disabled: submitting || (disablePristine && pristine) || disabled }, otherProps, { onClick: onClick })))));
});
AltSubmitButton.displayName = 'AltSubmitButton';
export default AltSubmitButton;
//# sourceMappingURL=AltSubmitButton.js.map