import { Directionality } from '@angular/cdk/bidi';
import * as i0 from '@angular/core';
import { inject, Renderer2, ElementRef, EventEmitter, booleanAttribute, Output, Input, ViewEncapsulation, Component, NgModule } from '@angular/core';
import { presetColors, statusColors, isPresetColor, isStatusColor } from 'ng-zorro-antd/core/color';
import * as i1 from 'ng-zorro-antd/icon';
import { NzIconModule } from 'ng-zorro-antd/icon';

/**
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */
class NzTagComponent {
    renderer = inject(Renderer2);
    el = inject((ElementRef)).nativeElement;
    dir = inject(Directionality).valueSignal;
    nzMode = 'default';
    nzColor;
    nzChecked = false;
    nzBordered = true;
    nzOnClose = new EventEmitter();
    nzCheckedChange = new EventEmitter();
    isPresetColor = false;
    updateCheckedStatus() {
        if (this.nzMode === 'checkable') {
            this.nzChecked = !this.nzChecked;
            this.nzCheckedChange.emit(this.nzChecked);
        }
    }
    closeTag(e) {
        this.nzOnClose.emit(e);
        if (!e.defaultPrevented) {
            this.renderer.removeChild(this.renderer.parentNode(this.el), this.el);
        }
    }
    clearPresetColor() {
        // /(ant-tag-(?:pink|red|...))/g
        const regexp = new RegExp(`(ant-tag-(?:${[...presetColors, ...statusColors].join('|')}))`, 'g');
        const classname = this.el.classList.toString();
        const matches = [];
        let match = regexp.exec(classname);
        while (match !== null) {
            matches.push(match[1]);
            match = regexp.exec(classname);
        }
        this.el.classList.remove(...matches);
    }
    setPresetColor() {
        this.clearPresetColor();
        if (!this.nzColor) {
            this.isPresetColor = false;
        }
        else {
            this.isPresetColor = isPresetColor(this.nzColor) || isStatusColor(this.nzColor);
        }
        if (this.isPresetColor) {
            this.el.classList.add(`ant-tag-${this.nzColor}`);
        }
    }
    ngOnChanges(changes) {
        const { nzColor } = changes;
        if (nzColor) {
            this.setPresetColor();
        }
    }
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NzTagComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
    static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: NzTagComponent, isStandalone: true, selector: "nz-tag", inputs: { nzMode: "nzMode", nzColor: "nzColor", nzChecked: ["nzChecked", "nzChecked", booleanAttribute], nzBordered: ["nzBordered", "nzBordered", booleanAttribute] }, outputs: { nzOnClose: "nzOnClose", nzCheckedChange: "nzCheckedChange" }, host: { listeners: { "click": "updateCheckedStatus()" }, properties: { "style.background-color": "isPresetColor ? '' : nzColor", "class.ant-tag-has-color": "nzColor && !isPresetColor", "class.ant-tag-checkable": "nzMode === 'checkable'", "class.ant-tag-checkable-checked": "nzChecked", "class.ant-tag-rtl": "dir() === 'rtl'", "class.ant-tag-borderless": "!nzBordered" }, classAttribute: "ant-tag" }, exportAs: ["nzTag"], usesOnChanges: true, ngImport: i0, template: `
    <ng-content />
    @if (nzMode === 'closeable') {
      <nz-icon nzType="close" class="ant-tag-close-icon" tabindex="-1" (click)="closeTag($event)" />
    }
  `, isInline: true, dependencies: [{ kind: "ngmodule", type: NzIconModule }, { kind: "directive", type: i1.NzIconDirective, selector: "nz-icon,[nz-icon]", inputs: ["nzType", "nzTheme", "nzTwotoneColor", "nzSpin", "nzRotate", "nzIconfont"], exportAs: ["nzIcon"] }], encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NzTagComponent, decorators: [{
            type: Component,
            args: [{
                    selector: 'nz-tag',
                    exportAs: 'nzTag',
                    template: `
    <ng-content />
    @if (nzMode === 'closeable') {
      <nz-icon nzType="close" class="ant-tag-close-icon" tabindex="-1" (click)="closeTag($event)" />
    }
  `,
                    encapsulation: ViewEncapsulation.None,
                    host: {
                        class: 'ant-tag',
                        '[style.background-color]': `isPresetColor ? '' : nzColor`,
                        '[class.ant-tag-has-color]': `nzColor && !isPresetColor`,
                        '[class.ant-tag-checkable]': `nzMode === 'checkable'`,
                        '[class.ant-tag-checkable-checked]': `nzChecked`,
                        '[class.ant-tag-rtl]': `dir() === 'rtl'`,
                        '[class.ant-tag-borderless]': `!nzBordered`,
                        '(click)': 'updateCheckedStatus()'
                    },
                    imports: [NzIconModule]
                }]
        }], propDecorators: { nzMode: [{
                type: Input
            }], nzColor: [{
                type: Input
            }], nzChecked: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], nzBordered: [{
                type: Input,
                args: [{ transform: booleanAttribute }]
            }], nzOnClose: [{
                type: Output
            }], nzCheckedChange: [{
                type: Output
            }] } });

/**
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */
class NzTagModule {
    static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NzTagModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
    static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.6", ngImport: i0, type: NzTagModule, imports: [NzTagComponent], exports: [NzTagComponent] });
    static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NzTagModule, imports: [NzTagComponent] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: NzTagModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [NzTagComponent],
                    exports: [NzTagComponent]
                }]
        }] });

/**
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */

/**
 * Use of this source code is governed by an MIT-style license that can be
 * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
 */

/**
 * Generated bundle index. Do not edit.
 */

export { NzTagComponent, NzTagModule };
//# sourceMappingURL=ng-zorro-antd-tag.mjs.map
