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';
let ElWindowComponent = class ElWindowComponent {
    constructor(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;
    }
    get isFullScreen() {
        return this.windowRef.state === ElWindowState.FULL_SCREEN;
    }
    get maximized() {
        return this.windowRef.state === ElWindowState.MAXIMIZED;
    }
    get minimized() {
        return this.windowRef.state === ElWindowState.MINIMIZED;
    }
    ngOnInit() {
        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);
        }
    }
    ngAfterViewChecked() {
        if (!this.overlayContainer || this.overlayContainer.isAttached) {
            return;
        }
        if (this.content instanceof TemplateRef) {
            this.attachTemplate();
        }
        else {
            this.attachComponent();
        }
    }
    ngOnDestroy() {
        if (this.focusTrap) {
            this.focusTrap.restoreFocus();
        }
        this.close();
    }
    minimize() {
        if (this.windowRef.state === ElWindowState.MINIMIZED) {
            this.windowRef.toPreviousState();
        }
        else {
            this.windowRef.minimize();
        }
    }
    maximize() {
        this.windowRef.maximize();
    }
    fullScreen() {
        this.windowRef.fullScreen();
    }
    maximizeOrFullScreen() {
        if (this.windowRef.state === ElWindowState.MINIMIZED) {
            this.maximize();
        }
        else {
            this.fullScreen();
        }
    }
    close() {
        this.windowRef.close();
    }
    attachTemplate() {
        this.overlayContainer
            .attachTemplatePortal(new ElTemplatePortal(this.content, null, this.context));
    }
    attachComponent() {
        const portal = new ElComponentPortal(this.content, null, null, this.cfr);
        const 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: `
    <el-card>
      <el-card-header>
        <div cdkFocusInitial class="title" tabindex="-1">{{ config.title }}</div>

        <div class="buttons">
          <button elButton ghost (click)="minimize()">
            <el-icon icon="minus-outline" pack="endlessjs-essentials"></el-icon>
          </button>
          <button elButton ghost *ngIf="isFullScreen" (click)="maximize()">
            <el-icon icon="collapse-outline" pack="endlessjs-essentials"></el-icon>
          </button>
          <button elButton ghost *ngIf="minimized || maximized" (click)="maximizeOrFullScreen()">
            <el-icon icon="expand-outline" pack="endlessjs-essentials"></el-icon>
          </button>
          <button elButton ghost (click)="close()">
            <el-icon icon="close-outline" pack="endlessjs-essentials"></el-icon>
          </button>
        </div>
      </el-card-header>
      <el-card-body *ngIf="maximized || isFullScreen">
        <el-overlay-container></el-overlay-container>
      </el-card-body>
    </el-card>
  `,
        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);
export { ElWindowComponent };
//# sourceMappingURL=window.component.js.map