import { __extends } from "tslib";
import { Subscriber } from 'rxjs';
var FinalizeWithLastSubscriber = (function (_super) {
    __extends(FinalizeWithLastSubscriber, _super);
    function FinalizeWithLastSubscriber(destination, callback, value) {
        var _this = _super.call(this, destination) || this;
        _this.callback = callback;
        _this.value = value;
        return _this;
    }
    FinalizeWithLastSubscriber.prototype._next = function (value) {
        var _a, _b;
        this.value = value;
        (_b = (_a = this.destination).next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
    };
    FinalizeWithLastSubscriber.prototype._complete = function () {
        var _a, _b, _c, _d;
        try {
            var callback = this.callback;
            callback(this.value);
        }
        catch (error) {
            (_b = (_a = this.destination).error) === null || _b === void 0 ? void 0 : _b.call(_a, error);
        }
        (_d = (_c = this.destination).complete) === null || _d === void 0 ? void 0 : _d.call(_c);
    };
    return FinalizeWithLastSubscriber;
}(Subscriber));
var FinalizeWithLastOperator = (function () {
    function FinalizeWithLastOperator(callback, defaultValue) {
        this.callback = callback;
        this.defaultValue = defaultValue;
    }
    FinalizeWithLastOperator.prototype.call = function (subscriber, source) {
        return source.subscribe(new FinalizeWithLastSubscriber(subscriber, this.callback, this.defaultValue));
    };
    return FinalizeWithLastOperator;
}());
export function finalizeWithLast(callback, defaultValue) {
    return function finalizeWithLastOperatorFunction(source) {
        return source.lift(new FinalizeWithLastOperator(callback, defaultValue));
    };
}
