import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatIconModule, MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer } from '@angular/platform-browser';
import { getConfig } from '@common-ui/services';

@NgModule({
    imports: [CommonModule, MatIconModule],
    declarations: [],
    exports: [MatIconModule],
})
export class IconsModule {
    readonly config = getConfig();

    constructor(private readonly _iconRegistry: MatIconRegistry, private readonly _sanitizer: DomSanitizer) {
        const icons = [
            'ai',
            'alert-circle',
            'align-horizontal-center',
            'align-horizontal-left',
            'align-horizontal-right',
            'align-vertical-bottom',
            'align-vertical-center',
            'align-vertical-top',
            'approved',
            'archive',
            'arrow-up',
            'arrow-down',
            'assign',
            'assign-me',
            'attribute',
            'case-sensitive',
            'color-picker',
            'comment',
            'comment-fill',
            'convert',
            'csv',
            'dictionary',
            'denied',
            'disable-analysis',
            'double-chevron-right',
            'enable-analysis',
            'enter',
            'entries',
            'exclude-pages',
            'excluded-page',
            'extract',
            'exit-fullscreen',
            'folder',
            'fullscreen',
            'html-file',
            'info',
            'import_redactions',
            'lightning',
            'needs-work',
            'new-tab',
            'notification',
            'open-in-new',
            'padding-left-right',
            'padding-top-bottom',
            'page',
            'preview',
            'push-pin',
            'put-back',
            'read-only',
            'ready-for-approval',
            'reanalyse',
            'reason',
            'redaction-changes',
            'reference',
            'remove-from-dict',
            'report',
            'resize',
            'rotation',
            'rss',
            'rule',
            'secret',
            'skeleton-stats',
            'status',
            'status-info',
            'template',
            'thumb-down',
            'thumb-up',
            'under-construction',
            'undo',
            'user',
            'visibility',
            'visibility-off',
            'warning',
        ];

        for (const icon of icons) {
            _iconRegistry.addSvgIconInNamespace(
                'red',
                icon,
                _sanitizer.bypassSecurityTrustResourceUrl(`/assets/icons/general/${icon}.svg`),
            );
        }

        const logo = this.config.IS_DOCUMINE ? 'documine-logo' : 'logo';

        _iconRegistry.addSvgIconInNamespace(
            'iqser',
            'logo',
            _sanitizer.bypassSecurityTrustResourceUrl(`/assets/icons/general/${logo}.svg`),
        );
    }
}
