'use strict';
Object.defineProperty(exports, '__esModule', {
    value: true
});
exports.default = void 0;
var _isEmpty = _interopRequireDefault(require('./isEmpty'));
var _shallowEqual = _interopRequireDefault(require('./shallowEqual'));
function _interopRequireDefault(e) {
    return e && e.__esModule
        ? e
        : {
              default: e
          };
}
function _toConsumableArray(e) {
    return _arrayWithoutHoles(e) || _iterableToArray(e) || _nonIterableSpread();
}
function _nonIterableSpread() {
    throw new TypeError('Invalid attempt to spread non-iterable instance');
}
function _iterableToArray(e) {
    if (Symbol.iterator in Object(e) || '[object Arguments]' === Object.prototype.toString.call(e)) {
        return Array.from(e);
    }
}
function _arrayWithoutHoles(e) {
    if (Array.isArray(e)) {
        for (r = 0, t = new Array(e.length), void 0; r < e.length; r++) {
            var r;
            var t;
            t[r] = e[r];
        }
        return t;
    }
}
function ownKeys(r, e) {
    var t = Object.keys(r);
    if (Object.getOwnPropertySymbols) {
        var n = Object.getOwnPropertySymbols(r);
        if (e) {
            n = n.filter(function (e) {
                return Object.getOwnPropertyDescriptor(r, e).enumerable;
            });
        }
        t.push.apply(t, n);
    }
    return t;
}
function _objectSpread(r) {
    for (var e = 1; e < arguments.length; e++) {
        if (null != arguments[e]) {
            var t = arguments[e];
        } else {
            var t = {};
        }
        e % 2
            ? ownKeys(t, true).forEach(function (e) {
                  _defineProperty(r, e, t[e]);
              })
            : Object.getOwnPropertyDescriptors
            ? Object.defineProperties(r, Object.getOwnPropertyDescriptors(t))
            : ownKeys(t).forEach(function (e) {
                  Object.defineProperty(r, e, Object.getOwnPropertyDescriptor(t, e));
              });
    }
    return r;
}
function _defineProperty(e, r, t) {
    r in e
        ? Object.defineProperty(e, r, {
              value: t,
              enumerable: true,
              configurable: true,
              writable: true
          })
        : (e[r] = t);
    return e;
}
function _slicedToArray(e, r) {
    return _arrayWithHoles(e) || _iterableToArrayLimit(e, r) || _nonIterableRest();
}
function _nonIterableRest() {
    throw new TypeError('Invalid attempt to destructure non-iterable instance');
}
function _iterableToArrayLimit(e, r) {
    var t = [];
    var n = true;
    var o = false;
    var i = void 0;
    try {
        for (u = e[Symbol.iterator](), void 0; !(n = (a = u.next()).done) && (t.push(a.value), !r || t.length !== r); n = true) {
            var a;
            var u;
        }
    } catch (e) {
        console.log('CatchClause', e);
        console.log('CatchClause', e);
        o = true;
        i = e;
    } finally {
        try {
            n || null == u.return || u.return();
        } finally {
            if (o) {
                throw i;
            }
        }
    }
    return t;
}
function _arrayWithHoles(e) {
    if (Array.isArray(e)) {
        return e;
    }
}
var ALL_DATA_KEY = '**';
var trim = function (e) {
    return (0 < arguments.length && void 0 !== e ? e : '').replace(/\s/g, '');
};
var _default = {
    lifetimes: {
        attached: function () {
            this.initComputed();
        }
    },
    definitionFilter: function (e) {
        var r = e.computed;
        if (void 0 === r) {
            var n = {};
        } else {
            var n = r;
        }
        var a = Object.keys(n).reduce(function (e, i) {
            var r = _slicedToArray(Array.isArray(n[i]) ? n[i] : [ALL_DATA_KEY, n[i]], 2);
            var t = r[0];
            var a = r[1];
            return _objectSpread(
                {},
                e,
                _defineProperty({}, t, function () {
                    if ('function' == typeof a) {
                        for (e = arguments.length, r = new Array(e), t = 0, void 0; t < e; t++) {
                            var e;
                            var r;
                            var t;
                            r[t] = arguments[t];
                        }
                        var n = a.apply(this, r);
                        var o = this[i];
                        (0, _isEmpty.default)(n) || (0, _shallowEqual.default)(n, o) || this.setData(_defineProperty({}, i, n));
                    }
                })
            );
        }, {});
        Object.assign((e.observers = e.observers || {}), a);
        Object.assign((e.methods = e.methods || {}), {
            initComputed: function (e, r) {
                var t = 0 < arguments.length && void 0 !== e ? e : {};
                var n = 1 < arguments.length && void 0 !== r && r;
                if (!this.runInitComputed || n) {
                    this.runInitComputed = false;
                    var that = this;
                    var i = _objectSpread({}, this, {}, t);
                    Object.keys(a).forEach(function (e) {
                        var r = trim(e)
                            .split(',')
                            .reduce(function (e, r) {
                                return [].concat(_toConsumableArray(e), [i[r]]);
                            }, []);
                        a[e].apply(that, r);
                    });
                    this.runInitComputed = true;
                }
            }
        });
    }
};
exports.default = _default;
