import * as i0 from '@angular/core';
import { Directive, Input, Component, ChangeDetectionStrategy, ViewEncapsulation, NgModule } from '@angular/core';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import { SharedModule } from 'primeng/api';
import { DomHandler } from 'primeng/dom';
import { UniqueComponentId } from 'primeng/utils';
class BadgeDirective {
constructor(el) {
this.el = el;
this.iconPos = 'left';
}
ngAfterViewInit() {
this.id = UniqueComponentId() + '_badge';
let el = this.el.nativeElement.nodeName.indexOf("-") != -1 ? this.el.nativeElement.firstChild : this.el.nativeElement;
let badge = document.createElement('span');
badge.id = this.id;
badge.className = 'p-badge p-component';
if (this.severity) {
DomHandler.addClass(badge, 'p-badge-' + this.severity);
}
if (this.value != null) {
badge.appendChild(document.createTextNode(this.value));
if (String(this.value).length === 1) {
DomHandler.addClass(badge, 'p-badge-no-gutter');
}
}
else {
DomHandler.addClass(badge, 'p-badge-dot');
}
DomHandler.addClass(el, 'p-overlay-badge');
el.appendChild(badge);
this.initialized = true;
}
get value() {
return this._value;
}
set value(val) {
if (val !== this._value) {
this._value = val;
if (this.initialized) {
let badge = document.getElementById(this.id);
if (this._value) {
if (DomHandler.hasClass(badge, 'p-badge-dot'))
DomHandler.removeClass(badge, 'p-badge-dot');
if (String(this._value).length === 1) {
DomHandler.addClass(badge, 'p-badge-no-gutter');
}
else {
DomHandler.removeClass(badge, 'p-badge-no-gutter');
}
}
else if (!this._value && !DomHandler.hasClass(badge, 'p-badge-dot')) {
DomHandler.addClass(badge, 'p-badge-dot');
}
badge.innerHTML = '';
badge.appendChild(document.createTextNode(this._value));
}
}
}
ngOnDestroy() {
this.initialized = false;
}
}
BadgeDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: BadgeDirective, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
BadgeDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.0.0", type: BadgeDirective, selector: "[pBadge]", inputs: { iconPos: "iconPos", value: "value", severity: "severity" }, host: { classAttribute: "p-element" }, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: BadgeDirective, decorators: [{
type: Directive,
args: [{
selector: '[pBadge]',
host: {
'class': 'p-element'
}
}]
}], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { iconPos: [{
type: Input
}], value: [{
type: Input
}], severity: [{
type: Input
}] } });
class Badge {
containerClass() {
return {
'p-badge p-component': true,
'p-badge-no-gutter': this.value != undefined && String(this.value).length === 1,
'p-badge-lg': this.size === 'large',
'p-badge-xl': this.size === 'xlarge',
'p-badge-info': this.severity === 'info',
'p-badge-success': this.severity === 'success',
'p-badge-warning': this.severity === 'warning',
'p-badge-danger': this.severity === 'danger'
};
}
}
Badge.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Badge, deps: [], target: i0.ɵɵFactoryTarget.Component });
Badge.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: Badge, selector: "p-badge", inputs: { styleClass: "styleClass", style: "style", size: "size", severity: "severity", value: "value" }, host: { classAttribute: "p-element" }, ngImport: i0, template: `
{{value}}
`, isInline: true, styles: [".p-badge{display:inline-block;border-radius:10px;text-align:center;padding:0 .5rem}.p-overlay-badge{position:relative}.p-overlay-badge .p-badge{position:absolute;top:0;right:0;transform:translate(50%,-50%);transform-origin:100% 0;margin:0}.p-badge-dot{width:.5rem;min-width:.5rem;height:.5rem;border-radius:50%;padding:0}.p-badge-no-gutter{padding:0;border-radius:50%}\n"], directives: [{ type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Badge, decorators: [{
type: Component,
args: [{ selector: 'p-badge', template: `
{{value}}
`, changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
'class': 'p-element'
}, styles: [".p-badge{display:inline-block;border-radius:10px;text-align:center;padding:0 .5rem}.p-overlay-badge{position:relative}.p-overlay-badge .p-badge{position:absolute;top:0;right:0;transform:translate(50%,-50%);transform-origin:100% 0;margin:0}.p-badge-dot{width:.5rem;min-width:.5rem;height:.5rem;border-radius:50%;padding:0}.p-badge-no-gutter{padding:0;border-radius:50%}\n"] }]
}], propDecorators: { styleClass: [{
type: Input
}], style: [{
type: Input
}], size: [{
type: Input
}], severity: [{
type: Input
}], value: [{
type: Input
}] } });
class BadgeModule {
}
BadgeModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: BadgeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
BadgeModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: BadgeModule, declarations: [Badge, BadgeDirective], imports: [CommonModule], exports: [Badge, BadgeDirective, SharedModule] });
BadgeModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: BadgeModule, imports: [[CommonModule], SharedModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: BadgeModule, decorators: [{
type: NgModule,
args: [{
imports: [CommonModule],
exports: [Badge, BadgeDirective, SharedModule],
declarations: [Badge, BadgeDirective]
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { Badge, BadgeDirective, BadgeModule };