"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var React = require("react");
var factory_1 = require("../factory");
var cx = require("classnames");
var Switch_1 = require("../components/Switch");
var SwitchField = /** @class */ (function (_super) {
    tslib_1.__extends(SwitchField, _super);
    function SwitchField(props) {
        var _this = _super.call(this, props) || this;
        _this.handleChange = _this.handleChange.bind(_this);
        return _this;
    }
    SwitchField.prototype.handleChange = function (checked) {
        var _a = this.props, onQuickChange = _a.onQuickChange, name = _a.name, trueValue = _a.trueValue, falseValue = _a.falseValue, saveImmediately = _a.saveImmediately, readOnly = _a.readOnly, disabled = _a.disabled;
        onQuickChange &&
            !readOnly &&
            !disabled &&
            onQuickChange((_b = {},
                _b[name] = checked ? trueValue : falseValue,
                _b), saveImmediately);
        var _b;
    };
    SwitchField.prototype.render = function () {
        var _a = this.props, className = _a.className, ns = _a.classPrefix, value = _a.value, placeholder = _a.placeholder, trueValue = _a.trueValue, falseValue = _a.falseValue, onQuickChange = _a.onQuickChange, option = _a.option, disabled = _a.disabled;
        var viewValue = React.createElement("span", { className: "text-muted" }, placeholder);
        var showOption = false;
        if (value == trueValue || value == falseValue) {
            showOption = !!option;
            viewValue = (React.createElement(Switch_1.default, { inline: true, classPrefix: ns, checked: value == trueValue, onChange: this.handleChange, disabled: disabled || !onQuickChange }));
        }
        return (React.createElement("span", { className: cx(ns + "SwitchField", className) },
            viewValue,
            showOption ? option : null));
    };
    SwitchField.defaultProps = {
        placeholder: '-',
        trueValue: true,
        falseValue: false,
        readOnly: true,
        saveImmediately: false,
    };
    return SwitchField;
}(React.Component));
exports.SwitchField = SwitchField;
var SwitchFieldRenderer = /** @class */ (function (_super) {
    tslib_1.__extends(SwitchFieldRenderer, _super);
    function SwitchFieldRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    SwitchFieldRenderer = tslib_1.__decorate([
        factory_1.Renderer({
            test: /(^|\/)switch$/,
            name: 'switch',
        })
    ], SwitchFieldRenderer);
    return SwitchFieldRenderer;
}(SwitchField));
exports.SwitchFieldRenderer = SwitchFieldRenderer;
//# sourceMappingURL=./renderers/Switch.js.map
