import { ChangeDetectionStrategy, Component, ElementRef, HostBinding, Input, Renderer2, } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { RIconLibrary } from './icon-library';
export class RIconComponent {
    constructor(sanitizer, iconLibrary, el, renderer) {
        this.sanitizer = sanitizer;
        this.iconLibrary = iconLibrary;
        this.el = el;
        this.renderer = renderer;
        this.prevClasses = [];
        this.html = '';
    }
    get primary() {
        return this.status === 'primary';
    }
    get info() {
        return this.status === 'info';
    }
    get success() {
        return this.status === 'success';
    }
    get warning() {
        return this.status === 'warning';
    }
    get danger() {
        return this.status === 'danger';
    }
    get basic() {
        return this.status === 'basic';
    }
    get control() {
        return this.status === 'control';
    }
    /**
     * Sets all icon configurable properties via config object.
     * If passed value is a string set icon name.
     * @docs-private
     */
    get config() {
        return this._config;
    }
    set config(value) {
        if (!value) {
            return;
        }
        this._config = value;
        if (typeof value === 'string') {
            this.icon = value;
        }
        else {
            this.icon = value.icon;
            this.pack = value.pack;
            this.status = value.status;
            this.options = value.options;
        }
    }
    ngOnInit() {
        this.iconDef = this.renderIcon(this.icon, this.pack, this.options);
    }
    ngOnChanges() {
        const iconDef = this.iconLibrary.getIcon(this.icon, this.pack);
        if (iconDef) {
            this.renderIcon(this.icon, this.pack, this.options);
        }
        else {
            this.clearIcon();
        }
    }
    renderIcon(name, pack, options) {
        const iconDefinition = this.iconLibrary.getIcon(name, pack);
        if (!iconDefinition) {
            return;
        }
        const content = iconDefinition.icon.getContent(options);
        if (content) {
            this.html = this.sanitizer.bypassSecurityTrustHtml(content);
        }
        this.assignClasses(iconDefinition.icon.getClasses(options));
        return iconDefinition;
    }
    clearIcon() {
        this.html = '';
        this.assignClasses([]);
    }
    assignClasses(classes) {
        this.prevClasses.forEach((className) => {
            this.renderer.removeClass(this.el.nativeElement, className);
        });
        classes.forEach((className) => {
            this.renderer.addClass(this.el.nativeElement, className);
        });
        this.prevClasses = classes;
    }
}
RIconComponent.decorators = [
    { type: Component, args: [{
                selector: 'r-icon',
                template: '',
                changeDetection: ChangeDetectionStrategy.OnPush,
                styles: [":host{display:inline-block}"]
            },] }
];
RIconComponent.ctorParameters = () => [
    { type: DomSanitizer },
    { type: RIconLibrary },
    { type: ElementRef },
    { type: Renderer2 }
];
RIconComponent.propDecorators = {
    html: [{ type: HostBinding, args: ['innerHtml',] }],
    primary: [{ type: HostBinding, args: ['class.status-primary',] }],
    info: [{ type: HostBinding, args: ['class.status-info',] }],
    success: [{ type: HostBinding, args: ['class.status-success',] }],
    warning: [{ type: HostBinding, args: ['class.status-warning',] }],
    danger: [{ type: HostBinding, args: ['class.status-danger',] }],
    basic: [{ type: HostBinding, args: ['class.status-basic',] }],
    control: [{ type: HostBinding, args: ['class.status-control',] }],
    icon: [{ type: Input }],
    pack: [{ type: Input }],
    options: [{ type: Input }],
    status: [{ type: Input }],
    config: [{ type: Input }]
};
//# sourceMappingURL=icon.component.js.map