import Button, { ButtonStyleType } from "../Button/Button";
import Input from "../Input/Input";
import IconProp from "../../../Types/Icon/IconProp";
import ObjectID from "../../../Types/ObjectID";
import React, { useEffect, useState, } from "react";
const IDGenerator = (props) => {
    const [value, setValue] = useState(null);
    useEffect(() => {
        if (props.initialValue) {
            setValue(props.initialValue);
        }
        if (props.value) {
            setValue(props.value);
        }
    }, []);
    useEffect(() => {
        if (props.initialValue) {
            setValue(props.initialValue);
        }
    }, [props.initialValue]);
    useEffect(() => {
        setValue(props.value ? props.value : props.initialValue || null);
    }, [props.value]);
    return (React.createElement(React.Fragment, null,
        React.createElement(React.Fragment, null,
            React.createElement("div", { className: "flex", "data-testid": props.dataTestId },
                value && (React.createElement(Input, { readOnly: props.readonly, tabIndex: props.tabIndex, onEnterPress: props.onEnterPress, value: value.toString() })),
                React.createElement("div", { className: "mt-2" },
                    React.createElement(Button, { icon: IconProp.Refresh, buttonStyle: ButtonStyleType.NORMAL, disabled: props.disabled || props.readonly, title: value ? "Regenerate" : "Generate", onClick: () => {
                            var _a;
                            const generatedID = ObjectID.generate();
                            setValue(generatedID);
                            (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, generatedID);
                        } })))),
        props.error && (React.createElement("p", { "data-testid": "error-message", className: "mt-1 text-sm text-red-400" }, props.error))));
};
export default IDGenerator;
//# sourceMappingURL=IDGenerator.js.map