"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CollaborativeInput = void 0;
const react_1 = require("react");
const collaborative_input_1 = require("collaborative-input");
class CollaborativeInputState {
    constructor(props) {
        this.props = props;
        this.unbind = () => {
            this._unbind?.();
            this._unbind = void 0;
        };
        this.stop = this.unbind;
        this.start = () => this.stop;
        this.ref = (el) => {
            if (!el)
                return this.unbind();
            const { str, polling } = this.props;
            this._unbind = (0, collaborative_input_1.bind)(str, el, !!polling);
        };
    }
}
const CollaborativeInput = (props) => {
    const { str, polling, inp: _inp, input, ...rest } = props;
    // biome-ignore lint: hook dependency list manually managed
    const state = (0, react_1.useMemo)(() => new CollaborativeInputState(props), [str, polling]);
    // biome-ignore lint: hook dependency list manually managed
    (0, react_1.useLayoutEffect)(state.start, [state]);
    if (input)
        return input(state.ref);
    rest.ref = state.ref;
    return (0, react_1.createElement)(rest.multiline ? 'textarea' : 'input', rest);
};
exports.CollaborativeInput = CollaborativeInput;
//# sourceMappingURL=CollaborativeInput.js.map