var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import * as React from 'react';
import { Form, Input, Label, Checkbox } from 'semantic-ui-react';
export function EditorField(props) {
    var inline = props.inline, field = props.field, item = props.item, onChange = props.onChange, label = props.label, type = props.type, customControl = props.customControl, errors = props.errors, readonly = props.readonly, children = props.children, inputProps = __rest(props, ["inline", "field", "item", "onChange", "label", "type", "customControl", "errors", "readonly", "children"]);
    var caption = label || field;
    var error = errors && errors[field];
    var CustomControl = customControl;
    var stringValue = item[field] || '';
    return <Form.Field inline={inline} error={error ? true : false}>
    <label style={{ width: 150 }}>{caption}</label>
    {readonly
        ? <Input value={stringValue} {...inputProps}/>
        : CustomControl
            ? <CustomControl {...inputProps} onChange={function (i) { onChange && onChange(field, i); }} value={item[field]}/>
            : type === 'boolean'
                ? <Checkbox {...inputProps} onChange={function (a, b) { return onChange(field, b.checked); }} toggle checked={item[field]}/>
                : <Input type={type || 'text'} placeholder={caption} {...inputProps} value={stringValue} onChange={function (a, b) { return onChange(field, b.value); }}/>}
    {error && <Label size="mini" color="red">
      {error}
    </Label>}
    {children}
  </Form.Field>;
}
