"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdaptablePopupPrompt = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const StringExtensions_1 = require("../../../Utilities/Extensions/StringExtensions");
const Dialog_1 = tslib_1.__importDefault(require("../../../components/Dialog"));
const rebass_1 = require("rebass");
const SimpleButton_1 = tslib_1.__importDefault(require("../../../components/SimpleButton"));
const Input_1 = tslib_1.__importDefault(require("../../../components/Input"));
const react_redux_1 = require("react-redux");
const AdaptablePopupPrompt = (props) => {
    const dispatch = (0, react_redux_1.useDispatch)();
    const [promptText, setPromptText] = React.useState(props.defaultValue ?? '');
    const onCloseForm = () => {
        setPromptText('');
        props.onClose();
    };
    const onConfirmForm = () => {
        props.onConfirm(promptText);
        const confirmationAction = typeof props.onConfirmActionCreator === 'function' &&
            props.onConfirmActionCreator(promptText);
        if (confirmationAction) {
            dispatch(confirmationAction);
        }
        setPromptText('');
    };
    const changeContent = (e) => {
        setPromptText(e.target.value);
    };
    return (React.createElement(Dialog_1.default, { modal: true, "data-name": `prompt-popup`, isOpen: true, onDismiss: props.onClose, showCloseButton: false, style: { minHeight: 'auto', maxWidth: '50%' } },
        React.createElement(rebass_1.Flex, { flexDirection: "column" },
            React.createElement(rebass_1.Box, { marginTop: 3, mx: 2 }, props.header),
            StringExtensions_1.StringExtensions.IsNotNullOrEmpty(props.message) && (React.createElement(rebass_1.Box, { marginTop: 3, mx: 2 },
                ' ',
                React.createElement("div", { style: { display: 'flex', alignItems: 'center' } }, props.message.split('\n').map(function (item, index) {
                    return (React.createElement("span", { key: index },
                        item,
                        React.createElement("br", null)));
                })))),
            React.createElement(Input_1.default, { autoFocus: true, marginTop: 3, mx: 3, value: promptText, type: "string", placeholder: "Enter text", onChange: (e) => changeContent(e) }),
            React.createElement(rebass_1.Box, { marginTop: 3 },
                React.createElement(rebass_1.Flex, { padding: 2 },
                    React.createElement(SimpleButton_1.default, { tone: "accent", "data-name": "ok", variant: "raised", disabled: StringExtensions_1.StringExtensions.IsNullOrEmpty(promptText), onClick: () => onConfirmForm() }, "OK"),
                    React.createElement("div", { style: { flex: 1 } }),
                    React.createElement(SimpleButton_1.default, { tone: "neutral", variant: "raised", onClick: () => onCloseForm(), "data-name": "cancel" }, "Cancel"))))));
};
exports.AdaptablePopupPrompt = AdaptablePopupPrompt;
