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',
            'arrow-right',
            'assign',
            'assign-me',
            'attribute',
            'case-sensitive',
            'comment',
            'comment-fill',
            'convert',
            'csv',
            'dictionary',
            'denied',
            'disable-analysis',
            'double-chevron-right',
            'draggable-dots',
            'enable-analysis',
            'enter',
            'entries',
            'exclude-pages',
            'excluded-page',
            'extract',
            'folder',
            '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',
            'rotation',
            'rss',
            'rule',
            'secret',
            'skeleton-stats',
            'status',
            'status-info',
            'template',
            'under-construction',
            'undo',
            'user',
            'warning',
            'pdftron-action-add-redaction',
        ];

        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`),
        );
    }
}
