"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LinkFieldRenderer = exports.LinkCmpt = void 0;
var tslib_1 = require("tslib");
var react_1 = (0, tslib_1.__importDefault)(require("react"));
var factory_1 = require("../factory");
var helper_1 = require("../utils/helper");
var tpl_1 = require("../utils/tpl");
var Badge_1 = require("../components/Badge");
var Link_1 = (0, tslib_1.__importDefault)(require("../components/Link"));
var LinkCmpt = /** @class */ (function (_super) {
    (0, tslib_1.__extends)(LinkCmpt, _super);
    function LinkCmpt() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    LinkCmpt.prototype.handleClick = function (href) {
        return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
            var _a, env, blank, body, dispatchEvent, data, rendererEvent;
            return (0, tslib_1.__generator)(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = this.props, env = _a.env, blank = _a.blank, body = _a.body, dispatchEvent = _a.dispatchEvent, data = _a.data;
                        env === null || env === void 0 ? void 0 : env.tracker({
                            eventType: 'url',
                            // 需要和 action 里命名一致方便后续分析
                            eventData: { url: href, blank: blank, label: body }
                        }, this.props);
                        return [4 /*yield*/, dispatchEvent('click', (0, helper_1.createObject)(data, {
                                // 注意：每个组件都必须把数据链带上
                                url: href,
                                blank: blank,
                                label: body
                            }))];
                    case 1:
                        rendererEvent = _b.sent();
                        // 阻止原有动作执行
                        if (rendererEvent === null || rendererEvent === void 0 ? void 0 : rendererEvent.prevented) {
                            return [2 /*return*/];
                        }
                        return [2 /*return*/];
                }
            });
        });
    };
    LinkCmpt.prototype.getHref = function () { };
    LinkCmpt.prototype.render = function () {
        var _a = this.props, className = _a.className, body = _a.body, href = _a.href, cx = _a.classnames, blank = _a.blank, disabled = _a.disabled, htmlTarget = _a.htmlTarget, data = _a.data, render = _a.render, __ = _a.translate, title = _a.title, icon = _a.icon, rightIcon = _a.rightIcon;
        var value = (typeof href === 'string' && href
            ? (0, tpl_1.filter)(href, data, '| raw')
            : undefined) || (0, helper_1.getPropValue)(this.props);
        return (react_1.default.createElement(Link_1.default, { className: className, href: value, disabled: disabled, title: title, htmlTarget: htmlTarget || (blank ? '_blank' : '_self'), icon: icon, rightIcon: rightIcon }, body ? render('body', body) : value || __('link')));
    };
    LinkCmpt.defaultProps = {
        blank: true,
        disabled: false,
        htmlTarget: ''
    };
    return LinkCmpt;
}(react_1.default.Component));
exports.LinkCmpt = LinkCmpt;
var LinkFieldRenderer = /** @class */ (function (_super) {
    (0, tslib_1.__extends)(LinkFieldRenderer, _super);
    function LinkFieldRenderer() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    LinkFieldRenderer = (0, tslib_1.__decorate)([
        (0, factory_1.Renderer)({
            type: 'link'
        })
        // @ts-ignore 类型没搞定
        ,
        Badge_1.withBadge
    ], LinkFieldRenderer);
    return LinkFieldRenderer;
}(LinkCmpt));
exports.LinkFieldRenderer = LinkFieldRenderer;
//# sourceMappingURL=./renderers/Link.js.map
