'use strict';
Object.defineProperty(exports, '__esModule', {
    value: true
});
exports.default = void 0;
var _isEmpty = _interopRequireDefault(require('./isEmpty'));
var _debounce2 = _interopRequireDefault(require('./debounce'));
function _interopRequireDefault(e) {
    return e && e.__esModule
        ? e
        : {
              default: e
          };
}
function _defineProperty(e, t, n) {
    t in e
        ? Object.defineProperty(e, t, {
              value: n,
              enumerable: true,
              configurable: true,
              writable: true
          })
        : (e[t] = n);
    return e;
}
function bindFunc(e, t, n) {
    var i = e[t];
    e[t] = function (e) {
        if (n) {
            n.call(this, e, _defineProperty({}, t, true));
        }
        if (i) {
            i.call(this, e);
        }
    };
}
var methods = ['linked', 'linkChanged', 'unlinked'];
var extProps = ['observer'];
var _default = {
    lifetimes: {
        created: function () {
            this._debounce = null;
        },
        detached: function () {
            if (this._debounce && this._debounce.cancel) {
                this._debounce.cancel();
            }
        }
    },
    definitionFilter: function (e) {
        var n = e.relations;
        if (!(0, _isEmpty.default)(n)) {
            var t = function (e) {
                var t = n[e];
                methods.forEach(function (e) {
                    return bindFunc(t, e, t.observer);
                });
                extProps.forEach(function (e) {
                    return delete t[e];
                });
            };
            for (var i in n) {
                t(i);
            }
        }
        Object.assign((e.methods = e.methods || {}), {
            getRelationsName: function (e) {
                if (0 < arguments.length && void 0 !== e) {
                    var t = e;
                } else {
                    var t = ['parent', 'child', 'ancestor', 'descendant'];
                }
                return Object.keys(n || {})
                    .map(function (e) {
                        return n[e] && t.includes(n[e].type) ? e : null;
                    })
                    .filter(function (e) {
                        return !!e;
                    });
            },
            debounce: function (e, t, n) {
                if (1 < arguments.length && void 0 !== t) {
                    var i = t;
                } else {
                    var i = 0;
                }
                var r = 2 < arguments.length && void 0 !== n && n;
                return (this._debounce = this._debounce || (0, _debounce2.default)(e.bind(this), i, r)).call(this);
            }
        });
    }
};
exports.default = _default;
