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 __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import * as React from "react";
import { Segment, Header, Button, Divider } from "semantic-ui-react";
import { createEditor } from "./createEditor";
import { createFields } from "./createFields";
var StandardEditorCompo = /** @class */ (function (_super) {
    __extends(StandardEditorCompo, _super);
    function StandardEditorCompo(props) {
        return _super.call(this, props) || this;
    }
    StandardEditorCompo.prototype.render = function () {
        var _a = this.props, title = _a.title, item = _a.item, fields = _a.fields, errors = _a.errors, hasErrors = _a.hasErrors, needToSave = _a.needToSave, onCancel = _a.onCancel, onSave = _a.onSave, onQuit = _a.onQuit;
        if (!item)
            return null;
        return (<Segment>
        <Header content={title}/>
        <Button disabled={needToSave || hasErrors} primary title="Go back" icon="chevron left" content="Back" onClick={onQuit}/>
        <Button disabled={!needToSave || hasErrors} primary title="Save report" icon="save" content="Save" onClick={onSave}/>
        {needToSave && (<Button title="Cancel" secondary icon="cancel" content="Cancel" onClick={onCancel}/>)}
        <Divider />
        {createFields({
            item: this.props.item,
            changeHandler: this.props.changeValue,
            fields: fields.map(function (f) { return (__assign({}, f, { errors: errors })); }) // Override Errors Object
        })}
      </Segment>);
    };
    return StandardEditorCompo;
}(React.Component));
export function createStandardEditor(title, newItem, getItem, saveItem, options, fields) {
    var Compo = /** @class */ (function (_super) {
        __extends(Compo, _super);
        function Compo() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        Compo.prototype.render = function () {
            return (<StandardEditorCompo {...this.props} title={title} fields={fields}/>);
        };
        return Compo;
    }(React.Component));
    return createEditor(newItem, getItem, saveItem, options)(Compo);
}
