/* Copyright CloudLinux Zug GmbH 2010-2017 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * http://cloudlinux.com/docs/LICENSE.TXT
 */

import { Component, Input } from '@angular/core';
import { Message } from '../../../model/message';

@Component({
    selector: 'modal-window',
    template: require('./modal-window.html'),
    styles: [
        require('./modal-window.less')
    ],
})

export class ModalWindow {
    @Input() confirmationMessage: Message;
    @Input() disabledAgreeButton: boolean = false;

    public promise: Promise<any>;
    public show: boolean = false;

    protected resolve: Function;
    protected reject: Function;

    protected data: {};

    open (data = null) {
        this.show = true;
        if (data !== null) this.data = data;
        this.promise = new Promise((resolve, reject) => {
            this.resolve = resolve;
            this.reject = reject;
        });
        return this.promise;
    }

    agree () {
        this.show = false;
        this.resolve();
    }

    cancel () {
        this.show = false;
        this.reject();
    }
}
