"use strict";
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 __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var utils_1 = require("../../utils");
var braft_editor_1 = require("braft-editor");
var BraftEditor = braft_editor_1.default;
var defaultNameSpace = 'com.vrv.portal';
var userId = null;
var userName = null;
utils_1.Ajax.SESION('/api-common/user/info');
utils_1.Ajax.GET('/api-common/user/info', function (json) {
    userId = json.data.id;
    userName = json.data.name;
});
var default_1 = /** @class */ (function (_super) {
    __extends(default_1, _super);
    function default_1() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            editorState: null
        };
        return _this;
    }
    default_1.prototype.onChange = function (editorState) {
        this.setState({ editorState: editorState });
        this.props.onChange(editorState.toHTML());
    };
    default_1.prototype.componentWillMount = function () {
        var editorState = BraftEditor.createEditorState(this.props.value);
        this.setState({ editorState: editorState });
    };
    default_1.prototype.render = function () {
        var _this = this;
        var param = {};
        if (this.props.height) {
            param.height = this.props.height;
        }
        return React.createElement(BraftEditor, { value: this.state.editorState, contentFormat: "raw", onChange: function (content) { return _this.onChange(content); }, controls: [
                'text-color', 'bold', 'italic', 'underline', 'strike-through', 'split',
                'emoji',
                'undo', 'redo', 'remove-styles', 'split', 'font-size', 'font-family', 'line-height', 'indent',
                'separator',
                // 'letter-spacing',
                // 'superscript', 'subscript',
                'text-align', 'split', 'headings', 'list_ul',
                'list_ol', 'blockquote', 'code', 'hr', 'split', 'media', 'link', 'split', 'clear'
            ], media: {
                uploadFn: function (param) {
                    utils_1.Ajax.UPLOAD(param.file, {
                        success: function (resp) {
                            param.success({
                                url: '/api-fileup/fileup/download/' + resp.data.guid,
                                meta: {
                                    id: resp.data.guid,
                                    title: resp.data.fileName,
                                    alt: resp.data.fileName,
                                    loop: false,
                                    poster: '/api-fileup/fileup/download/' + resp.data.guid,
                                }
                            });
                        },
                        progress: function (progress) { return param.progress(progress); },
                        error: function (evt) { return param.error({ msg: '上传失败' }); },
                    }, {
                        namespace: _this.props.namespace || defaultNameSpace,
                        userId: _this.props.userId || userId,
                        userName: _this.props.userName || userName
                    });
                }
            } });
    };
    return default_1;
}(React.PureComponent));
exports.default = default_1;
