var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
import { Component, ElementRef, HostBinding, Inject, TemplateRef, Renderer2, ViewChild, ComponentFactoryResolver, Input, } from '@angular/core';
import { ElFocusTrapFactoryService } from '../cdk/a11y/focus-trap';
import { ElComponentPortal, ElTemplatePortal } from '../cdk/overlay/mapping';
import { ElOverlayContainerComponent } from '../cdk/overlay/overlay-container';
import { EL_WINDOW_CONTENT, ElWindowConfig, ElWindowState, EL_WINDOW_CONTEXT } from './window.options';
import { ElWindowRef } from './window-ref';
var ElWindowComponent = /** @class */ (function () {
    function ElWindowComponent(content, context, windowRef, config, focusTrapFactory, elementRef, renderer) {
        this.content = content;
        this.context = context;
        this.windowRef = windowRef;
        this.config = config;
        this.focusTrapFactory = focusTrapFactory;
        this.elementRef = elementRef;
        this.renderer = renderer;
    }
    Object.defineProperty(ElWindowComponent.prototype, "isFullScreen", {
        get: function () {
            return this.windowRef.state === ElWindowState.FULL_SCREEN;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ElWindowComponent.prototype, "maximized", {
        get: function () {
            return this.windowRef.state === ElWindowState.MAXIMIZED;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(ElWindowComponent.prototype, "minimized", {
        get: function () {
            return this.windowRef.state === ElWindowState.MINIMIZED;
        },
        enumerable: true,
        configurable: true
    });
    ElWindowComponent.prototype.ngOnInit = function () {
        this.focusTrap = this.focusTrapFactory.create(this.elementRef.nativeElement);
        this.focusTrap.blurPreviouslyFocusedElement();
        this.focusTrap.focusInitialElement();
        if (this.config.windowClass) {
            this.renderer.addClass(this.elementRef.nativeElement, this.config.windowClass);
        }
    };
    ElWindowComponent.prototype.ngAfterViewChecked = function () {
        if (!this.overlayContainer || this.overlayContainer.isAttached) {
            return;
        }
        if (this.content instanceof TemplateRef) {
            this.attachTemplate();
        }
        else {
            this.attachComponent();
        }
    };
    ElWindowComponent.prototype.ngOnDestroy = function () {
        if (this.focusTrap) {
            this.focusTrap.restoreFocus();
        }
        this.close();
    };
    ElWindowComponent.prototype.minimize = function () {
        if (this.windowRef.state === ElWindowState.MINIMIZED) {
            this.windowRef.toPreviousState();
        }
        else {
            this.windowRef.minimize();
        }
    };
    ElWindowComponent.prototype.maximize = function () {
        this.windowRef.maximize();
    };
    ElWindowComponent.prototype.fullScreen = function () {
        this.windowRef.fullScreen();
    };
    ElWindowComponent.prototype.maximizeOrFullScreen = function () {
        if (this.windowRef.state === ElWindowState.MINIMIZED) {
            this.maximize();
        }
        else {
            this.fullScreen();
        }
    };
    ElWindowComponent.prototype.close = function () {
        this.windowRef.close();
    };
    ElWindowComponent.prototype.attachTemplate = function () {
        this.overlayContainer
            .attachTemplatePortal(new ElTemplatePortal(this.content, null, this.context));
    };
    ElWindowComponent.prototype.attachComponent = function () {
        var portal = new ElComponentPortal(this.content, null, null, this.cfr);
        var ref = this.overlayContainer.attachComponentPortal(portal, this.context);
        ref.changeDetectorRef.detectChanges();
    };
    __decorate([
        Input(),
        __metadata("design:type", ComponentFactoryResolver)
    ], ElWindowComponent.prototype, "cfr", void 0);
    __decorate([
        HostBinding('class.full-screen'),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [])
    ], ElWindowComponent.prototype, "isFullScreen", null);
    __decorate([
        HostBinding('class.maximized'),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [])
    ], ElWindowComponent.prototype, "maximized", null);
    __decorate([
        HostBinding('class.minimized'),
        __metadata("design:type", Object),
        __metadata("design:paramtypes", [])
    ], ElWindowComponent.prototype, "minimized", null);
    __decorate([
        ViewChild(ElOverlayContainerComponent, { static: false }),
        __metadata("design:type", ElOverlayContainerComponent)
    ], ElWindowComponent.prototype, "overlayContainer", void 0);
    ElWindowComponent = __decorate([
        Component({
            selector: 'el-window',
            template: "\n    <el-card>\n      <el-card-header>\n        <div cdkFocusInitial class=\"title\" tabindex=\"-1\">{{ config.title }}</div>\n\n        <div class=\"buttons\">\n          <button elButton ghost (click)=\"minimize()\">\n            <el-icon icon=\"minus-outline\" pack=\"endlessjs-essentials\"></el-icon>\n          </button>\n          <button elButton ghost *ngIf=\"isFullScreen\" (click)=\"maximize()\">\n            <el-icon icon=\"collapse-outline\" pack=\"endlessjs-essentials\"></el-icon>\n          </button>\n          <button elButton ghost *ngIf=\"minimized || maximized\" (click)=\"maximizeOrFullScreen()\">\n            <el-icon icon=\"expand-outline\" pack=\"endlessjs-essentials\"></el-icon>\n          </button>\n          <button elButton ghost (click)=\"close()\">\n            <el-icon icon=\"close-outline\" pack=\"endlessjs-essentials\"></el-icon>\n          </button>\n        </div>\n      </el-card-header>\n      <el-card-body *ngIf=\"maximized || isFullScreen\">\n        <el-overlay-container></el-overlay-container>\n      </el-card-body>\n    </el-card>\n  ",
            styles: [":host{flex:1 0 auto;min-width:20rem}:host el-card{margin:0}:host el-card-header{display:flex;justify-content:space-between;align-items:center;overflow:hidden}:host .title{flex:1 0 auto;margin-right:3rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}:host .buttons{width:9.5rem;display:flex;justify-content:space-evenly}:host .buttons [elButton]{flex:0 0 3rem}:host(.full-screen){position:fixed;top:50%;left:50%;transform:translate(-50%, -50%)}:host(.maximized) el-card{border-bottom-left-radius:0;border-bottom-right-radius:0}:host(.minimized) el-card{border-bottom-left-radius:0;border-bottom-right-radius:0;height:auto}:host(.minimized) el-card el-card-header{border-bottom:none}\n"]
        }),
        __param(0, Inject(EL_WINDOW_CONTENT)),
        __param(1, Inject(EL_WINDOW_CONTEXT)),
        __metadata("design:paramtypes", [Object, Object,
            ElWindowRef,
            ElWindowConfig,
            ElFocusTrapFactoryService,
            ElementRef,
            Renderer2])
    ], ElWindowComponent);
    return ElWindowComponent;
}());
export { ElWindowComponent };
//# sourceMappingURL=window.component.js.map