"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 });
/**
 * 导入图标性质Button
*/
var React = require("react");
var antd_1 = require("antd");
var UploadService_1 = require("./UploadService");
var _ = require("lodash");
var default_1 = /** @class */ (function (_super) {
    __extends(default_1, _super);
    function default_1() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.state = {
            loading: false,
            process: 0,
            imgUrl: ''
        };
        _this.handleChange = function (info) {
            if (info.file.status === 'uploading') {
                _this.setState({ loading: true, process: Math.floor(info.file.percent) });
                return;
            }
            if (info.file.status === 'done') {
                var imgUrl = '';
                if (_.has(_this.props, 'url') && !_this.props.url.startsWith('/api-fileup/')) {
                    imgUrl = info.file.response.data;
                }
                else {
                    imgUrl = '/api-fileup/fileup/download/' + info.file.response.data.guid;
                }
                _this.setState({
                    loading: false,
                    process: 0,
                    imgUrl: imgUrl,
                });
                _this.props.callback(imgUrl);
            }
            if (info.file.status === 'error') {
                antd_1.message.error("\u6587\u4EF6 " + info.file.name + "\u4E0A\u4F20\u5931\u8D25");
                _this.setState({
                    loading: false,
                    process: 0
                });
            }
        };
        return _this;
    }
    default_1.prototype.render = function () {
        var url = this.state.imgUrl || this.props.def || "";
        return React.createElement(antd_1.Upload, { name: "file", withCredentials: true, listType: "picture", showUploadList: false, onChange: this.handleChange, action: this.props.url || '/api-fileup/fileup/uploadFile', accept: "image/*", className: url ? 'upload-icon' : 'upload-icon upload-icon-empty', data: {
                namespace: this.props.namespace,
                userId: this.state.userId,
                userName: this.state.userName,
            } }, url ? React.createElement("img", { src: url }) :
            React.createElement("div", null,
                React.createElement(antd_1.Icon, { type: this.state.loading ? 'loading' : 'plus' }),
                React.createElement("div", { className: "ant-upload-text" }, "\u4E0A\u4F20")));
    };
    return default_1;
}(UploadService_1.default));
exports.default = default_1;
