var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import * as React from 'react';
import { isEqual } from 'lodash';
import { Modal, Input, Button } from 'semantic-ui-react';
var InputBox = /** @class */ (function (_super) {
    __extends(InputBox, _super);
    function InputBox(props) {
        var _this = _super.call(this, props) || this;
        _this.state = { editing: false, value: props.value };
        return _this;
    }
    InputBox.prototype.componentDidUpdate = function (prevProps) {
        if (!isEqual(prevProps.value, this.props.value)) {
            this.setState({ value: this.props.value });
        }
    };
    InputBox.prototype.render = function () {
        var _this = this;
        var _a = this.state, value = _a.value, editing = _a.editing;
        var _b = this.props, onChange = _b.onChange, trigger = _b.trigger;
        var Compo = trigger;
        return <>
            <Compo onClick={function () { return _this.setState({ editing: true }); }}/>
            {editing && <Modal open>
                <Modal.Content>
                    <Input fluid value={value} onChange={function (a, b) { return _this.setState({ value: b.value }); }}/>
                </Modal.Content>
                <Modal.Actions>
                    <Button content="Cancel" onClick={function () { return _this.setState({ value: _this.props.value, editing: false }); }}/>
                    <Button primary content="OK" onClick={function () { return _this.setState({ editing: false }, function () { return onChange(value); }); }}/>
                </Modal.Actions>
            </Modal>}
        </>;
    };
    return InputBox;
}(React.Component));
export { InputBox };
