import { effect, Injectable, Signal, signal } from '@angular/core';
import { bool } from '@iqser/common-ui/lib/utils';
import { REDAnnotationManager } from '../../pdf-viewer/services/annotation-manager.service';

@Injectable()
export class SkippedService {
    readonly #hideSkipped = signal(false);
    readonly hideSkipped: Signal<boolean>;

    constructor(private readonly _annotationManager: REDAnnotationManager) {
        this.hideSkipped = this.#hideSkipped.asReadonly();

        effect(() => {
            const ignored = this._annotationManager.get(a => bool(a.getCustomData('skipped')));
            if (this.#hideSkipped()) {
                this._annotationManager.hide(ignored);
            } else {
                this._annotationManager.show(ignored);
            }
        });
    }

    toggleSkipped(): void {
        this.#hideSkipped.set(!this.#hideSkipped());
    }
}
