import * as i0 from '@angular/core';
import { Directive, Input, Optional, Host, Pipe, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

class BsInstanceOfDirective {
    constructor() {
        this._defaultUsed = false;
        this._caseCount = 0;
        this._lastCaseCheckIndex = 0;
        this._lastCasesMatched = false;
    }
    set bsInstanceof(newValue) {
        this._instanceof = newValue;
        if (this._caseCount === 0) {
            this._updateDefaultCases(true);
        }
    }
    /** @internal */
    _addCase() {
        return this._caseCount++;
    }
    /** @internal */
    _addDefault(view) {
        if (!this._defaultViews) {
            this._defaultViews = [];
        }
        this._defaultViews.push(view);
    }
    /** @internal */
    _matchCase(type) {
        const matched = this._instanceof instanceof type
            ? this._instanceof
            : undefined;
        this._lastCasesMatched = this._lastCasesMatched || !!matched;
        this._lastCaseCheckIndex++;
        if (this._lastCaseCheckIndex === this._caseCount) {
            this._updateDefaultCases(!this._lastCasesMatched);
            this._lastCaseCheckIndex = 0;
            this._lastCasesMatched = false;
        }
        // debugger;
        return matched;
    }
    _updateDefaultCases(useDefault) {
        if (this._defaultViews && useDefault !== this._defaultUsed) {
            this._defaultUsed = useDefault;
            for (let i = 0; i < this._defaultViews.length; i++) {
                const defaultView = this._defaultViews[i];
                defaultView.enforceState(useDefault);
            }
        }
    }
}
BsInstanceOfDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceOfDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
BsInstanceOfDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.7", type: BsInstanceOfDirective, selector: "[bsInstanceof]", inputs: { bsInstanceof: "bsInstanceof" }, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceOfDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[bsInstanceof]',
                }]
        }], propDecorators: { bsInstanceof: [{
                type: Input
            }] } });

class BsInstanceOfContext {
    constructor() {
        this.$implicit = null;
        this.bsInstanceofCase = null;
    }
}

class SwitchView {
    constructor(_viewContainerRef, _templateRef) {
        this._viewContainerRef = _viewContainerRef;
        this._templateRef = _templateRef;
        this._created = false;
        this._context = new BsInstanceOfContext();
    }
    enforceState(result) {
        if (result && !this._created) {
            this.create(result);
        }
        else if (!result && this._created) {
            this.destroy();
        }
        else if (result) {
            this._context.$implicit = this._context.bsInstanceofCase = result;
        }
    }
    create(result) {
        this._created = true;
        this._context.$implicit = this._context.bsInstanceofCase = result;
        this._viewContainerRef.createEmbeddedView(this._templateRef, this._context);
    }
    destroy() {
        this._created = false;
        this._viewContainerRef.clear();
    }
}

class BsInstanceofCaseDirective {
    constructor(viewContainer, templateRef, bsInstanceof) {
        this.bsInstanceof = bsInstanceof;
        if (!bsInstanceof) {
            this.throwError('bsInstanceofCase');
        }
        bsInstanceof._addCase();
        this._view = new SwitchView(viewContainer, templateRef);
    }
    /**
     * Asserts the correct type of the context for the template that `InstanceofCaseDirective` will render.
     *
     * The presence of this method is a signal to the Ivy template type-check compiler that the
     * `InstanceofCaseDirective` structural directive renders its template with a specific context type.
     * Magic happens here!
     */
    static ngTemplateContextGuard(dir, ctx) {
        return true;
    }
    ngDoCheck() {
        this._view.enforceState(this.bsInstanceof._matchCase(this.bsInstanceofCase));
    }
    throwError(directiveName) {
        throw new Error(`An element with the "${directiveName}" attribute (matching the "${directiveName}" directive) must be located inside an element with the "bsInstanceof" attribute (matching "BsInstanceofDirective" directive)`);
    }
    ;
}
BsInstanceofCaseDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceofCaseDirective, deps: [{ token: i0.ViewContainerRef }, { token: i0.TemplateRef }, { token: BsInstanceOfDirective, host: true, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
BsInstanceofCaseDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.7", type: BsInstanceofCaseDirective, selector: "[bsInstanceofCase]", inputs: { bsInstanceofCase: "bsInstanceofCase" }, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceofCaseDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[bsInstanceofCase]',
                }]
        }], ctorParameters: function () {
        return [{ type: i0.ViewContainerRef }, { type: i0.TemplateRef }, { type: BsInstanceOfDirective, decorators: [{
                        type: Optional
                    }, {
                        type: Host
                    }] }];
    }, propDecorators: { bsInstanceofCase: [{
                type: Input
            }] } });

class BsInstanceOfDefaultDirective {
    constructor(viewContainer, templateRef, bsInstanceof) {
        if (!bsInstanceof) {
            this.throwError('bsInstanceofDefault');
        }
        bsInstanceof._addDefault(new SwitchView(viewContainer, templateRef));
    }
    throwError(directiveName) {
        throw new Error(`An element with the "${directiveName}" attribute (matching the "${directiveName}" directive) must be located inside an element with the "bsInstanceof" attribute (matching "BsInstanceofDirective" directive)`);
    }
    ;
}
BsInstanceOfDefaultDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceOfDefaultDirective, deps: [{ token: i0.ViewContainerRef }, { token: i0.TemplateRef }, { token: BsInstanceOfDirective, host: true, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
BsInstanceOfDefaultDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "15.2.7", type: BsInstanceOfDefaultDirective, selector: "[bsInstanceofDefault]", ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceOfDefaultDirective, decorators: [{
            type: Directive,
            args: [{
                    selector: '[bsInstanceofDefault]',
                }]
        }], ctorParameters: function () {
        return [{ type: i0.ViewContainerRef }, { type: i0.TemplateRef }, { type: BsInstanceOfDirective, decorators: [{
                        type: Optional
                    }, {
                        type: Host
                    }] }];
    } });

class BsInstanceofPipe {
    transform(value, type) {
        return value instanceof type ? value : undefined;
    }
}
BsInstanceofPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceofPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
BsInstanceofPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceofPipe, name: "bsInstanceof" });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceofPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'bsInstanceof',
                    pure: true,
                }]
        }] });

class BsInstanceOfModule {
}
BsInstanceOfModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceOfModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
BsInstanceOfModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceOfModule, declarations: [BsInstanceofPipe,
        BsInstanceOfDirective,
        BsInstanceofCaseDirective,
        BsInstanceOfDefaultDirective], imports: [CommonModule], exports: [BsInstanceofPipe,
        BsInstanceOfDirective,
        BsInstanceofCaseDirective,
        BsInstanceOfDefaultDirective] });
BsInstanceOfModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceOfModule, imports: [CommonModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.7", ngImport: i0, type: BsInstanceOfModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        BsInstanceofPipe,
                        BsInstanceOfDirective,
                        BsInstanceofCaseDirective,
                        BsInstanceOfDefaultDirective
                    ],
                    imports: [CommonModule],
                    exports: [
                        BsInstanceofPipe,
                        BsInstanceOfDirective,
                        BsInstanceofCaseDirective,
                        BsInstanceOfDefaultDirective
                    ]
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { BsInstanceOfContext, BsInstanceOfDefaultDirective, BsInstanceOfDirective, BsInstanceOfModule, BsInstanceofCaseDirective, BsInstanceofPipe, SwitchView };
//# sourceMappingURL=mintplayer-ng-bootstrap-instance-of.mjs.map
