"use strict";
var __extends = (this && this.__extends) || (function () {
    var 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 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) || 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;
};
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)
            t[p[i]] = s[p[i]];
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var _1 = require("../../");
var unstable_1 = require("../../unstable");
var Mermaid_1 = require("../Mermaid");
var Widget = (function (_super) {
    __extends(Widget, _super);
    function Widget(props) {
        var _this = _super.call(this, props) || this;
        _this.showPreview = function () {
            _this.setState({ showPreview: true });
        };
        _this.hidePreview = function () {
            _this.setState({ showPreview: false });
        };
        _this.state = {
            showPreview: false,
        };
        return _this;
    }
    Widget.prototype.render = function () {
        var _this = this;
        var _a = this.props, value = _a.value, readonly = _a.readonly, disabled = _a.disabled, autofocus = _a.autofocus, onBlur = _a.onBlur, onFocus = _a.onFocus, options = _a.options, schema = _a.schema, formContext = _a.formContext, inputProps = __rest(_a, ["value", "readonly", "disabled", "autofocus", "onBlur", "onFocus", "options", "schema", "formContext"]);
        var showPreview = this.state.showPreview;
        var change = function (_a) {
            var value = _a.target.value;
            return _this.props.onChange(value === '' ? options.emptyValue : value);
        };
        return (React.createElement(_1.Box, null,
            React.createElement(_1.Flex, { justify: "space-between", mb: 1 },
                React.createElement(_1.Flex, null,
                    React.createElement(_1.Button, { plaintext: true, mr: 3, onClick: this.hidePreview },
                        React.createElement(_1.Txt, { bold: !showPreview }, "Write")),
                    React.createElement(_1.Button, { plaintext: true, onClick: this.showPreview },
                        React.createElement(_1.Txt, { bold: showPreview }, "Preview"))),
                React.createElement(_1.Link, { fontSize: 2, href: 'https://mermaidjs.github.io/', blank: true }, "About mermaid")),
            showPreview && (React.createElement(Mermaid_1.Mermaid, { bg: _1.Theme.colors.gray.light, p: 3, style: {
                    borderRadius: _1.Theme.radius,
                    width: '100%',
                    minHeight: 180,
                }, value: value })),
            !showPreview && (React.createElement(_1.Textarea, __assign({ placeholder: "This text supports mermaid charts", readOnly: readonly, disabled: disabled, autoFocus: autofocus, value: value || '' }, inputProps, { onChange: change, onBlur: onBlur &&
                    (function (event) { return onBlur(inputProps.id, event.target.value); }), onFocus: onFocus &&
                    (function (event) { return onFocus(inputProps.id, event.target.value); }), rows: 5 })))));
    };
    return Widget;
}(React.Component));
unstable_1.Form.registerWidget('mermaid', Widget);
