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);
};
import { Component } from '@angular/core';
import { MDBModalRef } from 'angular-bootstrap-md';
import { Subject } from 'rxjs';
import { UsersService } from '../services/users.service';
var ApikeyModalComponent = /** @class */ (function () {
    function ApikeyModalComponent(modalRef, _usersService) {
        this.modalRef = modalRef;
        this._usersService = _usersService;
        this.action = new Subject();
        this.sendData = {};
    }
    ApikeyModalComponent.prototype.ngOnInit = function () {
        var _this = this;
        this._usersService.getUsers().subscribe(function (res) {
            _this.users = res.results;
            console.log("apiKey", _this.apiKey);
            if (_this.apiKey) {
                _this.sendData = JSON.parse(JSON.stringify(_this.apiKey));
            }
            if (_this.apiKey.user) {
                _this.selectedUser = _this.apiKey.user._id;
            }
        });
    };
    ApikeyModalComponent.prototype.ngOnDestroy = function () {
    };
    ApikeyModalComponent.prototype.confirm = function () {
        var _this = this;
        this.sendData.user = this.selectedUser;
        console.log("sendData", this.sendData);
        this._usersService.addApikey(this.sendData.user).subscribe(function (res) {
            console.log("done", res);
            _this.action.next("DONE!!!");
            _this.modalRef.hide();
        });
    };
    ApikeyModalComponent.prototype.delete = function () {
        var _this = this;
        this._usersService.delApikey(this.sendData._id).subscribe(function (res) {
            console.log("done", res);
            _this.action.next("DONE!!!");
            _this.modalRef.hide();
        });
    };
    ApikeyModalComponent = __decorate([
        Component({
            selector: 'qmi-new-apikey',
            templateUrl: './edit-apikey.component.html',
            styleUrls: ['./edit-apikey.component.scss']
        }),
        __metadata("design:paramtypes", [MDBModalRef, UsersService])
    ], ApikeyModalComponent);
    return ApikeyModalComponent;
}());
export { ApikeyModalComponent };
//# sourceMappingURL=edit-apikey.component.js.map