import { __decorate, __metadata } from "tslib";
import { CommonModule } from '@angular/common';
import { Component, EventEmitter, inject, ViewEncapsulation } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { ActivatedRoute } from '@angular/router';
import { BooleanInputConverter } from '../../decorators/input-converter';
import { PermissionsService } from '../../services';
import { Codes } from '../../util/codes';
import { Util } from '../../util';
import { OTranslatePipe } from '../../pipes/o-translate.pipe';
import * as i0 from "@angular/core";
import * as i1 from "@angular/router";
import * as i2 from "@angular/common";
import * as i3 from "@angular/material/button";
import * as i4 from "@angular/material/icon";
export const DEFAULT_INPUTS_O_BUTTON = [
    'oattr: attr',
    'olabel: label',
    'otype: type',
    'icon',
    'svgIcon : svg-icon',
    'iconPosition: icon-position',
    'image',
    'enabled',
    'color'
];
export const DEFAULT_OUTPUTS_O_BUTTON = [
    'onClick',
    'click'
];
export class OButtonComponent {
    static { this.DEFAULT_TYPE = 'STROKED'; }
    constructor(actRoute) {
        this.actRoute = actRoute;
        this.iconPosition = Codes.ICON_POSITION_LEFT;
        this.enabled = true;
        this.visible = true;
        this.onClick = new EventEmitter();
        this.click = new EventEmitter();
        this.permissionsService = inject(PermissionsService);
        this.otype = OButtonComponent.DEFAULT_TYPE;
    }
    ngOnInit() {
        if (this.otype) {
            this.otype = this.otype.toUpperCase();
        }
        this.permissions = this.permissionsService.getOButtonPermissions(this.oattr, this.actRoute);
        if (Util.isDefined(this.permissions)) {
            this.enabled = this.permissions.enabled;
            this.visible = this.permissions.visible;
        }
    }
    onButtonClick(event) {
        event.stopPropagation();
        if (this.enabled) {
            this.click.emit(event);
            this.onClick.emit(event);
        }
    }
    get needsIconButtonClass() {
        return (this.icon !== undefined || this.svgIcon !== undefined) && (this.olabel === undefined || this.olabel === '');
    }
    isFab() {
        return this.otype === 'FAB';
    }
    isRaised() {
        return this.otype === 'RAISED';
    }
    isFlat() {
        return this.otype === 'FLAT';
    }
    isStroked() {
        return (this.otype === 'STROKED' || !this.otype);
    }
    isBasic() {
        return this.otype === 'BASIC';
    }
    isMiniFab() {
        return this.otype === 'FAB-MINI';
    }
    isIconButton() {
        return this.otype === 'ICON';
    }
    isVisible() {
        return this.visible;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: OButtonComponent, deps: [{ token: i1.ActivatedRoute }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: OButtonComponent, isStandalone: true, selector: "o-button", inputs: { oattr: ["attr", "oattr"], olabel: ["label", "olabel"], otype: ["type", "otype"], icon: "icon", svgIcon: ["svg-icon", "svgIcon"], iconPosition: ["icon-position", "iconPosition"], image: "image", enabled: "enabled", color: "color" }, outputs: { onClick: "onClick", click: "click" }, host: { properties: { "class.o-button": "true", "class.o-button-icon-position-top": "iconPosition===\"top\"", "class.o-button-icon-position-bottom": "iconPosition===\"bottom\"" } }, ngImport: i0, template: "@if (isBasic() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-button [class.mat-icon-button]=\"needsIconButtonClass\"\n    [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isRaised() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-raised-button class=\"mat-raised-button\"\n    [class.mat-icon-button]=\"needsIconButtonClass\" [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isStroked() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-stroked-button\n    [class.mat-icon-button]=\"needsIconButtonClass\" [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isFlat() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-flat-button [class.mat-icon-button]=\"needsIconButtonClass\"\n    [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isIconButton() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-icon-button\n    [class.mat-icon-button]=\"needsIconButtonClass\" [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isFab() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-fab [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isMiniFab() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-mini-fab [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n\n<ng-template #iconTemplate>\n  @if (image!==undefined) {\n    <img src=\"{{ image }}\" class=\"o-button-image\" alt=\"button image\" />\n  }\n  @if (icon!==undefined) {\n    <mat-icon class=\"o-button-icon\">{{ icon }}\n    </mat-icon>\n  }\n  @if (svgIcon!==undefined) {\n    <mat-icon class=\"o-button-icon\" [svgIcon]=\"svgIcon\"></mat-icon>\n  }\n</ng-template>\n\n<ng-template #buttonTemplate>\n\n  @if (iconPosition==='left' || iconPosition==='top' ) {\n    <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n  }\n\n  @if (iconPosition==='top') {\n    <br />\n  }\n\n  {{ olabel | oTranslate }}\n\n  @if (iconPosition==='bottom') {\n    <br />\n  }\n\n  @if (iconPosition==='right' || iconPosition==='bottom') {\n    <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n  }\n</ng-template>\n", styles: [".o-button{display:inline-block;pointer-events:none}.o-button.o-button-icon-position-bottom .mat-mdc-button,.o-button.o-button-icon-position-bottom .mat-mdc-unelevated-button,.o-button.o-button-icon-position-bottom .mat-mdc-raised-button,.o-button.o-button-icon-position-bottom .mat-mdc-outlined-button,.o-button.o-button-icon-position-top .mat-mdc-button,.o-button.o-button-icon-position-top .mat-mdc-unelevated-button,.o-button.o-button-icon-position-top .mat-mdc-raised-button,.o-button.o-button-icon-position-top .mat-mdc-outlined-button{height:auto;line-height:normal}.o-button button{pointer-events:auto}.o-button button.mat-mdc-button,.o-button button.mat-mdc-unelevated-button,.o-button button.mat-mdc-raised-button,.o-button button.mat-mdc-outlined-button{width:100%}.o-button button *{pointer-events:none}.o-button button .o-button-image{max-height:24px;vertical-align:middle}.o-button button .mdc-button__label{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;display:flex;align-items:center}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "ngmodule", type: MatButtonModule }, { kind: "component", type: i3.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", exportAs: ["matButton"] }, { kind: "component", type: i3.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "component", type: i3.MatMiniFabButton, selector: "button[mat-mini-fab]", exportAs: ["matButton"] }, { kind: "component", type: i3.MatFabButton, selector: "button[mat-fab]", inputs: ["extended"], exportAs: ["matButton"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i4.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "pipe", type: OTranslatePipe, name: "oTranslate" }], encapsulation: i0.ViewEncapsulation.None }); }
}
__decorate([
    BooleanInputConverter(),
    __metadata("design:type", Boolean)
], OButtonComponent.prototype, "enabled", void 0);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: OButtonComponent, decorators: [{
            type: Component,
            args: [{ standalone: true, imports: [CommonModule, MatButtonModule, MatIconModule, OTranslatePipe], selector: 'o-button', inputs: DEFAULT_INPUTS_O_BUTTON, outputs: DEFAULT_OUTPUTS_O_BUTTON, encapsulation: ViewEncapsulation.None, host: {
                        '[class.o-button]': 'true',
                        '[class.o-button-icon-position-top]': 'iconPosition==="top"',
                        '[class.o-button-icon-position-bottom]': 'iconPosition==="bottom"'
                    }, template: "@if (isBasic() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-button [class.mat-icon-button]=\"needsIconButtonClass\"\n    [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isRaised() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-raised-button class=\"mat-raised-button\"\n    [class.mat-icon-button]=\"needsIconButtonClass\" [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isStroked() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-stroked-button\n    [class.mat-icon-button]=\"needsIconButtonClass\" [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isFlat() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-flat-button [class.mat-icon-button]=\"needsIconButtonClass\"\n    [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isIconButton() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-icon-button\n    [class.mat-icon-button]=\"needsIconButtonClass\" [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isFab() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-fab [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n@if (isMiniFab() && isVisible()) {\n  <button type=\"button\" (click)=\"onButtonClick($event)\" mat-mini-fab [disabled]=\"!enabled\" [color]=\"color\">\n    <ng-container *ngTemplateOutlet=\"buttonTemplate\"></ng-container>\n  </button>\n}\n\n\n<ng-template #iconTemplate>\n  @if (image!==undefined) {\n    <img src=\"{{ image }}\" class=\"o-button-image\" alt=\"button image\" />\n  }\n  @if (icon!==undefined) {\n    <mat-icon class=\"o-button-icon\">{{ icon }}\n    </mat-icon>\n  }\n  @if (svgIcon!==undefined) {\n    <mat-icon class=\"o-button-icon\" [svgIcon]=\"svgIcon\"></mat-icon>\n  }\n</ng-template>\n\n<ng-template #buttonTemplate>\n\n  @if (iconPosition==='left' || iconPosition==='top' ) {\n    <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n  }\n\n  @if (iconPosition==='top') {\n    <br />\n  }\n\n  {{ olabel | oTranslate }}\n\n  @if (iconPosition==='bottom') {\n    <br />\n  }\n\n  @if (iconPosition==='right' || iconPosition==='bottom') {\n    <ng-container *ngTemplateOutlet=\"iconTemplate\"></ng-container>\n  }\n</ng-template>\n", styles: [".o-button{display:inline-block;pointer-events:none}.o-button.o-button-icon-position-bottom .mat-mdc-button,.o-button.o-button-icon-position-bottom .mat-mdc-unelevated-button,.o-button.o-button-icon-position-bottom .mat-mdc-raised-button,.o-button.o-button-icon-position-bottom .mat-mdc-outlined-button,.o-button.o-button-icon-position-top .mat-mdc-button,.o-button.o-button-icon-position-top .mat-mdc-unelevated-button,.o-button.o-button-icon-position-top .mat-mdc-raised-button,.o-button.o-button-icon-position-top .mat-mdc-outlined-button{height:auto;line-height:normal}.o-button button{pointer-events:auto}.o-button button.mat-mdc-button,.o-button button.mat-mdc-unelevated-button,.o-button button.mat-mdc-raised-button,.o-button button.mat-mdc-outlined-button{width:100%}.o-button button *{pointer-events:none}.o-button button .o-button-image{max-height:24px;vertical-align:middle}.o-button button .mdc-button__label{overflow:hidden;white-space:nowrap;text-overflow:ellipsis;display:flex;align-items:center}\n"] }]
        }], ctorParameters: () => [{ type: i1.ActivatedRoute }], propDecorators: { enabled: [] } });
//# sourceMappingURL=data:application/json;base64, 