var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
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 { PageElement } from "../page-element";
import { Input, Output, Component } from "@angular/core";
import { KeyUtility } from "../../../utility/key-utility";
import { ButtonDetail } from "./button-detail";
import { StringUtility } from "../../../utility/string-utility";
import { ColorUtility } from "../../../utility/color-utility";
var ButtonComponent = /** @class */ (function () {
    function ButtonComponent() {
    }
    __decorate([
        Input("button"),
        Output("button"),
        __metadata("design:type", Button)
    ], ButtonComponent.prototype, "button", void 0);
    ButtonComponent = __decorate([
        Component({
            selector: "path-button",
            templateUrl: "button.component.html"
        })
    ], ButtonComponent);
    return ButtonComponent;
}());
export { ButtonComponent };
var Button = /** @class */ (function (_super) {
    __extends(Button, _super);
    function Button(app, pathService, translationService) {
        var _this = _super.call(this, app) || this;
        _this.pathService = pathService;
        _this.translationService = translationService;
        _this._details = [];
        return _this;
    }
    Button.prototype.onClick = function () {
        var _this = this;
        if (this._handler != null) {
            this._handler.doClick(this);
            return;
        }
        if (!StringUtility.isEmpty(this._url)) {
            this.pathService.serverGet(this.app.getBackendUrl(), this._url, function () {
                _this.app.refreshCurrentPage();
            }, null);
        }
        if (!StringUtility.isEmpty(this._page)) {
            this.app.setCurrentPage(this._page, this);
            return;
        }
        if (!StringUtility.isEmpty(this._form)) {
            this.app.setCurrentForm(this._form, this.key, this._formHandler, this);
            return;
        }
    };
    Button.prototype.setIcon = function (icon) {
        this.icon = icon;
    };
    Button.prototype.setForm = function (form) {
        this.form = form;
    };
    Button.prototype.setFormHandler = function (formHandler) {
        this.formHandler = formHandler;
    };
    Button.prototype.setPage = function (page) {
        this.page = page;
    };
    Button.prototype.setKey = function (key) {
        this.key = key;
    };
    Button.prototype.getApp = function () {
        return this.app;
    };
    Button.prototype.getName = function () {
        return this.name;
    };
    Object.defineProperty(Button.prototype, "icon", {
        get: function () {
            return this._icon;
        },
        set: function (value) {
            this._icon = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "cssStyle", {
        get: function () {
            return this._cssStyle;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "cssClass", {
        get: function () {
            return this._cssClass;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "cssButtonTarget", {
        get: function () {
            return this._cssButtonTarget;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "cssGroupBorder", {
        get: function () {
            return this._cssGroupBorder;
        },
        set: function (value) {
            this._cssGroupBorder = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "handler", {
        get: function () {
            return this._handler;
        },
        set: function (value) {
            this._handler = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "details", {
        get: function () {
            return this._details;
        },
        set: function (value) {
            this._details = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "page", {
        get: function () {
            return this._page;
        },
        set: function (value) {
            this._page = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "form", {
        get: function () {
            return this._form;
        },
        set: function (value) {
            this._form = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "formHandler", {
        get: function () {
            return this._formHandler;
        },
        set: function (value) {
            this._formHandler = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "url", {
        get: function () {
            return this._url;
        },
        set: function (value) {
            this._url = value;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Button.prototype, "tooltip", {
        get: function () {
            return this._tooltip;
        },
        set: function (value) {
            this._tooltip = value;
        },
        enumerable: false,
        configurable: true
    });
    Button.prototype.fromJson = function (modelElement) {
        _super.prototype.fromJson.call(this, modelElement);
        // general attributes
        this.type = "button";
        this.setIcon(modelElement["icon"]);
        if (modelElement["color"] != null) {
            var color = modelElement["color"];
            if (typeof color === "object") {
                this._cssStyle = color;
            }
            else if (typeof color === "string") {
                if (ColorUtility.isPathDefaultColor(color)) {
                    this._cssClass = "tile-" + color;
                }
                else {
                    this._cssClass = color;
                }
            }
        }
        if (modelElement["form"] != null) {
            this.setForm(modelElement["form"]["form"]);
            this.setFormHandler(modelElement["form"]["handler"]);
        }
        this.setPage(modelElement["page"]);
        if (this.key == null && this.parentPageElement != null && modelElement.type === "button") {
            this.key = this.parentPageElement.key;
        }
        this.name = this.translationService.getText(modelElement["name"]);
        this.url = KeyUtility.translateUrl(modelElement["url"], null, false, this);
        if (modelElement["tooltip"] != null) {
            this.tooltip = this.translationService.getText(modelElement["tooltip"]);
        }
        // button details
        if (modelElement["details"] != null) {
            this.details = [];
            for (var _i = 0, _a = modelElement["details"]; _i < _a.length; _i++) {
                var detail = _a[_i];
                var bd = new ButtonDetail();
                bd.text = detail;
                this.details.push(bd);
            }
        }
        // button target
        this._cssButtonTarget = true;
        if (this.type === "button") {
            if (StringUtility.isEmpty(this.form) && StringUtility.isEmpty(this.page) && StringUtility.isEmpty(this.url)) {
                this._cssButtonTarget = false;
            }
        }
    };
    return Button;
}(PageElement));
export { Button };
//# sourceMappingURL=button.component.js.map